Skip to content

Commit 2b1a998

Browse files
authored
Merge pull request #247 from AlchemyCMS/devise-paranoid-mode
feat: Enable Devise.paranoid mode by default
2 parents 739580b + 1af992a commit 2b1a998

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ group :test do
2020
if ENV["GITHUB_ACTIONS"]
2121
gem "simplecov-cobertura", "~> 3.0"
2222
end
23-
gem "selenium-webdriver", "~> 4.40"
24-
gem "capybara-screenshot", "~> 1.0"
2523
end
2624

2725
gem "github_fast_changelog", require: false

alchemy-devise.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ Gem::Specification.new do |s|
2020
s.add_dependency "flickwerk", ["~> 0.3.6"]
2121

2222
s.add_development_dependency "capybara"
23+
s.add_development_dependency "capybara-screenshot", "~> 1.0"
2324
s.add_development_dependency "factory_bot_rails"
2425
s.add_development_dependency "rails-controller-testing"
2526
s.add_development_dependency "rspec-activemodel-mocks", "~> 1.0"
2627
s.add_development_dependency "rspec-rails", "~> 8.0"
28+
s.add_development_dependency "selenium-webdriver", "~> 4.40"
2729
s.add_development_dependency "simplecov"
2830

2931
s.post_install_message = <<~MSG

lib/generators/alchemy/devise/install/templates/devise.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Devise.setup do |config|
9090
# It will change confirmation, password recovery and other workflows
9191
# to behave the same regardless if the e-mail provided was right or wrong.
9292
# Does not affect registerable.
93-
# config.paranoid = true
93+
config.paranoid = true
9494

9595
# By default Devise will store the user in session. You can skip storage for
9696
# particular strategies by setting this option.

spec/features/password_reset_feature_spec.rb

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,39 @@
1717
click_button "Send reset instructions"
1818

1919
expect(page)
20-
.to have_content("You will receive an email with instructions on how to reset your password in a few minutes.")
20+
.to have_content("If your email address exists in our database, you will receive a password recovery link")
2121
end
2222

23-
it "Displays error if email not found." do
24-
visit admin_new_password_path
23+
context "with paranoid mode disabled" do
24+
before do
25+
allow(Devise).to receive(:paranoid).and_return(false)
26+
end
2527

26-
fill_in :user_email, with: "wrong@email.com"
27-
click_button "Send reset instructions"
28+
it "Displays error if email not found." do
29+
visit admin_new_password_path
30+
31+
fill_in :user_email, with: "wrong@email.com"
32+
click_button "Send reset instructions"
33+
34+
expect(page).to have_content("Email not found")
35+
end
36+
end
37+
38+
context "with paranoid mode enabled" do
39+
before do
40+
allow(Devise).to receive(:paranoid).and_return(true)
41+
end
42+
43+
it "Displays notification about reset instructions.", :js do
44+
visit admin_new_password_path
45+
46+
fill_in :user_email, with: "wrong@email.com"
47+
click_button "Send reset instructions"
2848

29-
expect(page).to have_content("Email not found")
49+
expect(page).to have_content(
50+
"If your email address exists in our database, you will receive a password recovery link"
51+
)
52+
end
3053
end
3154

3255
it "User can visit edit password form." do

spec/rails_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ActionMailer::Base.perform_deliveries = true
2626
ActionMailer::Base.default_url_options[:host] = "test.com"
2727
Capybara.default_driver = :rack_test
28+
Capybara.javascript_driver = :selenium_headless
2829
Capybara.default_selector = :css
2930
Capybara.ignore_hidden_elements = false
3031
ActiveJob::Base.queue_adapter = :test

0 commit comments

Comments
 (0)