Skip to content

Commit 6436246

Browse files
committed
Rubocop linting
1 parent 37e2edc commit 6436246

15 files changed

+106
-73
lines changed

.rubocop_todo.yml

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2021-03-21 02:34:29 UTC using RuboCop version 1.11.0.
3+
# on 2021-03-24 02:03:11 UTC using RuboCop version 1.11.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
@@ -13,12 +13,13 @@ Gemspec/RequiredRubyVersion:
1313
Exclude:
1414
- 'omniauth-identity.gemspec'
1515

16-
# Offense count: 1
16+
# Offense count: 2
1717
# Configuration parameters: AllowedMethods.
1818
# AllowedMethods: enums
1919
Lint/ConstantDefinitionInBlock:
2020
Exclude:
21-
- 'spec/omniauth/identity/models/active_record_spec.rb'
21+
- 'spec_orms/active_record_spec.rb'
22+
- 'spec_orms/sequel_spec.rb'
2223

2324
# Offense count: 1
2425
# Configuration parameters: AllowComments.
@@ -27,11 +28,18 @@ Lint/EmptyClass:
2728
- 'spec/omniauth/identity/secure_password_spec.rb'
2829

2930
# Offense count: 1
30-
Lint/NestedMethodDefinition:
31+
Lint/MissingSuper:
3132
Exclude:
3233
- 'lib/omniauth/identity/secure_password.rb'
3334

3435
# Offense count: 1
36+
Lint/UselessAssignment:
37+
Exclude:
38+
- '**/*.md'
39+
- '**/*.markdown'
40+
- 'Rakefile'
41+
42+
# Offense count: 2
3543
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
3644
Metrics/AbcSize:
3745
Max: 30
@@ -40,14 +48,14 @@ Metrics/AbcSize:
4048
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
4149
# IgnoredMethods: refine
4250
Metrics/BlockLength:
43-
Max: 28
51+
Max: 32
4452

4553
# Offense count: 1
4654
# Configuration parameters: CountComments, CountAsOne.
4755
Metrics/ClassLength:
4856
Max: 145
4957

50-
# Offense count: 7
58+
# Offense count: 9
5159
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
5260
Metrics/MethodLength:
5361
Max: 20
@@ -82,19 +90,29 @@ Naming/PredicateName:
8290
- 'spec/**/*'
8391
- 'lib/omniauth/identity/secure_password.rb'
8492

85-
# Offense count: 7
93+
# Offense count: 3
94+
RSpec/BeforeAfterAll:
95+
Exclude:
96+
- 'spec/spec_helper.rb'
97+
- 'spec/rails_helper.rb'
98+
- 'spec/support/**/*.rb'
99+
- 'spec_orms/couch_potato_spec.rb'
100+
- 'spec_orms/nobrainer_spec.rb'
101+
- 'spec_orms/sequel_spec.rb'
102+
103+
# Offense count: 6
86104
# Configuration parameters: Prefixes.
87105
# Prefixes: when, with, without
88106
RSpec/ContextWording:
89107
Exclude:
90-
- 'spec/omniauth/identity/model_spec.rb'
91108
- 'spec/omniauth/strategies/identity_spec.rb'
109+
- 'spec/support/shared_contexts/persistable_model.rb'
92110

93111
# Offense count: 1
94112
# Configuration parameters: Max.
95113
RSpec/ExampleLength:
96114
Exclude:
97-
- 'spec/omniauth/identity/model_spec.rb'
115+
- 'spec/support/shared_contexts/instance_with_instance_methods.rb'
98116

99117
# Offense count: 3
100118
RSpec/ExpectInHook:
@@ -107,18 +125,19 @@ RSpec/ExpectInHook:
107125
RSpec/FilePath:
108126
Exclude:
109127
- 'spec/omniauth/identity/model_spec.rb'
110-
- 'spec/omniauth/identity/models/active_record_spec.rb'
111-
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
112-
- 'spec/omniauth/identity/models/mongoid_spec.rb'
113-
- 'spec/omniauth/identity/models/nobrainer_spec.rb'
114-
- 'spec/omniauth/identity/models/sequel_spec.rb'
115128
- 'spec/omniauth/identity/secure_password_spec.rb'
116129
- 'spec/omniauth/strategies/identity_spec.rb'
130+
- 'spec_orms/active_record_spec.rb'
131+
- 'spec_orms/couch_potato_spec.rb'
132+
- 'spec_orms/mongoid_spec.rb'
133+
- 'spec_orms/nobrainer_spec.rb'
134+
- 'spec_orms/sequel_spec.rb'
117135

