Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration tests of the password reset process #205

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -264,6 +268,7 @@ DEPENDENCIES
bcrypt-ruby (~> 3.1)
cancancan
capybara
capybara-email (= 3.0.1)
coffee-rails (~> 4.2)
coveralls
database_cleaner
Expand Down Expand Up @@ -298,4 +303,4 @@ RUBY VERSION
ruby 2.4.2p198

BUNDLED WITH
1.15.4
1.17.3
4 changes: 4 additions & 0 deletions src/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
58 changes: 58 additions & 0 deletions src/spec/features/password_resets_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'spec_helper'

feature 'Password reset' do
let(:user) { create(:participant, name: 'Hedy Lamarr', email: '[email protected]') }

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not extract this to a let ?


# Enter an invalid email address
visit new_password_reset_path
fill_in 'email', with: '[email protected]'
click_button 'Reset Password'
assert page.has_text?('No participant was found with email address [email protected]')

# Enter a valid email address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make each one of these individual example blocks. it "enters a valid email address" do etc...

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh I didnt know about this... I like it.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to remove this. If you specify a find('.some-selector.or-whatever', wait: 4) you can specify a default max wait time. You might want to check but it might already be 5 or more seconds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the only substantial change requested. I'd be happy to merge this if we can remove the sleep call.

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
1 change: 1 addition & 0 deletions src/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down