Skip to content

Commit 6fc4f98

Browse files
committed
comply with rubocop
1 parent 7f989e3 commit 6fc4f98

File tree

17 files changed

+110
-71
lines changed

17 files changed

+110
-71
lines changed

.rubocop.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
inherit_from: .rubocop_todo.yml
22

3+
require:
4+
- rubocop-capybara
5+
- rubocop-factory_bot
6+
- rubocop-rails
7+
- rubocop-rspec
8+
- rubocop-rspec_rails
9+
310
AllCops:
11+
NewCops: enable
12+
413
TargetRubyVersion: 3.3
514
Exclude:
615
- 'db/migrate/*.rb'
7-
- 'db/schema.rb'
8-
- 'bin/setup'
9-
- 'bin/update'
1016
- 'lib/templates/**/*'
1117
- 'vendor/**/*'
18+
- bin/setup
19+
- bin/update
1220

1321
Style/Documentation:
1422
Exclude:
15-
- 'spec/**/*'
1623
- 'Gemfile'
1724
- 'Rakefile'
1825

1926
Metrics/BlockLength:
2027
Exclude:
21-
- 'app/apis/**/*'
2228
- 'config/**/*'
23-
- 'spec/**/*'
29+
- 'db/schema.rb'
2430

25-
Metrics/LineLength:
31+
Layout/LineLength:
2632
Exclude:
2733
- 'config/**/*'
28-
- 'spec/**/*'
2934
- 'Gemfile'
3035
- 'Rakefile'
3136

.rubocop_todo.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2021-12-31 12:20:36 UTC using RuboCop version 1.24.0.
3+
# on 2024-05-26 04:54:19 UTC using RuboCop version 1.64.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 1
10+
# Configuration parameters: IgnoredMetadata.
11+
RSpec/DescribeClass:
12+
Exclude:
13+
- 'spec/browser/restricted_area_spec.rb'

Dangerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ end
2020
# Mainly to encourage writing up some reasoning about the PR, rather than
2121
# just leaving a title
2222
# ------------------------------------------------------------------------------
23-
fail 'Please provide a summary in the Pull Request description' if github.pr_body.length < 5
23+
raise 'Please provide a summary in the Pull Request description' if github.pr_body.length < 5
2424

2525
# ------------------------------------------------------------------------------
2626
# You've made changes to specs, but no library code has changed?
@@ -42,8 +42,8 @@ end
4242

