diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index 6b257885..00000000
--- a/.circleci/config.yml
+++ /dev/null
@@ -1,73 +0,0 @@
-version: 2.1
-
-orbs:
- # Required for feature specs.
- browser-tools: circleci/browser-tools@1.1
-
- # Always take the latest version of the orb, this allows us to
- # run specs against Solidus supported versions only without the need
- # to change this configuration every time a Solidus version is released
- # or goes EOL.
- solidusio_extensions: solidusio/extensions@volatile
-
-jobs:
- run-specs:
- parameters:
- solidus:
- type: string
- default: main
- db:
- type: string
- default: "postgres"
- ruby:
- type: string
- default: "3.2"
- executor:
- name: solidusio_extensions/<< parameters.db >>
- ruby_version: << parameters.ruby >>
- steps:
- - checkout
- - browser-tools/install-chrome
- - solidusio_extensions/run-tests-solidus-<< parameters.solidus >>
-
- lint-code:
- executor:
- name: solidusio_extensions/sqlite
- ruby_version: "3.0"
- steps:
- - solidusio_extensions/lint-code
-
-workflows:
- "Run specs on supported Solidus versions":
- jobs:
- - run-specs:
- name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>"
- matrix:
- parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
- - run-specs:
- name: *name
- matrix:
- parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
- - run-specs:
- name: *name
- matrix:
- parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] }
- - lint-code
-
- "Weekly run specs against main":
- triggers:
- - schedule:
- cron: "0 0 * * 4" # every Thursday
- filters:
- branches:
- only:
- - master
- jobs:
- - run-specs:
- name: *name
- matrix:
- parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
- - run-specs:
- name: *name
- matrix:
- parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
new file mode 100644
index 00000000..1aca1b41
--- /dev/null
+++ b/.git-blame-ignore-revs
@@ -0,0 +1,2 @@
+# Ignore standardrb --fix commit
+eaba0e4370a03d10a6064466a9197c330bb92c64
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 00000000..0c96e40c
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,22 @@
+name: Test
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+ schedule:
+ - cron: "0 0 * * 4" # every Thursday
+
+concurrency:
+ group: test-${{ github.ref_name }}
+ cancel-in-progress: ${{ github.ref_name != 'main' }}
+
+permissions:
+ contents: read
+
+jobs:
+ Test:
+ uses: solidusio/test-solidus-extension/.github/workflows/test.yml@v1
+ with:
+ ruby_versions: "['3.4', '4.0']"
diff --git a/.rubocop.yml b/.rubocop.yml
index 57ddb8ea..6207a647 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,10 +1,2 @@
-inherit_from: .rubocop_todo.yml
-
require:
- solidus_dev_support/rubocop
-
-AllCops:
- NewCops: disable
-
-Gemspec/RequiredRubyVersion:
- Enabled: false
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
deleted file mode 100644
index 58909603..00000000
--- a/.rubocop_todo.yml
+++ /dev/null
@@ -1,398 +0,0 @@
-# This configuration was generated by
-# `rubocop --auto-gen-config`
-# on 2022-09-09 11:12:37 UTC using RuboCop version 1.36.0.
-# The point is for the user to remove these configuration records
-# one by one as the offenses are removed from the code base.
-# Note that changes in the inspected code, or installation of new
-# versions of RuboCop, may require this file to be generated again.
-
-# Offense count: 2
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
-# Include: **/*.gemspec
-Gemspec/OrderedDependencies:
- Exclude:
- - 'solidus_auth_devise.gemspec'
-
-# Offense count: 8
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle, IndentationWidth.
-# SupportedStyles: with_first_argument, with_fixed_indentation
-Layout/ArgumentAlignment:
- Exclude:
- - 'app/models/spree/user.rb'
- - 'lib/spree/authentication_helpers.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/features/sign_out_spec.rb'
-
-# Offense count: 2
-# This cop supports safe autocorrection (--autocorrect).
-Layout/ElseAlignment:
- Exclude:
- - 'config/initializers/devise.rb'
- - 'spec/support/features/fill_addresses_fields.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
-Layout/EmptyLineBetweenDefs:
- Exclude:
- - 'lib/spree/auth/engine.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-Layout/EmptyLines:
- Exclude:
- - 'lib/spree/auth/engine.rb'
-
-# Offense count: 2
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyleAlignWith, Severity.
-# SupportedStylesAlignWith: keyword, variable, start_of_line
-Layout/EndAlignment:
- Exclude:
- - 'config/initializers/devise.rb'
- - 'spec/support/features/fill_addresses_fields.rb'
-
-# Offense count: 4
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: Width, AllowedPatterns, IgnoredPatterns.
-Layout/IndentationWidth:
- Exclude:
- - 'config/initializers/devise.rb'
- - 'spec/features/admin/sign_out_spec.rb'
- - 'spec/features/sign_out_spec.rb'
- - 'spec/support/features/fill_addresses_fields.rb'
-
-# Offense count: 4
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: symmetrical, new_line, same_line
-Layout/MultilineMethodCallBraceLayout:
- Exclude:
- - 'spec/controllers/spree/user_registrations_controller_spec.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/features/admin/password_reset_spec.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-Layout/SpaceAfterComma:
- Exclude:
- - 'spec/features/account_spec.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-Layout/SpaceBeforeComma:
- Exclude:
- - 'spec/features/account_spec.rb'
-
-# Offense count: 1
-# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
-Lint/AmbiguousBlockAssociation:
- Exclude:
- - 'spec/controllers/spree/checkout_controller_spec.rb'
-
-# Offense count: 3
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/BeEql:
- Exclude:
- - 'spec/models/user_spec.rb'
-
-# Offense count: 1
-RSpec/BeforeAfterAll:
- Exclude:
- - 'spec/models/user_spec.rb'
-
-# Offense count: 5
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/Capybara/CurrentPathExpectation:
- Exclude:
- - 'spec/features/admin/sign_in_spec.rb'
- - 'spec/features/sign_in_spec.rb'
-
-# Offense count: 69
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnabledMethods.
-RSpec/Capybara/FeatureMethods:
- Exclude:
- - 'spec/features/account_spec.rb'
- - 'spec/features/admin/password_reset_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/sign_in_spec.rb'
- - 'spec/features/admin/sign_out_spec.rb'
- - 'spec/features/admin_permissions_spec.rb'
- - 'spec/features/change_email_spec.rb'
- - 'spec/features/checkout_spec.rb'
- - 'spec/features/confirmation_spec.rb'
- - 'spec/features/order_spec.rb'
- - 'spec/features/password_reset_spec.rb'
- - 'spec/features/sign_in_spec.rb'
- - 'spec/features/sign_out_spec.rb'
- - 'spec/features/sign_up_spec.rb'
- - 'spec/requests/spree/frontend/user_update_spec.rb'
-
-# Offense count: 12
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/ContextMethod:
- Exclude:
- - 'spec/controllers/spree/checkout_controller_spec.rb'
- - 'spec/controllers/spree/user_passwords_controller_spec.rb'
- - 'spec/controllers/spree/user_registrations_controller_spec.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/controllers/spree/users_controller_spec.rb'
- - 'spec/models/order_spec.rb'
-
-# Offense count: 26
-# Configuration parameters: Prefixes.
-# Prefixes: when, with, without
-RSpec/ContextWording:
- Exclude:
- - 'spec/controllers/spree/checkout_controller_spec.rb'
- - 'spec/controllers/spree/user_passwords_controller_spec.rb'
- - 'spec/controllers/spree/user_registrations_controller_spec.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/controllers/spree/users_controller_spec.rb'
- - 'spec/features/account_spec.rb'
- - 'spec/features/admin/password_reset_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin_permissions_spec.rb'
- - 'spec/mailers/user_mailer_spec.rb'
- - 'spec/models/order_spec.rb'
- - 'spec/models/user_spec.rb'
- - 'spec/requests/spree/frontend/user_update_spec.rb'
-
-# Offense count: 6
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: SkipBlocks, EnforcedStyle.
-# SupportedStyles: described_class, explicit
-RSpec/DescribedClass:
- Exclude:
- - 'spec/mailers/user_mailer_spec.rb'
- - 'spec/models/user_spec.rb'
-
-# Offense count: 2
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/EmptyLineAfterFinalLet:
- Exclude:
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/models/order_spec.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/EmptyLineAfterSubject:
- Exclude:
- - 'spec/controllers/spree/checkout_controller_spec.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: CustomTransform, IgnoredWords.
-RSpec/ExampleWording:
- Exclude:
- - 'spec/features/sign_in_spec.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/ExpectActual:
- Exclude:
- - 'spec/controllers/spree/user_registrations_controller_spec.rb'
-
-# Offense count: 2
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: method_call, block
-RSpec/ExpectChange:
- Exclude:
- - 'spec/controllers/spree/checkout_controller_spec.rb'
- - 'spec/controllers/spree/user_registrations_controller_spec.rb'
-
-# Offense count: 3
-# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
-# Include: **/*_spec*rb*, **/spec/**/*
-RSpec/FilePath:
- Exclude:
- - 'spec/mailers/user_mailer_spec.rb'
- - 'spec/models/order_spec.rb'
- - 'spec/models/user_spec.rb'
-
-# Offense count: 15
-# Configuration parameters: AssignmentOnly.
-RSpec/InstanceVariable:
- Exclude:
- - 'spec/controllers/spree/admin/user_passwords_controller_spec.rb'
- - 'spec/controllers/spree/user_passwords_controller_spec.rb'
- - 'spec/controllers/spree/user_registrations_controller_spec.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/features/admin/sign_in_spec.rb'
- - 'spec/features/checkout_spec.rb'
- - 'spec/features/sign_in_spec.rb'
- - 'spec/mailers/user_mailer_spec.rb'
-
-# Offense count: 2
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/LeadingSubject:
- Exclude:
- - 'spec/controllers/spree/user_registrations_controller_spec.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
-
-# Offense count: 5
-RSpec/LetSetup:
- Exclude:
- - 'spec/features/admin/password_reset_spec.rb'
- - 'spec/features/confirmation_spec.rb'
- - 'spec/features/password_reset_spec.rb'
-
-# Offense count: 6
-# Configuration parameters: .
-# SupportedStyles: have_received, receive
-RSpec/MessageSpies:
- EnforcedStyle: receive
-
-# Offense count: 39
-RSpec/MultipleExpectations:
- Max: 5
-
-# Offense count: 26
-# Configuration parameters: IgnoreSharedExamples.
-RSpec/NamedSubject:
- Exclude:
- - 'spec/controllers/spree/checkout_controller_spec.rb'
- - 'spec/controllers/spree/user_registrations_controller_spec.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/controllers/spree/users_controller_spec.rb'
-
-# Offense count: 30
-RSpec/NestedGroups:
- Max: 5
-
-# Offense count: 3
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: not_to, to_not
-RSpec/NotToNot:
- Exclude:
- - 'spec/controllers/spree/users_controller_spec.rb'
- - 'spec/features/admin/password_reset_spec.rb'
- - 'spec/features/password_reset_spec.rb'
-
-# Offense count: 2
-RSpec/RepeatedExampleGroupDescription:
- Exclude:
- - 'spec/models/user_spec.rb'
-
-# Offense count: 7
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: and_return, block
-RSpec/ReturnFromStub:
- Exclude:
- - 'spec/controllers/spree/checkout_controller_spec.rb'
- - 'spec/controllers/spree/products_controller_spec.rb'
- - 'spec/models/order_spec.rb'
-
-# Offense count: 1
-RSpec/StubbedMock:
- Exclude:
- - 'spec/models/user_spec.rb'
-
-# Offense count: 2
-# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
-RSpec/VerifiedDoubles:
- Exclude:
- - 'spec/features/confirmation_spec.rb'
- - 'spec/models/user_spec.rb'
-
-# Offense count: 12
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: Include.
-# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
-Rails/Output:
- Exclude:
- - 'db/default/users.rb'
-
-# Offense count: 8
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: nested, compact
-Style/ClassAndModuleChildren:
- Exclude:
- - 'lib/controllers/backend/spree/admin/user_passwords_controller.rb'
- - 'lib/controllers/backend/spree/admin/user_sessions_controller.rb'
- - 'lib/controllers/frontend/spree/user_confirmations_controller.rb'
- - 'lib/controllers/frontend/spree/user_passwords_controller.rb'
- - 'lib/controllers/frontend/spree/user_registrations_controller.rb'
- - 'lib/controllers/frontend/spree/user_sessions_controller.rb'
- - 'lib/controllers/frontend/spree/users_controller.rb'
- - 'lib/decorators/backend/controllers/spree/admin/orders/customer_details_controller_decorator.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: compact, expanded
-Style/EmptyMethod:
- Exclude:
- - 'lib/controllers/backend/spree/admin/user_sessions_controller.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-Style/ExpandPathArguments:
- Exclude:
- - 'spec/support/confirm_helpers.rb'
-
-# Offense count: 3
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Style/GlobalStdStream:
- Exclude:
- - 'db/default/users.rb'
-
-# Offense count: 6
-# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
-Style/GuardClause:
- Exclude:
- - 'db/migrate/20101026184949_create_users.rb'
- - 'db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb'
- - 'db/migrate/20190125170630_add_reset_password_token_index_to_spree_users.rb'
- - 'db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb'
- - 'lib/spree/authentication_helpers.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-Style/RedundantFileExtensionInRequire:
- Exclude:
- - 'db/seeds.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
-# SupportedStyles: slashes, percent_r, mixed
-Style/RegexpLiteral:
- Exclude:
- - 'spec/features/checkout_spec.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: implicit, explicit
-Style/RescueStandardError:
- Exclude:
- - 'spec/requests/spree/frontend/user_update_spec.rb'
-
-# Offense count: 1
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowModifier.
-Style/SoleNestedConditional:
- Exclude:
- - 'config/initializers/warden.rb'
-
-# Offense count: 1
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: Mode.
-Style/StringConcatenation:
- Exclude:
- - 'app/models/spree/user.rb'
-
-# Offense count: 6
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
-# URISchemes: http, https
-Layout/LineLength:
- Max: 227
diff --git a/Gemfile b/Gemfile
index 8d10117d..3bc89949 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,41 +1,47 @@
# frozen_string_literal: true
-source 'https://rubygems.org'
+source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
-branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
-gem 'solidus', github: 'solidusio/solidus', branch: branch
-gem 'solidus_backend', github: 'solidusio/solidus', branch: branch
+branch = ENV.fetch("SOLIDUS_BRANCH", "main")
+gem "solidus", github: "solidusio/solidus", branch: branch
+gem "solidus_backend", github: "solidusio/solidus", branch: branch
+
+rails_requirement_string = ENV.fetch("RAILS_VERSION", "7.0")
+gem "rails", "~> #{rails_requirement_string}"
# The solidus_frontend gem has been pulled out since v3.2
-if branch >= 'v3.2'
- gem 'solidus_frontend'
-elsif branch == 'main'
- gem 'solidus_frontend', github: 'solidusio/solidus_frontend'
+if branch >= "v3.2"
+ gem "solidus_frontend"
+elsif branch == "main"
+ gem "solidus_frontend", github: "solidusio/solidus_frontend"
else
- gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch
+ gem "solidus_frontend", github: "solidusio/solidus", branch: branch
end
-case ENV.fetch('DB', nil)
-when 'mysql'
- gem 'mysql2'
-when 'postgresql'
- gem 'pg'
+case ENV.fetch("DB", nil)
+when "mysql"
+ gem "mysql2"
+when "postgresql"
+ gem "pg"
else
- gem 'sqlite3'
+ rails_version = Gem::Requirement.new(rails_requirement_string).requirements[0][1]
+ sqlite_version = (rails_version < Gem::Version.new(7.2)) ? "~> 1.4" : "~> 2.0"
+
+ gem "sqlite3", sqlite_version
end
-if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
+if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3")
# While we still support Ruby < 3 we need to workaround a limitation in
# the 'async' gem that relies on the latest ruby, since RubyGems doesn't
# resolve gems based on the required ruby version.
- gem 'async', '< 3', require: false
+ gem "async", "< 3", require: false
end
# 'net/smtp' is required by 'mail', see:
# - https://github.com/ruby/net-protocol/issues/10
# - https://stackoverflow.com/a/72474475
-gem 'net-smtp', require: false
+gem "net-smtp", require: false
gemspec
@@ -44,4 +50,12 @@ gemspec
#
# We use `send` instead of calling `eval_gemfile` to work around an issue with
# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
-send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
+send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local"
+
+# Pin state_machines
+gem "state_machines", "= 0.6.0"
+
+if RUBY_VERSION >= "4.0"
+ # Necessary for github_changelog_generator
+ gem "benchmark", "~> 0.5.0"
+end
diff --git a/README.md b/README.md
index 0e9ec33a..39423cd8 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Solidus Auth Devise
-[](https://circleci.com/gh/solidusio/solidus_auth_devise)
-[](https://codecov.io/gh/solidusio/solidus_auth_devise)
+[](https://github.com/solidusio/solidus_auth_devise/actions/workflows/test.yml)
+[](https://codecov.io/gh/solidusio/solidus_auth_devise)
Provides authentication services for Solidus, using the Devise gem.
@@ -36,7 +36,7 @@ To enable Devise's Confirmable module, which will send the user an email with a
* Add this line to an initializer in your Rails project (typically `config/initializers/spree.rb`):
```ruby
-Spree::Auth::Config[:confirmable] = true
+Spree::Auth::Config.confirmable = true
```
* Add a Devise initializer to your Rails project (typically `config/initializers/devise.rb`):
diff --git a/Rakefile b/Rakefile
index f2c8a958..1f3b5538 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,11 +1,11 @@
# frozen_string_literal: true
# Don't build a dummy app with solidus_bolt enabled
-ENV['SKIP_SOLIDUS_BOLT'] = 'true'
+ENV["SKIP_SOLIDUS_BOLT"] = "true"
-require 'bundler/gem_tasks'
+require "bundler/gem_tasks"
-require 'solidus_dev_support/rake_tasks'
-SolidusDevSupport::RakeTasks.install
+require "solidus_dev_support/rake_tasks"
+SolidusDevSupport::RakeTasks.install(user_class: "Spree::User")
-task default: 'extension:specs'
+task default: "extension:specs"
diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb
index ab0fd927..6c9c1ce2 100644
--- a/app/models/spree/user.rb
+++ b/app/models/spree/user.rb
@@ -3,20 +3,11 @@
module Spree
class User < Spree::Base
include UserMethods
+ include Spree::SoftDeletable
devise :database_authenticatable, :registerable, :recoverable,
- :rememberable, :trackable, :validatable, :encryptable
- devise :confirmable if Spree::Auth::Config[:confirmable]
-
- if defined?(Spree::SoftDeletable)
- include Spree::SoftDeletable
- else
- acts_as_paranoid
- include Spree::ParanoiaDeprecations
-
- include Discard::Model
- self.discard_column = :deleted_at
- end
+ :rememberable, :trackable, :validatable, :encryptable
+ devise :confirmable if Spree::Auth::Config.confirmable
after_destroy :scramble_email_and_password
after_discard :scramble_email_and_password
@@ -35,7 +26,7 @@ def self.admin_created?
end
def admin?
- has_spree_role?('admin')
+ has_spree_role?("admin")
end
def confirmed?
diff --git a/app/patches/controllers/solidus_auth_devise/application_controller_patch.rb b/app/patches/controllers/solidus_auth_devise/application_controller_patch.rb
new file mode 100644
index 00000000..07b0bc40
--- /dev/null
+++ b/app/patches/controllers/solidus_auth_devise/application_controller_patch.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module SolidusAuthDevise
+ module ApplicationControllerPatch
+ def self.prepended(base)
+ return unless base.respond_to?(:helper_method)
+
+ base.send(:helper_method, :spree_current_user)
+
+ return unless SolidusSupport.frontend_available?
+
+ base.send(:helper_method, :spree_login_path)
+ base.send(:helper_method, :spree_signup_path)
+ base.send(:helper_method, :spree_logout_path)
+ end
+
+ def spree_current_user
+ current_spree_user
+ end
+
+ if SolidusSupport.frontend_available?
+ delegate :login_path, :signup_path, :logout_path,
+ to: :spree,
+ prefix: :spree
+ end
+
+ ApplicationController.prepend self
+ end
+end
diff --git a/bin/rspec b/bin/rspec
new file mode 100755
index 00000000..93e191c2
--- /dev/null
+++ b/bin/rspec
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+#
+# This file was generated by Bundler.
+#
+# The application 'rspec' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
+
+require "rubygems"
+require "bundler/setup"
+
+load Gem.bin_path("rspec-core", "rspec")
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index 5f724ef1..e49f81a8 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -5,16 +5,16 @@
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer.
- config.mailer_sender = 'please-change-me@config-initializers-devise.com'
+ config.mailer_sender = "please-change-me@config-initializers-devise.com"
# Configure the class responsible to send e-mails.
- config.mailer = 'Spree::UserMailer'
+ config.mailer = "Spree::UserMailer"
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
- require 'devise/orm/active_record'
+ require "devise/orm/active_record"
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating an user. By default is
@@ -34,13 +34,13 @@
# config.http_authenticatable_on_xhr = false
# The realm used in Http Basic Authentication
- config.http_authentication_realm = 'Spree Application'
+ config.http_authentication_realm = "Spree Application"
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
# using other encryptors, it sets how many times you want the password re-encrypted.
config.stretches = 20
- config.encryptor = 'authlogic_sha512'
+ config.encryptor = "authlogic_sha512"
# Setup a pepper to generate the encrypted password.
config.pepper = if Rails.configuration.respond_to?(:secret_token) && Rails.configuration.secret_token.present?
@@ -143,4 +143,6 @@
config.reset_password_within = 6.hours
config.case_insensitive_keys = [:email]
+
+ config.reload_routes = false
end
diff --git a/config/initializers/warden.rb b/config/initializers/warden.rb
index f044dc13..9369d7f1 100644
--- a/config/initializers/warden.rb
+++ b/config/initializers/warden.rb
@@ -4,7 +4,7 @@
Warden::Manager.after_set_user except: :fetch do |user, auth, _opts|
if auth.cookies.signed[:guest_token].present?
if user.is_a?(Spree::User)
- Spree::Order.incomplete.where(guest_token: auth.cookies.signed[:guest_token], user_id: nil).each do |order|
+ Spree::Order.incomplete.where(guest_token: auth.cookies.signed[:guest_token], user_id: nil).find_each do |order|
order.associate_user!(user)
end
end
diff --git a/config/routes.rb b/config/routes.rb
index 39613b7d..02d61bef 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -3,15 +3,15 @@
Spree::Core::Engine.routes.draw do
if SolidusSupport.frontend_available? && Spree::Auth::Config.draw_frontend_routes
devise_for(:spree_user, {
- class_name: 'Spree::User',
+ class_name: "Spree::User",
controllers: {
- sessions: 'spree/user_sessions',
- registrations: 'spree/user_registrations',
- passwords: 'spree/user_passwords',
- confirmations: 'spree/user_confirmations'
+ sessions: "spree/user_sessions",
+ registrations: "spree/user_registrations",
+ passwords: "spree/user_passwords",
+ confirmations: "spree/user_confirmations"
},
skip: [:unlocks, :omniauth_callbacks],
- path_names: { sign_out: 'logout' },
+ path_names: {sign_out: "logout"},
path_prefix: :user,
router_name: :spree
})
@@ -19,48 +19,48 @@
resources :users, only: [:edit, :update]
devise_scope :spree_user do
- get '/login', to: 'user_sessions#new', as: :login
- post '/login', to: 'user_sessions#create', as: :create_new_session
- match '/logout', to: 'user_sessions#destroy', as: :logout, via: Devise.sign_out_via
- get '/signup', to: 'user_registrations#new', as: :signup
- post '/signup', to: 'user_registrations#create', as: :registration
- get '/password/recover', to: 'user_passwords#new', as: :recover_password
- post '/password/recover', to: 'user_passwords#create', as: :reset_password
- get '/password/change', to: 'user_passwords#edit', as: :edit_password
- put '/password/change', to: 'user_passwords#update', as: :update_password
- get '/confirm', to: 'user_confirmations#show', as: :confirmation if Spree::Auth::Config[:confirmable]
+ get "/login", to: "user_sessions#new", as: :login
+ post "/login", to: "user_sessions#create", as: :create_new_session
+ match "/logout", to: "user_sessions#destroy", as: :logout, via: Devise.sign_out_via
+ get "/signup", to: "user_registrations#new", as: :signup
+ post "/signup", to: "user_registrations#create", as: :registration
+ get "/password/recover", to: "user_passwords#new", as: :recover_password
+ post "/password/recover", to: "user_passwords#create", as: :reset_password
+ get "/password/change", to: "user_passwords#edit", as: :edit_password
+ put "/password/change", to: "user_passwords#update", as: :update_password
+ get "/confirm", to: "user_confirmations#show", as: :confirmation if Spree::Auth::Config.confirmable
end
- get '/checkout/registration', to: 'checkout#registration', as: :checkout_registration
- put '/checkout/registration', to: 'checkout#update_registration', as: :update_checkout_registration
+ get "/checkout/registration", to: "checkout#registration", as: :checkout_registration
+ put "/checkout/registration", to: "checkout#update_registration", as: :update_checkout_registration
- resource :account, controller: 'users'
+ resource :account, controller: "users"
end
if SolidusSupport.backend_available? && Spree::Auth::Config.draw_backend_routes
namespace :admin do
devise_for(:spree_user, {
- class_name: 'Spree::User',
+ class_name: "Spree::User",
singular: :spree_user,
skip: :all,
- path_names: { sign_out: 'logout' },
+ path_names: {sign_out: "logout"},
controllers: {
- sessions: 'spree/admin/user_sessions',
- passwords: 'spree/admin/user_passwords'
+ sessions: "spree/admin/user_sessions",
+ passwords: "spree/admin/user_passwords"
},
router_name: :spree
})
devise_scope :spree_user do
- get '/authorization_failure', to: 'user_sessions#authorization_failure', as: :unauthorized
- get '/login', to: 'user_sessions#new', as: :login
- post '/login', to: 'user_sessions#create', as: :create_new_session
- match '/logout', to: 'user_sessions#destroy', as: :logout, via: Devise.sign_out_via
+ get "/authorization_failure", to: "user_sessions#authorization_failure", as: :unauthorized
+ get "/login", to: "user_sessions#new", as: :login
+ post "/login", to: "user_sessions#create", as: :create_new_session
+ match "/logout", to: "user_sessions#destroy", as: :logout, via: Devise.sign_out_via
- get '/password/recover', to: 'user_passwords#new', as: :recover_password
- post '/password/recover', to: 'user_passwords#create', as: :reset_password
- get '/password/change', to: 'user_passwords#edit', as: :edit_password
- put '/password/change', to: 'user_passwords#update', as: :update_password
+ get "/password/recover", to: "user_passwords#new", as: :recover_password
+ post "/password/recover", to: "user_passwords#create", as: :reset_password
+ get "/password/change", to: "user_passwords#edit", as: :edit_password
+ put "/password/change", to: "user_passwords#update", as: :update_password
end
end
end
diff --git a/db/default/users.rb b/db/default/users.rb
index 2e034bd8..0b40f0f4 100644
--- a/db/default/users.rb
+++ b/db/default/users.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true
-admin_role = Spree::Role.find_or_create_by(name: 'admin')
+admin_role = Spree::Role.find_or_create_by(name: "admin")
if Spree::User.admin.any?
- puts 'No admin user created.'
+ puts "No admin user created."
return
end
-email = ENV['ADMIN_EMAIL'] || 'admin@example.com'
-password = ENV['ADMIN_PASSWORD'] || 'test123'
+email = ENV["ADMIN_EMAIL"] || "admin@example.com"
+password = ENV["ADMIN_PASSWORD"] || "test123"
puts "Creating admin user with:"
puts " - email: #{email}"
@@ -24,7 +24,7 @@
password: password,
password_confirmation: password,
email: email,
- login: email,
+ login: email
)
if admin.save
diff --git a/db/migrate/20101026184949_create_users.rb b/db/migrate/20101026184949_create_users.rb
index 2647585d..e0622974 100644
--- a/db/migrate/20101026184949_create_users.rb
+++ b/db/migrate/20101026184949_create_users.rb
@@ -1,30 +1,30 @@
# frozen_string_literal: true
-class CreateUsers < SolidusSupport::Migration[4.2]
+class CreateUsers < ActiveRecord::Migration[4.2]
def up
unless table_exists?("spree_users")
create_table "spree_users", force: true do |t|
- t.string "crypted_password", limit: 128
- t.string "salt", limit: 128
- t.string "email"
- t.string "remember_token"
- t.string "remember_token_expires_at"
- t.string "persistence_token"
- t.string "single_access_token"
- t.string "perishable_token"
- t.integer "login_count", default: 0, null: false
- t.integer "failed_login_count", default: 0, null: false
+ t.string "crypted_password", limit: 128
+ t.string "salt", limit: 128
+ t.string "email"
+ t.string "remember_token"
+ t.string "remember_token_expires_at"
+ t.string "persistence_token"
+ t.string "single_access_token"
+ t.string "perishable_token"
+ t.integer "login_count", default: 0, null: false
+ t.integer "failed_login_count", default: 0, null: false
t.datetime "last_request_at"
t.datetime "current_login_at"
t.datetime "last_login_at"
- t.string "current_login_ip"
- t.string "last_login_ip"
- t.string "login"
- t.integer "ship_address_id"
- t.integer "bill_address_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "openid_identifier"
+ t.string "current_login_ip"
+ t.string "last_login_ip"
+ t.string "login"
+ t.integer "ship_address_id"
+ t.integer "bill_address_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "openid_identifier"
end
end
end
diff --git a/db/migrate/20101026184950_rename_columns_for_devise.rb b/db/migrate/20101026184950_rename_columns_for_devise.rb
index 09babcb2..a7c74e84 100644
--- a/db/migrate/20101026184950_rename_columns_for_devise.rb
+++ b/db/migrate/20101026184950_rename_columns_for_devise.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class RenameColumnsForDevise < SolidusSupport::Migration[4.2]
+class RenameColumnsForDevise < ActiveRecord::Migration[4.2]
def up
return if column_exists?(:spree_users, :password_salt)
@@ -14,14 +14,12 @@ def up
rename_column :spree_users, :last_login_at, :last_sign_in_at
rename_column :spree_users, :current_login_ip, :current_sign_in_ip
rename_column :spree_users, :last_login_ip, :last_sign_in_ip
- add_column :spree_users, :authentication_token, :string
add_column :spree_users, :unlock_token, :string
add_column :spree_users, :locked_at, :datetime
remove_column :spree_users, :openid_identifier
end
def down
- remove_column :spree_users, :authentication_token
remove_column :spree_users, :locked_at
remove_column :spree_users, :unlock_token
rename_column :spree_users, :last_sign_in_ip, :last_login_ip
diff --git a/db/migrate/20101214150824_convert_user_remember_field.rb b/db/migrate/20101214150824_convert_user_remember_field.rb
index ba354b67..25fb2502 100644
--- a/db/migrate/20101214150824_convert_user_remember_field.rb
+++ b/db/migrate/20101214150824_convert_user_remember_field.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class ConvertUserRememberField < SolidusSupport::Migration[4.2]
+class ConvertUserRememberField < ActiveRecord::Migration[4.2]
def up
remove_column :spree_users, :remember_created_at
add_column :spree_users, :remember_created_at, :datetime
diff --git a/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb b/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb
index a45df829..988e483a 100644
--- a/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb
+++ b/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class AddResetPasswordSentAtToSpreeUsers < SolidusSupport::Migration[4.2]
+class AddResetPasswordSentAtToSpreeUsers < ActiveRecord::Migration[4.2]
def change
Spree::User.reset_column_information
unless Spree::User.column_names.include?("reset_password_sent_at")
diff --git a/db/migrate/20120605211305_make_users_email_index_unique.rb b/db/migrate/20120605211305_make_users_email_index_unique.rb
index 89080ae8..f521eed0 100644
--- a/db/migrate/20120605211305_make_users_email_index_unique.rb
+++ b/db/migrate/20120605211305_make_users_email_index_unique.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class MakeUsersEmailIndexUnique < SolidusSupport::Migration[4.2]
+class MakeUsersEmailIndexUnique < ActiveRecord::Migration[4.2]
def up
add_index "spree_users", ["email"], name: "email_idx_unique", unique: true
end
diff --git a/db/migrate/20140904000425_add_deleted_at_to_users.rb b/db/migrate/20140904000425_add_deleted_at_to_users.rb
index 824ddb6e..b98ec13b 100644
--- a/db/migrate/20140904000425_add_deleted_at_to_users.rb
+++ b/db/migrate/20140904000425_add_deleted_at_to_users.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class AddDeletedAtToUsers < SolidusSupport::Migration[4.2]
+class AddDeletedAtToUsers < ActiveRecord::Migration[4.2]
def change
add_column :spree_users, :deleted_at, :datetime
add_index :spree_users, :deleted_at
diff --git a/db/migrate/20141002154641_add_confirmable_to_users.rb b/db/migrate/20141002154641_add_confirmable_to_users.rb
index 6e932b85..c319f5ca 100644
--- a/db/migrate/20141002154641_add_confirmable_to_users.rb
+++ b/db/migrate/20141002154641_add_confirmable_to_users.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class AddConfirmableToUsers < SolidusSupport::Migration[4.2]
+class AddConfirmableToUsers < ActiveRecord::Migration[4.2]
def change
add_column :spree_users, :confirmation_token, :string
add_column :spree_users, :confirmed_at, :datetime
diff --git a/db/migrate/20190125170630_add_reset_password_token_index_to_spree_users.rb b/db/migrate/20190125170630_add_reset_password_token_index_to_spree_users.rb
index 0c80795a..ced11714 100644
--- a/db/migrate/20190125170630_add_reset_password_token_index_to_spree_users.rb
+++ b/db/migrate/20190125170630_add_reset_password_token_index_to_spree_users.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class AddResetPasswordTokenIndexToSpreeUsers < SolidusSupport::Migration[4.2]
+class AddResetPasswordTokenIndexToSpreeUsers < ActiveRecord::Migration[4.2]
# We're not using the standard Rails index name because somebody could have
# already added that index to the table. By using a custom name we ensure
# that the index can effectively be added and removed via migrations/rollbacks
@@ -8,7 +8,7 @@ class AddResetPasswordTokenIndexToSpreeUsers < SolidusSupport::Migration[4.2]
# standard name + "_solidus_auth_devise"; the length is 61 chars which is
# still OK for Sqlite, mySQL and Postgres.
def custom_index_name
- 'index_spree_users_on_reset_password_token_solidus_auth_devise'
+ "index_spree_users_on_reset_password_token_solidus_auth_devise"
end
def default_index_exists?
@@ -21,7 +21,7 @@ def custom_index_exists?
def up
Spree::User.reset_column_information
- if Spree::User.column_names.include?('reset_password_token') && !default_index_exists? && !custom_index_exists?
+ if Spree::User.column_names.include?("reset_password_token") && !default_index_exists? && !custom_index_exists?
add_index :spree_users, :reset_password_token, unique: true, name: custom_index_name
end
end
diff --git a/db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb b/db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb
index c1c69786..083fe8d5 100644
--- a/db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb
+++ b/db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb
@@ -1,4 +1,4 @@
-class AddUnconfirmedEmailToSpreeUsers < SolidusSupport::Migration[5.1]
+class AddUnconfirmedEmailToSpreeUsers < ActiveRecord::Migration[5.1]
def change
unless column_exists?(:spree_users, :unconfirmed_email)
add_column :spree_users, :unconfirmed_email, :string
diff --git a/db/migrate/20260422183113_add_timezone_to_spree_users.rb b/db/migrate/20260422183113_add_timezone_to_spree_users.rb
new file mode 100644
index 00000000..c57b322c
--- /dev/null
+++ b/db/migrate/20260422183113_add_timezone_to_spree_users.rb
@@ -0,0 +1,6 @@
+class AddTimezoneToSpreeUsers < ActiveRecord::Migration[7.2]
+ def change
+ add_column :spree_users, :timezone, :string, if_not_exists: true,
+ comment: "User's timezone, e.g., 'Eastern Time (US & Canada)'"
+ end
+end
diff --git a/db/seeds.rb b/db/seeds.rb
index af76ec94..219054d4 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
-require_relative 'default/users.rb'
+require_relative "default/users"
diff --git a/lib/controllers/backend/spree/admin/user_passwords_controller.rb b/lib/controllers/backend/spree/admin/user_passwords_controller.rb
index 9c520748..fc5ce69a 100644
--- a/lib/controllers/backend/spree/admin/user_passwords_controller.rb
+++ b/lib/controllers/backend/spree/admin/user_passwords_controller.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true
class Spree::Admin::UserPasswordsController < Devise::PasswordsController
- helper 'spree/base'
+ helper "spree/base"
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
include Spree::Core::ControllerHelpers::Store
- helper 'spree/admin/navigation'
- layout 'spree/layouts/admin'
+ helper "spree/admin/navigation"
+ layout "spree/layouts/admin"
skip_before_action :require_no_authentication, only: [:create]
diff --git a/lib/controllers/backend/spree/admin/user_sessions_controller.rb b/lib/controllers/backend/spree/admin/user_sessions_controller.rb
index 7fcdbb75..9deced44 100644
--- a/lib/controllers/backend/spree/admin/user_sessions_controller.rb
+++ b/lib/controllers/backend/spree/admin/user_sessions_controller.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true
class Spree::Admin::UserSessionsController < Devise::SessionsController
- helper 'spree/base'
+ helper "spree/base"
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
include Spree::Core::ControllerHelpers::Store
- helper 'spree/admin/navigation'
- layout 'spree/layouts/admin'
+ helper "spree/admin/navigation"
+ layout "spree/layouts/admin"
def create
authenticate_spree_user!
@@ -16,16 +16,16 @@ def create
if spree_user_signed_in?
respond_to do |format|
format.html {
- flash[:success] = I18n.t('spree.logged_in_succesfully')
+ flash[:success] = I18n.t("spree.logged_in_succesfully")
redirect_back_or_default(after_sign_in_path_for(spree_current_user))
}
format.js {
user = resource.record
- render json: { ship_address: user.ship_address, bill_address: user.bill_address }.to_json
+ render json: {ship_address: user.ship_address, bill_address: user.bill_address}.to_json
}
end
else
- flash.now[:error] = t('devise.failure.invalid')
+ flash.now[:error] = t("devise.failure.invalid")
render :new
end
end
@@ -35,6 +35,10 @@ def authorization_failure
private
+ def signed_in_root_path(_resource)
+ spree.admin_path
+ end
+
# NOTE: as soon as this gem stops supporting Solidus 3.1 if-else should be removed and left only include
if defined?(::Spree::Admin::SetsUserLanguageLocaleKey)
include ::Spree::Admin::SetsUserLanguageLocaleKey
@@ -45,7 +49,7 @@ def set_user_language_locale_key
end
def accurate_title
- I18n.t('spree.login')
+ I18n.t("spree.login")
end
def redirect_back_or_default(default)
diff --git a/lib/controllers/frontend/spree/user_confirmations_controller.rb b/lib/controllers/frontend/spree/user_confirmations_controller.rb
index 41bace4a..8b05cf37 100644
--- a/lib/controllers/frontend/spree/user_confirmations_controller.rb
+++ b/lib/controllers/frontend/spree/user_confirmations_controller.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class Spree::UserConfirmationsController < Devise::ConfirmationsController
- helper 'spree/base', 'spree/store'
+ helper "spree/base", "spree/store"
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
diff --git a/lib/controllers/frontend/spree/user_passwords_controller.rb b/lib/controllers/frontend/spree/user_passwords_controller.rb
index 80d24d53..946a3ea2 100644
--- a/lib/controllers/frontend/spree/user_passwords_controller.rb
+++ b/lib/controllers/frontend/spree/user_passwords_controller.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class Spree::UserPasswordsController < Devise::PasswordsController
- helper 'spree/base', 'spree/store'
+ helper "spree/base", "spree/store"
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
@@ -44,7 +44,7 @@ def update
protected
def translation_scope
- 'devise.user_passwords'
+ "devise.user_passwords"
end
def new_session_path(resource_name)
diff --git a/lib/controllers/frontend/spree/user_registrations_controller.rb b/lib/controllers/frontend/spree/user_registrations_controller.rb
index b1b42195..567ebdf5 100644
--- a/lib/controllers/frontend/spree/user_registrations_controller.rb
+++ b/lib/controllers/frontend/spree/user_registrations_controller.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class Spree::UserRegistrationsController < Devise::RegistrationsController
- helper 'spree/base', 'spree/store'
+ helper "spree/base", "spree/store"
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
@@ -29,7 +29,7 @@ def create
protected
def translation_scope
- 'devise.user_registrations'
+ "devise.user_registrations"
end
def check_permissions
diff --git a/lib/controllers/frontend/spree/user_sessions_controller.rb b/lib/controllers/frontend/spree/user_sessions_controller.rb
index dfa67d99..dab19350 100644
--- a/lib/controllers/frontend/spree/user_sessions_controller.rb
+++ b/lib/controllers/frontend/spree/user_sessions_controller.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class Spree::UserSessionsController < Devise::SessionsController
- helper 'spree/base', 'spree/store'
+ helper "spree/base", "spree/store"
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
@@ -18,7 +18,7 @@ def create
if spree_user_signed_in?
respond_to do |format|
format.html do
- flash[:success] = I18n.t('spree.logged_in_succesfully')
+ flash[:success] = I18n.t("spree.logged_in_succesfully")
redirect_back_or_default(after_sign_in_path_for(spree_current_user))
end
format.js { render success_json }
@@ -26,11 +26,11 @@ def create
else
respond_to do |format|
format.html do
- flash.now[:error] = t('devise.failure.invalid')
+ flash.now[:error] = t("devise.failure.invalid")
render :new
end
format.js do
- render json: { error: t('devise.failure.invalid') },
+ render json: {error: t("devise.failure.invalid")},
status: :unprocessable_entity
end
end
@@ -40,13 +40,13 @@ def create
protected
def translation_scope
- 'devise.user_sessions'
+ "devise.user_sessions"
end
private
def accurate_title
- I18n.t('spree.login')
+ I18n.t("spree.login")
end
def redirect_back_or_default(default)
diff --git a/lib/controllers/frontend/spree/users_controller.rb b/lib/controllers/frontend/spree/users_controller.rb
index b6f31b45..9a546643 100644
--- a/lib/controllers/frontend/spree/users_controller.rb
+++ b/lib/controllers/frontend/spree/users_controller.rb
@@ -4,9 +4,12 @@ class Spree::UsersController < Spree::StoreController
skip_before_action :set_current_order, only: :show, raise: false
prepend_before_action :authorize_actions, only: :new
+ def new
+ end
+
def show
load_object
- @orders = @user.orders.complete.order('completed_at desc')
+ @orders = @user.orders.complete.order("completed_at desc")
end
def create
@@ -35,13 +38,13 @@ def update
if params[:user][:password].present?
# this logic needed b/c devise wants to log us out after password changes
- if Spree::Auth::Config[:signout_after_password_change]
+ if Spree::Auth::Config.signout_after_password_change
redirect_url = spree.login_url
else
bypass_sign_in(@user)
end
end
- redirect_to redirect_url, notice: I18n.t('spree.account_updated')
+ redirect_to redirect_url, notice: I18n.t("spree.account_updated")
else
render :edit
end
@@ -63,6 +66,6 @@ def authorize_actions
end
def accurate_title
- I18n.t('spree.my_account')
+ I18n.t("spree.my_account")
end
end
diff --git a/lib/decorators/backend/controllers/spree/admin/orders/customer_details_controller_decorator.rb b/lib/decorators/backend/controllers/spree/admin/orders/customer_details_controller_decorator.rb
deleted file mode 100644
index 1628f53b..00000000
--- a/lib/decorators/backend/controllers/spree/admin/orders/customer_details_controller_decorator.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-module Spree::Admin::Orders::CustomerDetailsControllerDecorator
- def self.prepended(base)
- base.before_action :check_authorization
- end
-
- private
-
- def check_authorization
- load_order
- session[:access_token] ||= params[:token]
-
- resource = @order
- action = params[:action].to_sym
- action = :edit if action == :show # show route renders :edit for this controller
-
- authorize! action, resource, session[:access_token]
- end
-
- Spree::Admin::Orders::CustomerDetailsController.prepend self
-end
diff --git a/lib/generators/solidus/auth/install/install_generator.rb b/lib/generators/solidus/auth/install/install_generator.rb
index c6ef547e..a3805aeb 100644
--- a/lib/generators/solidus/auth/install/install_generator.rb
+++ b/lib/generators/solidus/auth/install/install_generator.rb
@@ -14,12 +14,12 @@ class InstallGenerator < Rails::Generators::Base
source_root "#{__dir__}/templates"
def generate_devise_key
- template 'config/initializers/devise.rb', 'config/initializers/devise.rb', skip: true
+ template "config/initializers/devise.rb.erb", "config/initializers/devise.rb", skip: true
end
def add_migrations
- admin_email = options[:admin_email] || (options[:interactive] && ask("Email:", default: 'admin@example.com'))
- admin_password = options[:admin_password] || (options[:interactive] && ask("Password:", default: 'test123'))
+ admin_email = options[:admin_email] || (options[:interactive] && ask("Email:", default: "admin@example.com"))
+ admin_password = options[:admin_password] || (options[:interactive] && ask("Password:", default: "test123"))
options = []
options << "ADMIN_EMAIL=#{admin_email}" if admin_email
@@ -30,12 +30,12 @@ def add_migrations
def run_migrations
if options[:skip_migrations] ||
- options[:auto_run_migrations] == false || # exclude nil
- options[:interactive] && no?('Would you like to run the migrations now?')
+ options[:auto_run_migrations] == false || # exclude nil
+ options[:interactive] && no?("Would you like to run the migrations now?")
- say_status :skip, 'Skipping rake db:migrate, don\'t forget to run it!', :yellow
+ say_status :skip, "Skipping rake db:migrate, don't forget to run it!", :yellow
else
- rake 'db:migrate'
+ rake "db:migrate"
end
end
end
diff --git a/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb b/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb
deleted file mode 100644
index ffe0f494..00000000
--- a/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-# frozen_string_literal: true
-
-Devise.secret_key = SecureRandom.hex(50).inspect
diff --git a/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb.erb b/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb.erb
new file mode 100644
index 00000000..f636e1f5
--- /dev/null
+++ b/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb.erb
@@ -0,0 +1,4 @@
+# frozen_string_literal: true
+
+Devise.secret_key = '<%= SecureRandom.hex(64) %>'
+Devise.email_regexp = Spree::Config.default_email_regexp
diff --git a/lib/generators/solidus_auth_devise/install/install_generator.rb b/lib/generators/solidus_auth_devise/install/install_generator.rb
index 2cc5aa2c..2459d8a1 100644
--- a/lib/generators/solidus_auth_devise/install/install_generator.rb
+++ b/lib/generators/solidus_auth_devise/install/install_generator.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative '../../solidus/auth/install/install_generator'
+require_relative "../../solidus/auth/install/install_generator"
module SolidusAuthDevise
module Generators
@@ -11,7 +11,7 @@ class InstallGenerator < Rails::Generators::Base
end
def forward_to_spree_auth_install
- generate 'solidus:auth:install', *ARGV
+ generate "solidus:auth:install", *ARGV
end
end
end
diff --git a/lib/decorators/backend/controllers/spree/admin/base_controller_decorator.rb b/lib/patches/backend/controllers/solidus_auth_devise/admin/base_controller_patch.rb
similarity index 85%
rename from lib/decorators/backend/controllers/spree/admin/base_controller_decorator.rb
rename to lib/patches/backend/controllers/solidus_auth_devise/admin/base_controller_patch.rb
index f0017543..2bf97c3e 100644
--- a/lib/decorators/backend/controllers/spree/admin/base_controller_decorator.rb
+++ b/lib/patches/backend/controllers/solidus_auth_devise/admin/base_controller_patch.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-module Spree
+module SolidusAuthDevise
module Admin
- module BaseControllerDecorator
+ module BaseControllerPatch
protected
def model_class
diff --git a/lib/patches/backend/controllers/solidus_auth_devise/admin/orders/customer_details_controller_patch.rb b/lib/patches/backend/controllers/solidus_auth_devise/admin/orders/customer_details_controller_patch.rb
new file mode 100644
index 00000000..62b0ca75
--- /dev/null
+++ b/lib/patches/backend/controllers/solidus_auth_devise/admin/orders/customer_details_controller_patch.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module SolidusAuthDevise
+ module Admin
+ module Orders
+ module CustomerDetailsControllerPatch
+ def self.prepended(base)
+ base.before_action :check_authorization
+ end
+
+ private
+
+ def check_authorization
+ load_order
+ session[:access_token] ||= params[:token]
+
+ resource = @order
+ action = params[:action].to_sym
+ action = :edit if action == :show # show route renders :edit for this controller
+
+ authorize! action, resource, session[:access_token]
+ end
+
+ Spree::Admin::Orders::CustomerDetailsController.prepend self
+ end
+ end
+ end
+end
diff --git a/lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb b/lib/patches/frontend/controllers/solidus_auth_devise/checkout_controller_patch.rb
similarity index 86%
rename from lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb
rename to lib/patches/frontend/controllers/solidus_auth_devise/checkout_controller_patch.rb
index a0f55a19..048434bc 100644
--- a/lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb
+++ b/lib/patches/frontend/controllers/solidus_auth_devise/checkout_controller_patch.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-module Spree
- module CheckoutControllerDecorator
+module SolidusAuthDevise
+ module CheckoutControllerPatch
def self.prepended(base)
base.before_action :check_registration, except: [:registration, :update_registration]
base.before_action :check_authorization
@@ -21,20 +21,20 @@ def update_registration
else
flash[:registration_error] = t(:email_is_invalid, scope: [:errors, :messages])
@user = Spree::User.new
- render 'registration'
+ render "registration"
end
end
private
def order_params
- params.
- fetch(:order, {}).
- permit(:email)
+ params
+ .fetch(:order, {})
+ .permit(:email)
end
def skip_state_validation?
- %w(registration update_registration).include?(params[:action])
+ %w[registration update_registration].include?(params[:action])
end
def check_authorization
@@ -50,7 +50,7 @@ def check_registration
end
def registration_required?
- Spree::Auth::Config[:registration_step] &&
+ Spree::Auth::Config.registration_step &&
!already_registered?
end
@@ -60,7 +60,7 @@ def already_registered?
def guest_authenticated?
current_order&.email.present? &&
- Spree::Config[:allow_guest_checkout]
+ Spree::Config.allow_guest_checkout
end
# Overrides the equivalent method defined in Spree::Core. This variation of the method will ensure that users
diff --git a/lib/solidus_auth_devise.rb b/lib/solidus_auth_devise.rb
index f38cd2f4..ef0b3c8d 100644
--- a/lib/solidus_auth_devise.rb
+++ b/lib/solidus_auth_devise.rb
@@ -1,14 +1,12 @@
# frozen_string_literal: true
-require 'solidus_core'
-require 'solidus_support'
-require 'deface'
-require 'devise'
-require 'devise-encryptable'
-require 'cancan'
+require "solidus_core"
+require "solidus_support"
+require "deface"
+require "devise"
+require "devise-encryptable"
+require "cancan"
-require 'solidus_auth_devise/configuration'
-require 'solidus_auth_devise/version'
-require 'solidus_auth_devise/engine'
-
-require 'spree/authentication_helpers'
+require "solidus_auth_devise/configuration"
+require "solidus_auth_devise/version"
+require "solidus_auth_devise/engine"
diff --git a/lib/solidus_auth_devise/configuration.rb b/lib/solidus_auth_devise/configuration.rb
index bc548981..78478b2a 100644
--- a/lib/solidus_auth_devise/configuration.rb
+++ b/lib/solidus_auth_devise/configuration.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
-require 'spree/auth_configuration'
+require "spree/auth_configuration"
diff --git a/lib/solidus_auth_devise/engine.rb b/lib/solidus_auth_devise/engine.rb
index f80cac75..db4e0968 100644
--- a/lib/solidus_auth_devise/engine.rb
+++ b/lib/solidus_auth_devise/engine.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
-require 'spree/auth/engine'
+require "spree/auth/engine"
diff --git a/lib/solidus_auth_devise/version.rb b/lib/solidus_auth_devise/version.rb
index 7178a1f2..f09769a3 100644
--- a/lib/solidus_auth_devise/version.rb
+++ b/lib/solidus_auth_devise/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module SolidusAuthDevise
- VERSION = '2.5.7'
+ VERSION = "2.6.0"
end
diff --git a/lib/spree/auth/engine.rb b/lib/spree/auth/engine.rb
index d32f0035..ca546bf0 100644
--- a/lib/spree/auth/engine.rb
+++ b/lib/spree/auth/engine.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require 'solidus_auth_devise'
-require 'devise'
-require 'devise-encryptable'
-require 'spree/auth/version'
+require "solidus_auth_devise"
+require "devise"
+require "devise-encryptable"
+require "spree/auth/version"
module Spree
module Auth
@@ -11,23 +11,19 @@ class Engine < Rails::Engine
include SolidusSupport::EngineExtensions
isolate_namespace Spree
- engine_name 'solidus_auth'
+ engine_name "solidus_auth"
+
+ Spree.user_class = "Spree::User"
initializer "spree.auth.environment", before: :load_config_initializers do |_app|
- require 'spree/auth_configuration'
+ require "spree/auth_configuration"
Spree::Auth::Config = Spree::AuthConfiguration.new
end
- initializer "solidus_auth_devise.set_user_class", after: :load_config_initializers do
- Spree.user_class = "Spree::User"
- end
-
config.to_prepare do
Spree::Auth::Engine.prepare_backend if SolidusSupport.backend_available?
Spree::Auth::Engine.prepare_frontend if SolidusSupport.frontend_available?
-
- ApplicationController.include Spree::AuthenticationHelpers
end
def self.redirect_back_on_unauthorized?
@@ -51,7 +47,7 @@ def self.redirect_back_on_unauthorized?
def self.prepare_backend
Spree::Admin::BaseController.unauthorized_redirect = -> do
if spree_current_user
- flash[:error] = I18n.t('spree.authorization_failure')
+ flash[:error] = I18n.t("spree.authorization_failure")
if Spree::Auth::Engine.redirect_back_on_unauthorized?
redirect_back(fallback_location: spree.admin_unauthorized_path)
@@ -70,11 +66,10 @@ def self.prepare_backend
end
end
-
def self.prepare_frontend
Spree::BaseController.unauthorized_redirect = -> do
if spree_current_user
- flash[:error] = I18n.t('spree.authorization_failure')
+ flash[:error] = I18n.t("spree.authorization_failure")
if Spree::Auth::Engine.redirect_back_on_unauthorized?
redirect_back(fallback_location: spree.unauthorized_path)
diff --git a/lib/spree/auth/version.rb b/lib/spree/auth/version.rb
index 6f7dc900..bdb93137 100644
--- a/lib/spree/auth/version.rb
+++ b/lib/spree/auth/version.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'solidus_auth_devise/version'
+require "solidus_auth_devise/version"
module Spree
module Auth
diff --git a/lib/spree/authentication_helpers.rb b/lib/spree/authentication_helpers.rb
deleted file mode 100644
index d62a20c4..00000000
--- a/lib/spree/authentication_helpers.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-module Spree
- module AuthenticationHelpers
- def self.included(receiver)
- if receiver.send(:respond_to?, :helper_method)
- receiver.send(:helper_method, :spree_current_user)
-
- if SolidusSupport.frontend_available?
- receiver.send(:helper_method, :spree_login_path)
- receiver.send(:helper_method, :spree_signup_path)
- receiver.send(:helper_method, :spree_logout_path)
- end
- end
- end
-
- def spree_current_user
- current_spree_user
- end
-
- if SolidusSupport.frontend_available?
- delegate :login_path, :signup_path, :logout_path,
- to: :spree,
- prefix: :spree
- end
- end
-end
diff --git a/lib/tasks/auth.rake b/lib/tasks/auth.rake
index a2c4576a..323b615d 100644
--- a/lib/tasks/auth.rake
+++ b/lib/tasks/auth.rake
@@ -4,7 +4,7 @@ namespace :spree_auth do
namespace :admin do
desc "Create admin username and password"
task create: :environment do
- require File.join(File.dirname(__FILE__), '..', '..', 'db', 'default', 'users.rb')
+ require File.join(File.dirname(__FILE__), "..", "..", "db", "default", "users.rb")
puts "Done!"
end
end
diff --git a/lib/views/frontend/spree/checkout/registration.html.erb b/lib/views/frontend/spree/checkout/registration.html.erb
index 15af8565..955fe27b 100644
--- a/lib/views/frontend/spree/checkout/registration.html.erb
+++ b/lib/views/frontend/spree/checkout/registration.html.erb
@@ -4,7 +4,7 @@
<%= render template: 'spree/user_sessions/new' %>
- <% if Spree::Config[:allow_guest_checkout] %>
+ <% if Spree::Config.allow_guest_checkout %>
<%= t('spree.guest_user_account') %>
<% if flash[:registration_error] %>
diff --git a/solidus_auth_devise.gemspec b/solidus_auth_devise.gemspec
index d8704049..17c61029 100644
--- a/solidus_auth_devise.gemspec
+++ b/solidus_auth_devise.gemspec
@@ -1,41 +1,40 @@
# frozen_string_literal: true
-require_relative 'lib/solidus_auth_devise/version'
+require_relative "lib/solidus_auth_devise/version"
Gem::Specification.new do |spec|
- spec.name = 'solidus_auth_devise'
+ spec.name = "solidus_auth_devise"
spec.version = SolidusAuthDevise::VERSION
- spec.authors = ['Solidus Team']
- spec.email = 'contact@solidus.io'
+ spec.authors = ["Solidus Team"]
+ spec.email = "contact@solidus.io"
- spec.summary = 'Provides authentication and authorization services for use with Solidus by using Devise and CanCan.'
- spec.homepage = 'https://github.com/solidusio/solidus_auth_devise'
- spec.license = 'BSD-3-Clause'
+ spec.summary = "Provides authentication and authorization services for use with Solidus by using Devise and CanCan."
+ spec.homepage = "https://github.com/solidusio/solidus_auth_devise"
+ spec.license = "BSD-3-Clause"
- spec.metadata['homepage_uri'] = spec.homepage
- spec.metadata['source_code_uri'] = 'https://github.com/solidusio/solidus_auth_devise'
- spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_auth_devise/releases'
+ spec.metadata["homepage_uri"] = spec.homepage
+ spec.metadata["source_code_uri"] = "https://github.com/solidusio/solidus_auth_devise"
+ spec.metadata["changelog_uri"] = "https://github.com/solidusio/solidus_auth_devise/releases"
- spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5", "< 5")
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
spec.files = files.grep_v(%r{^(test|spec|features)/})
- spec.test_files = files.grep(%r{^(test|spec|features)/})
spec.bindir = "exe"
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
- spec.add_dependency 'deface', '~> 1.0'
- spec.add_dependency 'devise', '~> 4.1'
- spec.add_dependency 'devise-encryptable', '0.2.0'
- spec.add_dependency 'solidus_core', ['>= 3', '< 5']
- spec.add_dependency 'solidus_support', '~> 0.5'
+ spec.add_dependency "deface", "~> 1.0"
+ spec.add_dependency "devise", ">= 4.1"
+ spec.add_dependency "devise-encryptable", "0.2.0"
+ spec.add_dependency "solidus_core", [">= 3", "< 5"]
+ spec.add_dependency "solidus_support", "~> 0.11"
- spec.add_development_dependency 'solidus_backend'
- spec.add_development_dependency 'solidus_frontend'
- spec.add_development_dependency 'solidus_dev_support', '~> 2.5'
- spec.add_development_dependency 'rails-controller-testing'
+ spec.add_development_dependency "solidus_backend"
+ spec.add_development_dependency "solidus_frontend"
+ spec.add_development_dependency "solidus_dev_support", "~> 2.10"
+ spec.add_development_dependency "rails-controller-testing"
end
diff --git a/spec/controllers/spree/admin/base_controller_spec.rb b/spec/controllers/spree/admin/base_controller_spec.rb
index 5b81942a..15d32a89 100644
--- a/spec/controllers/spree/admin/base_controller_spec.rb
+++ b/spec/controllers/spree/admin/base_controller_spec.rb
@@ -1,11 +1,13 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
RSpec.describe Spree::Admin::BaseController, type: :controller do
- describe '#unauthorized_redirect' do
+ describe "#unauthorized_redirect" do
controller(described_class) do
- def index; authorize!(:read, :something); end
+ def index
+ authorize!(:read, :something)
+ end
end
before do
@@ -23,11 +25,11 @@ def index; authorize!(:read, :something); end
end
context "when http_referrer is present" do
- before { request.env['HTTP_REFERER'] = '/redirect' }
+ before { request.env["HTTP_REFERER"] = "/redirect" }
it "redirects back" do
get :index
- expect(response).to redirect_to('/redirect')
+ expect(response).to redirect_to("/redirect")
end
end
end
@@ -41,11 +43,11 @@ def index; authorize!(:read, :something); end
end
context "when http_referrer is present" do
- before { request.env['HTTP_REFERER'] = '/redirect' }
+ before { request.env["HTTP_REFERER"] = "/redirect" }
it "redirects back" do
get :index
- expect(response).to redirect_to('/redirect')
+ expect(response).to redirect_to("/redirect")
end
end
end
diff --git a/spec/controllers/spree/admin/user_passwords_controller_spec.rb b/spec/controllers/spree/admin/user_passwords_controller_spec.rb
index 97aaf7d5..c54aeee5 100644
--- a/spec/controllers/spree/admin/user_passwords_controller_spec.rb
+++ b/spec/controllers/spree/admin/user_passwords_controller_spec.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true
RSpec.describe Spree::Admin::UserPasswordsController, type: :controller do
- before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
+ before { @request.env["devise.mapping"] = Devise.mappings[:spree_user] }
- describe '#create' do
- it 'responds with success' do
- post :create, params: { spree_user: { email: 'admin@example.com' } }
+ describe "#create" do
+ it "responds with success" do
+ post :create, params: {spree_user: {email: "admin@example.com"}}
- expect(assigns[:spree_user].email).to eq('admin@example.com')
- expect(response.code).to eq('200')
+ expect(assigns[:spree_user].email).to eq("admin@example.com")
+ expect(response.code).to eq("200")
end
end
end
diff --git a/spec/controllers/spree/admin/user_sessions_controller_spec.rb b/spec/controllers/spree/admin/user_sessions_controller_spec.rb
new file mode 100644
index 00000000..52137579
--- /dev/null
+++ b/spec/controllers/spree/admin/user_sessions_controller_spec.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+RSpec.describe Spree::Admin::UserSessionsController, type: :controller do
+ let(:user) { create(:user, password: "secret") }
+
+ before { @request.env["devise.mapping"] = Devise.mappings[:spree_user] } # rubocop:disable RSpec/InstanceVariable
+
+ it "redirects to the admin root after signing in with no stored location" do
+ get :new
+
+ post(:create, params: {
+ spree_user: {
+ email: user.email,
+ password: "secret"
+ }
+ })
+
+ expect(response).to redirect_to spree.admin_path
+ end
+end
diff --git a/spec/controllers/spree/base_controller_spec.rb b/spec/controllers/spree/base_controller_spec.rb
index 9dc565cd..3a05c261 100644
--- a/spec/controllers/spree/base_controller_spec.rb
+++ b/spec/controllers/spree/base_controller_spec.rb
@@ -1,11 +1,13 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
RSpec.describe Spree::BaseController, type: :controller do
- describe '#unauthorized_redirect' do
+ describe "#unauthorized_redirect" do
controller(described_class) do
- def index; authorize!(:read, :something); end
+ def index
+ authorize!(:read, :something)
+ end
end
before do
@@ -23,11 +25,11 @@ def index; authorize!(:read, :something); end
end
context "when http_referrer is present" do
- before { request.env['HTTP_REFERER'] = '/redirect' }
+ before { request.env["HTTP_REFERER"] = "/redirect" }
it "redirects back" do
get :index
- expect(response).to redirect_to('/redirect')
+ expect(response).to redirect_to("/redirect")
end
end
end
@@ -41,11 +43,11 @@ def index; authorize!(:read, :something); end
end
context "when http_referrer is present" do
- before { request.env['HTTP_REFERER'] = '/redirect' }
+ before { request.env["HTTP_REFERER"] = "/redirect" }
it "redirects back" do
get :index
- expect(response).to redirect_to('/redirect')
+ expect(response).to redirect_to("/redirect")
end
end
end
diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb
index f831a07d..46f6f192 100644
--- a/spec/controllers/spree/checkout_controller_spec.rb
+++ b/spec/controllers/spree/checkout_controller_spec.rb
@@ -2,8 +2,8 @@
RSpec.describe Spree::CheckoutController, type: :controller do
let(:order) { create(:order_with_line_items, email: nil, user: nil, guest_token: token) }
- let(:user) { build(:user, spree_api_key: 'fake') }
- let(:token) { 'some_token' }
+ let(:user) { build(:user, spree_api_key: "fake") }
+ let(:token) { "some_token" }
let(:cookie_token) { token }
before do
@@ -12,132 +12,132 @@
allow(order).to receive(:confirmation_required?) { true }
end
- context '#edit' do
- context 'when registration step enabled' do
- context 'when authenticated as registered user' do
+ context "#edit" do
+ context "when registration step enabled" do
+ context "when authenticated as registered user" do
before { allow(controller).to receive(:spree_current_user) { user } }
- it 'proceeds to the first checkout step' do
- get :edit, params: { state: 'address' }
+ it "proceeds to the first checkout step" do
+ get :edit, params: {state: "address"}
expect(response).to render_template :edit
end
end
- context 'when not authenticated as guest' do
- it 'redirects to registration step' do
- get :edit, params: { state: 'address' }
+ context "when not authenticated as guest" do
+ it "redirects to registration step" do
+ get :edit, params: {state: "address"}
expect(response).to redirect_to spree.checkout_registration_path
end
end
- context 'when authenticated as guest' do
- before { order.email = 'guest@solidus.io' }
+ context "when authenticated as guest" do
+ before { order.email = "guest@solidus.io" }
- it 'proceeds to the first checkout step' do
- get :edit, params: { state: 'address' }
+ it "proceeds to the first checkout step" do
+ get :edit, params: {state: "address"}
expect(response).to render_template :edit
end
- context 'when guest checkout not allowed' do
+ context "when guest checkout not allowed" do
before do
stub_spree_preferences(allow_guest_checkout: false)
end
- it 'redirects to registration step' do
- get :edit, params: { state: 'address' }
+ it "redirects to registration step" do
+ get :edit, params: {state: "address"}
expect(response).to redirect_to spree.checkout_registration_path
end
end
end
end
- context 'when registration step disabled' do
+ context "when registration step disabled" do
before do
stub_spree_preferences(Spree::Auth::Config, registration_step: false)
end
- context 'when authenticated as registered' do
+ context "when authenticated as registered" do
before { allow(controller).to receive(:spree_current_user) { user } }
- it 'proceeds to the first checkout step' do
- get :edit, params: { state: 'address' }
+ it "proceeds to the first checkout step" do
+ get :edit, params: {state: "address"}
expect(response).to render_template :edit
end
end
- context 'when authenticated as guest' do
- it 'proceeds to the first checkout step' do
- get :edit, params: { state: 'address' }
+ context "when authenticated as guest" do
+ it "proceeds to the first checkout step" do
+ get :edit, params: {state: "address"}
expect(response).to render_template :edit
end
end
end
end
- context '#update' do
- context 'when in the confirm state' do
+ context "#update" do
+ context "when in the confirm state" do
before do
- order.update(email: 'spree@example.com', state: 'confirm')
+ order.update(email: "spree@example.com", state: "confirm")
# So that the order can transition to complete successfully
allow(order).to receive(:payment_required?) { false }
end
- context 'with a token' do
- before { allow(order).to receive(:guest_token) { 'ABC' } }
+ context "with a token" do
+ before { allow(order).to receive(:guest_token) { "ABC" } }
- it 'redirects to the tokenized order view' do
- request.cookie_jar.signed[:guest_token] = 'ABC'
- post :update, params: { state: 'confirm' }
- expect(response).to redirect_to spree.token_order_path(order, 'ABC')
- expect(flash.notice).to eq I18n.t('spree.order_processed_successfully')
+ it "redirects to the tokenized order view" do
+ request.cookie_jar.signed[:guest_token] = "ABC"
+ post :update, params: {state: "confirm"}
+ expect(response).to redirect_to spree.token_order_path(order, "ABC")
+ expect(flash.notice).to eq I18n.t("spree.order_processed_successfully")
end
end
- context 'with a registered user' do
+ context "with a registered user" do
before do
allow(controller).to receive(:spree_current_user) { user }
allow(order).to receive(:user) { user }
allow(order).to receive(:guest_token) { nil }
end
- it 'redirects to the standard order view' do
- post :update, params: { state: 'confirm' }
+ it "redirects to the standard order view" do
+ post :update, params: {state: "confirm"}
expect(response).to redirect_to spree.order_path(order)
end
end
end
end
- context '#registration' do
- it 'does not check registration' do
+ context "#registration" do
+ it "does not check registration" do
expect(controller).not_to receive(:check_registration)
get :registration
end
- it 'checks if the user is authorized for :edit' do
+ it "checks if the user is authorized for :edit" do
expect(controller).to receive(:authorize!).with(:edit, order, token)
request.cookie_jar.signed[:guest_token] = token
get :registration, params: {}
end
end
- context '#update_registration' do
- subject { put :update_registration, params: { order: { email: email } } }
- let(:email) { 'foo@example.com' }
+ context "#update_registration" do
+ subject { put :update_registration, params: {order: {email: email}} }
+ let(:email) { "foo@example.com" }
- it 'does not check registration' do
+ it "does not check registration" do
expect(controller).not_to receive(:check_registration)
subject
end
- it 'redirects to the checkout_path after saving' do
+ it "redirects to the checkout_path after saving" do
subject
expect(response).to redirect_to spree.checkout_path
end
# Regression test for https://github.com/solidusio/solidus/issues/1588
- context 'order in address state' do
+ context "order in address state" do
let(:order) do
create(
:order_with_line_items,
@@ -146,7 +146,7 @@
guest_token: token,
bill_address: nil,
ship_address: nil,
- state: 'address'
+ state: "address"
)
end
@@ -161,30 +161,30 @@
end
end
- context 'invalid email' do
- let(:email) { 'invalid' }
+ context "invalid email" do
+ let(:email) { "invalid" }
- it 'renders the registration view' do
+ it "renders the registration view" do
subject
expect(flash[:registration_error]).to eq I18n.t(:email_is_invalid, scope: [:errors, :messages])
expect(response).to render_template :registration
end
end
- context 'with wrong order token' do
- let(:cookie_token) { 'lol_no_access' }
+ context "with wrong order token" do
+ let(:cookie_token) { "lol_no_access" }
- it 'redirects to login' do
- put :update_registration, params: { order: { email: 'foo@example.com' } }
+ it "redirects to login" do
+ put :update_registration, params: {order: {email: "foo@example.com"}}
expect(response).to redirect_to(login_path)
end
end
- context 'without order token' do
+ context "without order token" do
let(:cookie_token) { nil }
- it 'redirects to login' do
- put :update_registration, params: { order: { email: 'foo@example.com' } }
+ it "redirects to login" do
+ put :update_registration, params: {order: {email: "foo@example.com"}}
expect(response).to redirect_to(login_path)
end
end
diff --git a/spec/controllers/spree/products_controller_spec.rb b/spec/controllers/spree/products_controller_spec.rb
index 8596f3b0..f3ef921a 100644
--- a/spec/controllers/spree/products_controller_spec.rb
+++ b/spec/controllers/spree/products_controller_spec.rb
@@ -2,23 +2,23 @@
RSpec.describe Spree::ProductsController, type: :controller do
let!(:product) { create(:product, available_on: 1.year.from_now) }
- let!(:user) { build(:user, spree_api_key: 'fake') }
+ let!(:user) { build(:user, spree_api_key: "fake") }
- it 'allows admins to view non-active products' do
+ it "allows admins to view non-active products" do
allow(controller).to receive(:before_save_new_order)
allow(controller).to receive(:spree_current_user) { user }
allow(user).to receive(:has_spree_role?) { true }
- get :show, params: { id: product.to_param }
+ get :show, params: {id: product.to_param}
expect(response.status).to eq(200)
end
- it 'cannot view non-active products' do
+ it "cannot view non-active products" do
allow(controller).to receive(:before_save_new_order)
allow(controller).to receive(:spree_current_user) { user }
allow(user).to receive(:has_spree_role?) { false }
expect {
- get :show, params: { id: product.to_param }
+ get :show, params: {id: product.to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/spec/controllers/spree/user_passwords_controller_spec.rb b/spec/controllers/spree/user_passwords_controller_spec.rb
index 2165a22c..9b2fe5b1 100644
--- a/spec/controllers/spree/user_passwords_controller_spec.rb
+++ b/spec/controllers/spree/user_passwords_controller_spec.rb
@@ -1,40 +1,40 @@
# frozen_string_literal: true
RSpec.describe Spree::UserPasswordsController, type: :controller do
- let(:token) { 'some_token' }
+ let(:token) { "some_token" }
- before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
+ before { @request.env["devise.mapping"] = Devise.mappings[:spree_user] }
- describe 'GET edit' do
- context 'when the user token has not been specified' do
- it 'redirects to the new session path' do
+ describe "GET edit" do
+ context "when the user token has not been specified" do
+ it "redirects to the new session path" do
get :edit
expect(response).to redirect_to(
- 'http://test.host/user/spree_user/sign_in'
+ "http://test.host/user/spree_user/sign_in"
)
end
- it 'flashes an error' do
+ it "flashes an error" do
get :edit
expect(flash[:alert]).to include(
"You can't access this page without coming from a password reset " \
- 'email'
+ "email"
)
end
end
- context 'when the user token has been specified' do
- it 'does something' do
- get :edit, params: { reset_password_token: token }
- expect(response.code).to eq('200')
+ context "when the user token has been specified" do
+ it "does something" do
+ get :edit, params: {reset_password_token: token}
+ expect(response.code).to eq("200")
end
end
end
- context '#update' do
- context 'when updating password with blank password' do
- it 'shows error flash message, sets spree_user with token and re-displays password edit form' do
- put :update, params: { spree_user: { password: '', password_confirmation: '', reset_password_token: token } }
+ context "#update" do
+ context "when updating password with blank password" do
+ it "shows error flash message, sets spree_user with token and re-displays password edit form" do
+ put :update, params: {spree_user: {password: "", password_confirmation: "", reset_password_token: token}}
expect(assigns(:spree_user).is_a?(Spree::User)).to eq true
expect(assigns(:spree_user).reset_password_token).to eq token
expect(flash[:error]).to eq I18n.t(:cannot_be_blank, scope: [:devise, :user_passwords, :spree_user])
diff --git a/spec/controllers/spree/user_registrations_controller_spec.rb b/spec/controllers/spree/user_registrations_controller_spec.rb
index 579ff9c2..5eddedb1 100644
--- a/spec/controllers/spree/user_registrations_controller_spec.rb
+++ b/spec/controllers/spree/user_registrations_controller_spec.rb
@@ -1,78 +1,77 @@
# frozen_string_literal: true
RSpec.describe Spree::UserRegistrationsController, type: :controller do
- before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
+ before { @request.env["devise.mapping"] = Devise.mappings[:spree_user] }
- context '#create' do
+ context "#create" do
before do
allow(controller).to receive(:after_sign_up_path_for) do
spree.root_path(thing: 7)
end
end
- let(:password_confirmation) { 'foobar123' }
+ let(:password_confirmation) { "foobar123" }
subject do
post(:create,
params: {
spree_user: {
- email: 'foobar@example.com',
- password: 'foobar123',
+ email: "foobar@example.com",
+ password: "foobar123",
password_confirmation: password_confirmation
}
- }
- )
+ })
end
- context 'when user created successfuly' do
- it 'saves the user' do
+ context "when user created successfuly" do
+ it "saves the user" do
expect { subject }.to change { Spree::User.count }.from(0).to(1)
end
- it 'sets flash message' do
+ it "sets flash message" do
subject
- expect(flash[:notice]).to eq('Welcome! You have signed up successfully.')
+ expect(flash[:notice]).to eq("Welcome! You have signed up successfully.")
end
- it 'signs in user' do
+ it "signs in user" do
expect(controller.warden).to receive(:set_user)
subject
end
- it 'sets spree_user_signup session' do
+ it "sets spree_user_signup session" do
subject
expect(session[:spree_user_signup]).to be true
end
- it 'redirects to after_sign_up path' do
+ it "redirects to after_sign_up path" do
subject
expect(response).to redirect_to spree.root_path(thing: 7)
end
- context 'with a guest token present' do
+ context "with a guest token present" do
before do
- request.cookie_jar.signed[:guest_token] = 'ABC'
+ request.cookie_jar.signed[:guest_token] = "ABC"
end
- it 'assigns orders with the correct token and no user present' do
- order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
+ it "assigns orders with the correct token and no user present" do
+ order = create(:order, guest_token: "ABC", user_id: nil, created_by_id: nil)
subject
- user = Spree::User.find_by(email: 'foobar@example.com')
+ user = Spree::User.find_by(email: "foobar@example.com")
order.reload
expect(order.user_id).to eq user.id
expect(order.created_by_id).to eq user.id
end
- it 'does not assign orders with an existing user' do
- order = create(:order, guest_token: 'ABC', user_id: 200)
+ it "does not assign orders with an existing user" do
+ order = create(:order, guest_token: "ABC", user_id: 200)
subject
expect(order.reload.user_id).to eq 200
end
- it 'does not assign orders with a different token' do
- order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil)
+ it "does not assign orders with a different token" do
+ order = create(:order, guest_token: "DEF", user_id: nil, created_by_id: nil)
subject
expect(order.reload.user_id).to be_nil
@@ -80,15 +79,15 @@
end
end
- context 'when user not valid' do
- let(:password_confirmation) { 'foobard123' }
+ context "when user not valid" do
+ let(:password_confirmation) { "foobard123" }
- it 'resets password fields' do
+ it "resets password fields" do
expect(controller).to receive(:clean_up_passwords)
subject
end
- it 'renders new view' do
+ it "renders new view" do
subject
expect(:response).to render_template(:new)
end
diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb
index d49de10c..0ddf3672 100644
--- a/spec/controllers/spree/user_sessions_controller_spec.rb
+++ b/spec/controllers/spree/user_sessions_controller_spec.rb
@@ -3,32 +3,30 @@
RSpec.describe Spree::UserSessionsController, type: :controller do
let(:user) { create(:user) }
- before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
+ before { @request.env["devise.mapping"] = Devise.mappings[:spree_user] } # rubocop:disable RSpec/InstanceVariable
context "#create" do
let(:format) { :html }
- let(:password) { 'secret' }
+ let(:password) { "secret" }
subject do
- post(:create,
- params: {
- spree_user: {
- email: user.email,
- password: password
- },
- format: format
- }
- )
+ post(:create, params: {
+ spree_user: {
+ email: user.email,
+ password: password
+ },
+ format: format
+ })
end
context "when using correct login information" do
- context 'with a guest token present' do
+ context "with a guest token present" do
before do
- request.cookie_jar.signed[:guest_token] = 'ABC'
+ request.cookie_jar.signed[:guest_token] = "ABC"
end
- it 'assigns orders with the correct token and no user present' do
- order = create(:order, email: user.email, guest_token: 'ABC', user_id: nil, created_by_id: nil)
+ it "assigns orders with the correct token and no user present" do
+ order = create(:order, email: user.email, guest_token: "ABC", user_id: nil, created_by_id: nil)
subject
order.reload
@@ -36,8 +34,8 @@
expect(order.created_by_id).to eq user.id
end
- it 'assigns orders with the correct token and no user or email present' do
- order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
+ it "assigns orders with the correct token and no user or email present" do
+ order = create(:order, guest_token: "ABC", user_id: nil, created_by_id: nil)
subject
order.reload
@@ -45,10 +43,10 @@
expect(order.created_by_id).to eq user.id
end
- it 'does not assign completed orders' do
- order = create(:order, email: user.email, guest_token: 'ABC',
- user_id: nil, created_by_id: nil,
- completed_at: 1.minute.ago)
+ it "does not assign completed orders" do
+ order = create(:order, email: user.email, guest_token: "ABC",
+ user_id: nil, created_by_id: nil,
+ completed_at: 1.minute.ago)
subject
order.reload
@@ -56,15 +54,15 @@
expect(order.created_by_id).to be_nil
end
- it 'does not assign orders with an existing user' do
- order = create(:order, guest_token: 'ABC', user_id: 200)
+ it "does not assign orders with an existing user" do
+ order = create(:order, guest_token: "ABC", user_id: 200)
subject
expect(order.reload.user_id).to eq 200
end
- it 'does not assign orders with a different token' do
- order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil)
+ it "does not assign orders with a different token" do
+ order = create(:order, guest_token: "DEF", user_id: nil, created_by_id: nil)
subject
expect(order.reload.user_id).to be_nil
@@ -92,13 +90,13 @@
end
context "when using incorrect login information" do
- let(:password) { 'wrong' }
+ let(:password) { "wrong" }
context "when html format is requested" do
it "renders new template again with errors" do
subject
expect(response).to render_template(:new)
- expect(flash[:error]).to eq I18n.t(:'devise.failure.invalid')
+ expect(flash[:error]).to eq I18n.t(:"devise.failure.invalid")
end
end
diff --git a/spec/controllers/spree/users_controller_spec.rb b/spec/controllers/spree/users_controller_spec.rb
index c4ca9586..95403090 100644
--- a/spec/controllers/spree/users_controller_spec.rb
+++ b/spec/controllers/spree/users_controller_spec.rb
@@ -5,74 +5,74 @@
let(:user) { create(:user) }
let(:role) { create(:role) }
- context '#load_object' do
- it 'redirects to signup path if user is not found' do
- put :update, params: { user: { email: 'foobar@example.com' } }
+ context "#load_object" do
+ it "redirects to signup path if user is not found" do
+ put :update, params: {user: {email: "foobar@example.com"}}
expect(response).to redirect_to spree.login_path
end
end
- context '#create' do
- it 'creates a new user' do
- post :create, params: { user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } }
+ context "#create" do
+ it "creates a new user" do
+ post :create, params: {user: {email: "foobar@example.com", password: "foobar123", password_confirmation: "foobar123"}}
expect(assigns[:user].new_record?).to be false
end
end
- context '#update' do
+ context "#update" do
before { sign_in(user) }
- context 'when updating own account' do
- context 'when user updated successfuly' do
- before { put :update, params: { user: { email: 'mynew@email-address.com' } } }
+ context "when updating own account" do
+ context "when user updated successfuly" do
+ before { put :update, params: {user: {email: "mynew@email-address.com"}} }
- it 'saves user' do
- expect(assigns[:user].email).to eq 'mynew@email-address.com'
+ it "saves user" do
+ expect(assigns[:user].email).to eq "mynew@email-address.com"
end
- it 'updates spree_current_user' do
- expect(subject.spree_current_user.email).to eq 'mynew@email-address.com'
+ it "updates spree_current_user" do
+ expect(subject.spree_current_user.email).to eq "mynew@email-address.com"
end
- it 'redirects to account url' do
+ it "redirects to account url" do
expect(response).to redirect_to spree.account_url(only_path: true)
end
end
- context 'when user not valid' do
- before { put :update, params: { user: { email: '' } } }
+ context "when user not valid" do
+ before { put :update, params: {user: {email: ""}} }
- it 'does not affect spree_current_user' do
+ it "does not affect spree_current_user" do
expect(subject.spree_current_user.email).to eq user.email
end
end
- context 'when updating password' do
+ context "when updating password" do
before do
stub_spree_preferences(Spree::Auth::Config, signout_after_password_change: signout_after_change)
- put :update, params: { user: { password: 'foobar123', password_confirmation: 'foobar123' } }
+ put :update, params: {user: {password: "foobar123", password_confirmation: "foobar123"}}
end
- context 'when signout after password change is enabled' do
+ context "when signout after password change is enabled" do
let(:signout_after_change) { true }
- it 'redirects to login url' do
+ it "redirects to login url" do
expect(response).to redirect_to spree.login_url(only_path: true)
end
end
- context 'when signout after password change is disabled' do
+ context "when signout after password change is disabled" do
let(:signout_after_change) { false }
- it 'redirects to account url' do
+ it "redirects to account url" do
expect(response).to redirect_to spree.account_url(only_path: true)
end
end
end
end
- it 'does not update roles' do
- put :update, params: { user: { spree_role_ids: [role.id] } }
+ it "does not update roles" do
+ put :update, params: {user: {spree_role_ids: [role.id]}}
expect(assigns[:user].spree_roles).to_not include role
end
end
diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb
index a517d1cb..c47d650c 100644
--- a/spec/features/account_spec.rb
+++ b/spec/features/account_spec.rb
@@ -1,59 +1,62 @@
# frozen_string_literal: true
-RSpec.feature 'Accounts', type: :feature do
- context 'editing' do
- scenario 'can edit an admin user' do
- user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password')
+RSpec.feature "Accounts", type: :feature do
+ context "editing" do
+ scenario "can edit an admin user" do
+ user = create(:admin_user, email: "admin@person.com", password: "password", password_confirmation: "password")
visit spree.login_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: user.password
- click_button 'Login'
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
- click_link 'My Account'
- expect(page).to have_text 'admin@person.com'
+ click_link "My Account"
+ expect(page).to have_text "admin@person.com"
end
- scenario 'can edit a new user' do
+ scenario "can edit a new user" do
stub_spree_preferences(Spree::Auth::Config, signout_after_password_change: false)
visit spree.signup_path
- fill_in 'Email', with: 'email@person.com'
- fill_in 'Password', with: 'password'
- fill_in 'Password Confirmation', with: 'password'
- click_button 'Create'
+ fill_in "Email", with: "email@person.com"
+ fill_in "Password", with: "password"
+ fill_in "Password Confirmation", with: "password"
+ click_button "Create"
+ expect(page).to have_text "You have signed up successfully"
- click_link 'My Account'
- expect(page).to have_text 'email@person.com'
- click_link 'Edit'
+ click_link "My Account"
+ expect(page).to have_text "email@person.com"
+ click_link "Edit"
- fill_in 'Password', with: 'foobar'
- fill_in 'Password Confirmation', with: 'foobar'
- click_button 'Update'
+ fill_in "Password", with: "foobar"
+ fill_in "Password Confirmation", with: "foobar"
+ click_button "Update"
- expect(page).to have_text 'email@person.com'
- expect(page).to have_text 'Account updated'
+ expect(page).to have_text "email@person.com"
+ expect(page).to have_text "Account updated"
end
- scenario 'can edit an existing user account' do
- stub_spree_preferences(Spree::Auth::Config ,signout_after_password_change: false)
- user = create(:user, email: 'email@person.com', password: 'secret', password_confirmation: 'secret')
+ scenario "can edit an existing user account" do
+ stub_spree_preferences(Spree::Auth::Config, signout_after_password_change: false)
+ user = create(:user, email: "email@person.com", password: "secret", password_confirmation: "secret")
visit spree.login_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: user.password
- click_button 'Login'
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
- click_link 'My Account'
- expect(page).to have_text 'email@person.com'
- click_link 'Edit'
+ click_link "My Account"
+ expect(page).to have_text "email@person.com"
+ click_link "Edit"
- fill_in 'Password', with: 'foobar'
- fill_in 'Password Confirmation', with: 'foobar'
- click_button 'Update'
+ fill_in "Password", with: "foobar"
+ fill_in "Password Confirmation", with: "foobar"
+ click_button "Update"
- expect(page).to have_text 'email@person.com'
- expect(page).to have_text 'Account updated'
+ expect(page).to have_text "email@person.com"
+ expect(page).to have_text "Account updated"
end
end
end
diff --git a/spec/features/admin/password_reset_spec.rb b/spec/features/admin/password_reset_spec.rb
index 4d44408f..9838cae0 100644
--- a/spec/features/admin/password_reset_spec.rb
+++ b/spec/features/admin/password_reset_spec.rb
@@ -1,77 +1,75 @@
# frozen_string_literal: true
-RSpec.feature 'Admin - Reset Password', type: :feature do
+RSpec.feature "Admin - Reset Password", type: :feature do
let!(:store) { create(:store) }
background do
- ActionMailer::Base.default_url_options[:host] = 'http://example.com'
+ ActionMailer::Base.default_url_options[:host] = "http://example.com"
end
- context 'when an account with this email address exists' do
- let!(:user) { create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret') }
+ context "when an account with this email address exists" do
+ let!(:user) { create(:user, email: "foobar@example.com", password: "secret", password_confirmation: "secret") }
- scenario 'allows a user to supply an email for the password reset' do
+ scenario "allows a user to supply an email for the password reset" do
visit spree.admin_login_path
- click_link 'Forgot Password?'
+ click_link "Forgot Password?"
fill_in_email
- click_button 'Reset my password'
- expect(page).to have_text 'you will receive an email with instructions'
+ click_button "Reset my password"
+ expect(page).to have_text "you will receive an email with instructions"
end
end
# Revealing that an admin email address is not found allows an attacker to
# find admin account email addresses by trying email addresses until this
# error is not shown.
- scenario 'does not reveal email addresses if they are not found' do
+ scenario "does not reveal email addresses if they are not found" do
visit spree.admin_login_path
- click_link 'Forgot Password?'
+ click_link "Forgot Password?"
fill_in_email
- click_button 'Reset my password'
+ click_button "Reset my password"
expect(page).to_not have_text "Email not found"
- expect(page).to have_text 'you will receive an email with instructions'
+ expect(page).to have_text "you will receive an email with instructions"
end
def fill_in_email
- fill_in 'Email', with: 'foobar@example.com'
+ fill_in "Email", with: "foobar@example.com"
end
- context 'password management' do
+ context "password management" do
let!(:admin) do
create(:admin_user,
- email: 'admin@example.com',
- password: 'secret',
- password_confirmation: 'secret'
- )
+ email: "admin@example.com",
+ password: "secret",
+ password_confirmation: "secret")
end
let!(:user) do
create(:user,
- email: 'user@example.com',
- password: 'test123',
- password_confirmation: 'test123'
- )
+ email: "user@example.com",
+ password: "test123",
+ password_confirmation: "test123")
end
before do
visit spree.admin_login_path
- fill_in 'Email', with: admin.email
- fill_in 'Password', with: admin.password
- click_button 'Login'
+ fill_in "Email", with: admin.email
+ fill_in "Password", with: admin.password
+ click_button "Login"
visit spree.admin_users_path
end
- context 'if currently logged-in admin' do
+ context "if currently logged-in admin" do
context "clicks on an user's page" do
- it 'can reset its password' do
+ it "can reset its password" do
within("#spree_user_#{user.id}") do
click_link user.email
end
- click_button 'Reset password'
+ click_button "Reset password"
expect(page).to have_content(
- 'If an account with that email address exists, '\
- 'you will receive an email with instructions about '\
- 'how to reset your password in a few minutes.'
+ "If an account with that email address exists, " \
+ "you will receive an email with instructions about " \
+ "how to reset your password in a few minutes."
)
end
end
diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb
index 1daeb3e8..6f8d565e 100644
--- a/spec/features/admin/products_spec.rb
+++ b/spec/features/admin/products_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-RSpec.feature 'Admin products', type: :feature do
- context 'as anonymous user' do
+RSpec.feature "Admin products", type: :feature do
+ context "as anonymous user" do
# Regression test for #1250
- scenario 'redirects to login page when attempting to access product listing' do
+ scenario "redirects to login page when attempting to access product listing" do
expect { visit spree.admin_products_path }.not_to raise_error
end
end
diff --git a/spec/features/admin/sign_in_spec.rb b/spec/features/admin/sign_in_spec.rb
index 25840f1c..500f949d 100644
--- a/spec/features/admin/sign_in_spec.rb
+++ b/spec/features/admin/sign_in_spec.rb
@@ -1,45 +1,45 @@
# frozen_string_literal: true
-RSpec.feature 'Admin - Sign In', type: :feature do
+RSpec.feature "Admin - Sign In", type: :feature do
background do
- @user = create(:user, email: 'email@person.com')
+ @user = create(:admin_user, email: "email@person.com")
visit spree.admin_login_path
end
- scenario 'asks user to sign in' do
+ scenario "asks user to sign in" do
visit spree.admin_path
- expect(page).not_to have_text 'Authorization Failure'
+ expect(page).not_to have_text "Authorization Failure"
end
- scenario 'lets a user sign in successfully' do
- fill_in 'Email', with: @user.email
- fill_in 'Password', with: 'secret'
- click_button 'Login'
+ scenario "lets a user sign in successfully" do
+ fill_in "Email", with: @user.email
+ fill_in "Password", with: "secret"
+ click_button "Login"
- expect(page).to have_text 'Logged in successfully'
- expect(page).not_to have_text 'Login'
- expect(page).to have_text 'Logout'
- expect(current_path).to eq '/'
+ expect(page).to have_text "Logged in successfully"
+ expect(page).not_to have_text "Login"
+ expect(page).to have_text "Logout"
+ expect(current_path).to eq "/admin/orders"
end
- scenario 'shows validation erros' do
- fill_in 'Email', with: @user.email
- fill_in 'Password', with: 'wrong_password'
- click_button 'Login'
+ scenario "shows validation erros" do
+ fill_in "Email", with: @user.email
+ fill_in "Password", with: "wrong_password"
+ click_button "Login"
- expect(page).to have_text 'Invalid email or password'
- expect(page).to have_text 'Login'
+ expect(page).to have_text "Invalid email or password"
+ expect(page).to have_text "Login"
end
- scenario 'allows a user to access a restricted page after logging in' do
- user = create(:admin_user, email: 'admin@person.com')
+ scenario "allows a user to access a restricted page after logging in" do
+ user = create(:admin_user, email: "admin@person.com")
visit spree.admin_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: 'secret'
- click_button 'Login'
+ fill_in "Email", with: user.email
+ fill_in "Password", with: "secret"
+ click_button "Login"
- expect(page).to have_text 'admin@person.com'
- expect(current_path).to eq '/admin/orders'
+ expect(page).to have_text "admin@person.com"
+ expect(current_path).to eq "/admin/orders"
end
end
diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb
index 420ad145..85ae29fc 100644
--- a/spec/features/admin/sign_out_spec.rb
+++ b/spec/features/admin/sign_out_spec.rb
@@ -1,23 +1,43 @@
# frozen_string_literal: true
-RSpec.feature 'Admin - Sign Out', type: :feature, js: true do
+RSpec.feature "Admin - Sign Out", type: :feature, js: true do
given!(:user) do
- create :user, email: 'email@person.com'
+ create :admin_user, email: "email@person.com"
end
background do
visit spree.admin_login_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: 'secret'
+ fill_in "Email", with: user.email
+ fill_in "Password", with: "secret"
# Regression test for #1257
- check 'Remember me'
- click_button 'Login'
+ check "Remember me"
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
end
- scenario 'allows a signed in user to logout' do
- click_link 'Logout'
+ scenario "allows a signed in user to logout" do
+ click_logout_link
visit spree.admin_login_path
- expect(page).to have_text 'Login'
- expect(page).not_to have_text 'Logout'
+ expect(page).to have_text "Login"
+ expect(page).not_to have_text "Logout"
+ end
+
+ def click_logout_link
+ new_version? ? logout_new_version : logout_old_version
+ end
+
+ def new_version?
+ Gem::Requirement.new(">= 4.2").satisfied_by?(Spree.solidus_gem_version)
+ end
+
+ def logout_new_version
+ find("details div", text: user.email, wait: 10).click
+ within("details") do
+ click_link "Logout"
+ end
+ end
+
+ def logout_old_version
+ click_link "Logout"
end
end
diff --git a/spec/features/admin_permissions_spec.rb b/spec/features/admin_permissions_spec.rb
index 2306d387..2a1f1495 100644
--- a/spec/features/admin_permissions_spec.rb
+++ b/spec/features/admin_permissions_spec.rb
@@ -1,46 +1,47 @@
# frozen_string_literal: true
-RSpec.feature 'Admin Permissions', type: :feature do
- context 'orders' do
+RSpec.feature "Admin Permissions", type: :feature do
+ context "orders" do
background do
- user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password')
+ user = create(:admin_user, email: "admin@person.com", password: "password", password_confirmation: "password")
Spree::Ability.register_ability(AbilityDecorator)
visit spree.login_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: user.password
- click_button 'Login'
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
end
- context 'admin is restricted from accessing orders' do
- scenario 'can not list orders' do
+ context "admin is restricted from accessing orders" do
+ scenario "can not list orders" do
visit spree.admin_orders_path
- expect(page).to have_text 'Authorization Failure'
+ expect(page).to have_text "Authorization Failure"
end
- scenario 'can not edit orders' do
- create(:order, number: 'R123')
- visit spree.edit_admin_order_path('R123')
- expect(page).to have_text 'Authorization Failure'
+ scenario "can not edit orders" do
+ create(:order, number: "R123")
+ visit spree.edit_admin_order_path("R123")
+ expect(page).to have_text "Authorization Failure"
end
- scenario 'can not new orders' do
+ scenario "can not new orders" do
visit spree.new_admin_order_path
- expect(page).to have_text 'Authorization Failure'
+ expect(page).to have_text "Authorization Failure"
end
end
context "admin is restricted from accessing an order's customer details" do
given(:order) { create(:order_with_totals) }
- scenario 'can not list customer details for an order' do
+ scenario "can not list customer details for an order" do
visit spree.admin_order_customer_path(order)
- expect(page).to have_text 'Authorization Failure'
+ expect(page).to have_text "Authorization Failure"
end
scenario "can not edit an order's customer details" do
visit spree.edit_admin_order_customer_path(order)
- expect(page).to have_text 'Authorization Failure'
+ expect(page).to have_text "Authorization Failure"
end
end
end
diff --git a/spec/features/change_email_spec.rb b/spec/features/change_email_spec.rb
index c04ee5db..5c2c4d03 100644
--- a/spec/features/change_email_spec.rb
+++ b/spec/features/change_email_spec.rb
@@ -1,27 +1,28 @@
# frozen_string_literal: true
-RSpec.feature 'Change email', type: :feature do
+RSpec.feature "Change email", type: :feature do
background do
stub_spree_preferences(Spree::Auth::Config, signout_after_password_change: false)
user = create(:user)
visit spree.root_path
- click_link 'Login'
+ click_link "Login"
- fill_in 'spree_user[email]', with: user.email
- fill_in 'spree_user[password]', with: 'secret'
- click_button 'Login'
+ fill_in "spree_user[email]", with: user.email
+ fill_in "spree_user[password]", with: "secret"
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
visit spree.edit_account_path
end
- scenario 'work with correct password' do
- fill_in 'user_email', with: 'tests@example.com'
- fill_in 'user_password', with: 'password'
- fill_in 'user_password_confirmation', with: 'password'
- click_button 'Update'
+ scenario "work with correct password" do
+ fill_in "user_email", with: "tests@example.com"
+ fill_in "user_password", with: "password"
+ fill_in "user_password_confirmation", with: "password"
+ click_button "Update"
- expect(page).to have_text 'Account updated'
- expect(page).to have_text 'tests@example.com'
+ expect(page).to have_text "Account updated"
+ expect(page).to have_text "tests@example.com"
end
end
diff --git a/spec/features/checkout_spec.rb b/spec/features/checkout_spec.rb
index 3221aaae..f309a18a 100644
--- a/spec/features/checkout_spec.rb
+++ b/spec/features/checkout_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-RSpec.feature 'Checkout', :js, type: :feature do
+RSpec.feature "Checkout", :js, type: :feature do
given!(:store) { create(:store) }
- given!(:country) { create(:country, name: 'United States', states_required: true) }
- given!(:state) { create(:state, name: 'Maryland', country: country) }
+ given!(:country) { create(:country, name: "United States", states_required: true) }
+ given!(:state) { create(:state, name: "Maryland", country: country) }
given!(:shipping_method) do
shipping_method = create(:shipping_method)
calculator = Spree::Calculator::Shipping::PerItem.create!(calculable: shipping_method, preferred_amount: 10)
@@ -11,12 +11,12 @@
shipping_method.tap(&:save)
end
- given!(:zone) { create(:zone) }
+ given!(:zone) { create(:zone) }
given!(:address) { create(:address, state: state, country: country) }
- given!(:payment_method){ create :check_payment_method }
+ given!(:payment_method) { create :check_payment_method }
background do
- @product = create(:product, name: 'RoR Mug')
+ @product = create(:product, name: "RoR Mug")
@product.master.stock_items.first.set_count_on_hand(1)
# Bypass gateway error on checkout | ..or stub a gateway
@@ -26,87 +26,101 @@
end
# Regression test for https://github.com/solidusio/solidus/issues/1588
- scenario 'leaving and returning to address step' do
+ scenario "leaving and returning to address step" do
stub_spree_preferences(Spree::Auth::Config, registration_step: true)
- click_link 'RoR Mug'
- click_button 'Add To Cart'
- within('h1') { expect(page).to have_text 'Shopping Cart' }
- click_button 'Checkout'
+ click_link "RoR Mug"
+ click_button "Add To Cart"
+ within("h1") { expect(page).to have_text "Shopping Cart" }
+ click_button "Checkout"
- within '#guest_checkout' do
- fill_in 'Email', with: 'test@example.com'
+ within "#guest_checkout" do
+ fill_in "Email", with: "test@example.com"
end
- click_on 'Continue'
+ click_on "Continue"
- click_on 'Cart'
+ click_on "Cart"
- click_on 'Checkout'
+ click_on "Checkout"
expect(page).to have_content "Billing Address"
end
- context 'without payment being required' do
- scenario 'allow a visitor to checkout as guest, without registration' do
- click_link 'RoR Mug'
- click_button 'Add To Cart'
- within('h1') { expect(page).to have_text 'Shopping Cart' }
- click_button 'Checkout'
+ context "without payment being required" do
+ scenario "allow a visitor to checkout as guest, without registration" do
+ click_link "RoR Mug"
+ click_button "Add To Cart"
+ within("h1") { expect(page).to have_text "Shopping Cart" }
+ click_button "Checkout"
expect(page).to have_content(/Checkout as a Guest/i)
- within('#guest_checkout') { fill_in 'Email', with: 'spree@test.com' }
- click_button 'Continue'
+ within("#guest_checkout") { fill_in "Email", with: "spree@test.com" }
+ click_button "Continue"
expect(page).to have_text(/Billing Address/i)
expect(page).to have_text(/Shipping Address/i)
fill_addresses_fields_with(address)
- click_button 'Save and Continue'
+ click_button "Save and Continue"
- click_button 'Save and Continue'
- click_button 'Save and Continue'
- click_button 'Place Order'
+ expect(page).to have_content "UPS Ground"
- expect(page).to have_text 'Your order has been processed successfully'
+ click_button "Save and Continue"
+
+ expect(page).to have_content(/Payment Information/i)
+
+ click_button "Save and Continue"
+ click_button "Place Order"
+
+ expect(page).to have_text "Your order has been processed successfully"
end
- scenario 'associate an uncompleted guest order with user after logging in' do
- user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
- click_link 'RoR Mug'
- click_button 'Add To Cart'
+ scenario "associate an uncompleted guest order with user after logging in" do
+ user = create(:user, email: "email@person.com", password: "password", password_confirmation: "password")
+ click_link "RoR Mug"
+ click_button "Add To Cart"
+ within("h1") { expect(page).to have_text "Shopping Cart" }
- visit spree.login_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: user.password
- click_button 'Login'
- click_link 'Cart'
+ click_link "Login"
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
+ click_link "Cart"
- expect(page).to have_text 'RoR Mug'
- within('h1') { expect(page).to have_text 'Shopping Cart' }
+ expect(page).to have_text "RoR Mug"
+ within("h1") { expect(page).to have_text "Shopping Cart" }
- click_button 'Checkout'
+ click_button "Checkout"
fill_addresses_fields_with(address)
- click_button 'Save and Continue'
+ click_button "Save and Continue"
+
+ expect(page).to have_content "UPS Ground"
+
+ click_button "Save and Continue"
+
+ expect(page).to have_content(/Payment Information/i)
- click_button 'Save and Continue'
- click_button 'Save and Continue'
- click_button 'Place Order'
+ click_button "Save and Continue"
+ click_button "Place Order"
- expect(page).to have_text 'Your order has been processed successfully'
+ expect(page).to have_text "Your order has been processed successfully"
expect(Spree::Order.first.user).to eq user
end
# Regression test for #890
- scenario 'associate an incomplete guest order with user after successful password reset' do
- create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
- click_link 'RoR Mug'
- click_button 'Add To Cart'
-
- visit spree.login_path
- click_link 'Forgot Password?'
- fill_in 'spree_user_email', with: 'email@person.com'
- click_button 'Reset my password'
+ scenario "associate an incomplete guest order with user after successful password reset" do
+ create(:user, email: "email@person.com", password: "password", password_confirmation: "password")
+ click_link "RoR Mug"
+ click_button "Add To Cart"
+ within("h1") { expect(page).to have_text "Shopping Cart" }
+
+ click_link "Login"
+ click_link "Forgot Password?"
+ fill_in "spree_user_email", with: "email@person.com"
+ click_button "Reset my password"
+ expect(page).to have_content("you will receive an email with instructions")
# Need to do this now because the token stored in the DB is the encrypted version
# The 'plain-text' version is sent in the email and there's one way to get that!
@@ -115,44 +129,51 @@
token = token_url_regex.match(reset_password_email.body.to_s)[1]
visit spree.edit_spree_user_password_path(reset_password_token: token)
- fill_in 'Password', with: 'password'
- fill_in 'Password Confirmation', with: 'password'
- click_button 'Update'
+ fill_in "Password", with: "password"
+ fill_in "Password Confirmation", with: "password"
+ click_button "Update"
- click_link 'Cart'
- click_button 'Checkout'
+ click_link "Cart"
+ click_button "Checkout"
fill_addresses_fields_with(address)
- click_button 'Save and Continue'
+ click_button "Save and Continue"
- expect(page).not_to have_text 'Email is invalid'
+ expect(page).not_to have_text "Email is invalid"
end
- scenario 'allow a user to register during checkout' do
- click_link 'RoR Mug'
- click_button 'Add To Cart'
- click_button 'Checkout'
+ scenario "allow a user to register during checkout" do
+ click_link "RoR Mug"
+ click_button "Add To Cart"
+ within("h1") { expect(page).to have_text "Shopping Cart" }
+ click_button "Checkout"
- expect(page).to have_text 'Registration'
+ expect(page).to have_text "Registration"
- click_link 'Create a new account'
+ click_link "Create a new account"
- fill_in 'Email', with: 'email@person.com'
- fill_in 'Password', with: 'spree123'
- fill_in 'Password Confirmation', with: 'spree123'
- click_button 'Create'
+ fill_in "Email", with: "email@person.com"
+ fill_in "Password", with: "spree123"
+ fill_in "Password Confirmation", with: "spree123"
+ click_button "Create"
- expect(page).to have_text 'You have signed up successfully.'
+ expect(page).to have_text "You have signed up successfully."
fill_addresses_fields_with(address)
- click_button 'Save and Continue'
- click_button 'Save and Continue'
- click_button 'Save and Continue'
- click_button 'Place Order'
+ click_button "Save and Continue"
+
+ expect(page).to have_content "UPS Ground"
+
+ click_button "Save and Continue"
+
+ expect(page).to have_content(/Payment Information/i)
+
+ click_button "Save and Continue"
+ click_button "Place Order"
- expect(page).to have_text 'Your order has been processed successfully'
- expect(Spree::Order.first.user).to eq Spree::User.find_by(email: 'email@person.com')
+ expect(page).to have_text "Your order has been processed successfully"
+ expect(Spree::Order.first.user).to eq Spree::User.find_by(email: "email@person.com")
end
end
end
diff --git a/spec/features/confirmation_spec.rb b/spec/features/confirmation_spec.rb
index f50df67c..90f7b583 100644
--- a/spec/features/confirmation_spec.rb
+++ b/spec/features/confirmation_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
-RSpec.feature 'Confirmation' do
+RSpec.feature "Confirmation" do
before do
allow(Spree::UserMailer).to receive(:confirmation_instructions)
.and_return(double(deliver: true))
@@ -11,18 +11,18 @@
let!(:store) { create(:store) }
background do
- ActionMailer::Base.default_url_options[:host] = 'http://example.com'
+ ActionMailer::Base.default_url_options[:host] = "http://example.com"
end
- scenario 'create a new user', js: true, confirmable: false do
+ scenario "create a new user", js: true, confirmable: false do
visit spree.signup_path
- fill_in 'Email', with: 'email@person.com'
- fill_in 'Password', with: 'password'
- fill_in 'Password Confirmation', with: 'password'
- click_button 'Create'
+ fill_in "Email", with: "email@person.com"
+ fill_in "Password", with: "password"
+ fill_in "Password Confirmation", with: "password"
+ click_button "Create"
- expect(page).to have_text 'You have signed up successfully.'
+ expect(page).to have_text "You have signed up successfully."
expect(Spree::User.last.confirmed?).to be(false)
end
end
diff --git a/spec/features/order_spec.rb b/spec/features/order_spec.rb
index 70dd4f80..2fc932e1 100644
--- a/spec/features/order_spec.rb
+++ b/spec/features/order_spec.rb
@@ -1,59 +1,61 @@
# frozen_string_literal: true
-RSpec.feature 'Orders', :js, type: :feature do
- scenario 'allow a user to view their cart at any time' do
+RSpec.feature "Orders", :js, type: :feature do
+ scenario "allow a user to view their cart at any time" do
visit spree.cart_path
- expect(page).to have_text 'Your cart is empty'
+ expect(page).to have_text "Your cart is empty"
end
# regression test for spree/spree#1687
- scenario 'merge incomplete orders from different sessions' do
+ scenario "merge incomplete orders from different sessions" do
create(:store)
- create(:product, name: 'RoR Mug')
- create(:product, name: 'RoR Shirt')
+ create(:product, name: "RoR Mug")
+ create(:product, name: "RoR Shirt")
- user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
+ user = create(:user, email: "email@person.com", password: "password", password_confirmation: "password")
- using_session('first') do
+ using_session("first") do
visit spree.root_path
- click_link 'RoR Mug'
- click_button 'Add To Cart'
+ click_link "RoR Mug"
+ click_button "Add To Cart"
- visit spree.login_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: user.password
- click_button 'Login'
+ click_link "Login"
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
- click_link 'Cart'
- expect(page).to have_text 'RoR Mug'
+ click_link "Cart"
+ expect(page).to have_text "RoR Mug"
end
- using_session('second') do
+ using_session("second") do
visit spree.root_path
- click_link 'RoR Shirt'
- click_button 'Add To Cart'
+ click_link "RoR Shirt"
+ click_button "Add To Cart"
- visit spree.login_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: user.password
- click_button 'Login'
+ click_link "Login"
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
# Order should have been merged with first session
- click_link 'Cart'
- expect(page).to have_text 'RoR Mug'
- expect(page).to have_text 'RoR Shirt'
+ click_link "Cart"
+ expect(page).to have_text "RoR Mug"
+ expect(page).to have_text "RoR Shirt"
end
- using_session('first') do
+ using_session("first") do
visit spree.root_path
- click_link 'Cart'
+ click_link "Cart"
# Order should have been merged with second session
- expect(page).to have_text 'RoR Mug'
- expect(page).to have_text 'RoR Shirt'
+ expect(page).to have_text "RoR Mug"
+ expect(page).to have_text "RoR Shirt"
end
end
end
diff --git a/spec/features/password_reset_spec.rb b/spec/features/password_reset_spec.rb
index 70ee7a8d..02417380 100644
--- a/spec/features/password_reset_spec.rb
+++ b/spec/features/password_reset_spec.rb
@@ -1,37 +1,37 @@
# frozen_string_literal: true
-RSpec.feature 'Reset Password', type: :feature do
+RSpec.feature "Reset Password", type: :feature do
let!(:store) { create(:store) }
background do
- ActionMailer::Base.default_url_options[:host] = 'http://example.com'
+ ActionMailer::Base.default_url_options[:host] = "http://example.com"
end
- context 'when an account with this email address exists' do
- let!(:user) { create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret') }
+ context "when an account with this email address exists" do
+ let!(:user) { create(:user, email: "foobar@example.com", password: "secret", password_confirmation: "secret") }
- scenario 'allows a user to supply an email for the password reset' do
+ scenario "allows a user to supply an email for the password reset" do
visit spree.login_path
- click_link 'Forgot Password?'
+ click_link "Forgot Password?"
fill_in_email
- click_button 'Reset my password'
- expect(page).to have_text 'you will receive an email with instructions'
+ click_button "Reset my password"
+ expect(page).to have_text "you will receive an email with instructions"
end
end
# Test that we are extending the functionality from
# https://github.com/solidusio/solidus_auth_devise/pull/155
# to the non-admin login
- scenario 'does not reveal email addresses if they are not found' do
+ scenario "does not reveal email addresses if they are not found" do
visit spree.login_path
- click_link 'Forgot Password?'
+ click_link "Forgot Password?"
fill_in_email
- click_button 'Reset my password'
+ click_button "Reset my password"
expect(page).to_not have_text "Email not found"
- expect(page).to have_text 'you will receive an email with instructions'
+ expect(page).to have_text "you will receive an email with instructions"
end
def fill_in_email
- fill_in 'Email', with: 'foobar@example.com'
+ fill_in "Email", with: "foobar@example.com"
end
end
diff --git a/spec/features/sign_in_spec.rb b/spec/features/sign_in_spec.rb
index 006cf5ba..be00d392 100644
--- a/spec/features/sign_in_spec.rb
+++ b/spec/features/sign_in_spec.rb
@@ -1,46 +1,46 @@
# frozen_string_literal: true
-RSpec.feature 'Sign In', type: :feature do
+RSpec.feature "Sign In", type: :feature do
background do
- @user = create(:user, email: 'email@person.com', password: 'secret', password_confirmation: 'secret')
+ @user = create(:user, email: "email@person.com", password: "secret", password_confirmation: "secret")
visit spree.login_path
end
- scenario 'ask user to sign in' do
+ scenario "ask user to sign in" do
visit spree.admin_path
- expect(page).not_to have_text 'Authorization Failure'
+ expect(page).not_to have_text "Authorization Failure"
end
- scenario 'let a user sign in successfully' do
- fill_in 'Email', with: @user.email
- fill_in 'Password', with: @user.password
- click_button 'Login'
+ scenario "let a user sign in successfully" do
+ fill_in "Email", with: @user.email
+ fill_in "Password", with: @user.password
+ click_button "Login"
- expect(page).to have_text 'Logged in successfully'
- expect(page).not_to have_text 'Login'
- expect(page).to have_text 'Logout'
- expect(current_path).to eq '/'
+ expect(page).to have_text "Logged in successfully"
+ expect(page).not_to have_text "Login"
+ expect(page).to have_text "Logout"
+ expect(current_path).to eq "/"
end
- scenario 'show validation erros' do
- fill_in 'Email', with: @user.email
- fill_in 'Password', with: 'wrong_password'
- click_button 'Login'
+ scenario "show validation erros" do
+ fill_in "Email", with: @user.email
+ fill_in "Password", with: "wrong_password"
+ click_button "Login"
- expect(page).to have_text 'Invalid email or password'
- expect(page).to have_text 'Login'
+ expect(page).to have_text "Invalid email or password"
+ expect(page).to have_text "Login"
end
- scenario 'allow a user to access a restricted page after logging in' do
- user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password')
+ scenario "allow a user to access a restricted page after logging in" do
+ user = create(:admin_user, email: "admin@person.com", password: "password", password_confirmation: "password")
visit spree.admin_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: user.password
- click_button 'Login'
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
+ click_button "Login"
- expect(page).to have_text 'admin@person.com'
- expect(current_path).to eq '/admin/orders'
+ expect(page).to have_text "admin@person.com"
+ expect(current_path).to eq "/admin/orders"
end
it "should store the user previous location" do
@@ -48,6 +48,7 @@
fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "Login"
+ expect(page).to have_text "Logged in successfully"
expect(current_path).to eq "/account"
end
end
diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb
index a61f5b20..25aa368b 100644
--- a/spec/features/sign_out_spec.rb
+++ b/spec/features/sign_out_spec.rb
@@ -1,26 +1,27 @@
# frozen_string_literal: true
-RSpec.feature 'Sign Out', type: :feature, js: true do
+RSpec.feature "Sign Out", type: :feature, js: true do
given!(:user) do
- create(:user,
- email: 'email@person.com',
- password: 'secret',
- password_confirmation: 'secret')
+ create(:user,
+ email: "email@person.com",
+ password: "secret",
+ password_confirmation: "secret")
end
background do
visit spree.login_path
- fill_in 'Email', with: user.email
- fill_in 'Password', with: user.password
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
# Regression test for #1257
- check 'Remember me'
- click_button 'Login'
+ check "Remember me"
+ click_button "Login"
+ expect(page).to have_text "Logged in successfully"
end
- scenario 'allow a signed in user to logout' do
- click_link 'Logout'
+ scenario "allow a signed in user to logout" do
+ click_link "Logout"
visit spree.root_path
- expect(page).to have_text 'LOGIN'
- expect(page).not_to have_text 'LOGOUT'
+ expect(page).to have_text "LOGIN"
+ expect(page).not_to have_text "LOGOUT"
end
end
diff --git a/spec/features/sign_up_spec.rb b/spec/features/sign_up_spec.rb
index 98a40dc7..356632f5 100644
--- a/spec/features/sign_up_spec.rb
+++ b/spec/features/sign_up_spec.rb
@@ -1,30 +1,30 @@
# frozen_string_literal: true
-RSpec.feature 'Sign Up', type: :feature do
- context 'with valid data' do
- scenario 'create a new user' do
+RSpec.feature "Sign Up", type: :feature do
+ context "with valid data" do
+ scenario "create a new user" do
visit spree.signup_path
- fill_in 'Email', with: 'email@person.com'
- fill_in 'Password', with: 'password'
- fill_in 'Password Confirmation', with: 'password'
- click_button 'Create'
+ fill_in "Email", with: "email@person.com"
+ fill_in "Password", with: "password"
+ fill_in "Password Confirmation", with: "password"
+ click_button "Create"
- expect(page).to have_text 'You have signed up successfully.'
+ expect(page).to have_text "You have signed up successfully."
expect(Spree::User.count).to eq(1)
end
end
- context 'with invalid data' do
- scenario 'does not create a new user' do
+ context "with invalid data" do
+ scenario "does not create a new user" do
visit spree.signup_path
- fill_in 'Email', with: 'email@person.com'
- fill_in 'Password', with: 'password'
- fill_in 'Password Confirmation', with: ''
- click_button 'Create'
+ fill_in "Email", with: "email@person.com"
+ fill_in "Password", with: "password"
+ fill_in "Password Confirmation", with: ""
+ click_button "Create"
- expect(page).to have_css '#errorExplanation'
+ expect(page).to have_css "#errorExplanation"
expect(Spree::User.count).to eq(0)
end
end
diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb
index a5ae4904..626bbdbd 100644
--- a/spec/mailers/user_mailer_spec.rb
+++ b/spec/mailers/user_mailer_spec.rb
@@ -6,40 +6,40 @@
before do
user = create(:user)
- Spree::UserMailer.reset_password_instructions(user, 'token goes here').deliver_now
+ Spree::UserMailer.reset_password_instructions(user, "token goes here").deliver_now
@message = ActionMailer::Base.deliveries.last
end
- describe '#reset_password_instructions' do
- describe 'message contents' do
+ describe "#reset_password_instructions" do
+ describe "message contents" do
before do
- described_class.reset_password_instructions(user, 'token goes here').deliver_now
+ described_class.reset_password_instructions(user, "token goes here").deliver_now
@message = ActionMailer::Base.deliveries.last
end
- context 'subject includes' do
- it 'translated devise instructions' do
+ context "subject includes" do
+ it "translated devise instructions" do
expect(@message.subject).to include(
I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])
)
end
- it 'Spree site name' do
+ it "Spree site name" do
expect(@message.subject).to include store.name
end
end
- context 'body includes' do
- it 'password reset url' do
+ context "body includes" do
+ it "password reset url" do
expect(@message.body.raw_source).to include "http://#{store.url}/user/spree_user/password/edit"
end
end
end
- describe 'legacy support for User object' do
- it 'sends an email' do
+ describe "legacy support for User object" do
+ it "sends an email" do
expect {
- described_class.reset_password_instructions(user, 'token goes here').deliver_now
+ described_class.reset_password_instructions(user, "token goes here").deliver_now
}.to change(ActionMailer::Base.deliveries, :size).by(1)
end
end
diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb
index b8030b3e..7ca125ef 100644
--- a/spec/models/order_spec.rb
+++ b/spec/models/order_spec.rb
@@ -3,11 +3,11 @@
RSpec.describe Spree::Order, type: :model do
let(:order) { described_class.new }
- context '#associate_user!' do
- let(:user) { build_stubbed(:user, email: 'spree@example.com') }
+ context "#associate_user!" do
+ let(:user) { build_stubbed(:user, email: "spree@example.com") }
before { allow(order).to receive(:save!) { true } }
- it 'associates the order with the specified user' do
+ it "associates the order with the specified user" do
order.associate_user! user
expect(order.user).to eq user
end
@@ -17,7 +17,7 @@
expect(order.email).to eq user.email
end
- it 'destroys any previous association with a guest user' do
+ it "destroys any previous association with a guest user" do
guest_user = build_stubbed(:user)
order.user = guest_user
order.associate_user! user
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index c3e6e544..c686cc43 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1,18 +1,23 @@
# frozen_string_literal: true
RSpec.describe Spree::User, type: :model do
- before(:all) { Spree::Role.create name: 'admin' }
+ before(:all) { Spree::Role.create name: "admin" }
- it '#admin?' do
+ it "#admin?" do
expect(create(:admin_user).admin?).to be true
expect(create(:user).admin?).to be false
end
+ describe "#timezone" do
+ subject(:user) { create(:user) }
+ it { expect(user).to respond_to(:timezone) }
+ end
+
context "recoverable" do
let(:user) { create(:user) }
- it 'generates the reset password token' do
- expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver: true))
+ it "generates the reset password token" do
+ expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver_now: true))
expect { user.send_reset_password_instructions }.to change(user, :reset_password_token).to be_present
end
@@ -49,11 +54,11 @@
end
end
- describe '#destroy' do
+ describe "#destroy" do
let(:user) { create(:user) }
- context 'with same email address as previously deleted account' do
- it 'will allow users to register later' do
+ context "with same email address as previously deleted account" do
+ it "allows users to register later" do
user1 = build(:user)
user1.save
@@ -68,10 +73,10 @@
end
end
- describe '#destroy' do
+ describe "#destroy" do
let(:user) { create(:user) }
- it 'removes the record from the database' do
+ it "removes the record from the database" do
user.destroy
if defined?(Spree::ParanoiaDeprecations)
@@ -82,10 +87,10 @@
end
end
- describe '#really_destroy!', if: defined?(Spree::ParanoiaDeprecations) do
+ describe "#really_destroy!", if: defined?(Spree::ParanoiaDeprecations) do
let(:user) { create(:user) }
- it 'removes the record from the database' do
+ it "removes the record from the database" do
user.really_destroy!
expect(Spree::User.with_deleted.exists?(id: user.id)).to eql false
end
diff --git a/spec/requests/spree/frontend/user_update_spec.rb b/spec/requests/spree/frontend/user_update_spec.rb
index f569199e..75e0c01f 100644
--- a/spec/requests/spree/frontend/user_update_spec.rb
+++ b/spec/requests/spree/frontend/user_update_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-RSpec.feature 'User update', type: :request do
- context 'CSRF protection' do
+RSpec.feature "User update", type: :request do
+ context "CSRF protection" do
%i[exception reset_session null_session].each do |strategy|
# Completely clean the configuration of forgery protection for the
# controller and reset it after the expectations. However, besides `:with`,
@@ -25,17 +25,17 @@
end
it "is not possible to take account over with the #{strategy} forgery protection strategy" do
- user = create(:user, email: 'legit@mail.com', password: 'password')
+ user = create(:user, email: "legit@mail.com", password: "password")
- post '/login', params: "spree_user[email]=legit@mail.com&spree_user[password]=password"
+ post "/login", params: "spree_user[email]=legit@mail.com&spree_user[password]=password"
begin
- put '/users/123456', params: 'user[email]=hacked@example.com'
+ put "/users/123456", params: "user[email]=hacked@example.com"
rescue
# testing that the account is not compromised regardless of any raised
# exception
end
- expect(user.reload.email).to eq('legit@mail.com')
+ expect(user.reload.email).to eq("legit@mail.com")
end
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index aabfc06f..d7b411a4 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,20 +1,26 @@
# frozen_string_literal: true
# Configure Rails Environment
-ENV['RAILS_ENV'] = 'test'
+ENV["RAILS_ENV"] = "test"
-require 'rails-controller-testing'
+require "rails-controller-testing"
# Run Coverage report
-require 'solidus_dev_support/rspec/coverage'
+require "solidus_dev_support/rspec/coverage"
# Create the dummy app if it's still missing.
dummy_env = "#{__dir__}/dummy/config/environment.rb"
-system 'bin/rake extension:test_app' unless File.exist? dummy_env
+system "bin/rake extension:test_app" unless File.exist? dummy_env
require dummy_env
# Requires factories and other useful helpers defined in spree_core.
-require 'solidus_dev_support/rspec/feature_helper'
+require "solidus_dev_support/rspec/feature_helper"
+
+Capybara::Screenshot.register_driver(:selenium_headless) do |driver, path|
+ driver.browser.save_screenshot(path)
+end
+
+Capybara.javascript_driver = :selenium_headless
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
@@ -27,7 +33,7 @@
config.infer_spec_type_from_file_location!
config.use_transactional_fixtures = false
- if Spree.solidus_gem_version < Gem::Version.new('2.11')
+ if Spree.solidus_gem_version < Gem::Version.new("2.11")
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
end
end
diff --git a/spec/support/authentication_helpers.rb b/spec/support/authentication_helpers.rb
index 5366f130..7abe7e87 100644
--- a/spec/support/authentication_helpers.rb
+++ b/spec/support/authentication_helpers.rb
@@ -2,10 +2,10 @@
module AuthenticationHelpers
def sign_in_as!(user)
- visit '/login'
- fill_in 'Email', with: user.email
- fill_in 'Password', with: 'secret'
- click_button 'Login'
+ visit "/login"
+ fill_in "Email", with: user.email
+ fill_in "Password", with: "secret"
+ click_button "Login"
end
end
diff --git a/spec/support/confirm_helpers.rb b/spec/support/confirm_helpers.rb
index cfdf85c4..7d4c3b6d 100644
--- a/spec/support/confirm_helpers.rb
+++ b/spec/support/confirm_helpers.rb
@@ -9,7 +9,7 @@
example.run
ensure
Spree.send(:remove_const, :User)
- Spree.const_set('User', old_user)
+ Spree.const_set(:User, old_user)
end
else
example.run
@@ -21,7 +21,7 @@
stub_spree_preferences(Spree::Auth::Config, confirmable: example.metadata[:confirmable])
Spree.send(:remove_const, :User)
- load File.expand_path('../../../app/models/spree/user.rb', __FILE__)
+ load File.expand_path("../../../app/models/spree/user.rb", __FILE__)
end
end
end
diff --git a/spec/support/features/fill_addresses_fields.rb b/spec/support/features/fill_addresses_fields.rb
index 8beb82a7..a155fd01 100644
--- a/spec/support/features/fill_addresses_fields.rb
+++ b/spec/support/features/fill_addresses_fields.rb
@@ -14,13 +14,15 @@ def fill_addresses_fields_with(address)
%w[firstname lastname]
end
+ expect(page).to have_text "Billing Address"
+
fields.each do |field|
fill_in "order_bill_address_attributes_#{field}", with: address.send(field).to_s
end
- select 'United States', from: "order_bill_address_attributes_country_id"
+ select "United States", from: "order_bill_address_attributes_country_id"
select address.state.name.to_s, from: "order_bill_address_attributes_state_id"
- check 'order_use_billing'
+ check "order_use_billing"
end
end
diff --git a/spec/support/spree.rb b/spec/support/spree.rb
index 79579c78..23110f46 100644
--- a/spec/support/spree.rb
+++ b/spec/support/spree.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require 'spree/testing_support/url_helpers'
-require 'spree/testing_support/controller_requests'
-require 'spree/testing_support/authorization_helpers'
-require 'spree/testing_support/capybara_ext'
+require "spree/testing_support/url_helpers"
+require "spree/testing_support/controller_requests"
+require "spree/testing_support/authorization_helpers"
+require "spree/testing_support/capybara_ext"
RSpec.configure do |config|
config.include Spree::TestingSupport::UrlHelpers