Skip to content

Commit

Permalink
fixes code-quality-job build issues (#129)
Browse files Browse the repository at this point in the history
* fixes code-quality-job issues

* adds rubocop_todo YML config file

* keep validates at model
  • Loading branch information
taylorrf authored Jun 6, 2024
1 parent b13374d commit 153f7bc
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
inherit_from: .rubocop_todo.yml

require:
- 'rubocop-rails'

Expand Down
31 changes: 31 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-06-06 19:50:30 UTC using RuboCop version 1.64.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 20
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'devise-secure_password.gemspec'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/ApplicationRecord:
Exclude:
- 'lib/devise/secure_password/models/previous_password.rb'

Rails/RedundantPresenceValidationOnBelongsTo:
Exclude:
- 'lib/devise/secure_password/models/previous_password.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantConstantBase:
Exclude:
- 'spec/benchmarks/character_counter.rb'
1 change: 0 additions & 1 deletion devise-secure_password.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Gem::Specification.new do |spec|
}

spec.executables = spec.files.grep(%r{^bin/}).map { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_runtime_dependency 'devise', '>= 4.0.0', '< 5.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def password_recent?
def before_resource_initialized
return if self.class.respond_to?(:password_previously_used_count)

raise ConfigurationError, <<-ERROR.strip_heredoc
raise ConfigurationError, <<~ERROR
The password_disallows_frequent_changes module depends on the
password_disallows_frequent_reuse module. Verify that you have
added both modules to your model, for example:
The password_disallows_frequent_changes module depends on the
password_disallows_frequent_reuse module. Verify that you have
added both modules to your model, for example:
devise :database_authenticatable, :registerable,
:password_disallows_frequent_reuse,
:password_disallows_frequent_changes
devise :database_authenticatable, :registerable,
:password_disallows_frequent_reuse,
:password_disallows_frequent_changes
ERROR
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def after_resource_saved
end

def previous_password?(password)
salts = previous_passwords.select(:salt).map(&:salt)
salts = previous_passwords.pluck(:salt)
pepper = self.class.pepper.presence || ''

salts.each do |salt|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def password_expired?
def before_regular_update_initialized
return if self.class.respond_to?(:password_previously_used_count)

raise ConfigurationError, <<-ERROR.strip_heredoc
raise ConfigurationError, <<~ERROR
The password_requires_regular_updates module depends on the
password_disallows_frequent_reuse module. Verify that you have
added both modules to your model, for example:
The password_requires_regular_updates module depends on the
password_disallows_frequent_reuse module. Verify that you have
added both modules to your model, for example:
devise :database_authenticatable, :registerable,
:password_disallows_frequent_reuse,
:password_requires_regular_updates
devise :database_authenticatable, :registerable,
:password_disallows_frequent_reuse,
:password_requires_regular_updates
ERROR
end

Expand Down
2 changes: 1 addition & 1 deletion spec/feature/user_changes_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
before do
user.save
last_password = user.previous_passwords.first
last_password.created_at = Time.zone.now - 2.days
last_password.created_at = 2.days.ago
last_password.save
login_as(user, scope: :user)
visit '/users/change_password/edit'
Expand Down
2 changes: 1 addition & 1 deletion spec/models/password_disallows_frequent_reuse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# create a previous_password
user.save(validate: false)
last_password = user.previous_passwords.first
last_password.created_at = Time.zone.now - 2.days
last_password.created_at = 2.days.ago
last_password.save
user.password = user.password_confirmation = user.password
user.save
Expand Down
4 changes: 2 additions & 2 deletions spec/models/previous_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

context 'when a password is not recent' do
it 'returns false' do
previous_password.created_at = Time.zone.now - 1.day
previous_password.created_at = 1.day.ago
expect(previous_password.fresh?(1.day)).to be false
end
end
Expand All @@ -93,7 +93,7 @@

context 'when a password is old' do
it 'returns true' do
previous_password.created_at = Time.zone.now - 1.day
previous_password.created_at = 1.day.ago
expect(previous_password.stale?(1.day)).to be true
end
end
Expand Down

0 comments on commit 153f7bc

Please sign in to comment.