4343
contents = File.read(file)
4444
if file.start_with?('spec')
45-
fail("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/
46-
fail("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/
45+
raise("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/
46+
raise("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/
4747
end
4848
end
4949

@@ -76,6 +76,6 @@ message(':tada:') if github.pr_author != 'davidsiaw'
7676
# Ensure a clean commits history
7777
# ------------------------------------------------------------------------------
7878
branch = github.branch_for_base
79-
if git.commits.any? { |c| c.message =~ /^Merge branch '#{branch}'/ }
80-
fail('Please rebase to get rid of the merge commits in this PR')
79+
raise('Please rebase to get rid of the merge commits in this PR') if git.commits.any? do |c|
80+
c.message =~ /^Merge branch '#{branch}'/
8181
end

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ group :development do
7272
gem 'web-console', '>= 3.3.0'
7373
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
7474
gem 'rubocop'
75+
gem 'rubocop-capybara'
76+
gem 'rubocop-factory_bot'
77+
gem 'rubocop-rails'
78+
gem 'rubocop-rspec'
79+
gem 'rubocop-rspec_rails'
7580
gem 'spring'
7681
gem 'spring-watcher-listen', '~> 2.1.0'
7782
end

Gemfile.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,22 @@ GEM
395395
unicode-display_width (>= 2.4.0, < 3.0)
396396
rubocop-ast (1.31.3)
397397
parser (>= 3.3.1.0)
398+
rubocop-capybara (2.20.0)
399+
rubocop (~> 1.41)
400+
rubocop-factory_bot (2.25.1)
401+
rubocop (~> 1.41)
402+
rubocop-rails (2.25.0)
403+
activesupport (>= 4.2.0)
404+
rack (>= 1.1)
405+
rubocop (>= 1.33.0, < 2.0)
406+
rubocop-ast (>= 1.31.1, < 2.0)
407+
rubocop-rspec (2.29.2)
408+
rubocop (~> 1.40)
409+
rubocop-capybara (~> 2.17)
410+
rubocop-factory_bot (~> 2.22)
411+
rubocop-rspec_rails (~> 2.28)
412+
rubocop-rspec_rails (2.28.3)
413+
rubocop (~> 1.40)
398414
ruby-progressbar (1.13.0)
399415
ruby2_keywords (0.0.5)
400416
rubyzip (2.3.2)
@@ -507,6 +523,11 @@ DEPENDENCIES
507523
rspec-rails
508524
rspec_junit_formatter
509525
rubocop
526+
rubocop-capybara
527+
rubocop-factory_bot
528+
rubocop-rails
529+
rubocop-rspec
530+
rubocop-rspec_rails
510531
sass-rails (~> 6.0)
511532
selenium-webdriver
512533
shoulda-matchers

app/models/paper_trail/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module PaperTrail
44
# Extension to allow papertrail versions to use ULID
5-
class Version < ActiveRecord::Base
5+
class Version < ApplicationRecord
66
include PaperTrail::VersionConcern
77
include ULID::Rails
88
ulid :id

config/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Application < Rails::Application
3737
config.generators.system_tests = nil
3838

3939
config.paths.add File.join('app', 'apis'), glob: File.join('**', '*.rb')
40-
config.autoload_paths += Dir[Rails.root.join('app', 'apis', '*')]
40+
config.autoload_paths += Dir[Rails.root.join('app/apis/*')]
4141
config.active_job.queue_adapter = :sidekiq
4242

4343
# Use default logging formatter so that PID and timestamp are not suppressed.

config/environments/development.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
config.action_controller.perform_caching = true
2222
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
2323

24-
elsif Rails.root.join('tmp', 'caching-dev.txt').exist?
24+
elsif Rails.root.join('tmp/caching-dev.txt').exist?
2525
config.action_controller.perform_caching = true
2626

2727
config.cache_store = :memory_store

config/initializers/sidekiq.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
Sidekiq.configure_server do |config|
4-
config.redis = { url: ENV['REDIS_URL'] }
4+
config.redis = { url: ENV.fetch('REDIS_URL', nil) }
55
end

db/migrate/20190204152040_enable_extensions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
class EnableExtensions < ActiveRecord::Migration[5.2]
44
def change
55
enable_extension('pgcrypto')
6-
enable_extension('citext')
6+
enable_extension('citext')
77
end
88
end

db/migrate/20190219160906_devise_create_admins.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class DeviseCreateAdmins < ActiveRecord::Migration[5.2]
44
def change
55
create_table :admins, id: :uuid do |t|
66
## Database authenticatable
7-
t.string :email, null: false, default: ""
8-
t.string :encrypted_password, null: false, default: ""
7+
t.string :email, null: false, default: ''
8+
t.string :encrypted_password, null: false, default: ''
99

1010
## Recoverable
1111
t.string :reset_password_token

db/schema.rb

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# This file is auto-generated from the current state of the database. Instead
24
# of editing this file, please use the migrations feature of Active Record to
35
# incrementally modify your database, and then regenerate this schema definition.
@@ -10,46 +12,45 @@
1012
#
1113
# It's strongly recommended that you check this file into your version control system.
1214

13-
ActiveRecord::Schema[7.1].define(version: 2019_02_19_160906) do
15+
ActiveRecord::Schema[7.1].define(version: 20_190_219_160_906) do
1416
# These are extensions that must be enabled in order to support this database
15-
enable_extension "citext"
16-
enable_extension "pgcrypto"
17-
enable_extension "plpgsql"
17+
enable_extension 'citext'
18+
enable_extension 'pgcrypto'
19+
enable_extension 'plpgsql'
1820

19-
create_table "admins", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
20-
t.string "email", default: "", null: false
21-
t.string "encrypted_password", default: "", null: false
22-
t.string "reset_password_token"
23-
t.datetime "reset_password_sent_at", precision: nil
24-
t.datetime "remember_created_at", precision: nil
25-
t.integer "sign_in_count", default: 0, null: false
26-
t.datetime "current_sign_in_at", precision: nil
27-
t.datetime "last_sign_in_at", precision: nil
28-
t.inet "current_sign_in_ip"
29-
t.inet "last_sign_in_ip"
30-
t.string "confirmation_token"
31-
t.datetime "confirmed_at", precision: nil
32-
t.datetime "confirmation_sent_at", precision: nil
33-
t.string "unconfirmed_email"
34-
t.integer "failed_attempts", default: 0, null: false
35-
t.string "unlock_token"
36-
t.datetime "locked_at", precision: nil
37-
t.datetime "updated_at", precision: nil
38-
t.index ["confirmation_token"], name: "index_admins_on_confirmation_token", unique: true
39-
t.index ["email"], name: "index_admins_on_email", unique: true
40-
t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true
41-
t.index ["unlock_token"], name: "index_admins_on_unlock_token", unique: true
21+
create_table 'admins', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t|
22+
t.string 'email', default: '', null: false
23+
t.string 'encrypted_password', default: '', null: false
24+
t.string 'reset_password_token'
25+
t.datetime 'reset_password_sent_at', precision: nil
26+
t.datetime 'remember_created_at', precision: nil
27+
t.integer 'sign_in_count', default: 0, null: false
28+
t.datetime 'current_sign_in_at', precision: nil
29+
t.datetime 'last_sign_in_at', precision: nil
30+
t.inet 'current_sign_in_ip'
31+
t.inet 'last_sign_in_ip'
32+
t.string 'confirmation_token'
33+
t.datetime 'confirmed_at', precision: nil
34+
t.datetime 'confirmation_sent_at', precision: nil
35+
t.string 'unconfirmed_email'
36+
t.integer 'failed_attempts', default: 0, null: false
37+
t.string 'unlock_token'
38+
t.datetime 'locked_at', precision: nil
39+
t.datetime 'updated_at', precision: nil
40+
t.index ['confirmation_token'], name: 'index_admins_on_confirmation_token', unique: true
41+
t.index ['email'], name: 'index_admins_on_email', unique: true
42+
t.index ['reset_password_token'], name: 'index_admins_on_reset_password_token', unique: true
43+
t.index ['unlock_token'], name: 'index_admins_on_unlock_token', unique: true
4244
end
4345

44-
create_table "versions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
45-
t.string "item_type", null: false
46-
t.uuid "item_id", null: false
47-
t.string "event", null: false
48-
t.string "whodunnit"
49-
t.jsonb "object"
50-
t.jsonb "object_changes"
51-
t.datetime "created_at", precision: nil
52-
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
46+
create_table 'versions', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t|
47+
t.string 'item_type', null: false
48+
t.uuid 'item_id', null: false
49+
t.string 'event', null: false
50+
t.string 'whodunnit'
51+
t.jsonb 'object'
52+
t.jsonb 'object_changes'
53+
t.datetime 'created_at', precision: nil
54+
t.index %w[item_type item_id], name: 'index_versions_on_item_type_and_item_id'
5355
end
54-
5556
end

lib/generators/api/api_generator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ def pname_of(tokens)
4747
end
4848

4949
def fields
50-
@fields ||= member_list.map do |member|
50+
@fields ||= member_list.to_h do |member|
5151
tokens = member.split(':')
5252
[tokens[0], {
5353
param_name: pname_of(tokens),
5454
param_type: ptype_of(tokens),
5555
full_type: tokens[1]
5656
}]
57-
end.to_h
57+
end
5858
end
5959

6060
private
@@ -128,7 +128,7 @@ def mount_api
128128
" #{mount_statement}",
129129
mount_end].map { |x| "#{x}\n" }
130130

131-
File.open(main_api_path, 'wb') { |file| file.write(result) }
131+
File.binwrite(main_api_path, result)
132132
end
133133

134134
def unmount_api
@@ -138,7 +138,7 @@ def unmount_api
138138
mount_list_sans_statement,
139139
mount_end].map { |x| "#{x}\n" }
140140

141-
File.open(main_api_path, 'wb') { |file| file.write(result) }
141+
File.binwrite(main_api_path, result)
142142
end
143143
end
144144
# rubocop:enable Metrics/ClassLength

spec/apis/v1/health_api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
it 'returns ok status' do
1212
get '/api/v1/health'
13-
expect(response.status).to eq 200
13+
expect(response).to have_http_status :ok
1414
end
1515
end

spec/browser/restricted_area_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
require 'browser_helper'
55

66
RSpec.describe 'Restricted Area', :js, type: :browser do
7-
let(:admin) { create :admin }
7+
let(:admin) { create(:admin) }
88

99
it 'sidekiq cannot be accessed without logging in' do
1010
visit('/sidekiq')
1111
fill_in 'Email', with: admin.email
1212
fill_in 'Password', with: admin.password
13-
click_button
13+
click_link_or_button
1414
expect(page.body).to match 'Sidekiq'
1515
end
1616

1717
it 'swagger cannot be accessed without logging in' do
1818
visit('/swagger')
1919
fill_in 'Email', with: admin.email
2020
fill_in 'Password', with: admin.password
21-
click_button
21+
click_link_or_button
2222
expect(page.body).to match 'Swagger'
2323
end
2424
end

spec/rails_helper.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# directory. Alternatively, in the individual `*_spec.rb` files, manually
2424
# require only the support files necessary.
2525
#
26-
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
26+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
2727

2828
# Checks for pending migrations and applies them before tests are run.
2929
# If you are not using ActiveRecord, you can remove these lines.
@@ -37,7 +37,7 @@
3737
# Remember to include global test helpers here
3838
include ConcernHelper
3939

40-
config.fixture_paths = ["#{::Rails.root}/spec/fixtures"]
40+
config.fixture_paths = [Rails.root.join('spec/fixtures').to_s]
4141

4242
DatabaseCleaner.allow_remote_database_url = true
4343
config.use_transactional_fixtures = false
@@ -59,7 +59,7 @@
5959
DatabaseCleaner.clean_with(:truncation)
6060
end
6161

62-
config.before(:each) do
62+
config.before do
6363
DatabaseCleaner.strategy = :transaction
6464
end
6565

@@ -76,11 +76,11 @@
7676
end
7777
end
7878

79-
config.before(:each) do
79+
config.before do
8080
DatabaseCleaner.start
8181
end
8282

83-
config.after(:each) do
83+
config.after do
8484
DatabaseCleaner.clean
8585
end
8686

spec/support/helpers/concern_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# helps us test concerns
34
module ConcernHelper
45
def spec_dir
56
File.dirname metadata[:file_path]

0 commit comments

Comments
 (0)