118-
# Offense count: 1
136+
# Offense count: 2
119137
RSpec/LeakyConstantDeclaration:
120138
Exclude:
121-
- 'spec/omniauth/identity/models/active_record_spec.rb'
139+
- 'spec_orms/active_record_spec.rb'
140+
- 'spec_orms/sequel_spec.rb'
122141

123142
# Offense count: 8
124143
# Configuration parameters: .
@@ -135,13 +154,11 @@ RSpec/MultipleExpectations:
135154
RSpec/MultipleMemoizedHelpers:
136155
Max: 8
137156

138-
# Offense count: 44
157+
# Offense count: 1
139158
# Configuration parameters: IgnoreSharedExamples.
140159
RSpec/NamedSubject:
141160
Exclude:
142-
- 'spec/omniauth/identity/model_spec.rb'
143-
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
144-
- 'spec/omniauth/identity/models/mongoid_spec.rb'
161+
- 'spec_orms/mongoid_spec.rb'
145162

146163
# Offense count: 12
147164
RSpec/NestedGroups:
@@ -152,27 +169,28 @@ RSpec/StubbedMock:
152169
Exclude:
153170
- 'spec/omniauth/strategies/identity_spec.rb'
154171

155-
# Offense count: 22
172+
# Offense count: 5
156173
RSpec/SubjectStub:
157174
Exclude:
158-
- 'spec/omniauth/identity/model_spec.rb'
159-
- 'spec/omniauth/identity/models/active_record_spec.rb'
160-
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
161-
- 'spec/omniauth/identity/models/mongoid_spec.rb'
175+
- 'spec_orms/active_record_spec.rb'
176+
- 'spec_orms/couch_potato_spec.rb'
177+
- 'spec_orms/mongoid_spec.rb'
178+
- 'spec_orms/nobrainer_spec.rb'
179+
- 'spec_orms/sequel_spec.rb'
162180

163181
# Offense count: 4
164182
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
165183
RSpec/VerifiedDoubles:
166184
Exclude:
167-
- 'spec/omniauth/identity/model_spec.rb'
168185
- 'spec/omniauth/strategies/identity_spec.rb'
186+
- 'spec/support/shared_contexts/model_with_class_methods.rb'
169187

170188
# Offense count: 1
171189
Rake/Desc:
172190
Exclude:
173191
- 'Rakefile'
174192

175-
# Offense count: 7
193+
# Offense count: 10
176194
Style/Documentation:
177195
Exclude:
178196
- '**/*.md'
@@ -184,24 +202,30 @@ Style/Documentation:
184202
- 'lib/omniauth/identity/secure_password.rb'
185203
- 'spec/omniauth/identity/secure_password_spec.rb'
186204

187-
# Offense count: 5
205+
# Offense count: 4
188206
# Configuration parameters: MinBodyLength.
189207
Style/GuardClause:
190208
Exclude:
191209
- 'lib/omniauth/identity/model.rb'
192210
- 'lib/omniauth/identity/secure_password.rb'
193211

212+
# Offense count: 1
213+
# Cop supports --auto-correct.
214+
Style/IfUnlessModifier:
215+
Exclude:
216+
- 'lib/omniauth/strategies/identity.rb'
217+
194218
# Offense count: 1
195219
# Configuration parameters: AllowedMethods.
196220
# AllowedMethods: respond_to_missing?
197221
Style/OptionalBooleanParameter:
198222
Exclude:
199223
- 'lib/omniauth/identity/model.rb'
200224

