Skip to content

Commit

Permalink
Merge pull request #295 from mugijiru/add-rubocop-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mugijiru authored May 29, 2023
2 parents 51b4e69 + 96d173e commit 4983e8a
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
with:
rubocop_version: gemfile
rubocop_flags: -a
rubocop_extensions: rubocop-rails:gemfile rubocop-performance:gemfile
rubocop_extensions: rubocop-capybara:gemfile rubocop-factory_bot:gemfile rubocop-rails:gemfile rubocop-rspec:gemfile rubocop-performance:gemfile
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
fail_on_error: true
Expand Down
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-capybara
- rubocop-factory_bot
- rubocop-performance
- rubocop-rails
- rubocop-rspec

AllCops:
TargetRubyVersion: 3.0
Expand All @@ -14,3 +17,10 @@ AllCops:
- "db/schema.rb"
- "ember/**/*"
- "doc"
NewCops: enable
RSpec/ExampleLength:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false
Style/Documentation:
Enabled: false
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ group :development, :test do
gem 'committee-rails'
gem 'factory_bot_rails'
gem 'rspec-rails'
gem 'rubocop-capybara', require: false
gem 'rubocop-factory_bot', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false
end

group :development do
Expand Down
17 changes: 14 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,21 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.1)
parser (>= 3.2.1.0)
rubocop-capybara (2.18.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.23.1)
rubocop (~> 1.33)
rubocop-performance (1.18.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.19.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.22.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
sassc (2.4.0)
Expand All @@ -298,12 +306,12 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
spring (4.1.1)
spring (2.1.1)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
spring-watcher-listen (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 4)
spring (>= 1.2, < 3.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -368,8 +376,11 @@ DEPENDENCIES
puma (~> 4.3)
rails (~> 6.1.0)
rspec-rails
rubocop-capybara
rubocop-factory_bot
rubocop-performance
rubocop-rails
rubocop-rspec
sassc-rails (>= 2.1.0)
selenium-webdriver
simplecov (~> 0.17.1)
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
config.active_support.disallowed_deprecation_warnings = []

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
config.log_formatter = Logger::Formatter.new

# Use a different logger for distributed setups.
# require "syslog/logger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def up

add_column :active_storage_blobs, :service_name, :string

if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
if configured_service = ActiveStorage::Blob.service.name # rubocop:disable Lint/AssignmentInCondition
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) # rubocop:disable Rails/SkipsModelValidations
end

change_column :active_storage_blobs, :service_name, :string, null: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def change
return unless table_exists?(:active_storage_blobs)

# Use Active Record's configured type for primary key
create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t|
create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t| # rubocop:disable Rails/CreateTableWithTimestamps
t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
t.string :variation_digest, null: false

Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/todo_items_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
# end
# end
# end
RSpec.describe TodoItemsHelper, type: :helper do
RSpec.describe TodoItemsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
2 changes: 1 addition & 1 deletion spec/models/todo_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rails_helper'

RSpec.describe TodoItem, type: :model do
RSpec.describe TodoItem do
pending "add some examples to (or delete) #{__FILE__}"
end
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rails_helper'

RSpec.describe User, type: :model do
RSpec.describe User do
pending "add some examples to (or delete) #{__FILE__}"
end
4 changes: 2 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
Expand All @@ -32,7 +32,7 @@
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.fixture_path = "#{Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
Expand Down
30 changes: 14 additions & 16 deletions spec/requests/api/v1/todo_items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.

RSpec.describe '/todo_items', type: :request do
before do
@user = create(:user)
sign_in @user
end

RSpec.describe '/todo_items' do
let(:user) { create(:user) }
let(:request_headers) { { 'CONTENT_TYPE' => 'application/vnd.api+json' } }

before { sign_in user }

describe 'GET /index' do
it 'renders a successful response' do
create(:todo_item, name: 'valid name', user: @user)
create(:todo_item, name: 'valid name', user: user)
get '/api/v1/todo_items'
json = JSON.parse(response.body)
json = JSON.parse(response.parsed_body)
expect(json['data'][0]['attributes']['name']).to eq 'valid name'
assert_response_schema_confirm(200)
end
Expand All @@ -47,23 +45,23 @@
post '/api/v1/todo_items',
headers: request_headers,
params: generate_params(name: nil)
}.to change(TodoItem, :count).by(0)
}.not_to change(TodoItem, :count)
end

it 'response status is 422(unprocessable entity)' do
post '/api/v1/todo_items',
headers: request_headers,
params: generate_params(name: nil)

expect(response.status).to eq(422)
expect(response).to have_http_status(:unprocessable_entity)
end
end
end

