Created
March 18, 2016 19:05
-
-
Save gregblass/1b878d92a2b9dad355e0 to your computer and use it in GitHub Desktop.
Failing test examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rails_helper" | |
feature "account lookups" do | |
let(:account) { create(:account) } | |
scenario "attempts to lookup an account without entering anything into the input" do | |
visit login_path | |
click_button "Continue" | |
expect(page).not_to have_css('.alert') | |
expect(page.current_url).to eq("http://lvh.me/login") | |
end | |
scenario "attempts to lookup an account that doesn't exist" do | |
visit login_path | |
fill_in "domain", with: 'nonexistant' | |
click_button "Continue" | |
expect(page).to have_css('.alert-danger') | |
expect(page.current_url).to eq("http://lvh.me/login") | |
end | |
scenario "attempts to lookup an account that exists" do | |
visit login_path | |
fill_in "domain", with: account.subdomain | |
click_button "Continue" | |
expect(page).to have_content("Log in to #{account.subdomain}.derp.co") | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/") | |
end | |
scenario "redirects to the login page on an attempt to visit the account lookup page with a valid subdomain" do | |
switch_to_subdomain(account.subdomain) | |
visit login_path | |
expect(page).to have_content("Log in to #{account.subdomain}.derp.co") | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rails_helper" | |
feature "Create password reset link" do | |
let(:account) { create(:account) } | |
let(:account2) { create(:account) } | |
let(:user) { account.owner } | |
let(:user2) { account2.owner } | |
scenario "user visits page without a subdomain" do | |
visit forgot_path | |
expect(page.current_url).to eq("http://lvh.me/login/find") | |
expect(last_email).to be_nil | |
end | |
scenario "user enters nothing" do | |
switch_to_subdomain(account.subdomain) | |
visit forgot_path | |
click_button "Reset my password" | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/forgot") | |
expect(page).to have_css(".alert-danger") | |
expect(last_email).to be_nil | |
end | |
scenario "user enters invalid email" do | |
switch_to_subdomain(account.subdomain) | |
visit forgot_path | |
fill_in "email", with: "phillesh@friends.net" | |
click_button "Reset my password" | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/forgot") | |
expect(page).to have_css(".alert-danger") | |
expect(last_email).to be_nil | |
end | |
scenario "user enters an email from another account" do | |
switch_to_subdomain(account.subdomain) | |
visit forgot_path | |
fill_in "email", with: user2.email | |
click_button "Reset my password" | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/forgot") | |
expect(page).to have_css(".alert-danger") | |
expect(last_email).to be_nil | |
end | |
scenario "user enters valid email" do | |
switch_to_subdomain(account.subdomain) | |
visit forgot_path | |
fill_in "email", with: user.email | |
click_button "Reset my password" | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/") | |
expect(page).to have_css(".alert-success") | |
expect(last_email).to have_content(user.email) | |
end | |
scenario "user visits page while logged in" do | |
capybara_login(user) | |
visit forgot_path | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/brews") | |
end | |
end | |
feature "Update password" do | |
let(:password_reset_user) { create(:password_reset_user) } | |
let(:expired_user) { create(:expired_password_reset_user) } | |
scenario "user visits page without a subdomain" do | |
visit reset_path(password_reset_user.password_reset_token) | |
expect(page.current_url).to eq("http://lvh.me/login/find") | |
end | |
scenario "user enters nothing" do | |
switch_to_subdomain(account.subdomain) | |
visit reset_path(password_reset_user.password_reset_token) | |
click_button "Change my password" | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/reset/#{password_reset_user.password_reset_token}") | |
expect(page).to have_css(".alert-danger") | |
end | |
scenario "user inputs a password that has less than 6 chars" do | |
switch_to_subdomain(account.subdomain) | |
visit reset_path(password_reset_user.password_reset_token) | |
fill_in "pass", with: "fiver" | |
click_button "Change my password" | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/reset/#{password_reset_user.password_reset_token}") | |
expect(page).to have_css(".alert-danger") | |
end | |
scenario "user visits the page with an expired link" do | |
switch_to_subdomain(account.subdomain) | |
visit reset_path(expired_user.password_reset_token) | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/forgot") | |
expect(page).to have_css(".alert-danger") | |
end | |
scenario "user submits the form with an expired link" do | |
switch_to_subdomain(account.subdomain) | |
visit reset_path(password_reset_user.password_reset_token) | |
password_reset_user.password_reset_sent_at = Time.now - 4.hours | |
password_reset_user.save | |
fill_in "pass", with: "ValidPassword" | |
click_button "Change my password" | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/forgot") | |
expect(page).to have_css(".alert-danger") | |
end | |
scenario "user inputs a valid password with a valid link" do | |
switch_to_subdomain(account.subdomain) | |
visit reset_path(password_reset_user.password_reset_token) | |
old_password_digest = password_reset_user.password_digest | |
fill_in "pass", with: "ValidPassword" | |
click_button "Change my password" | |
password_reset_user.reload | |
expect(old_password_digest).to_not eq(password_reset_user.password_digest) | |
expect(page.current_url).to eq("http://#{account.subdomain}.lvh.me/") | |
expect(page).to have_css(".alert-success") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def switch_to_subdomain(subdomain) | |
site = "#{subdomain}.lvh.me" | |
Capybara.app_host = "http://#{site}" | |
default_url_options[:host] = "#{site}" | |
end | |
RSpec.configure do |config| | |
Capybara.always_include_port = true | |
config.before type: :feature do | |
Capybara.app_host = "http://lvh.me" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment