diff --git a/src/Gemfile b/src/Gemfile index 6b3311d5..b6ca6bb2 100644 --- a/src/Gemfile +++ b/src/Gemfile @@ -54,6 +54,7 @@ group :development, :test do gem "rspec-rails", "~> 3.1" gem 'rails-controller-testing' gem 'capybara' + gem 'capybara-email', '3.0.1' gem 'pry' gem 'coveralls', require: false end diff --git a/src/Gemfile.lock b/src/Gemfile.lock index d3f343d1..42d1e901 100644 --- a/src/Gemfile.lock +++ b/src/Gemfile.lock @@ -59,6 +59,10 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + capybara-email (3.0.1) + capybara (>= 2.4, < 4.0) + mail + choice (0.2.0) cliver (0.3.2) coderay (1.1.2) coffee-rails (4.2.2) @@ -264,6 +268,7 @@ DEPENDENCIES bcrypt-ruby (~> 3.1) cancancan capybara + capybara-email (= 3.0.1) coffee-rails (~> 4.2) coveralls database_cleaner @@ -298,4 +303,4 @@ RUBY VERSION ruby 2.4.2p198 BUNDLED WITH - 1.15.4 + 1.17.3 diff --git a/src/config/environments/test.rb b/src/config/environments/test.rb index 094dedb7..6c367ef1 100644 --- a/src/config/environments/test.rb +++ b/src/config/environments/test.rb @@ -1,6 +1,10 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + # BEGIN: needed for email confirmations + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + # END: needed for email confirmations + # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped diff --git a/src/spec/features/password_resets_spec.rb b/src/spec/features/password_resets_spec.rb new file mode 100644 index 00000000..60a042f0 --- /dev/null +++ b/src/spec/features/password_resets_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +feature 'Password reset' do + let(:user) { create(:participant, name: 'Hedy Lamarr', email: 'freq-hopper@example.org') } + + scenario 'The home page has a link to the reset password page' do + visit root_path + assert page.has_link?('Forgot Password?', href: new_password_reset_path) + end + + scenario 'The reset password page has the expected content' do + visit new_password_reset_path + assert page.has_css?('h1', text: 'Reset Password') + assert page.has_text?('Please enter your email address below') + end + + scenario 'Participant can reset password' do + # Event needed until Pull Request #202 is merged into the code base + Event.create!(name: 'Event 1', date: Time.now) + + # Enter an invalid email address + visit new_password_reset_path + fill_in 'email', with: 'not_exist@example.com' + click_button 'Reset Password' + assert page.has_text?('No participant was found with email address not_exist@example.com') + + # Enter a valid email address + visit new_password_reset_path + fill_in 'email', with: user.email + click_button 'Reset Password' + assert page.has_text?('Instructions to reset your password have been emailed to you') + + # Open and follow instructions + open_email(user.email) + assert current_email.subject.include?('Password Reset Instructions') + assert current_email.body.include?('A request to reset your password has been made.') + current_email.click_link 'Reset Password!' + clear_emails + + # Provide new password + assert page.has_css?('h1', text: 'Update your password') + assert page.has_text?('Please enter the new password below') + fill_in('password', with: 'MN Tech Community') + sleep 4.1 + click_on 'Update Password' + assert page.has_text?('Your password was successfully updated') + click_on 'Log out' + + # Log in under the normal method + visit root_path + click_link "Log in" + fill_in 'Email', with: user.email + fill_in 'Password', with: 'MN Tech Community' + check 'Remember me' + click_button "Log in" + expect(page).to have_content "You're logged in. Welcome back." + end +end diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb index 1f67c889..400bc9bb 100644 --- a/src/spec/spec_helper.rb +++ b/src/spec/spec_helper.rb @@ -18,6 +18,7 @@ Capybara.default_max_wait_time = ENV['TRAVIS'] ? 30 : 15 require 'capybara/rspec' require 'capybara/rails' +require 'capybara/email/rspec' require 'authlogic/test_case'