describe 'PATCH /update' do
context 'with valid parameters' do
it 'updates the requested todo_item' do
todo_item = create(:todo_item, name: 'existing item', user: @user)
todo_item = create(:todo_item, name: 'existing item', user: user)
patch "/api/v1/todo_items/#{todo_item.id}",
headers: request_headers,
params: generate_params(name: 'edited name')
Expand All @@ -77,27 +75,27 @@

context 'with invalid parameters' do
it 'response status is 422(unprocessable entity)' do
todo_item = create(:todo_item, name: 'TODO item', user: @user)
todo_item = create(:todo_item, name: 'TODO item', user: user)
patch "/api/v1/todo_items/#{todo_item.id}",
headers: request_headers,
params: generate_params(name: nil)
expect(response.status).to eq(422)
expect(response).to have_http_status(:unprocessable_entity)
end
end
end

describe 'DELETE /destroy' do
it 'destroys the requested todo_item' do
todo_item = create(:todo_item, name: 'TODO item', user: @user)
todo_item = create(:todo_item, name: 'TODO item', user: user)
expect {
delete "/api/v1/todo_items/#{todo_item.id}"
}.to change(TodoItem, :count).by(-1)
end

it 'response status is 204(no content)' do
todo_item = create(:todo_item, name: 'TODO item', user: @user)
todo_item = create(:todo_item, name: 'TODO item', user: user)
delete "/api/v1/todo_items/#{todo_item.id}"
expect(response.status).to eq(204)
expect(response).to have_http_status(:no_content)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/routing/todo_items_routing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe TodoItemsController, type: :routing do
RSpec.describe TodoItemsController do
describe 'routing' do
it 'routes to #index' do
expect(get: '/todo_items').to route_to('todo_items#index')
Expand Down
4 changes: 2 additions & 2 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if ENV['CI'] == 'true'
Capybara.register_driver :selenium_chrome_headless do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options = Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--headless'
browser_options.args << '--disable-gpu'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
Expand All @@ -18,7 +18,7 @@
url = ENV.fetch('SELENIUM_REMOTE_URL')
args = ['no-sandbox', 'disable-gpu']
args.push('headless') unless ENV.fetch('USE_XVFB') == 'true'
caps = ::Selenium::WebDriver::Remote::Capabilities.chrome(
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
'goog:chromeOptions' => {
'args' => args
}
Expand Down
2 changes: 1 addition & 1 deletion spec/support/database_rewinder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DatabaseRewinder.clean_all
end

config.before(:each) do
config.before do
DatabaseRewinder.clean
end
end
2 changes: 1 addition & 1 deletion spec/support/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
config.include Warden::Test::Helpers, type: :system
config.include Warden::Test::Helpers, type: :routing

config.after(:each) do
config.after do
Warden.test_reset!
end
end
2 changes: 1 addition & 1 deletion spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods

config.before(:each) do
config.before do
FactoryBot.rewind_sequences
end
end
19 changes: 10 additions & 9 deletions spec/system/todo_items_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'rails_helper'

RSpec.describe 'Todo Items', type: :system do
RSpec.describe 'Todo Items' do
let(:user) { create(:user, email: '[email protected]') }

before do
@user = create(:user, email: '[email protected]')
login_as(@user)
login_as(user)
end

it 'display user email' do
Expand All @@ -13,16 +14,16 @@
end

it 'display registered todo items' do
create_list(:todo_item, 10, user: @user)
create_list(:todo_item, 10, user: user)

visit '/todo_items'

expect(page).to have_content 'TODO item 10'
end

it 'hide comopleted todo items when switched hidden' do
create_list(:todo_item, 5, user: @user, name: "Completed Todo Item", is_completed: true)
create_list(:todo_item, 5, user: @user)
create_list(:todo_item, 5, user: user, name: "Completed Todo Item", is_completed: true)
create_list(:todo_item, 5, user: user)

visit '/todo_items'

Expand All @@ -38,7 +39,7 @@
end

it 'can create new todo item' do
create_list(:todo_item, 10, user: @user)
create_list(:todo_item, 10, user: user)

visit '/todo_items'

Expand All @@ -56,7 +57,7 @@
end

it 'can edit existing todo item' do
create_list(:todo_item, 10, user: @user)
create_list(:todo_item, 10, user: user)

visit '/todo_items'

Expand All @@ -78,7 +79,7 @@
end

it 'can delete existing todo item' do
create_list(:todo_item, 10, user: @user)
create_list(:todo_item, 10, user: user)

visit '/todo_items'

Expand Down

0 comments on commit 4983e8a

Please sign in to comment.