201-
# Offense count: 1
225+
# Offense count: 4
202226
# Cop supports --auto-correct.
203227
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
204228
# URISchemes: http, https
205229
# IgnoredPatterns: (?-mix:^\#)
206230
Layout/LineLength:
207-
Max: 123
231+
Max: 138

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ group :development, :test do
2424
gem 'activerecord', '~> 6', require: false # rails 6 requires Ruby 2.5 or later
2525
end
2626
gem 'anonymous_active_record', '~> 1', require: false
27+
gem 'couch_potato', github: 'langalex/couch_potato', require: false
2728
gem 'mongoid', '~> 7', require: false
29+
gem 'mongoid-rspec', github: 'mongoid/mongoid-rspec', require: false
2830
gem 'nobrainer', '~> 0', require: false
2931
gem 'sequel', '~> 5', require: false
30-
gem 'couch_potato', github: 'langalex/couch_potato', require: false
31-
gem 'mongoid-rspec', github: 'mongoid/mongoid-rspec', require: false
3232

3333
if ruby_version >= Gem::Version.new('2.4')
3434
# No need to run byebug / pry on earlier versions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,16 @@ Please contribute some documentation if you have the gumption! The maintainer's
294294
```bash
295295
# CouchDB / CouchPotato
296296
bundle exec rspec spec spec_orms --tag 'couchdb'
297-
297+
298298
# ActiveRecord and Sequel, as they both use the in-memory SQLite driver.
299299
bundle exec rspec spec spec_orms --tag 'sqlite3'
300300
301301
# NOTE - mongoid and nobrainer specs can't be isolated with "tag" because it still loads everything,
302302
# and the two libraries are fundamentally incompatible.
303-
303+
304304
# MongoDB / Mongoid
305305
bundle exec rspec spec_orms/mongoid_spec.rb
306-
306+
307307
# RethinkDB / NoBrainer
308308
bundle exec rspec spec_orms/nobrainer_spec.rb
309309
```

Rakefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ begin
66
require 'rspec/core/rake_task'
77
primary = RSpec::Core::RakeTask.new(:spec)
88
active_record = RSpec::Core::RakeTask.new(:spec_orm_active_record)
9-
active_record.pattern = "spec_orms/active_record_spec.rb"
9+
active_record.pattern = 'spec_orms/active_record_spec.rb'
1010
couch_potato = RSpec::Core::RakeTask.new(:spec_orm_couch_potato)
11-
couch_potato.pattern = "spec_orms/couch_potato_spec.rb"
11+
couch_potato.pattern = 'spec_orms/couch_potato_spec.rb'
1212
mongoid = RSpec::Core::RakeTask.new(:spec_orm_mongoid)
13-
mongoid.pattern = "spec_orms/mongoid_spec.rb"
13+
mongoid.pattern = 'spec_orms/mongoid_spec.rb'
1414
nobrainer = RSpec::Core::RakeTask.new(:spec_orm_nobrainer)
15-
nobrainer.pattern = "spec_orms/nobrainer_spec.rb"
15+
nobrainer.pattern = 'spec_orms/nobrainer_spec.rb'
1616
sequel = RSpec::Core::RakeTask.new(:spec_orm_sequel)
17-
sequel.pattern = "spec_orms/sequel_spec.rb"
17+
sequel.pattern = 'spec_orms/sequel_spec.rb'
1818
rescue LoadError
1919
task :spec do
2020
warn 'RSpec is disabled'
@@ -31,11 +31,11 @@ rescue LoadError
3131
end
3232
end
3333

