Skip to content

Commit e7f470e

Browse files
committed
Update Rubocop config, fix offenses
1 parent e9f089c commit e7f470e

7 files changed

+85
-38
lines changed

.rubocop.yml

+31-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ AllCops:
99
Exclude:
1010
- bin/*
1111
- gemfiles/*
12-
- spec/**/*
1312
- lib/store_base_sti_class_for_*.rb
1413

1514
Gemspec/RequireMFA:
@@ -22,9 +21,39 @@ Gemspec/RequireMFA:
2221
Style/Documentation:
2322
Enabled: false
2423

24+
Style/ArgumentsForwarding:
25+
Enabled: false
26+
27+
Style/HashSyntax:
28+
EnforcedShorthandSyntax: never
29+
2530
##########
2631
# LAYOUT #
2732
##########
2833

2934
Layout/LineLength:
30-
Max: 125
35+
Max: 150
36+
37+
Layout/HashAlignment:
38+
EnforcedColonStyle: table
39+
EnforcedHashRocketStyle: table
40+
41+
##########
42+
# NAMING #
43+
##########
44+
45+
Naming/BlockForwarding:
46+
Enabled: false
47+
48+
#########
49+
# RSPEC #
50+
#########
51+
52+
RSpec/ExampleLength:
53+
Max: 8
54+
55+
RSpec/MultipleExpectations:
56+
Max: 5
57+
58+
RSpec/NotToNot:
59+
EnforcedStyle: to_not

spec/rspec_patch.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module RSpecPatch
24
module Expectations
35
def expectation_count
@@ -11,22 +13,22 @@ def update_expectation_count
1113

1214
module Matchers
1315
def expect(*args, &block)
14-
::RSpec::Expectations.update_expectation_count
16+
RSpec::Expectations.update_expectation_count
1517
super
1618
end
1719
end
1820

1921
module SummaryNotification
2022
def totals_line(*args)
2123
text = super
22-
count = ::RSpec::Expectations.expectation_count
23-
message = RSpec::Core::Formatters::Helpers.pluralize(count, "expectation")
24+
count = RSpec::Expectations.expectation_count
25+
message = RSpec::Core::Formatters::Helpers.pluralize(count, 'expectation')
2426
"#{text.chomp}, #{message}"
2527
end
2628
end
2729
end
2830

29-
unless ::RSpec::Expectations.respond_to?(:expectation_count)
31+
unless RSpec::Expectations.respond_to?(:expectation_count)
3032
RSpec::Expectations.extend(RSpecPatch::Expectations)
3133
RSpec::Matchers.prepend(RSpecPatch::Matchers)
3234
RSpec::Core::Notifications::SummaryNotification.prepend(RSpecPatch::SummaryNotification)

spec/store_base_sti_class_spec.rb

+21-21
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
end
1010

1111
after do
12-
ActiveRecord::Base.store_base_sti_class = @old_store_base_sti_class
12+
ActiveRecord::Base.store_base_sti_class = @old_store_base_sti_class # rubocop:disable RSpec/InstanceVariable
1313
end
1414

