From dc63fc26f226f0a98a94f0018abcbcba3848dcd9 Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Wed, 8 May 2024 15:14:28 -0400 Subject: [PATCH 01/14] add standardrb + --fix --- Gemfile | 31 ++--- Gemfile.lock | 17 +++ Rakefile | 2 +- .../clearance/passwords_controller.rb | 10 +- app/mailers/clearance_mailer.rb | 2 +- clearance.gemspec | 76 ++++++----- config/routes.rb | 12 +- gemfiles/rails_6.1.gemfile | 1 + gemfiles/rails_7.0.gemfile | 1 + gemfiles/rails_7.1.gemfile | 1 + lib/clearance/authentication.rb | 4 +- lib/clearance/authorization.rb | 4 +- lib/clearance/back_door.rb | 6 +- lib/clearance/configuration.rb | 10 +- lib/clearance/constraints.rb | 4 +- lib/clearance/controller.rb | 4 +- lib/clearance/default_sign_in_guard.rb | 2 +- lib/clearance/password_strategies/bcrypt.rb | 4 +- lib/clearance/session.rb | 8 +- lib/clearance/sign_in_guard.rb | 2 +- lib/clearance/testing/deny_access_matcher.rb | 8 +- lib/clearance/token.rb | 2 +- lib/clearance/user.rb | 10 +- .../clearance/install/install_generator.rb | 20 +-- .../clearance/routes/routes_generator.rb | 10 +- .../clearance/routes/templates/routes.rb | 20 +-- .../clearance/specs/specs_generator.rb | 8 +- .../clearance/views/views_generator.rb | 8 +- .../acceptance/clearance_installation_spec.rb | 6 +- spec/clearance/back_door_spec.rb | 10 +- spec/clearance/constraints/signed_in_spec.rb | 28 ++-- spec/clearance/constraints/signed_out_spec.rb | 8 +- spec/clearance/default_sign_in_guard_spec.rb | 12 +- spec/clearance/rack_session_spec.rb | 18 +-- spec/clearance/session_spec.rb | 122 +++++++++--------- spec/clearance/sign_in_guard_spec.rb | 14 +- .../testing/controller_helpers_spec.rb | 6 +- .../testing/deny_access_matcher_spec.rb | 2 +- spec/clearance/testing/view_helpers_spec.rb | 4 +- spec/clearance/token_spec.rb | 6 +- spec/controllers/apis_controller_spec.rb | 4 +- spec/controllers/forgeries_controller_spec.rb | 24 ++-- spec/controllers/passwords_controller_spec.rb | 50 +++---- .../permissions_controller_spec.rb | 24 ++-- spec/controllers/sessions_controller_spec.rb | 12 +- spec/controllers/users_controller_spec.rb | 10 +- spec/dummy/application.rb | 2 +- spec/factories.rb | 6 +- .../install/install_generator_spec.rb | 22 ++-- .../clearance/specs/specs_generator_spec.rb | 4 +- .../clearance/views/views_generator_spec.rb | 4 +- spec/mailers/clearance_mailer_spec.rb | 2 +- spec/models/user_spec.rb | 4 +- spec/password_strategies/argon2_spec.rb | 6 +- spec/password_strategies/bcrypt_spec.rb | 6 +- spec/requests/authentication_cookie_spec.rb | 6 +- spec/requests/cookie_options_spec.rb | 4 +- spec/requests/csrf_rotation_spec.rb | 4 +- spec/requests/password_maintenance_spec.rb | 2 +- spec/requests/token_expiration_spec.rb | 4 +- spec/routing/clearance_routes_spec.rb | 60 ++++----- spec/support/clearance.rb | 2 +- spec/support/cookies.rb | 8 +- .../fake_model_without_password_strategy.rb | 7 +- spec/support/generator_spec_helpers.rb | 4 +- spec/support/request_with_remember_token.rb | 2 +- 66 files changed, 411 insertions(+), 395 deletions(-) diff --git a/Gemfile b/Gemfile index 973a4ccc9..c85934a83 100644 --- a/Gemfile +++ b/Gemfile @@ -1,18 +1,19 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec -gem 'addressable' -gem 'ammeter' -gem 'appraisal' -gem 'capybara' -gem 'database_cleaner' -gem 'erb_lint', require: false -gem 'factory_bot_rails' -gem 'nokogiri' -gem 'pry', require: false -gem 'rails-controller-testing' -gem 'rspec-rails' -gem 'shoulda-matchers' -gem 'sqlite3', '~> 1.7' -gem 'timecop' +gem "addressable" +gem "ammeter" +gem "appraisal" +gem "capybara" +gem "database_cleaner" +gem "erb_lint", require: false +gem "factory_bot_rails" +gem "nokogiri" +gem "pry", require: false +gem "rails-controller-testing" +gem "rspec-rails" +gem "shoulda-matchers" +gem "sqlite3", "~> 1.7" +gem "standard" +gem "timecop" diff --git a/Gemfile.lock b/Gemfile.lock index f8833fc22..ec5bd79a7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,6 +117,7 @@ GEM concurrent-ruby (~> 1.0) json (2.7.2) language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -206,12 +207,27 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.31.3) parser (>= 3.3.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) shoulda-matchers (5.1.0) activesupport (>= 5.2.0) smart_properties (1.17.0) sqlite3 (1.7.3) mini_portile2 (~> 2.8.0) + standard (1.35.0.1) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.62) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) timecop (0.9.5) timeout (0.4.1) @@ -240,6 +256,7 @@ DEPENDENCIES rspec-rails shoulda-matchers sqlite3 (~> 1.7) + standard timecop BUNDLED WITH diff --git a/Rakefile b/Rakefile index bbf731b9e..c93546938 100644 --- a/Rakefile +++ b/Rakefile @@ -28,4 +28,4 @@ task :erb_lint do end desc "Run the specs and acceptance tests" -task default: %w(spec spec:acceptance erb_lint) +task default: %w[spec spec:acceptance erb_lint] diff --git a/app/controllers/clearance/passwords_controller.rb b/app/controllers/clearance/passwords_controller.rb index 552d718a0..102496010 100644 --- a/app/controllers/clearance/passwords_controller.rb +++ b/app/controllers/clearance/passwords_controller.rb @@ -1,4 +1,4 @@ -require 'active_support/deprecation' +require "active_support/deprecation" class Clearance::PasswordsController < Clearance::BaseController before_action :ensure_existing_user, only: [:edit, :update] @@ -56,8 +56,8 @@ def find_user_by_id_and_confirmation_token user_param = Clearance.configuration.user_id_parameter token = params[:token] || session[:password_reset_token] - Clearance.configuration.user_model. - find_by(id: params[user_param], confirmation_token: token.to_s) + Clearance.configuration.user_model + .find_by(id: params[user_param], confirmation_token: token.to_s) end def email_from_password_params @@ -65,8 +65,8 @@ def email_from_password_params end def find_user_for_create - Clearance.configuration.user_model. - find_by_normalized_email(email_from_password_params) + Clearance.configuration.user_model + .find_by_normalized_email(email_from_password_params) end def find_user_for_edit diff --git a/app/mailers/clearance_mailer.rb b/app/mailers/clearance_mailer.rb index ffd91aa01..bda8801be 100644 --- a/app/mailers/clearance_mailer.rb +++ b/app/mailers/clearance_mailer.rb @@ -7,7 +7,7 @@ def change_password(user) subject: I18n.t( :change_password, scope: [:clearance, :models, :clearance_mailer] - ), + ) ) end end diff --git a/clearance.gemspec b/clearance.gemspec index e91d8c12e..16c561da9 100644 --- a/clearance.gemspec +++ b/clearance.gemspec @@ -1,35 +1,34 @@ -$LOAD_PATH.push File.expand_path('../lib', __FILE__) -require 'clearance/version' +$LOAD_PATH.push File.expand_path("../lib", __FILE__) +require "clearance/version" Gem::Specification.new do |s| - s.add_dependency 'bcrypt', '>= 3.1.1' - s.add_dependency 'argon2', '~> 2.0', '>= 2.0.2' - s.add_dependency 'email_validator', '~> 2.0' - s.add_dependency 'railties', '>= 5.0' - s.add_dependency 'activemodel', '>= 5.0' - s.add_dependency 'activerecord', '>= 5.0' - s.add_dependency 'actionmailer', '>= 5.0' + s.add_dependency "bcrypt", ">= 3.1.1" + s.add_dependency "argon2", "~> 2.0", ">= 2.0.2" + s.add_dependency "email_validator", "~> 2.0" + s.add_dependency "railties", ">= 5.0" + s.add_dependency "activemodel", ">= 5.0" + s.add_dependency "activerecord", ">= 5.0" + s.add_dependency "actionmailer", ">= 5.0" s.authors = [ - 'Dan Croak', - 'Eugene Bolshakov', - 'Mike Burns', - 'Joe Ferris', - 'Nick Quaranto', - 'Josh Nichols', - 'Matt Jankowski', - 'Josh Clayton', - 'Gabe Berke-Williams', - 'Greg Lazarev', - 'Mike Breen', - 'Prem Sichanugrist', - 'Harlow Ward', - 'Ryan McGeary', - 'Derek Prior', - 'Jason Morrison', - 'Galen Frechette', - 'Josh Steiner', - 'Dorian MariƩ', - 'Sara Jackson' + "Dan Croak", + "Eugene Bolshakov", + "Mike Burns", + "Joe Ferris", + "Nick Quaranto", + "Josh Nichols", + "Matt Jankowski", + "Josh Clayton", + "Gabe Berke-Williams", + "Greg Lazarev", + "Mike Breen", + "Prem Sichanugrist", + "Harlow Ward", + "Ryan McGeary", + "Derek Prior", + "Jason Morrison", + "Galen Frechette", + "Josh Steiner", + "Dorian MariƩ" ] s.description = <<-DESCRIPTION Clearance is built to support authentication and authorization via an @@ -38,16 +37,15 @@ Gem::Specification.new do |s| It provides some core classes commonly used for these features, along with some opinionated defaults - but is intended to be easy to override. DESCRIPTION - s.email = 'support@thoughtbot.com' - s.extra_rdoc_files = %w(LICENSE README.md) + s.email = "support@thoughtbot.com" + s.extra_rdoc_files = %w[LICENSE README.md] s.files = `git ls-files`.split("\n") - s.homepage = 'https://github.com/thoughtbot/clearance' - s.license = 'MIT' - s.name = %q{clearance} - s.rdoc_options = ['--charset=UTF-8'] - s.require_paths = ['lib'] - s.required_ruby_version = Gem::Requirement.new('>= 2.4.0') - s.summary = 'Rails authentication & authorization with email & password.' - s.test_files = `git ls-files -- {spec}/*`.split("\n") + s.homepage = "https://github.com/thoughtbot/clearance" + s.license = "MIT" + s.name = "clearance" + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.required_ruby_version = Gem::Requirement.new(">= 2.4.0") + s.summary = "Rails authentication & authorization with email & password." s.version = Clearance::VERSION end diff --git a/config/routes.rb b/config/routes.rb index 08de03e34..69af65225 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,15 @@ if Clearance.configuration.routes_enabled? Rails.application.routes.draw do resources :passwords, - controller: 'clearance/passwords', + controller: "clearance/passwords", only: [:create, :new] resource :session, - controller: 'clearance/sessions', + controller: "clearance/sessions", only: [:create] resources :users, - controller: 'clearance/users', + controller: "clearance/users", only: Clearance.configuration.user_actions do if Clearance.configuration.allow_password_reset? resource :password, @@ -18,11 +18,11 @@ end end - get '/sign_in' => 'clearance/sessions#new', as: 'sign_in' - delete '/sign_out' => 'clearance/sessions#destroy', as: 'sign_out' + get "/sign_in" => "clearance/sessions#new", :as => "sign_in" + delete "/sign_out" => "clearance/sessions#destroy", :as => "sign_out" if Clearance.configuration.allow_sign_up? - get '/sign_up' => 'clearance/users#new', as: 'sign_up' + get "/sign_up" => "clearance/users#new", :as => "sign_up" end end end diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index fa52260cf..246e6dffd 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -15,6 +15,7 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" +gem "standard" gem "timecop" gem "railties", "~> 6.1.0" gem "net-smtp", require: false diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index 5b6bc25d9..3fb7cf948 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -15,6 +15,7 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" +gem "standard" gem "timecop" gem "railties", "~> 7.0.0" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile index a39b7c9c2..78aaf7603 100644 --- a/gemfiles/rails_7.1.gemfile +++ b/gemfiles/rails_7.1.gemfile @@ -15,6 +15,7 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" +gem "standard" gem "timecop" gem "railties", "~> 7.1.0" diff --git a/lib/clearance/authentication.rb b/lib/clearance/authentication.rb index b3c1f2eb4..db81fb447 100644 --- a/lib/clearance/authentication.rb +++ b/lib/clearance/authentication.rb @@ -62,8 +62,8 @@ def current_user # # Signing in will also regenerate the CSRF token for the current session, # provided {Configuration#rotate_csrf_on_sign_in?} is set. - def sign_in(user, &block) - clearance_session.sign_in(user, &block) + def sign_in(user, &) + clearance_session.sign_in(user, &) if signed_in? && Clearance.configuration.rotate_csrf_on_sign_in? if request.respond_to?(:reset_csrf_token) diff --git a/lib/clearance/authorization.rb b/lib/clearance/authorization.rb index 87c3c3eb3..21ea1db4e 100644 --- a/lib/clearance/authorization.rb +++ b/lib/clearance/authorization.rb @@ -77,8 +77,8 @@ def store_location end # @api private - def redirect_back_or(default, **options) - redirect_to(return_to || default, **options) + def redirect_back_or(default, **) + redirect_to(return_to || default, **) clear_return_to end diff --git a/lib/clearance/back_door.rb b/lib/clearance/back_door.rb index 7736e91d8..f90bee082 100644 --- a/lib/clearance/back_door.rb +++ b/lib/clearance/back_door.rb @@ -79,13 +79,13 @@ def allowed_environments # @api private def error_message - unless allowed_environments.empty? + if allowed_environments.empty? + "BackDoor auth is disabled." + else <<-EOS.squish Can't use auth backdoor outside of configured environments (#{allowed_environments.join(", ")}). EOS - else - "BackDoor auth is disabled." end end end diff --git a/lib/clearance/configuration.rb b/lib/clearance/configuration.rb index 75e564f06..ac121ace5 100644 --- a/lib/clearance/configuration.rb +++ b/lib/clearance/configuration.rb @@ -157,11 +157,11 @@ def initialize @cookie_domain = nil @cookie_expiration = ->(cookies) { 1.year.from_now.utc } @cookie_name = "remember_token" - @cookie_path = '/' + @cookie_path = "/" @httponly = true @same_site = nil - @mailer_sender = 'reply@example.com' - @redirect_url = '/' + @mailer_sender = "reply@example.com" + @redirect_url = "/" @url_after_destroy = nil @url_after_denied_access_when_signed_out = nil @rotate_csrf_on_sign_in = true @@ -213,7 +213,7 @@ def allow_password_reset? # This will be `[:create]` is `allow_sign_up` is true (the default), and # empty otherwise. # @return [Array] - def user_actions + def user_actions if allow_sign_up? [:create] else @@ -234,7 +234,7 @@ def user_parameter # In the default configuration, this is `user_id`. # @return [Symbol] def user_id_parameter - "#{user_parameter}_id".to_sym + :"#{user_parameter}_id" end # @return [Boolean] are Clearance's built-in routes enabled? diff --git a/lib/clearance/constraints.rb b/lib/clearance/constraints.rb index 199ce0333..b2ac2715d 100644 --- a/lib/clearance/constraints.rb +++ b/lib/clearance/constraints.rb @@ -1,5 +1,5 @@ -require 'clearance/constraints/signed_in' -require 'clearance/constraints/signed_out' +require "clearance/constraints/signed_in" +require "clearance/constraints/signed_out" module Clearance # Clearance provides Rails routing constraints that can control access and the diff --git a/lib/clearance/controller.rb b/lib/clearance/controller.rb index 5ba57684a..b9a051558 100644 --- a/lib/clearance/controller.rb +++ b/lib/clearance/controller.rb @@ -1,5 +1,5 @@ -require 'clearance/authentication' -require 'clearance/authorization' +require "clearance/authentication" +require "clearance/authorization" module Clearance # Adds clearance controller helpers to the controller it is mixed into. diff --git a/lib/clearance/default_sign_in_guard.rb b/lib/clearance/default_sign_in_guard.rb index e9fcba15a..2c0a95d89 100644 --- a/lib/clearance/default_sign_in_guard.rb +++ b/lib/clearance/default_sign_in_guard.rb @@ -29,7 +29,7 @@ def default_failure_message I18n.t( :bad_email_or_password, scope: [:clearance, :controllers, :sessions], - default: I18n.t('flashes.failure_after_create').html_safe + default: I18n.t("flashes.failure_after_create").html_safe ) end end diff --git a/lib/clearance/password_strategies/bcrypt.rb b/lib/clearance/password_strategies/bcrypt.rb index 98e2911c9..6d15009d5 100644 --- a/lib/clearance/password_strategies/bcrypt.rb +++ b/lib/clearance/password_strategies/bcrypt.rb @@ -11,7 +11,7 @@ module PasswordStrategies # by setting a higher cost in an initializer: # `BCrypt::Engine.cost = 12` module BCrypt - require 'bcrypt' + require "bcrypt" def authenticated?(password) if encrypted_password.present? @@ -25,7 +25,7 @@ def password=(new_password) if new_password.present? self.encrypted_password = ::BCrypt::Password.create( new_password, - cost: configured_bcrypt_cost, + cost: configured_bcrypt_cost ) end end diff --git a/lib/clearance/session.rb b/lib/clearance/session.rb index 85142df88..df529ff3f 100644 --- a/lib/clearance/session.rb +++ b/lib/clearance/session.rb @@ -1,4 +1,4 @@ -require 'clearance/default_sign_in_guard' +require "clearance/default_sign_in_guard" module Clearance # Represents a clearance session, ultimately persisted in @@ -57,7 +57,7 @@ def sign_in(user, &block) @current_user = nil end - if block_given? + if block block.call(status) end end @@ -89,7 +89,7 @@ def signed_in? # # @return [Boolean] def signed_out? - ! signed_in? + !signed_in? end # True if a successful authentication has been performed @@ -179,7 +179,7 @@ def cookie_options(value) same_site: Clearance.configuration.same_site, path: Clearance.configuration.cookie_path, secure: Clearance.configuration.secure_cookie, - value: value, + value: value } end diff --git a/lib/clearance/sign_in_guard.rb b/lib/clearance/sign_in_guard.rb index 709cfdfb1..d946ec4c5 100644 --- a/lib/clearance/sign_in_guard.rb +++ b/lib/clearance/sign_in_guard.rb @@ -1,4 +1,4 @@ -require 'clearance/session_status' +require "clearance/session_status" module Clearance # The base class for {DefaultSignInGuard} and all custom sign in guards. diff --git a/lib/clearance/testing/deny_access_matcher.rb b/lib/clearance/testing/deny_access_matcher.rb index dfa9cc260..b75ce0058 100644 --- a/lib/clearance/testing/deny_access_matcher.rb +++ b/lib/clearance/testing/deny_access_matcher.rb @@ -43,12 +43,12 @@ def initialize(context, opts) @flash = opts[:flash] @url = opts[:redirect] - @failure_message = '' - @failure_message_when_negated = '' + @failure_message = "" + @failure_message_when_negated = "" end def description - 'deny access' + "deny access" end def matches?(controller) @@ -104,7 +104,7 @@ def sets_the_flash? "Didn't expect to set the flash to #{@flash}" true else - @failure_message << "Expected the flash to be set to #{@flash} "\ + @failure_message << "Expected the flash to be set to #{@flash} " \ "but was #{flash_alert_value}" false end diff --git a/lib/clearance/token.rb b/lib/clearance/token.rb index 74eb49453..fae71d5cb 100644 --- a/lib/clearance/token.rb +++ b/lib/clearance/token.rb @@ -8,7 +8,7 @@ class Token # # @return [String] def self.new - SecureRandom.hex(20).encode('UTF-8') + SecureRandom.hex(20).encode("UTF-8") end end end diff --git a/lib/clearance/user.rb b/lib/clearance/user.rb index 7597452f2..07f559296 100644 --- a/lib/clearance/user.rb +++ b/lib/clearance/user.rb @@ -1,7 +1,7 @@ -require 'digest/sha1' -require 'active_model' -require 'email_validator' -require 'clearance/token' +require "digest/sha1" +require "active_model" +require "email_validator" +require "clearance/token" module Clearance # Required to be included in your configued user class, which is `User` by @@ -152,7 +152,7 @@ module Validations validates :email, email: { mode: :strict }, presence: true, - uniqueness: { allow_blank: true, case_sensitive: true }, + uniqueness: {allow_blank: true, case_sensitive: true}, unless: :email_optional? validates :password, presence: true, unless: :skip_password_validation? diff --git a/lib/generators/clearance/install/install_generator.rb b/lib/generators/clearance/install/install_generator.rb index 1722f92a8..37b9c0617 100644 --- a/lib/generators/clearance/install/install_generator.rb +++ b/lib/generators/clearance/install/install_generator.rb @@ -1,14 +1,14 @@ -require 'rails/generators/base' -require 'rails/generators/active_record' +require "rails/generators/base" +require "rails/generators/active_record" module Clearance module Generators class InstallGenerator < Rails::Generators::Base include Rails::Generators::Migration - source_root File.expand_path('../templates', __FILE__) + source_root File.expand_path("../templates", __FILE__) def create_clearance_initializer - copy_file 'clearance.rb', 'config/initializers/clearance.rb' + copy_file "clearance.rb", "config/initializers/clearance.rb" end def inject_clearance_into_application_controller @@ -24,7 +24,7 @@ def create_or_inject_clearance_into_user_model inject_into_file( "app/models/user.rb", " include Clearance::User\n\n", - after: "class User < #{models_inherit_from}\n", + after: "class User < #{models_inherit_from}\n" ) else @inherit_from = models_inherit_from @@ -41,7 +41,7 @@ def create_clearance_migration end def display_readme_in_terminal - readme 'README' + readme "README" end private @@ -62,7 +62,7 @@ def copy_migration(migration_name, config = {}) migration_template( "db/migrate/#{migration_name}.rb.erb", "db/migrate/#{migration_name}.rb", - config.merge(migration_version: migration_version), + config.merge(migration_version: migration_version) ) end end @@ -76,7 +76,7 @@ def new_columns email: "t.string :email", encrypted_password: "t.string :encrypted_password, limit: 128", confirmation_token: "t.string :confirmation_token, limit: 128", - remember_token: "t.string :remember_token, limit: 128", + remember_token: "t.string :remember_token, limit: 128" }.reject { |column| existing_users_columns.include?(column.to_s) } end @@ -87,7 +87,7 @@ def new_indexes index_users_on_confirmation_token: "add_index :users, :confirmation_token, unique: true", index_users_on_remember_token: - "add_index :users, :remember_token, unique: true", + "add_index :users, :remember_token, unique: true" }.reject { |index| existing_users_indexes.include?(index.to_s) } end @@ -102,7 +102,7 @@ def existing_migrations end def migration_name_without_timestamp(file) - file.sub(%r{^.*(db/migrate/)(?:\d+_)?}, '') + file.sub(%r{^.*(db/migrate/)(?:\d+_)?}, "") end def users_table_exists? diff --git a/lib/generators/clearance/routes/routes_generator.rb b/lib/generators/clearance/routes/routes_generator.rb index dbe902124..b66b1b2f2 100644 --- a/lib/generators/clearance/routes/routes_generator.rb +++ b/lib/generators/clearance/routes/routes_generator.rb @@ -1,9 +1,9 @@ -require 'rails/generators/base' +require "rails/generators/base" module Clearance module Generators class RoutesGenerator < Rails::Generators::Base - source_root File.expand_path('../templates', __FILE__) + source_root File.expand_path("../templates", __FILE__) def inject_clearance_routes_into_application_routes route(clearance_routes) @@ -13,7 +13,7 @@ def disable_clearance_internal_routes inject_into_file( "config/initializers/clearance.rb", " config.routes = false\n", - after: "Clearance.configure do |config|\n", + after: "Clearance.configure do |config|\n" ) end @@ -24,7 +24,7 @@ def clearance_routes end def routes_file_path - File.expand_path(find_in_source_paths('routes.rb')) + File.expand_path(find_in_source_paths("routes.rb")) end def route(routing_code) @@ -37,7 +37,7 @@ def route(routing_code) routing_code, after: sentinel, verbose: false, - force: true, + force: true ) end end diff --git a/lib/generators/clearance/routes/templates/routes.rb b/lib/generators/clearance/routes/templates/routes.rb index 04caf2677..542a66cc3 100644 --- a/lib/generators/clearance/routes/templates/routes.rb +++ b/lib/generators/clearance/routes/templates/routes.rb @@ -1,12 +1,12 @@ - resources :passwords, controller: "clearance/passwords", only: [:create, :new] - resource :session, controller: "clearance/sessions", only: [:create] +resources :passwords, controller: "clearance/passwords", only: [:create, :new] +resource :session, controller: "clearance/sessions", only: [:create] - resources :users, controller: "clearance/users", only: [:create] do - resource :password, - controller: "clearance/passwords", - only: [:edit, :update] - end +resources :users, controller: "clearance/users", only: [:create] do + resource :password, + controller: "clearance/passwords", + only: [:edit, :update] +end - get "/sign_in" => "clearance/sessions#new", as: "sign_in" - delete "/sign_out" => "clearance/sessions#destroy", as: "sign_out" - get "/sign_up" => "clearance/users#new", as: "sign_up" +get "/sign_in" => "clearance/sessions#new", :as => "sign_in" +delete "/sign_out" => "clearance/sessions#destroy", :as => "sign_out" +get "/sign_up" => "clearance/users#new", :as => "sign_up" diff --git a/lib/generators/clearance/specs/specs_generator.rb b/lib/generators/clearance/specs/specs_generator.rb index a7fd1eef2..9dbe107c2 100644 --- a/lib/generators/clearance/specs/specs_generator.rb +++ b/lib/generators/clearance/specs/specs_generator.rb @@ -1,14 +1,14 @@ -require 'rails/generators/base' -require 'rspec/rails/version' +require "rails/generators/base" +require "rspec/rails/version" module Clearance module Generators class SpecsGenerator < Rails::Generators::Base - source_root File.expand_path('../templates', __FILE__) + source_root File.expand_path("../templates", __FILE__) def create_specs @helper_file = rspec_helper_file - directory '.', 'spec' + directory ".", "spec" end private diff --git a/lib/generators/clearance/views/views_generator.rb b/lib/generators/clearance/views/views_generator.rb index 94692d426..9ce682f9f 100644 --- a/lib/generators/clearance/views/views_generator.rb +++ b/lib/generators/clearance/views/views_generator.rb @@ -1,4 +1,4 @@ -require 'rails/generators/base' +require "rails/generators/base" module Clearance module Generators @@ -20,18 +20,18 @@ def create_locales private def views - files_within_root('.', 'app/views/**/*.*') + files_within_root(".", "app/views/**/*.*") end def locales - files_within_root('.', 'config/locales/**/*.*') + files_within_root(".", "config/locales/**/*.*") end def files_within_root(prefix, glob) root = "#{self.class.source_root}/#{prefix}" Dir["#{root}/#{glob}"].sort.map do |full_path| - full_path.sub(root, '.').gsub('/./', '/') + full_path.sub(root, ".").gsub("/./", "/") end end end diff --git a/spec/acceptance/clearance_installation_spec.rb b/spec/acceptance/clearance_installation_spec.rb index c38df68e7..f6a3c4a1c 100644 --- a/spec/acceptance/clearance_installation_spec.rb +++ b/spec/acceptance/clearance_installation_spec.rb @@ -67,10 +67,10 @@ def run_specs end def successfully(command, silent = true) - if silent - silencer = "1>/dev/null" + silencer = if silent + "1>/dev/null" else - silencer = "" + "" end return_value = system("#{command} #{silencer}") diff --git a/spec/clearance/back_door_spec.rb b/spec/clearance/back_door_spec.rb index 90503aed2..08d672164 100644 --- a/spec/clearance/back_door_spec.rb +++ b/spec/clearance/back_door_spec.rb @@ -40,8 +40,8 @@ it "can't be used outside the allowed environments" do with_environment("production") do - expect { Clearance::BackDoor.new(mock_app) }. - to raise_exception "Can't use auth backdoor outside of configured \ + expect { Clearance::BackDoor.new(mock_app) } + .to raise_exception "Can't use auth backdoor outside of configured \ environments (test, ci, development).".squish end end @@ -65,15 +65,15 @@ it "raises an error for a default allowed env" do with_environment("test") do - expect { Clearance::BackDoor.new(mock_app) }. - to raise_exception "BackDoor auth is disabled." + expect { Clearance::BackDoor.new(mock_app) } + .to raise_exception "BackDoor auth is disabled." end end end context "when the environments are not defaults" do before do - Clearance.configuration.allowed_backdoor_environments = ['demo'] + Clearance.configuration.allowed_backdoor_environments = ["demo"] end it "can be used with configured allowed environments" do diff --git a/spec/clearance/constraints/signed_in_spec.rb b/spec/clearance/constraints/signed_in_spec.rb index 71218a724..d02ae1728 100644 --- a/spec/clearance/constraints/signed_in_spec.rb +++ b/spec/clearance/constraints/signed_in_spec.rb @@ -1,55 +1,55 @@ -require 'spec_helper' +require "spec_helper" describe Clearance::Constraints::SignedIn do - it 'returns true when user is signed in' do + it "returns true when user is signed in" do user = create(:user) constraint = Clearance::Constraints::SignedIn.new request = request_with_remember_token(user.remember_token) expect(constraint.matches?(request)).to eq true end - it 'returns false when user is not signed in' do + it "returns false when user is not signed in" do constraint = Clearance::Constraints::SignedIn.new request = request_without_remember_token expect(constraint.matches?(request)).to eq false end - it 'returns false when clearance session data is not present' do + it "returns false when clearance session data is not present" do constraint = Clearance::Constraints::SignedIn.new request = Rack::Request.new({}) expect(constraint.matches?(request)).to eq false end - it 'yields a signed-in user to a provided block' do - user = create(:user, email: 'before@example.com') + it "yields a signed-in user to a provided block" do + user = create(:user, email: "before@example.com") constraint = Clearance::Constraints::SignedIn.new do |signed_in_user| - signed_in_user.update_attribute :email, 'after@example.com' + signed_in_user.update_attribute :email, "after@example.com" end constraint.matches?(request_with_remember_token(user.remember_token)) - expect(user.reload.email).to eq 'after@example.com' + expect(user.reload.email).to eq "after@example.com" end - it 'does not yield a user if they are not signed in' do - user = create(:user, email: 'before@example.com') + it "does not yield a user if they are not signed in" do + user = create(:user, email: "before@example.com") constraint = Clearance::Constraints::SignedIn.new do |signed_in_user| - signed_in_user.update_attribute :email, 'after@example.com' + signed_in_user.update_attribute :email, "after@example.com" end constraint.matches?(request_without_remember_token) - expect(user.reload.email).to eq 'before@example.com' + expect(user.reload.email).to eq "before@example.com" end - it 'matches if the user-provided block returns true' do + it "matches if the user-provided block returns true" do user = create(:user) constraint = Clearance::Constraints::SignedIn.new { true } request = request_with_remember_token(user.remember_token) expect(constraint.matches?(request)).to eq true end - it 'does not match if the user-provided block returns false' do + it "does not match if the user-provided block returns false" do user = create(:user) constraint = Clearance::Constraints::SignedIn.new { false } request = request_with_remember_token(user.remember_token) diff --git a/spec/clearance/constraints/signed_out_spec.rb b/spec/clearance/constraints/signed_out_spec.rb index d8b585a0e..4901424f1 100644 --- a/spec/clearance/constraints/signed_out_spec.rb +++ b/spec/clearance/constraints/signed_out_spec.rb @@ -1,20 +1,20 @@ -require 'spec_helper' +require "spec_helper" describe Clearance::Constraints::SignedOut do - it 'returns true when user is signed out' do + it "returns true when user is signed out" do constraint = Clearance::Constraints::SignedOut.new request = request_without_remember_token expect(constraint.matches?(request)).to eq true end - it 'returns false when user is not signed out' do + it "returns false when user is not signed out" do user = create(:user) constraint = Clearance::Constraints::SignedOut.new request = request_with_remember_token(user.remember_token) expect(constraint.matches?(request)).to eq false end - it 'returns true when clearance info is missing from request' do + it "returns true when clearance info is missing from request" do constraint = Clearance::Constraints::SignedOut.new request = Rack::Request.new({}) expect(constraint.matches?(request)).to eq true diff --git a/spec/clearance/default_sign_in_guard_spec.rb b/spec/clearance/default_sign_in_guard_spec.rb index 955e0fa0a..9b1d2f7e4 100644 --- a/spec/clearance/default_sign_in_guard_spec.rb +++ b/spec/clearance/default_sign_in_guard_spec.rb @@ -1,8 +1,8 @@ -require 'spec_helper' +require "spec_helper" describe Clearance::DefaultSignInGuard do - context 'session is signed in' do - it 'returns success' do + context "session is signed in" do + it "returns success" do session = double("Session", signed_in?: true) guard = Clearance::DefaultSignInGuard.new(session) @@ -10,8 +10,8 @@ end end - context 'session is not signed in' do - it 'returns failure' do + context "session is not signed in" do + it "returns failure" do session = double("Session", signed_in?: false) guard = Clearance::DefaultSignInGuard.new(session) @@ -23,6 +23,6 @@ end def default_failure_message - I18n.t('flashes.failure_after_create').html_safe + I18n.t("flashes.failure_after_create").html_safe end end diff --git a/spec/clearance/rack_session_spec.rb b/spec/clearance/rack_session_spec.rb index 4d735f2b5..37810924e 100644 --- a/spec/clearance/rack_session_spec.rb +++ b/spec/clearance/rack_session_spec.rb @@ -1,21 +1,21 @@ -require 'spec_helper' +require "spec_helper" describe Clearance::RackSession do - it 'injects a clearance session into the environment' do - headers = { 'X-Roaring-Lobster' => 'Red' } + it "injects a clearance session into the environment" do + headers = {"X-Roaring-Lobster" => "Red"} app = Rack::Builder.new do use Clearance::RackSession run lambda { |env| Rack::Response.new(env[:clearance], 200, headers).finish } end - env = Rack::MockRequest.env_for('/') + env = Rack::MockRequest.env_for("/") expected_session = "the session" allow(expected_session).to receive(:add_cookie_to_headers) - allow(expected_session).to receive(:authentication_successful?). - and_return(true) - allow(Clearance::Session).to receive(:new). - with(env). - and_return(expected_session) + allow(expected_session).to receive(:authentication_successful?) + .and_return(true) + allow(Clearance::Session).to receive(:new) + .with(env) + .and_return(expected_session) response = Rack::MockResponse.new(*app.call(env)) diff --git a/spec/clearance/session_spec.rb b/spec/clearance/session_spec.rb index ec5517f21..0218b8a52 100644 --- a/spec/clearance/session_spec.rb +++ b/spec/clearance/session_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Clearance::Session do before { Timecop.freeze } @@ -7,7 +7,7 @@ let(:session) { Clearance::Session.new(env_without_remember_token) } let(:user) { create(:user) } - it 'finds a user from a cookie' do + it "finds a user from a cookie" do user = create(:user) env = env_with_remember_token(user.remember_token) session = Clearance::Session.new(env) @@ -16,15 +16,15 @@ expect(session.current_user).to eq user end - it 'returns nil for an unknown user' do - env = env_with_remember_token('bogus') + it "returns nil for an unknown user" do + env = env_with_remember_token("bogus") session = Clearance::Session.new(env) expect(session).to be_signed_out expect(session.current_user).to be_nil end - it 'returns nil without a remember token' do + it "returns nil without a remember token" do expect(session).to be_signed_out expect(session.current_user).to be_nil end @@ -71,7 +71,7 @@ context "signed cookie exists" do it "uses cookies.signed[remember_token]" do - cookie_jar = { "remember_token" => "signed cookie" } + cookie_jar = {"remember_token" => "signed cookie"} expect(session).to receive(:cookies).and_return(cookie_jar) expect(cookie_jar).to receive(:signed).and_return(cookie_jar) @@ -81,7 +81,7 @@ context "signed cookie does not exist yet" do it "uses cookies[remember_token] instead" do - cookie_jar = { "remember_token" => "signed cookie" } + cookie_jar = {"remember_token" => "signed cookie"} # first call will try to get the signed cookie expect(session).to receive(:cookies).and_return(cookie_jar) # ... but signed_cookie doesn't exist @@ -94,8 +94,8 @@ end end - describe '#sign_in' do - it 'sets current_user' do + describe "#sign_in" do + it "sets current_user" do user = build(:user) session.sign_in user @@ -103,8 +103,8 @@ expect(session.current_user).to eq user end - context 'with a block' do - it 'passes the success status to the block when sign in succeeds' do + context "with a block" do + it "passes the success status to the block when sign in succeeds" do success_status = stub_status(Clearance::SuccessStatus, true) success_lambda = stub_callable @@ -113,7 +113,7 @@ expect(success_lambda).to have_been_called.with(success_status) end - it 'passes the failure status to the block when sign in fails' do + it "passes the failure status to the block when sign in fails" do failure_status = stub_status(Clearance::FailureStatus, false) failure_lambda = stub_callable @@ -135,17 +135,16 @@ def stub_callable end end - context 'with nil argument' do - it 'assigns current_user' do + context "with nil argument" do + it "assigns current_user" do session.sign_in nil expect(session.current_user).to be_nil end end - context 'with a sign in stack' do - - it 'runs the first guard' do + context "with a sign in stack" do + it "runs the first guard" do guard = stub_sign_in_guard(succeed: true) user = build(:user) @@ -154,13 +153,13 @@ def stub_callable expect(guard).to have_received(:call) end - it 'will not sign in the user if the guard stack fails' do + it "will not sign in the user if the guard stack fails" do stub_sign_in_guard(succeed: false) user = build(:user) session.sign_in user - expect(session.instance_variable_get("@cookies")).to be_nil + expect(session.instance_variable_get(:@cookies)).to be_nil expect(session.current_user).to be_nil end @@ -174,23 +173,23 @@ def stub_sign_in_guard(options) def stub_default_sign_in_guard double("default_sign_in_guard").tap do |sign_in_guard| - allow(Clearance::DefaultSignInGuard).to receive(:new). - with(session). - and_return(sign_in_guard) + allow(Clearance::DefaultSignInGuard).to receive(:new) + .with(session) + .and_return(sign_in_guard) end end def stub_guard_class(guard) double("guard_class").tap do |guard_class| - allow(guard_class).to receive(:to_s). - and_return(guard_class) + allow(guard_class).to receive(:to_s) + .and_return(guard_class) - allow(guard_class).to receive(:constantize). - and_return(guard_class) + allow(guard_class).to receive(:constantize) + .and_return(guard_class) - allow(guard_class).to receive(:new). - with(session, stub_default_sign_in_guard). - and_return(guard) + allow(guard_class).to receive(:new) + .with(session, stub_default_sign_in_guard) + .and_return(guard) end end @@ -204,25 +203,25 @@ def stub_status(success) end end - context 'if httponly is set' do + context "if httponly is set" do before do session.sign_in(user) end - it 'sets a httponly cookie' do + it "sets a httponly cookie" do session.add_cookie_to_headers expect(remember_token_cookie(session)[:httponly]).to be_truthy end end - context 'if httponly is not set' do + context "if httponly is not set" do before do Clearance.configuration.httponly = false session.sign_in(user) end - it 'sets a standard cookie' do + it "sets a standard cookie" do session.add_cookie_to_headers expect(remember_token_cookie(session)[:httponly]).to be_falsey @@ -254,9 +253,9 @@ def stub_status(success) end end - describe 'remember token cookie expiration' do - context 'default configuration' do - it 'is set to 1 year from now' do + describe "remember token cookie expiration" do + context "default configuration" do + it "is set to 1 year from now" do user = double("User", remember_token: "123abc") session = Clearance::Session.new(env_without_remember_token) session.sign_in user @@ -266,15 +265,15 @@ def stub_status(success) end end - context 'configured with lambda taking one argument' do - it 'it can use other cookies to set the value of the expires token' do + context "configured with lambda taking one argument" do + it "it can use other cookies to set the value of the expires token" do remembered_expires = 12.hours.from_now expires_at = ->(cookies) do - cookies['remember_me'] ? remembered_expires : nil + cookies["remember_me"] ? remembered_expires : nil end with_custom_expiration expires_at do user = double("User", remember_token: "123abc") - environment = env_with_cookies(remember_me: 'true') + environment = env_with_cookies(remember_me: "true") session = Clearance::Session.new(environment) session.sign_in user session.add_cookie_to_headers @@ -287,26 +286,26 @@ def stub_status(success) end end - describe 'secure cookie option' do - context 'when not set' do + describe "secure cookie option" do + context "when not set" do before do session.sign_in(user) end - it 'sets a standard cookie' do + it "sets a standard cookie" do session.add_cookie_to_headers expect(remember_token_cookie(session)[:secure]).to be_falsey end end - context 'when set' do + context "when set" do before do Clearance.configuration.secure_cookie = true session.sign_in(user) end - it 'sets a secure cookie' do + it "sets a secure cookie" do session.add_cookie_to_headers expect(remember_token_cookie(session)[:secure]).to be_truthy @@ -342,10 +341,10 @@ def stub_status(success) end end - context 'when not set' do + context "when not set" do before { session.sign_in(user) } - it 'sets a standard cookie' do + it "sets a standard cookie" do session.add_cookie_to_headers expect(remember_token_cookie(session)[:domain]).to be_nil @@ -353,24 +352,24 @@ def stub_status(success) end end - describe 'cookie path option' do - context 'when not set' do + describe "cookie path option" do + context "when not set" do before { session.sign_in(user) } - it 'sets a standard cookie' do + it "sets a standard cookie" do session.add_cookie_to_headers expect(remember_token_cookie(session)[:domain]).to be_nil end end - context 'when set' do + context "when set" do before do - Clearance.configuration.cookie_path = '/user' + Clearance.configuration.cookie_path = "/user" session.sign_in(user) end - it 'sets a standard cookie' do + it "sets a standard cookie" do session.add_cookie_to_headers expect(remember_token_cookie(session)[:path]).to eq("/user") @@ -378,7 +377,7 @@ def stub_status(success) end end - it 'does not set a remember token when signed out' do + it "does not set a remember token when signed out" do session = Clearance::Session.new(env_without_remember_token) session.add_cookie_to_headers expect(remember_token_cookie(session)).to be_nil @@ -411,7 +410,7 @@ def stub_status(success) user = create(:user) env = env_with_remember_token( value: user.remember_token, - domain: domain, + domain: domain ) session = Clearance::Session.new(env) cookie_jar = ActionDispatch::Request.new(env).cookie_jar @@ -423,9 +422,9 @@ def stub_status(success) end end - context 'with callable cookie domain' do - it 'clears cookie' do - domain = '.example.com' + context "with callable cookie domain" do + it "clears cookie" do + domain = ".example.com" Clearance.configuration.cookie_domain = ->(_) { domain } user = create(:user) env = env_with_remember_token( @@ -454,11 +453,11 @@ def remember_token_cookie(session, cookie_name = "remember_token") end def env_with_cookies(cookies) - Rack::MockRequest.env_for '/', 'HTTP_COOKIE' => serialize_cookies(cookies) + Rack::MockRequest.env_for "/", "HTTP_COOKIE" => serialize_cookies(cookies) end def env_with_remember_token(token) - env_with_cookies 'remember_token' => token + env_with_cookies "remember_token" => token end def env_without_remember_token @@ -472,8 +471,7 @@ def serialize_cookies(hash) Rack::Utils.set_cookie_header! header, key, value end - cookie = header["set-cookie"] || header["Set-Cookie"] - cookie + header["set-cookie"] || header["Set-Cookie"] end def have_been_called diff --git a/spec/clearance/sign_in_guard_spec.rb b/spec/clearance/sign_in_guard_spec.rb index aa728657c..4cb515abc 100644 --- a/spec/clearance/sign_in_guard_spec.rb +++ b/spec/clearance/sign_in_guard_spec.rb @@ -1,8 +1,8 @@ -require 'spec_helper' +require "spec_helper" module Clearance describe SignInGuard do - it 'handles success' do + it "handles success" do sign_in_guard = SignInGuard.new(double("session")) status = double("status") allow(SuccessStatus).to receive(:new).and_return(status) @@ -10,18 +10,18 @@ module Clearance expect(sign_in_guard.success).to eq(status) end - it 'handles failure' do + it "handles failure" do sign_in_guard = SignInGuard.new(double("session")) status = double("status") failure_message = "Failed" - allow(FailureStatus).to receive(:new). - with(failure_message). - and_return(status) + allow(FailureStatus).to receive(:new) + .with(failure_message) + .and_return(status) expect(sign_in_guard.failure(failure_message)).to eq(status) end - it 'can proceed to the next guard' do + it "can proceed to the next guard" do guards = double("guards", call: true) sign_in_guard = SignInGuard.new(double("session"), guards) sign_in_guard.next_guard diff --git a/spec/clearance/testing/controller_helpers_spec.rb b/spec/clearance/testing/controller_helpers_spec.rb index dd8820091..21f7a29cc 100644 --- a/spec/clearance/testing/controller_helpers_spec.rb +++ b/spec/clearance/testing/controller_helpers_spec.rb @@ -7,7 +7,7 @@ class TestClass def initialize @request = Class.new do def env - { clearance: Clearance::Session.new({}) } + {clearance: Clearance::Session.new({})} end end.new end @@ -17,8 +17,8 @@ def env it "creates an instance of the clearance user model with FactoryBot" do MyUserModel = Class.new allow(FactoryBot).to receive(:create) - allow(Clearance.configuration).to receive(:user_model). - and_return(MyUserModel) + allow(Clearance.configuration).to receive(:user_model) + .and_return(MyUserModel) TestClass.new.sign_in diff --git a/spec/clearance/testing/deny_access_matcher_spec.rb b/spec/clearance/testing/deny_access_matcher_spec.rb index 4af4bde7d..2c5d2160a 100644 --- a/spec/clearance/testing/deny_access_matcher_spec.rb +++ b/spec/clearance/testing/deny_access_matcher_spec.rb @@ -12,7 +12,7 @@ def index before do Rails.application.routes.draw do resources :pretend_friends, only: :index - get "/sign_in" => "clearance/sessions#new", as: "sign_in" + get "/sign_in" => "clearance/sessions#new", :as => "sign_in" end end diff --git a/spec/clearance/testing/view_helpers_spec.rb b/spec/clearance/testing/view_helpers_spec.rb index 25e329c6c..41dca1c12 100644 --- a/spec/clearance/testing/view_helpers_spec.rb +++ b/spec/clearance/testing/view_helpers_spec.rb @@ -4,8 +4,8 @@ describe "#sign_in" do it "sets the signed in user to a new user object" do user_model = Class.new - allow(Clearance.configuration).to receive(:user_model). - and_return(user_model) + allow(Clearance.configuration).to receive(:user_model) + .and_return(user_model) view = test_view_class.new view.sign_in diff --git a/spec/clearance/token_spec.rb b/spec/clearance/token_spec.rb index 05c91b55e..bb0e405bf 100644 --- a/spec/clearance/token_spec.rb +++ b/spec/clearance/token_spec.rb @@ -1,8 +1,8 @@ -require 'spec_helper' +require "spec_helper" describe Clearance::Token do - it 'is a random hex string' do - token = 'my_token' + it "is a random hex string" do + token = "my_token" allow(SecureRandom).to receive(:hex).with(20).and_return(token) expect(Clearance::Token.new).to eq token diff --git a/spec/controllers/apis_controller_spec.rb b/spec/controllers/apis_controller_spec.rb index abd254ff5..1c65edfd7 100644 --- a/spec/controllers/apis_controller_spec.rb +++ b/spec/controllers/apis_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" class ApisController < ActionController::Base include Clearance::Controller @@ -21,7 +21,7 @@ def show Rails.application.reload_routes! end - it 'responds with HTTP status code 401 when denied' do + it "responds with HTTP status code 401 when denied" do get :show, format: :js expect(subject).to respond_with(:unauthorized) end diff --git a/spec/controllers/forgeries_controller_spec.rb b/spec/controllers/forgeries_controller_spec.rb index 60beed054..569031f16 100644 --- a/spec/controllers/forgeries_controller_spec.rb +++ b/spec/controllers/forgeries_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" class ForgeriesController < ActionController::Base include Clearance::Controller @@ -11,43 +11,43 @@ class ForgeriesController < ActionController::Base self.allow_forgery_protection = true def create - redirect_to action: 'index' + redirect_to action: "index" end end describe ForgeriesController do - context 'signed in user' do + context "signed in user" do before do Rails.application.routes.draw do resources :forgeries - get '/sign_in' => 'clearance/sessions#new', as: 'sign_in' + get "/sign_in" => "clearance/sessions#new", :as => "sign_in" end @user = create(:user) - @user.update_attribute(:remember_token, 'old-token') - @request.cookies['remember_token'] = 'old-token' + @user.update_attribute(:remember_token, "old-token") + @request.cookies["remember_token"] = "old-token" end after do Rails.application.reload_routes! end - it 'succeeds with authentic token' do + it "succeeds with authentic token" do token = controller.send(:form_authenticity_token) post :create, params: { - authenticity_token: token, + authenticity_token: token } - expect(subject).to redirect_to(action: 'index') + expect(subject).to redirect_to(action: "index") end - it 'fails with invalid token' do + it "fails with invalid token" do post :create, params: { - authenticity_token: "hax0r", + authenticity_token: "hax0r" } expect(subject).to deny_access end - it 'fails with no token' do + it "fails with no token" do post :create expect(subject).to deny_access end diff --git a/spec/controllers/passwords_controller_spec.rb b/spec/controllers/passwords_controller_spec.rb index 5557bf3a1..7b383407a 100644 --- a/spec/controllers/passwords_controller_spec.rb +++ b/spec/controllers/passwords_controller_spec.rb @@ -18,7 +18,7 @@ user = create(:user) post :create, params: { - password: { email: user.email.upcase }, + password: {email: user.email.upcase} } expect(user.reload.confirmation_token).not_to be_nil @@ -29,7 +29,7 @@ user = create(:user) post :create, params: { - password: { email: user.email }, + password: {email: user.email} } email = ActionMailer::Base.deliveries.last @@ -40,7 +40,7 @@ user = create(:user) post :create, params: { - password: { email: user.email.upcase }, + password: {email: user.email.upcase} } expect(response).to have_http_status(:accepted) @@ -50,7 +50,7 @@ context "email param is missing" do it "displays flash error on new page" do post :create, params: { - password: {}, + password: {} } expect(flash.now[:alert]).to match(translated_string("flashes.failure_when_missing_email")) @@ -59,7 +59,7 @@ it "re-renders the page when turbo is enabled" do post :create, params: { - password: {}, + password: {} } expect(response).to have_http_status(:unprocessable_entity) @@ -70,8 +70,8 @@ it "displays flash error on new page" do post :create, params: { password: { - email: "", - }, + email: "" + } } expect(flash.now[:alert]).to match(translated_string("flashes.failure_when_missing_email")) @@ -81,8 +81,8 @@ it "re-renders the page when turbo is enabled" do post :create, params: { password: { - email: "", - }, + email: "" + } } expect(response).to have_http_status(:unprocessable_entity) @@ -95,7 +95,7 @@ email = "this_user_does_not_exist@non_existent_domain.com" post :create, params: { - password: { email: email }, + password: {email: email} } expect(ActionMailer::Base.deliveries).to be_empty @@ -105,7 +105,7 @@ email = "this_user_does_not_exist@non_existent_domain.com" post :create, params: { - password: { email: email }, + password: {email: email} } expect(response).to be_successful @@ -116,7 +116,7 @@ email = "this_user_does_not_exist@non_existent_domain.com" post :create, params: { - password: { email: email }, + password: {email: email} } expect(response).to have_http_status(:accepted) @@ -131,7 +131,7 @@ get :edit, params: { user_id: user, - token: user.confirmation_token, + token: user.confirmation_token } expect(response).to be_redirect @@ -147,7 +147,7 @@ request.session[:password_reset_token] = user.confirmation_token get :edit, params: { - user_id: user, + user_id: user } expect(response).to be_successful @@ -160,7 +160,7 @@ it "renders the new password reset form with a flash alert" do get :edit, params: { user_id: 1, - token: "", + token: "" } expect(response).to render_template(:new) @@ -174,7 +174,7 @@ get :edit, params: { user_id: 1, - token: user.confirmation_token + "a", + token: user.confirmation_token + "a" } expect(response).to render_template(:new) @@ -190,7 +190,7 @@ user.forgot_password! get :edit, params: { user_id: user.id, - token: user.reload.confirmation_token, + token: user.reload.confirmation_token } expect(response).to redirect_to(edit_user_password_url(user)) @@ -207,7 +207,7 @@ put :update, params: update_parameters( user, - new_password: "my_new_password", + new_password: "my_new_password" ) expect(user.reload.encrypted_password).not_to eq old_encrypted_password @@ -219,7 +219,7 @@ put :update, params: update_parameters( user, - new_password: "my_new_password", + new_password: "my_new_password" ) expect(current_user).to eq(user) @@ -235,7 +235,7 @@ put :update, params: update_parameters( user, - new_password: "my_new_password", + new_password: "my_new_password" ) expect(current_user).to be_nil @@ -250,7 +250,7 @@ put :update, params: update_parameters( user, - new_password: "", + new_password: "" ) user.reload @@ -265,7 +265,7 @@ put :update, params: { user_id: user, token: user.confirmation_token, - password_reset: {}, + password_reset: {} } end.not_to raise_error end @@ -275,7 +275,7 @@ put :update, params: update_parameters( user, - new_password: "", + new_password: "" ) expect(flash.now[:alert]).to match(translated_string("flashes.failure_after_update")) @@ -288,7 +288,7 @@ put :update, params: update_parameters( user, - new_password: "", + new_password: "" ) expect(current_user).to be_nil @@ -302,7 +302,7 @@ def update_parameters(user, options = {}) { user_id: user, token: user.confirmation_token, - password_reset: { password: new_password } + password_reset: {password: new_password} } end diff --git a/spec/controllers/permissions_controller_spec.rb b/spec/controllers/permissions_controller_spec.rb index d53381774..d56fbc326 100644 --- a/spec/controllers/permissions_controller_spec.rb +++ b/spec/controllers/permissions_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" class PermissionsController < ActionController::Base include Clearance::Controller @@ -18,7 +18,7 @@ def show before do Rails.application.routes.draw do resource :permission, only: [:new, :show] - get '/sign_in' => 'clearance/sessions#new', as: 'sign_in' + get "/sign_in" => "clearance/sessions#new", :as => "sign_in" end end @@ -26,30 +26,30 @@ def show Rails.application.reload_routes! end - context 'with signed in user' do + context "with signed in user" do before { sign_in } - it 'allows access to new' do + it "allows access to new" do get :new expect(subject).not_to deny_access end - it 'allows access to show' do + it "allows access to show" do get :show expect(subject).not_to deny_access end end - context 'with visitor' do - it 'allows access to new' do + context "with visitor" do + it "allows access to new" do get :new expect(subject).not_to deny_access end - it 'denies access to show' do + it "denies access to show" do get :show expect(subject).to deny_access(redirect: sign_in_url) @@ -62,11 +62,11 @@ def show end end - context 'when remember_token is blank' do - it 'denies acess to show' do + context "when remember_token is blank" do + it "denies acess to show" do user = create(:user) - user.update(remember_token: '') - cookies[:remember_token] = '' + user.update(remember_token: "") + cookies[:remember_token] = "" get :show diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index c4fc6944d..3ef9974fd 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -37,7 +37,7 @@ user = create(:user_with_optional_password) post :create, params: { - session: { email: user.email, password: user.password }, + session: {email: user.email, password: user.password} } expect(response).to render_template(:new) @@ -50,7 +50,7 @@ @user = create(:user) @user.update_attribute :remember_token, "old-token" post :create, params: { - session: { email: @user.email, password: @user.password }, + session: {email: @user.email, password: @user.password} } end @@ -73,7 +73,7 @@ request.session[:return_to] = return_url post :create, params: { - session: { email: user.email, password: user.password }, + session: {email: user.email, password: user.password} } should redirect_to(url) @@ -85,7 +85,7 @@ request.session[:return_to] = return_url post :create, params: { - session: { email: user.email, password: user.password }, + session: {email: user.email, password: user.password} } should redirect_to(return_url) @@ -97,7 +97,7 @@ request.session[:return_to] = return_url post :create, params: { - session: { email: user.email, password: user.password }, + session: {email: user.email, password: user.password} } should redirect_to(return_url) @@ -109,7 +109,7 @@ request.session[:return_to] = return_url post :create, params: { - session: { email: user.email, password: user.password }, + session: {email: user.email, password: user.password} } should redirect_to(return_url) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index fc643dd98..11344e253 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -14,7 +14,7 @@ it "defaults email field to the value provided in the query string" do get :new, params: { - user: { email: "a@example.com" }, + user: {email: "a@example.com"} } expect(assigns(:user).email).to eq "a@example.com" @@ -42,7 +42,7 @@ old_user_count = User.count post :create, params: { - user: user_attributes, + user: user_attributes } expect(assigns(:user)).to be_present @@ -59,7 +59,7 @@ @request.session[:return_to] = return_url post :create, params: { - user: user_attributes, + user: user_attributes } expect(assigns(:user)).to be_present @@ -74,7 +74,7 @@ old_user_count = User.count post :create, params: { - user: user_attributes, + user: user_attributes } expect(User.count).to eq old_user_count @@ -88,7 +88,7 @@ sign_in post :create, params: { - user: {}, + user: {} } expect(response).to redirect_to(Clearance.configuration.redirect_url) diff --git a/spec/dummy/application.rb b/spec/dummy/application.rb index 884e27bc5..6613e8a4a 100644 --- a/spec/dummy/application.rb +++ b/spec/dummy/application.rb @@ -7,7 +7,7 @@ module Dummy class Application < Rails::Application config.action_controller.perform_caching = false - config.action_mailer.default_url_options = { host: "dummy.example.com" } + config.action_mailer.default_url_options = {host: "dummy.example.com"} config.action_mailer.delivery_method = :test if Rails.version.match?(/(6.1|7.0)/) config.active_record.legacy_connection_handling = false diff --git a/spec/factories.rb b/spec/factories.rb index 3ee0e82e1..dfb092058 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -5,15 +5,15 @@ factory :user do email - password { 'password' } + password { "password" } trait :with_forgotten_password do confirmation_token { Clearance::Token.new } end - factory :user_with_optional_password, class: 'UserWithOptionalPassword' do + factory :user_with_optional_password, class: "UserWithOptionalPassword" do password { nil } - encrypted_password { '' } + encrypted_password { "" } end end end diff --git a/spec/generators/clearance/install/install_generator_spec.rb b/spec/generators/clearance/install/install_generator_spec.rb index 8c50a8941..4ff2b1912 100644 --- a/spec/generators/clearance/install/install_generator_spec.rb +++ b/spec/generators/clearance/install/install_generator_spec.rb @@ -121,13 +121,13 @@ def get_migration(path) existing_columns = [Struct::Named.new("remember_token")] existing_indexes = [Struct::Named.new("index_users_on_remember_token")] - allow(ActiveRecord::Base.connection).to receive(:columns). - with(:users). - and_return(existing_columns) + allow(ActiveRecord::Base.connection).to receive(:columns) + .with(:users) + .and_return(existing_columns) - allow(ActiveRecord::Base.connection).to receive(:indexes). - with(:users). - and_return(existing_indexes) + allow(ActiveRecord::Base.connection).to receive(:indexes) + .with(:users) + .and_return(existing_indexes) run_generator migration = get_migration("db/migrate/add_clearance_to_users.rb") @@ -140,10 +140,10 @@ def get_migration(path) expect(migration).not_to contain("t.string :remember_token") expect(migration).not_to contain("add_index :users, :remember_token") expect(migration).to( - contain("add_index :users, :confirmation_token, unique: true"), + contain("add_index :users, :confirmation_token, unique: true") ) expect(migration).to( - contain("remove_index :users, :confirmation_token, unique: true"), + contain("remove_index :users, :confirmation_token, unique: true") ) end end @@ -151,9 +151,9 @@ def get_migration(path) def table_does_not_exist(name) connection = ActiveRecord::Base.connection - allow(connection).to receive(:data_source_exists?). - with(name). - and_return(false) + allow(connection).to receive(:data_source_exists?) + .with(name) + .and_return(false) end def preserve_original_primary_key_type_setting diff --git a/spec/generators/clearance/specs/specs_generator_spec.rb b/spec/generators/clearance/specs/specs_generator_spec.rb index 7b43d412e..794bfd122 100644 --- a/spec/generators/clearance/specs/specs_generator_spec.rb +++ b/spec/generators/clearance/specs/specs_generator_spec.rb @@ -5,7 +5,7 @@ it "copies specs to host app" do run_generator - specs = %w( + specs = %w[ factories/clearance features/clearance/user_signs_out_spec features/clearance/visitor_resets_password_spec @@ -14,7 +14,7 @@ features/clearance/visitor_updates_password_spec support/clearance support/features/clearance_helpers - ) + ] spec_files = specs.map { |spec| file("spec/#{spec}.rb") } diff --git a/spec/generators/clearance/views/views_generator_spec.rb b/spec/generators/clearance/views/views_generator_spec.rb index 47cfd3879..28f41a6f0 100644 --- a/spec/generators/clearance/views/views_generator_spec.rb +++ b/spec/generators/clearance/views/views_generator_spec.rb @@ -5,7 +5,7 @@ it "copies clearance views to the host application" do run_generator - views = %w( + views = %w[ clearance_mailer/change_password.html.erb clearance_mailer/change_password.text.erb passwords/create.html.erb @@ -15,7 +15,7 @@ sessions/new.html.erb users/_form.html.erb users/new.html.erb - ) + ] view_files = views.map { |view| file("app/views/#{view}") } diff --git a/spec/mailers/clearance_mailer_spec.rb b/spec/mailers/clearance_mailer_spec.rb index e6b29fe86..14bfb3d51 100644 --- a/spec/mailers/clearance_mailer_spec.rb +++ b/spec/mailers/clearance_mailer_spec.rb @@ -82,7 +82,7 @@ def define_people_routes resource( :password, controller: "clearance/passwords", - only: %i[edit update], + only: %i[edit update] ) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ccaf1f543..f46155265 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -60,7 +60,7 @@ User.authenticate("bad_email@example.com", password) end - expect(user_does_not_exist_time). to be_within(0.01).of(user_exists_time) + expect(user_does_not_exist_time).to be_within(0.01).of(user_exists_time) end it "takes the same amount of time to fail authentication regardless of whether user exists" do @@ -74,7 +74,7 @@ User.authenticate("bad_email@example.com", "bad_password") end - expect(user_does_not_exist_time). to be_within(0.01).of(user_exists_time) + expect(user_does_not_exist_time).to be_within(0.01).of(user_exists_time) end it "is retrieved via a case-insensitive search" do diff --git a/spec/password_strategies/argon2_spec.rb b/spec/password_strategies/argon2_spec.rb index 61133ddba..cb026c767 100644 --- a/spec/password_strategies/argon2_spec.rb +++ b/spec/password_strategies/argon2_spec.rb @@ -16,8 +16,8 @@ it "encrypts with Argon2 using default cost in non test environments" do hasher = stub_argon2_password model_instance = fake_model_with_argon2_strategy - allow(Rails).to receive(:env). - and_return(ActiveSupport::StringInquirer.new("production")) + allow(Rails).to receive(:env) + .and_return(ActiveSupport::StringInquirer.new("production")) model_instance.password = password @@ -69,7 +69,7 @@ def encrypted_password def fake_model_with_argon2_strategy @fake_model_with_argon2_strategy ||= fake_model_with_password_strategy( - Clearance::PasswordStrategies::Argon2, + Clearance::PasswordStrategies::Argon2 ) end diff --git a/spec/password_strategies/bcrypt_spec.rb b/spec/password_strategies/bcrypt_spec.rb index b4308e364..e2669c3af 100644 --- a/spec/password_strategies/bcrypt_spec.rb +++ b/spec/password_strategies/bcrypt_spec.rb @@ -15,14 +15,14 @@ it "encrypts with BCrypt using default cost in non test environments" do stub_bcrypt_password model_instance = fake_model_with_bcrypt_strategy - allow(Rails).to receive(:env). - and_return(ActiveSupport::StringInquirer.new("production")) + allow(Rails).to receive(:env) + .and_return(ActiveSupport::StringInquirer.new("production")) model_instance.password = password expect(BCrypt::Password).to have_received(:create).with( password, - cost: ::BCrypt::Engine::DEFAULT_COST, + cost: ::BCrypt::Engine::DEFAULT_COST ) end diff --git a/spec/requests/authentication_cookie_spec.rb b/spec/requests/authentication_cookie_spec.rb index e6f07d4eb..0a58c8d50 100644 --- a/spec/requests/authentication_cookie_spec.rb +++ b/spec/requests/authentication_cookie_spec.rb @@ -39,8 +39,8 @@ def public def draw_test_routes Rails.application.routes.draw do - get "/private" => "pages#private", as: :private - get "/public" => "pages#public", as: :public + get "/private" => "pages#private", :as => :private + get "/public" => "pages#public", :as => :public resource :session, controller: "clearance/sessions", only: [:create] end end @@ -49,7 +49,7 @@ def create_user_and_sign_in user = create(:user, password: "password") post session_path, params: { - session: { email: user.email, password: "password" }, + session: {email: user.email, password: "password"} } end end diff --git a/spec/requests/cookie_options_spec.rb b/spec/requests/cookie_options_spec.rb index a2213d7e3..c20d1fa6e 100644 --- a/spec/requests/cookie_options_spec.rb +++ b/spec/requests/cookie_options_spec.rb @@ -13,7 +13,7 @@ get sign_in_path post session_path, params: { - session: { email: user.email, password: "password" }, + session: {email: user.email, password: "password"} } end @@ -33,7 +33,7 @@ get sign_in_path post session_path, params: { - session: { email: user.email, password: "password" }, + session: {email: user.email, password: "password"} } end diff --git a/spec/requests/csrf_rotation_spec.rb b/spec/requests/csrf_rotation_spec.rb index 2119c8d67..8da78de21 100644 --- a/spec/requests/csrf_rotation_spec.rb +++ b/spec/requests/csrf_rotation_spec.rb @@ -16,7 +16,7 @@ original_token = csrf_token post session_path, params: { - session: session_params(user, "password"), + session: session_params(user, "password") } expect(csrf_token).not_to eq original_token @@ -30,6 +30,6 @@ def csrf_token end def session_params(user, password) - { email: user.email, password: password, authenticity_token: csrf_token } + {email: user.email, password: password, authenticity_token: csrf_token} end end diff --git a/spec/requests/password_maintenance_spec.rb b/spec/requests/password_maintenance_spec.rb index e7f97b0de..87d14c08e 100644 --- a/spec/requests/password_maintenance_spec.rb +++ b/spec/requests/password_maintenance_spec.rb @@ -8,7 +8,7 @@ put user_password_url(user), params: { user_id: user, token: user.confirmation_token, - password_reset: { password: "my_new_password" }, + password_reset: {password: "my_new_password"} } expect(response).to redirect_to(Clearance.configuration.redirect_url) diff --git a/spec/requests/token_expiration_spec.rb b/spec/requests/token_expiration_spec.rb index 0db8e9d25..950cc09fb 100644 --- a/spec/requests/token_expiration_spec.rb +++ b/spec/requests/token_expiration_spec.rb @@ -15,7 +15,7 @@ it "should have a remember_token cookie with a future expiration" do expect(first_cookie.expires).to be_between( 1.years.from_now - 1.second, - 1.years.from_now, + 1.years.from_now ) end end @@ -53,7 +53,7 @@ def create_user_and_sign_in get sign_in_path post session_path, params: { - session: { email: user.email, password: "password" }, + session: {email: user.email, password: "password"} } end end diff --git a/spec/routing/clearance_routes_spec.rb b/spec/routing/clearance_routes_spec.rb index 633824b95..c18d03919 100644 --- a/spec/routing/clearance_routes_spec.rb +++ b/spec/routing/clearance_routes_spec.rb @@ -1,18 +1,18 @@ -require 'spec_helper' +require "spec_helper" -describe 'routes for Clearance' do - context 'routes enabled' do - it 'draws the default routes' do - expect(get: 'sign_up').to be_routable - expect(get: 'sign_in').to be_routable - expect(get: 'passwords/new').to be_routable - expect(post: 'session').to be_routable - expect(post: 'passwords').to be_routable - expect(post: 'users').to be_routable +describe "routes for Clearance" do + context "routes enabled" do + it "draws the default routes" do + expect(get: "sign_up").to be_routable + expect(get: "sign_in").to be_routable + expect(get: "passwords/new").to be_routable + expect(post: "session").to be_routable + expect(post: "passwords").to be_routable + expect(post: "users").to be_routable end end - context 'routes disabled' do + context "routes disabled" do around do |example| Clearance.configure { |config| config.routes = false } Rails.application.reload_routes! @@ -21,17 +21,17 @@ Rails.application.reload_routes! end - it 'does not draw any routes' do - expect(get: 'sign_up').not_to be_routable - expect(get: 'sign_in').not_to be_routable - expect(get: 'passwords/new').not_to be_routable - expect(post: 'session').not_to be_routable - expect(post: 'passwords').not_to be_routable - expect(post: 'users').not_to be_routable + it "does not draw any routes" do + expect(get: "sign_up").not_to be_routable + expect(get: "sign_in").not_to be_routable + expect(get: "passwords/new").not_to be_routable + expect(post: "session").not_to be_routable + expect(post: "passwords").not_to be_routable + expect(post: "users").not_to be_routable end end - context 'signup disabled' do + context "signup disabled" do around do |example| Clearance.configure { |config| config.allow_sign_up = false } Rails.application.reload_routes! @@ -40,26 +40,26 @@ Rails.application.reload_routes! end - it 'does not route sign_up' do - expect(get: 'sign_up').not_to be_routable + it "does not route sign_up" do + expect(get: "sign_up").not_to be_routable end - it 'does not route to users#create' do - expect(post: 'users').not_to be_routable + it "does not route to users#create" do + expect(post: "users").not_to be_routable end - it 'does not route to users#new' do - expect(get: 'users/new').not_to be_routable + it "does not route to users#new" do + expect(get: "users/new").not_to be_routable end end - context 'signup enabled' do - it 'does route sign_up' do - expect(get: 'sign_up').to be_routable + context "signup enabled" do + it "does route sign_up" do + expect(get: "sign_up").to be_routable end - it 'does route to users#create' do - expect(post: 'users').to be_routable + it "does route to users#create" do + expect(post: "users").to be_routable end end diff --git a/spec/support/clearance.rb b/spec/support/clearance.rb index b6737bb53..4f3dba887 100644 --- a/spec/support/clearance.rb +++ b/spec/support/clearance.rb @@ -1,4 +1,4 @@ -require 'clearance' +require "clearance" Clearance.configure do |config| # need an empty block to initialize the configuration object diff --git a/spec/support/cookies.rb b/spec/support/cookies.rb index fd608b9d5..b5eb23ea4 100644 --- a/spec/support/cookies.rb +++ b/spec/support/cookies.rb @@ -28,7 +28,7 @@ def ensure_expiration_correct end def ensure_path_is_correct - expect(@path).to eq '/' + expect(@path).to eq "/" end def expectation @@ -65,10 +65,6 @@ def parse_value end def result - if @cookie - @cookie - else - @cookie_headers.join("; ") - end + @cookie || @cookie_headers.join("; ") end end diff --git a/spec/support/fake_model_without_password_strategy.rb b/spec/support/fake_model_without_password_strategy.rb index 600ec11ca..744d2d279 100644 --- a/spec/support/fake_model_without_password_strategy.rb +++ b/spec/support/fake_model_without_password_strategy.rb @@ -5,8 +5,11 @@ def fake_model_without_password_strategy validates_with UniquenessValidator - def self.before_validation(*); end - def self.before_create(*); end + def self.before_validation(*) + end + + def self.before_create(*) + end include Clearance::User end.new diff --git a/spec/support/generator_spec_helpers.rb b/spec/support/generator_spec_helpers.rb index 9c296d72d..2ffffed24 100644 --- a/spec/support/generator_spec_helpers.rb +++ b/spec/support/generator_spec_helpers.rb @@ -1,5 +1,5 @@ -require "ammeter/rspec/generator/example.rb" -require "ammeter/rspec/generator/matchers.rb" +require "ammeter/rspec/generator/example" +require "ammeter/rspec/generator/matchers" require "ammeter/init" module GeneratorSpecHelpers diff --git a/spec/support/request_with_remember_token.rb b/spec/support/request_with_remember_token.rb index 8f9dc2fd9..5566ffb5a 100644 --- a/spec/support/request_with_remember_token.rb +++ b/spec/support/request_with_remember_token.rb @@ -7,7 +7,7 @@ def request_with_remember_token(remember_token) cookies[Clearance.configuration.cookie_name] = remember_token end - env = { clearance: Clearance::Session.new(cookies.request.env) } + env = {clearance: Clearance::Session.new(cookies.request.env)} Rack::Request.new env end From 704c14d67962398be526e392864a9315c48313b2 Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Wed, 8 May 2024 15:32:31 -0400 Subject: [PATCH 02/14] fix wrap assignments --- app/controllers/clearance/passwords_controller.rb | 2 +- lib/clearance/session.rb | 4 +--- lib/clearance/user.rb | 2 +- lib/generators/clearance/install/install_generator.rb | 2 +- spec/password_strategies/bcrypt_spec.rb | 2 +- spec/password_strategies/password_strategies_spec.rb | 2 +- spec/support/cookies.rb | 6 +++--- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/controllers/clearance/passwords_controller.rb b/app/controllers/clearance/passwords_controller.rb index 102496010..686929f9c 100644 --- a/app/controllers/clearance/passwords_controller.rb +++ b/app/controllers/clearance/passwords_controller.rb @@ -10,7 +10,7 @@ def new end def create - if user = find_user_for_create + if (user = find_user_for_create) user.forgot_password! deliver_email(user) end diff --git a/lib/clearance/session.rb b/lib/clearance/session.rb index df529ff3f..317250088 100644 --- a/lib/clearance/session.rb +++ b/lib/clearance/session.rb @@ -57,9 +57,7 @@ def sign_in(user, &block) @current_user = nil end - if block - block.call(status) - end + block&.call(status) end # Invalidates the users remember token and removes the remember token cookie diff --git a/lib/clearance/user.rb b/lib/clearance/user.rb index 07f559296..0ba9e43c1 100644 --- a/lib/clearance/user.rb +++ b/lib/clearance/user.rb @@ -113,7 +113,7 @@ def password=(value) # @api private module ClassMethods def authenticate(email, password) - if user = find_by_normalized_email(email) + if (user = find_by_normalized_email(email)) if password.present? && user.authenticated?(password) user end diff --git a/lib/generators/clearance/install/install_generator.rb b/lib/generators/clearance/install/install_generator.rb index 37b9c0617..7a374655a 100644 --- a/lib/generators/clearance/install/install_generator.rb +++ b/lib/generators/clearance/install/install_generator.rb @@ -118,7 +118,7 @@ def existing_users_indexes end # for generating a timestamp when using `create_migration` - def self.next_migration_number(dir) + private_class_method def self.next_migration_number(dir) ActiveRecord::Generators::Base.next_migration_number(dir) end diff --git a/spec/password_strategies/bcrypt_spec.rb b/spec/password_strategies/bcrypt_spec.rb index e2669c3af..d048479f1 100644 --- a/spec/password_strategies/bcrypt_spec.rb +++ b/spec/password_strategies/bcrypt_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" -include FakeModelWithPasswordStrategy describe Clearance::PasswordStrategies::BCrypt do + include FakeModelWithPasswordStrategy describe "#password=" do it "encrypts the password into encrypted_password" do stub_bcrypt_password diff --git a/spec/password_strategies/password_strategies_spec.rb b/spec/password_strategies/password_strategies_spec.rb index d0b3280ae..5d5c2ad7a 100644 --- a/spec/password_strategies/password_strategies_spec.rb +++ b/spec/password_strategies/password_strategies_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" -include FakeModelWithoutPasswordStrategy describe "Password strategy configuration" do + include FakeModelWithoutPasswordStrategy describe "when Clearance.configuration.password_strategy is set" do it "includes the value it is set to" do mock_password_strategy = Module.new diff --git a/spec/support/cookies.rb b/spec/support/cookies.rb index b5eb23ea4..f3e9c6fa3 100644 --- a/spec/support/cookies.rb +++ b/spec/support/cookies.rb @@ -47,19 +47,19 @@ def find_expected_cookie end def parse_expiration - if @cookie && result = @cookie.match(/; expires=(.*?)(;|$)/) + if @cookie && (result = @cookie.match(/; expires=(.*?)(;|$)/)) @expires_at = Time.parse(result[1]) end end def parse_path - if @cookie && result = @cookie.match(/; path=(.*?)(;|$)/) + if @cookie && (result = @cookie.match(/; path=(.*?)(;|$)/)) @path = result[1] end end def parse_value - if @cookie && result = @cookie.match(/=(.*?)(?:;|$)/) + if @cookie && (result = @cookie.match(/=(.*?)(?:;|$)/)) @value = result[1] end end From 024015e1e4b1872f1de45a731ca52b5121c72e41 Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Wed, 8 May 2024 15:38:29 -0400 Subject: [PATCH 03/14] move next_migration_number to non-private Standardrb flagged this class method being defined under private isn't actually private. We in fact doesn't want it to be private because it's being called by create_migration. --- lib/generators/clearance/install/install_generator.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/generators/clearance/install/install_generator.rb b/lib/generators/clearance/install/install_generator.rb index 7a374655a..df6ebf437 100644 --- a/lib/generators/clearance/install/install_generator.rb +++ b/lib/generators/clearance/install/install_generator.rb @@ -44,6 +44,11 @@ def display_readme_in_terminal readme "README" end + # for generating a timestamp when using `create_migration` + def self.next_migration_number(dir) + ActiveRecord::Generators::Base.next_migration_number(dir) + end + private def create_add_columns_migration @@ -117,11 +122,6 @@ def existing_users_indexes ActiveRecord::Base.connection.indexes(:users).map(&:name) end - # for generating a timestamp when using `create_migration` - private_class_method def self.next_migration_number(dir) - ActiveRecord::Generators::Base.next_migration_number(dir) - end - def migration_version "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end From 1ceeb9a01682a83caf088adda024d31ecfa47c07 Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Wed, 8 May 2024 16:11:33 -0400 Subject: [PATCH 04/14] move const definitions in specs out of describe block --- .../testing/controller_helpers_spec.rb | 25 ++++++++--------- spec/configuration_spec.rb | 27 +++++-------------- spec/mailers/clearance_mailer_spec.rb | 3 ++- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/spec/clearance/testing/controller_helpers_spec.rb b/spec/clearance/testing/controller_helpers_spec.rb index 21f7a29cc..039c88e06 100644 --- a/spec/clearance/testing/controller_helpers_spec.rb +++ b/spec/clearance/testing/controller_helpers_spec.rb @@ -1,21 +1,22 @@ require "spec_helper" -describe Clearance::Testing::ControllerHelpers do - class TestClass - include Clearance::Testing::ControllerHelpers - - def initialize - @request = Class.new do - def env - {clearance: Clearance::Session.new({})} - end - end.new - end +class TestClass + include Clearance::Testing::ControllerHelpers + + def initialize + @request = Class.new do + def env + {clearance: Clearance::Session.new({})} + end + end.new end +end +MyUserModel = Class.new + +describe Clearance::Testing::ControllerHelpers do describe "#sign_in" do it "creates an instance of the clearance user model with FactoryBot" do - MyUserModel = Class.new allow(FactoryBot).to receive(:create) allow(Clearance.configuration).to receive(:user_model) .and_return(MyUserModel) diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index c6436ece7..ee7378db8 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -1,5 +1,12 @@ require "spec_helper" +MyController = Class.new +DummyGuard = Class.new +Account = Class.new(ActiveRecord::Base) +CustomUser = Class.new(ActiveRecord::Base) +ConfiguredUser = Class.new +MyUser = Class.new + describe Clearance::Configuration do let(:config) { Clearance.configuration } @@ -10,14 +17,6 @@ end context "when a custom user_model_name is specified" do - before(:each) do - MyUser = Class.new - end - - after(:each) do - Object.send(:remove_const, :MyUser) - end - it "is used instead of User" do Clearance.configure { |config| config.user_model = MyUser } @@ -38,14 +37,6 @@ end context "when a custom parent_controller is specified" do - before(:each) do - MyController = Class.new - end - - after(:each) do - Object.send(:remove_const, :MyController) - end - it "is used instead of ApplicationController" do Clearance.configure { |config| config.parent_controller = MyController } @@ -139,7 +130,6 @@ context "when specifying sign in guards" do it "returns the stack with added guards" do - DummyGuard = Class.new Clearance.configure { |config| config.sign_in_guards = [DummyGuard] } expect(Clearance.configuration.sign_in_guards).to eq [DummyGuard] @@ -218,7 +208,6 @@ end it "returns the parameter key to use based on the user_model by default" do - Account = Class.new(ActiveRecord::Base) Clearance.configure { |config| config.user_model = Account } expect(Clearance.configuration.user_parameter).to eq :account @@ -227,7 +216,6 @@ describe "#user_id_parameter" do it "returns the parameter key to use based on the user_model" do - CustomUser = Class.new(ActiveRecord::Base) Clearance.configure { |config| config.user_model = CustomUser } expect(Clearance.configuration.user_id_parameter).to eq :custom_user_id @@ -247,7 +235,6 @@ describe "#reload_user_model" do it "returns the user model class if one has already been configured" do - ConfiguredUser = Class.new Clearance.configure { |config| config.user_model = ConfiguredUser } expect(Clearance.configuration.reload_user_model).to eq ConfiguredUser diff --git a/spec/mailers/clearance_mailer_spec.rb b/spec/mailers/clearance_mailer_spec.rb index 14bfb3d51..23da82a8f 100644 --- a/spec/mailers/clearance_mailer_spec.rb +++ b/spec/mailers/clearance_mailer_spec.rb @@ -1,5 +1,7 @@ require "spec_helper" +Person = Class.new(User) + describe ClearanceMailer do it "is from DO_NOT_REPLY" do user = create(:user) @@ -59,7 +61,6 @@ context "when using a custom model" do it "contains a link for a custom model" do define_people_routes - Person = Class.new(User) person = Person.new(email: "person@example.com", password: "password") person.forgot_password! From 377845bded01f0dbbfebd04ce1b6c75d89478f85 Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Wed, 8 May 2024 16:21:40 -0400 Subject: [PATCH 05/14] fix hash rocket standard generator --- spec/generators/clearance/routes/routes_generator_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/generators/clearance/routes/routes_generator_spec.rb b/spec/generators/clearance/routes/routes_generator_spec.rb index aabfd52c6..0250a4e7c 100644 --- a/spec/generators/clearance/routes/routes_generator_spec.rb +++ b/spec/generators/clearance/routes/routes_generator_spec.rb @@ -15,7 +15,7 @@ expect(initializer).to contain("config.routes = false") expect(routes).to have_correct_syntax expect(routes).to contain( - 'get "/sign_in" => "clearance/sessions#new", as: "sign_in"' + 'get "/sign_in" => "clearance/sessions#new", :as => "sign_in"' ) end end From 5538b0a544df3b2a3f2be5244b8896a913f74696 Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Wed, 8 May 2024 16:26:16 -0400 Subject: [PATCH 06/14] add GHA to run Standard --- .github/workflows/standardrb.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/standardrb.yml diff --git a/.github/workflows/standardrb.yml b/.github/workflows/standardrb.yml new file mode 100644 index 000000000..72f75fd7e --- /dev/null +++ b/.github/workflows/standardrb.yml @@ -0,0 +1,18 @@ +name: Run Linter + +on: + push: + branches: "main" + pull_request: + branches: "*" + +jobs: + standardrb: + name: StandardRB + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - run: bundle exec standardrb --format github --parallel \ No newline at end of file From 0a963627301b3bd90c0a36d6f7a236b02d40c263 Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Wed, 8 May 2024 16:27:39 -0400 Subject: [PATCH 07/14] add ruby-version to standard GHA --- .github/workflows/standardrb.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/standardrb.yml b/.github/workflows/standardrb.yml index 72f75fd7e..fe77d5b4b 100644 --- a/.github/workflows/standardrb.yml +++ b/.github/workflows/standardrb.yml @@ -15,4 +15,5 @@ jobs: - uses: ruby/setup-ruby@v1 with: bundler-cache: true + ruby-version: 3.0.0 - run: bundle exec standardrb --format github --parallel \ No newline at end of file From 3f3139f3571fed05ac184faf31db7e91d0fa1bcc Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Wed, 8 May 2024 16:41:44 -0400 Subject: [PATCH 08/14] pin standard version for GHA --- Gemfile | 2 +- Gemfile.lock | 192 +++++++++++++++++++++---------------- gemfiles/rails_6.1.gemfile | 2 +- gemfiles/rails_7.0.gemfile | 2 +- gemfiles/rails_7.1.gemfile | 2 +- 5 files changed, 114 insertions(+), 86 deletions(-) diff --git a/Gemfile b/Gemfile index c85934a83..24bac41a9 100644 --- a/Gemfile +++ b/Gemfile @@ -15,5 +15,5 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" -gem "standard" +gem "standard", ">= 1.35.1", require: false gem "timecop" diff --git a/Gemfile.lock b/Gemfile.lock index ec5bd79a7..58ec06d6d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,49 +13,58 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (7.0.3) - actionpack (= 7.0.3) - actionview (= 7.0.3) - activejob (= 7.0.3) - activesupport (= 7.0.3) + actionmailer (7.1.3.2) + actionpack (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.3) - actionview (= 7.0.3) - activesupport (= 7.0.3) - rack (~> 2.0, >= 2.2.0) + rails-dom-testing (~> 2.2) + actionpack (7.1.3.2) + actionview (= 7.1.3.2) + activesupport (= 7.1.3.2) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (7.0.3) - activesupport (= 7.0.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actionview (7.1.3.2) + activesupport (= 7.1.3.2) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.3) - activesupport (= 7.0.3) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.3.6) - activemodel (7.0.3) - activesupport (= 7.0.3) - activerecord (7.0.3) - activemodel (= 7.0.3) - activesupport (= 7.0.3) - activesupport (7.0.3) + activemodel (7.1.3.2) + activesupport (= 7.1.3.2) + activerecord (7.1.3.2) + activemodel (= 7.1.3.2) + activesupport (= 7.1.3.2) + timeout (>= 0.4.0) + activesupport (7.1.3.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - ammeter (1.1.5) + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + ammeter (1.1.7) activesupport (>= 3.0) railties (>= 3.0) rspec-rails (>= 2.2) - appraisal (2.4.1) + appraisal (2.5.0) bundler rake thor (>= 0.14.0) @@ -63,6 +72,7 @@ GEM ffi (~> 1.15) ffi-compiler (~> 1.0) ast (2.4.2) + base64 (0.2.0) bcrypt (3.1.20) better_html (2.1.1) actionview (>= 6.0) @@ -71,27 +81,30 @@ GEM erubi (~> 1.4) parser (>= 2.4) smart_properties + bigdecimal (3.1.8) builder (3.2.4) - capybara (3.37.1) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) coderay (1.1.3) concurrent-ruby (1.2.3) + connection_pool (2.4.1) crass (1.0.6) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.1) + database_cleaner (2.0.2) + database_cleaner-active_record (>= 2, < 3) + database_cleaner-active_record (2.1.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) date (3.3.4) - diff-lcs (1.5.0) + diff-lcs (1.5.1) + drb (2.2.1) email_validator (2.2.4) activemodel erb_lint (0.5.0) @@ -102,10 +115,10 @@ GEM rubocop smart_properties erubi (1.12.0) - factory_bot (6.2.1) + factory_bot (6.4.6) activesupport (>= 5.0.0) - factory_bot_rails (6.2.0) - factory_bot (~> 6.2.0) + factory_bot_rails (6.4.3) + factory_bot (~> 6.4) railties (>= 5.0.0) ffi (1.17.0) ffi-compiler (1.3.2) @@ -115,6 +128,10 @@ GEM activesupport (>= 6.1) i18n (1.14.5) concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.13.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) json (2.7.2) language_server-protocol (3.17.0.3) lint_roller (1.1.0) @@ -127,9 +144,8 @@ GEM net-pop net-smtp matrix (0.4.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.8.6) + method_source (1.1.0) + mini_mime (1.1.5) minitest (5.22.3) net-imap (0.4.14) date @@ -140,21 +156,27 @@ GEM timeout net-smtp (0.5.0) net-protocol - nokogiri (1.16.4) - mini_portile2 (~> 2.8.2) + nokogiri (1.16.4-arm64-darwin) racc (~> 1.4) parallel (1.24.0) parser (3.3.1.0) ast (~> 2.4.1) racc - pry (0.14.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - public_suffix (4.0.7) + psych (5.1.2) + stringio + public_suffix (5.0.5) racc (1.7.3) - rack (2.2.3.1) - rack-test (1.1.0) - rack (>= 1.0, < 3) + rack (3.0.10) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -166,35 +188,40 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.3) - actionpack (= 7.0.3) - activesupport (= 7.0.3) - method_source + railties (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) + rdoc (6.6.3.1) + psych (>= 4.0.0) regexp_parser (2.9.0) + reline (0.5.5) + io-console (~> 0.5) rexml (3.2.6) - rspec-core (3.11.0) - rspec-support (~> 3.11.0) - rspec-expectations (3.11.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-mocks (3.11.1) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-rails (5.1.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - railties (>= 5.2) - rspec-core (~> 3.10) - rspec-expectations (~> 3.10) - rspec-mocks (~> 3.10) - rspec-support (~> 3.10) - rspec-support (3.11.0) - rubocop (1.63.4) + rspec-support (~> 3.13.0) + rspec-rails (6.1.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) + rubocop (1.62.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -211,15 +238,14 @@ GEM rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) - shoulda-matchers (5.1.0) + shoulda-matchers (6.2.0) activesupport (>= 5.2.0) smart_properties (1.17.0) - sqlite3 (1.7.3) - mini_portile2 (~> 2.8.0) - standard (1.35.0.1) + sqlite3 (1.7.3-arm64-darwin) + standard (1.35.1) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) - rubocop (~> 1.62) + rubocop (~> 1.62.0) standard-custom (~> 1.0.0) standard-performance (~> 1.3) standard-custom (1.0.2) @@ -228,18 +254,20 @@ GEM standard-performance (1.3.1) lint_roller (~> 1.1) rubocop-performance (~> 1.20.2) - thor (1.2.1) - timecop (0.9.5) + stringio (3.1.0) + thor (1.3.1) + timecop (0.9.8) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) + webrick (1.8.1) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.5.4) + zeitwerk (2.6.13) PLATFORMS - ruby + arm64-darwin DEPENDENCIES addressable @@ -256,8 +284,8 @@ DEPENDENCIES rspec-rails shoulda-matchers sqlite3 (~> 1.7) - standard + standard (>= 1.35.1) timecop BUNDLED WITH - 2.3.15 + 2.5.6 diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index 246e6dffd..10842507b 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -15,7 +15,7 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" -gem "standard" +gem "standard", ">= 1.35.1", require: false gem "timecop" gem "railties", "~> 6.1.0" gem "net-smtp", require: false diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index 3fb7cf948..52d1bec9f 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -15,7 +15,7 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" -gem "standard" +gem "standard", ">= 1.35.1", require: false gem "timecop" gem "railties", "~> 7.0.0" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile index 78aaf7603..3e46dba1b 100644 --- a/gemfiles/rails_7.1.gemfile +++ b/gemfiles/rails_7.1.gemfile @@ -15,7 +15,7 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" -gem "standard" +gem "standard", ">= 1.35.1", require: false gem "timecop" gem "railties", "~> 7.1.0" From 660f1cb975e2a1d469f614dfdf2c3eaeb183bd8b Mon Sep 17 00:00:00 2001 From: Mina Slater Date: Fri, 10 May 2024 14:12:20 -0400 Subject: [PATCH 09/14] disable Style/ArgumentsForwarding check Rubocop/Standard wants to use `&` instead of `&block` and that newer syntax rule breaks Ruby 3.0.4 tests --- lib/clearance/authentication.rb | 8 ++++++-- lib/clearance/authorization.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/clearance/authentication.rb b/lib/clearance/authentication.rb index db81fb447..3a22402f0 100644 --- a/lib/clearance/authentication.rb +++ b/lib/clearance/authentication.rb @@ -62,8 +62,12 @@ def current_user # # Signing in will also regenerate the CSRF token for the current session, # provided {Configuration#rotate_csrf_on_sign_in?} is set. - def sign_in(user, &) - clearance_session.sign_in(user, &) + # Disabling this because rubocop/standardrb wants to change `&block` to `&`, + # and that breaks Ruby 3.0.4 tests + # rubocop:disable Style/ArgumentsForwarding + def sign_in(user, &block) + clearance_session.sign_in(user, &block) + # rubocop:enable Style/ArgumentsForwarding if signed_in? && Clearance.configuration.rotate_csrf_on_sign_in? if request.respond_to?(:reset_csrf_token) diff --git a/lib/clearance/authorization.rb b/lib/clearance/authorization.rb index 21ea1db4e..d34e4f7b4 100644 --- a/lib/clearance/authorization.rb +++ b/lib/clearance/authorization.rb @@ -78,7 +78,7 @@ def store_location # @api private def redirect_back_or(default, **) - redirect_to(return_to || default, **) + redirect_to(return_to || default, **options) clear_return_to end From e15eb2fb50a464572f764dc80cb0ca5bf1366f4e Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Fri, 28 Jun 2024 11:30:18 -0400 Subject: [PATCH 10/14] Fix specs and update Gemfile.lock Standard accidentally took away **options in Authorization. This change replaces it and updates the Gemfile.lock while I'm here. --- Gemfile.lock | 4 ++++ lib/clearance/authorization.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 58ec06d6d..d1f13005a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -158,6 +158,8 @@ GEM net-protocol nokogiri (1.16.4-arm64-darwin) racc (~> 1.4) + nokogiri (1.16.4-x86_64-darwin) + racc (~> 1.4) parallel (1.24.0) parser (3.3.1.0) ast (~> 2.4.1) @@ -242,6 +244,7 @@ GEM activesupport (>= 5.2.0) smart_properties (1.17.0) sqlite3 (1.7.3-arm64-darwin) + sqlite3 (1.7.3-x86_64-darwin) standard (1.35.1) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) @@ -268,6 +271,7 @@ GEM PLATFORMS arm64-darwin + x86_64-darwin-21 DEPENDENCIES addressable diff --git a/lib/clearance/authorization.rb b/lib/clearance/authorization.rb index d34e4f7b4..87c3c3eb3 100644 --- a/lib/clearance/authorization.rb +++ b/lib/clearance/authorization.rb @@ -77,7 +77,7 @@ def store_location end # @api private - def redirect_back_or(default, **) + def redirect_back_or(default, **options) redirect_to(return_to || default, **options) clear_return_to end From 382462ae89c6062d85f0529857cb8538f5d2b7b5 Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Fri, 9 Aug 2024 12:00:37 -0400 Subject: [PATCH 11/14] Updated Gemfile.lock and linting --- .github/workflows/standardrb.yml | 2 +- Gemfile.lock | 9 +++------ config/routes.rb | 2 +- lib/clearance.rb | 20 ++++++++++---------- lib/clearance/configuration.rb | 2 +- lib/clearance/user.rb | 2 +- spec/configuration_spec.rb | 2 +- spec/routing/clearance_routes_spec.rb | 12 ++++++------ 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/.github/workflows/standardrb.yml b/.github/workflows/standardrb.yml index fe77d5b4b..92ee6b48a 100644 --- a/.github/workflows/standardrb.yml +++ b/.github/workflows/standardrb.yml @@ -16,4 +16,4 @@ jobs: with: bundler-cache: true ruby-version: 3.0.0 - - run: bundle exec standardrb --format github --parallel \ No newline at end of file + - run: bundle exec standardrb --format github --parallel diff --git a/Gemfile.lock b/Gemfile.lock index d1f13005a..f2ed0d2af 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,7 +93,7 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) coderay (1.1.3) - concurrent-ruby (1.2.3) + concurrent-ruby (1.3.3) connection_pool (2.4.1) crass (1.0.6) database_cleaner (2.0.2) @@ -120,7 +120,7 @@ GEM factory_bot_rails (6.4.3) factory_bot (~> 6.4) railties (>= 5.0.0) - ffi (1.17.0) + ffi (1.17.0-x86_64-darwin) ffi-compiler (1.3.2) ffi (>= 1.15.5) rake @@ -147,6 +147,7 @@ GEM method_source (1.1.0) mini_mime (1.1.5) minitest (5.22.3) + mutex_m (0.2.0) net-imap (0.4.14) date net-protocol @@ -156,8 +157,6 @@ GEM timeout net-smtp (0.5.0) net-protocol - nokogiri (1.16.4-arm64-darwin) - racc (~> 1.4) nokogiri (1.16.4-x86_64-darwin) racc (~> 1.4) parallel (1.24.0) @@ -243,7 +242,6 @@ GEM shoulda-matchers (6.2.0) activesupport (>= 5.2.0) smart_properties (1.17.0) - sqlite3 (1.7.3-arm64-darwin) sqlite3 (1.7.3-x86_64-darwin) standard (1.35.1) language_server-protocol (~> 3.17.0.2) @@ -270,7 +268,6 @@ GEM zeitwerk (2.6.13) PLATFORMS - arm64-darwin x86_64-darwin-21 DEPENDENCIES diff --git a/config/routes.rb b/config/routes.rb index 69af65225..ab2d6d759 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,7 +13,7 @@ only: Clearance.configuration.user_actions do if Clearance.configuration.allow_password_reset? resource :password, - controller: 'clearance/passwords', + controller: "clearance/passwords", only: [:edit, :update] end end diff --git a/lib/clearance.rb b/lib/clearance.rb index 197b4d37b..02841e7c2 100644 --- a/lib/clearance.rb +++ b/lib/clearance.rb @@ -1,13 +1,13 @@ -require 'clearance/configuration' -require 'clearance/sign_in_guard' -require 'clearance/session' -require 'clearance/rack_session' -require 'clearance/back_door' -require 'clearance/controller' -require 'clearance/user' -require 'clearance/password_strategies' -require 'clearance/constraints' -require 'clearance/engine' +require "clearance/configuration" +require "clearance/sign_in_guard" +require "clearance/session" +require "clearance/rack_session" +require "clearance/back_door" +require "clearance/controller" +require "clearance/user" +require "clearance/password_strategies" +require "clearance/constraints" +require "clearance/engine" module Clearance end diff --git a/lib/clearance/configuration.rb b/lib/clearance/configuration.rb index ac121ace5..755f77afa 100644 --- a/lib/clearance/configuration.rb +++ b/lib/clearance/configuration.rb @@ -208,7 +208,7 @@ def allow_sign_up? def allow_password_reset? @allow_password_reset end - + # Specifies which controller actions are allowed for user resources. # This will be `[:create]` is `allow_sign_up` is true (the default), and # empty otherwise. diff --git a/lib/clearance/user.rb b/lib/clearance/user.rb index 0ba9e43c1..4debf776b 100644 --- a/lib/clearance/user.rb +++ b/lib/clearance/user.rb @@ -150,7 +150,7 @@ module Validations included do validates :email, - email: { mode: :strict }, + email: {mode: :strict}, presence: true, uniqueness: {allow_blank: true, case_sensitive: true}, unless: :email_optional? diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index ee7378db8..1421e6db2 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -182,7 +182,7 @@ expect(Clearance.configuration.allow_password_reset?).to eq true end end - end + end describe "#user_actions" do context "when allow_sign_up is configured to false" do diff --git a/spec/routing/clearance_routes_spec.rb b/spec/routing/clearance_routes_spec.rb index c18d03919..265c39f7e 100644 --- a/spec/routing/clearance_routes_spec.rb +++ b/spec/routing/clearance_routes_spec.rb @@ -63,7 +63,7 @@ end end - context 'password reset disabled' do + context "password reset disabled" do around do |example| Clearance.configure { |config| config.allow_password_reset = false } Rails.application.reload_routes! @@ -72,24 +72,24 @@ Rails.application.reload_routes! end - it 'does not route password edit' do + it "does not route password edit" do user = create(:user) expect(get: "users/#{user.id}/password/edit").not_to be_routable end - it 'does not route to clearance/passwords#update' do + it "does not route to clearance/passwords#update" do user = create(:user) expect(patch: "/users/#{user.id}/password").not_to be_routable end end - context 'reset enabled' do - it 'does route password edit' do + context "reset enabled" do + it "does route password edit" do user = create(:user) expect(get: "users/#{user.id}/password/edit").to be_routable end - it 'does route to clearance/passwords#update' do + it "does route to clearance/passwords#update" do user = create(:user) expect(patch: "/users/#{user.id}/password").to be_routable end From aa56c2264d02c25fc0bf39e69b40a281ca89d919 Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Thu, 12 Sep 2024 09:48:04 -0400 Subject: [PATCH 12/14] Add x86_64-linux to Gemfile.lock Platforms --- Gemfile.lock | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index f2ed0d2af..64456fd64 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -121,6 +121,7 @@ GEM factory_bot (~> 6.4) railties (>= 5.0.0) ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) ffi-compiler (1.3.2) ffi (>= 1.15.5) rake @@ -159,6 +160,8 @@ GEM net-protocol nokogiri (1.16.4-x86_64-darwin) racc (~> 1.4) + nokogiri (1.16.4-x86_64-linux) + racc (~> 1.4) parallel (1.24.0) parser (3.3.1.0) ast (~> 2.4.1) @@ -243,6 +246,7 @@ GEM activesupport (>= 5.2.0) smart_properties (1.17.0) sqlite3 (1.7.3-x86_64-darwin) + sqlite3 (1.7.3-x86_64-linux) standard (1.35.1) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) @@ -269,6 +273,7 @@ GEM PLATFORMS x86_64-darwin-21 + x86_64-linux DEPENDENCIES addressable From 5a950126e62f07eeb54549b0edf198278101872f Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Thu, 12 Sep 2024 09:52:28 -0400 Subject: [PATCH 13/14] Lock gem ffi to < 1.17.0 https://github.com/ffi/ffi/issues/1103 --- Gemfile | 1 + Gemfile.lock | 4 ++-- gemfiles/rails_6.1.gemfile | 1 + gemfiles/rails_7.0.gemfile | 1 + gemfiles/rails_7.1.gemfile | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 24bac41a9..def5609f7 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem "capybara" gem "database_cleaner" gem "erb_lint", require: false gem "factory_bot_rails" +gem "ffi", "< 1.17.0" gem "nokogiri" gem "pry", require: false gem "rails-controller-testing" diff --git a/Gemfile.lock b/Gemfile.lock index 64456fd64..22e27b12a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -120,8 +120,7 @@ GEM factory_bot_rails (6.4.3) factory_bot (~> 6.4) railties (>= 5.0.0) - ffi (1.17.0-x86_64-darwin) - ffi (1.17.0-x86_64-linux-gnu) + ffi (1.16.3) ffi-compiler (1.3.2) ffi (>= 1.15.5) rake @@ -284,6 +283,7 @@ DEPENDENCIES database_cleaner erb_lint factory_bot_rails + ffi (< 1.17.0) nokogiri pry rails-controller-testing diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index 10842507b..b74e40f84 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -9,6 +9,7 @@ gem "capybara" gem "database_cleaner" gem "erb_lint", require: false gem "factory_bot_rails" +gem "ffi", "< 1.17.0" gem "nokogiri" gem "pry", require: false gem "rails-controller-testing" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index 52d1bec9f..47ddc23b7 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -9,6 +9,7 @@ gem "capybara" gem "database_cleaner" gem "erb_lint", require: false gem "factory_bot_rails" +gem "ffi", "< 1.17.0" gem "nokogiri" gem "pry", require: false gem "rails-controller-testing" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile index 3e46dba1b..37b4afbfc 100644 --- a/gemfiles/rails_7.1.gemfile +++ b/gemfiles/rails_7.1.gemfile @@ -9,6 +9,7 @@ gem "capybara" gem "database_cleaner" gem "erb_lint", require: false gem "factory_bot_rails" +gem "ffi", "< 1.17.0" gem "nokogiri" gem "pry", require: false gem "rails-controller-testing" From ba8a6e616075e421b2d512eaf675ed081ebe7772 Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Thu, 12 Sep 2024 10:10:30 -0400 Subject: [PATCH 14/14] Update Ruby version in workflow --- .github/workflows/standardrb.yml | 2 +- .github/workflows/tests.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/standardrb.yml b/.github/workflows/standardrb.yml index 92ee6b48a..6281492e7 100644 --- a/.github/workflows/standardrb.yml +++ b/.github/workflows/standardrb.yml @@ -15,5 +15,5 @@ jobs: - uses: ruby/setup-ruby@v1 with: bundler-cache: true - ruby-version: 3.0.0 + ruby-version: 3.0.7 - run: bundle exec standardrb --format github --parallel diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e9d36be79..8978502fd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,9 +20,9 @@ jobs: - "7.0" - "7.1" ruby: - - "3.0.4" - - "3.1.2" - - "3.2.2" + - "3.0.7" + - "3.1.6" + - "3.2.5" env: BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.gemfile }}.gemfile