34-
task default: [
35-
:test,
36-
:spec_orm_active_record,
37-
:spec_orm_couch_potato,
38-
:spec_orm_mongoid,
39-
:spec_orm_nobrainer,
40-
:spec_orm_sequel
34+
task default: %i[
35+
test
36+
spec_orm_active_record
37+
spec_orm_couch_potato
38+
spec_orm_mongoid
39+
spec_orm_nobrainer
40+
spec_orm_sequel
4141
]

lib/omniauth/identity/model.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def auth_key(method = false)
5454
@auth_key || 'email'
5555
end
5656

57-
5857
# Locate an identity given its unique login key.
5958
#
6059
# @abstract

lib/omniauth/identity/secure_password.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def has_secure_password(attribute = :password, validations: true)
7373
# This is to avoid ActiveModel (and by extension the entire framework)
7474
# being dependent on a binary library.
7575
begin
76-
require "bcrypt"
76+
require 'bcrypt'
7777
rescue LoadError
78-
$stderr.puts "You don't have bcrypt installed in your application. Please add it to your Gemfile and run bundle install"
78+
warn "You don't have bcrypt installed in your application. Please add it to your Gemfile and run bundle install"
7979
raise
8080
end
8181

@@ -104,11 +104,11 @@ def initialize(attribute)
104104

105105
define_method("#{attribute}=") do |unencrypted_password|
106106
if unencrypted_password.nil?
107-
self.public_send("#{attribute}_digest=", nil)
107+
public_send("#{attribute}_digest=", nil)
108108
elsif !unencrypted_password.empty?
109109
instance_variable_set("@#{attribute}", unencrypted_password)
110110
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
111-
self.public_send("#{attribute}_digest=", BCrypt::Password.create(unencrypted_password, cost: cost))
111+
public_send("#{attribute}_digest=", BCrypt::Password.create(unencrypted_password, cost: cost))
112112
end
113113
end
114114

omniauth-identity.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Gem::Specification.new do |gem|
88
gem.add_runtime_dependency 'bcrypt'
99
gem.add_runtime_dependency 'omniauth'
1010

11-
gem.add_development_dependency 'rspec-block_is_expected', '~> 1.0'
1211
gem.add_development_dependency 'rack-test', '~> 1'
1312
gem.add_development_dependency 'rake', '~> 13'
1413
gem.add_development_dependency 'rspec', '~> 3'
14+
gem.add_development_dependency 'rspec-block_is_expected', '~> 1.0'
1515
gem.add_development_dependency 'sqlite3', '~> 1.4'
1616
# NOTE: Released version of couch_potato depends on activemodel ~> 4.0, so pull latest from github in Gemfile.
1717
# gem.add_development_dependency 'couch_potato', '~> 1.7'

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
require 'omniauth/identity'
1919

2020
spec_root_matcher = %r{#{__dir__}/(.+)\.rb\Z}
21-
Dir.glob(Pathname.new(__dir__).join("support/**/", "*.rb")).each { |f| require f.match(spec_root_matcher)[1] }
21+
Dir.glob(Pathname.new(__dir__).join('support/**/', '*.rb')).each { |f| require f.match(spec_root_matcher)[1] }
2222

2323
DEFAULT_PASSWORD = 'hang-a-left-at-the-diner'
2424
DEFAULT_EMAIL = 'mojo@example.com'

spec/support/shared_contexts/instance_with_instance_methods.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
RSpec.shared_context 'instance with instance methods' do
1+
# frozen_string_literal: true
2+
3+
RSpec.shared_examples 'instance with instance methods' do
24
describe '#initialize' do
35
it 'does not raise an error' do
46
block_is_expected.not_to raise_error
@@ -61,9 +63,9 @@
6163
allow(instance).to receive(:nickname).and_return('bob')
6264

6365
expect(instance.info).to include({
64-
'name' => 'Bob Bobson',
65-
'nickname' => 'bob'
66-
})
66+
'name' => 'Bob Bobson',
67+
'nickname' => 'bob'
68+
})
6769
end
6870

6971
it 'uses firstname and lastname, over nickname, to set missing name' do
@@ -84,4 +86,4 @@
8486
expect(instance.info['name']).to eq('Awesome Dude')
8587
end
8688
end
87-
end
89+
end

spec/support/shared_contexts/model_with_class_methods.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
RSpec.shared_context 'model with class methods' do
1+
# frozen_string_literal: true
2+
3+
RSpec.shared_examples 'model with class methods' do
24
describe 'class definition' do
35
it 'does not raise an error' do
46
block_is_expected.not_to raise_error
@@ -15,7 +17,7 @@
1517
it 'calls locate with additional scopes when provided' do
1618
mocked_instance = double('ExampleModel', authenticate: 'abbadoo')
1719
allow(model_klass).to receive(:locate).with('email' => 'example',
18-
'user_type' => 'admin').and_return(mocked_instance)
20+
'user_type' => 'admin').and_return(mocked_instance)
1921
expect(model_klass.authenticate({ 'email' => 'example', 'user_type' => 'admin' }, 'pass')).to eq('abbadoo')
2022
end
2123

0 commit comments

Comments
 (0)