1515
describe 'test_polymorphic_belongs_to_assignment_with_inheritance' do
1616
context 'when assigning a saved record' do
17-
let(:post) { SpecialPost.create(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
17+
let(:post) { SpecialPost.create(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
1818
let(:tagging) { Tagging.new }
1919

2020
it do
@@ -25,7 +25,7 @@
2525
end
2626

2727
context 'when assigning a new record' do
28-
let(:post) { SpecialPost.new(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
28+
let(:post) { SpecialPost.new(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
2929
let(:tagging) { Tagging.new }
3030

3131
it do
@@ -37,7 +37,7 @@
3737
end
3838

3939
describe 'test_polymorphic_has_many_create_model_with_inheritance' do
40-
let(:post) { SpecialPost.new(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
40+
let(:post) { SpecialPost.new(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
4141
let(:misc_tag) { Tag.create(name: 'Misc') }
4242

4343
it do
@@ -50,7 +50,7 @@
5050
end
5151

5252
describe 'test_polymorphic_has_one_create_model_with_inheritance' do
53-
let(:post) { SpecialPost.new(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
53+
let(:post) { SpecialPost.new(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
5454
let(:misc_tag) { Tag.create(name: 'Misc') }
5555

5656
it do
@@ -76,14 +76,14 @@
7676
let(:tag) { SpecialTag.create!(name: 'Special') }
7777

7878
it do
79-
tag.polytagged_posts.create!(title: 'To Be or Not To Be?', body: "the body")
79+
tag.polytagged_posts.create!(title: 'To Be or Not To Be?', body: 'the body')
8080

8181
expect(tag.polytaggings.first.polytag_type).to eq 'SpecialTag'
8282
end
8383
end
8484

8585
describe 'include_polymorphic_has_one' do
86-
let(:post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
86+
let(:post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
8787
let(:misc_tag) { Tag.create(name: 'Misc') }
8888

8989
it do
@@ -96,8 +96,8 @@
9696

9797
describe 'include_polymorphic_has_many' do
9898
let(:tag) { SpecialTag.create!(name: 'Special') }
99-
let(:post) { SpecialPost.create(title: 'Thinking', body: "the body") }
100-
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
99+
let(:post) { SpecialPost.create(title: 'Thinking', body: 'the body') }
100+
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
101101

102102
it do
103103
tag.polytagged_posts << special_post
@@ -110,8 +110,8 @@
110110

111111
describe 'include_polymorphic_has_many_through' do
112112
let(:tag) { SpecialTag.create!(name: 'Special') }
113-
let(:post) { SpecialPost.create(title: 'Thinking', body: "the body") }
114-
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
113+
let(:post) { SpecialPost.create(title: 'Thinking', body: 'the body') }
114+
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
115115

116116
it do
117117
tag.polytagged_posts << special_post
@@ -124,8 +124,8 @@
124124

125125
describe 'join_polymorhic_has_many' do
126126
let(:tag) { SpecialTag.create!(name: 'Special') }
127-
let(:post) { SpecialPost.create(title: 'Thinking', body: "the body") }
128-
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
127+
let(:post) { SpecialPost.create(title: 'Thinking', body: 'the body') }
128+
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
129129

130130
it do
131131
tag.polytagged_posts << special_post
@@ -137,8 +137,8 @@
137137

138138
describe 'join_polymorhic_has_many_through' do
139139
let(:tag) { SpecialTag.create!(name: 'Special') }
140-
let(:post) { SpecialPost.create(title: 'Thinking', body: "the body") }
141-
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
140+
let(:post) { SpecialPost.create(title: 'Thinking', body: 'the body') }
141+
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
142142

143143
it do
144144
tag.polytagged_posts << special_post
@@ -150,8 +150,8 @@
150150

151151
describe 'has_many_through_polymorphic_has_one' do
152152
let(:author) { Author.create!(name: 'Bob') }
153-
let(:post) { Post.create!(title: 'Budget Forecasts Bigger 2011 Deficit', author: author, body: "the body") }
154-
let(:special_post) { SpecialPost.create!(title: 'IBM Watson' 's Jeopardy play', author: author, body: "the body") }
153+
let(:post) { Post.create!(title: 'Budget Forecasts Bigger 2011 Deficit', author: author, body: 'the body') }
154+
let(:special_post) { SpecialPost.create!(title: 'IBM Watsons Jeopardy play', author: author, body: 'the body') }
155155
let(:special_tag) { SpecialTag.create!(name: 'SpecialGeneral') }
156156

157157
it do
@@ -162,8 +162,8 @@
162162

163163
describe 'has_many_polymorphic_with_source_type' do
164164
let(:tag) { SpecialTag.create!(name: 'Special') }
165-
let(:post) { SpecialPost.create(title: 'Thinking', body: "the body") }
166-
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: "the body") }
165+
let(:post) { SpecialPost.create(title: 'Thinking', body: 'the body') }
166+
let(:special_post) { SpecialPost.create!(title: 'Budget Forecasts Bigger 2011 Deficit', body: 'the body') }
167167

168168
it do
169169
tag.polytagged_posts << special_post
@@ -180,7 +180,7 @@
180180

181181
describe 'test_polymorphic_has_many_through_with_double_sti_on_join_model' do
182182
let(:tag) { SpecialTag.create!(name: 'Special') }
183-
let(:post) { SpecialPost.create(title: 'Thinking', body: "the body") }
183+
let(:post) { SpecialPost.create(title: 'Thinking', body: 'the body') }
184184

185185
it do
186186
tag.polytagged_posts << post
@@ -210,7 +210,7 @@
210210

211211
describe 'where_query' do
212212
let(:tag) { SpecialTag.create!(name: 'Special') }
213-
let(:post) { SpecialPost.create(title: 'Thinking', body: "the body") }
213+
let(:post) { SpecialPost.create(title: 'Thinking', body: 'the body') }
214214

215215
it do
216216
tag.polytagged_posts << post

spec/support/models.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class SpecialPost < Post
1919

2020
class Tagging < ActiveRecord::Base
2121
belongs_to :tag
22-
belongs_to :polytag, polymorphic: true
23-
belongs_to :taggable, polymorphic: true, counter_cache: true
22+
belongs_to :polytag, polymorphic: true
23+
belongs_to :taggable, polymorphic: true, counter_cache: true
2424
end
2525

2626
class Tag < ActiveRecord::Base

spec/support/schema.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class Schema < ActiveRecord::Migration[5.0]
4-
def self.up
4+
def self.up # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
55
suppress_messages do
66
create_table :authors, force: true do |t|
77
t.string :name, null: false

spec/support/sql_counter.rb

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@
22

33
# the following is needed because ActiveRecord::TestCase uses ActiveRecord::SQLCounter, which is
44
# not bundled as part of the gem
5+
# rubocop:disable Style/RedundantSelf
56
module ActiveRecord
67
class SQLCounter
78
class << self
89
attr_accessor :ignored_sql, :log, :log_all
910

10-
def clear_log;
11-
self.log = []; self.log_all = [];
11+
def clear_log
12+
self.log = []
13+
self.log_all = []
1214
end
1315
end
1416

1517
self.clear_log
16-
17-
self.ignored_sql = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/, /^BEGIN/, /^COMMIT/]
18+
self.ignored_sql = [
19+
/^PRAGMA/,
20+
/^SELECT currval/,
21+
/^SELECT CAST/,
22+
/^SELECT @@IDENTITY/,
23+
/^SELECT @@ROWCOUNT/,
24+
/^SAVEPOINT/,
25+
/^ROLLBACK TO SAVEPOINT/,
26+
/^RELEASE SAVEPOINT/,
27+
/^SHOW max_identifier_length/,
28+
/^BEGIN/,
29+
/^COMMIT/
30+
]
1831

1932
# FIXME: this needs to be refactored so specific database can add their own
2033
# ignored SQL, or better yet, use a different notification for the queries
@@ -34,12 +47,12 @@ def initialize(ignore = Regexp.union(self.class.ignored_sql))
3447
@ignore = ignore
3548
end
3649

37-
def call(name, start, finish, message_id, values)
50+
def call(_name, _start, _finish, _message_id, values)
3851
sql = values[:sql]
3952

4053
# FIXME: this seems bad. we should probably have a better way to indicate
4154
# the query was cached
42-
return if 'CACHE' == values[:name]
55+
return if values[:name] == 'CACHE'
4356

4457
self.class.log_all << sql
4558
self.class.log << sql unless ignore =~ sql
@@ -48,3 +61,4 @@ def call(name, start, finish, message_id, values)
4861

4962
ActiveSupport::Notifications.subscribe('sql.active_record', SQLCounter.new)
5063
end
64+
# rubocop:enable Style/RedundantSelf

spec/support/test_helper.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# frozen_string_literal: true
22

33
module TestHelper
4-
def assert_queries(num = 1, options = {})
4+
# rubocop:disable Style/ZeroLengthPredicate
5+
def assert_queries(num = 1, options = {}) # rubocop:disable Metrics/MethodLength
56
ignore_none = options.fetch(:ignore_none) { num == :any }
67
ActiveRecord::SQLCounter.clear_log
78
yield
89
ensure
910
the_log = ignore_none ? ActiveRecord::SQLCounter.log_all : ActiveRecord::SQLCounter.log
1011
if num == :any
11-
assert_operator the_log.size, :>=, 1, "1 or more queries expected, but none were executed."
12+
assert_operator the_log.size, :>=, 1, '1 or more queries expected, but none were executed.'
1213
else
1314
mesg = "#{the_log.size} instead of #{num} queries were executed.#{the_log.size == 0 ? '' : "\nQueries:\n#{the_log.join("\n")}"}"
1415

1516
expect(the_log.size).to eq(num), mesg
1617
end
1718
end
19+
# rubocop:enable Style/ZeroLengthPredicate
1820

1921
def assert_no_queries(&block)
2022
assert_queries(0, ignore_none: true, &block)

0 commit comments

Comments
 (0)