-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add system specs for login and password reset flow (#68)
* Add specs for login and password reset flow * Configure action mailer for test env
- Loading branch information
1 parent
b409334
commit c72f35b
Showing
2 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,98 @@ | |
driven_by(:rack_test) | ||
end | ||
|
||
describe "sign up flow" do | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:sign_in_url) { "/users/sign_in" } | ||
let(:visit_login_route) { visit sign_in_url } | ||
let(:user) { FactoryBot.create(:user) } | ||
|
||
it "works" do | ||
visit "/users/sign_in" | ||
describe "sign in flow" do | ||
context "when input fields are correctly filled" do | ||
it "logs in the user" do | ||
visit_login_route | ||
|
||
fill_in "Email", with: user.email | ||
fill_in "Password", with: user.password | ||
click_on "Log in" | ||
fill_in "Email", with: user.email | ||
fill_in "Password", with: user.password | ||
click_on "Log in" | ||
|
||
expect(page.current_path).to eq(root_path) | ||
expect(page.current_path).to eq(root_path) | ||
end | ||
end | ||
|
||
context "when email input is empty" do | ||
it "does not login the user" do | ||
visit_login_route | ||
|
||
fill_in "Email", with: "" | ||
fill_in "Password", with: user.password | ||
click_on "Log in" | ||
|
||
expect(page.current_path).to eq(sign_in_url) | ||
expect(page.status_code).to eq(422) | ||
end | ||
end | ||
|
||
context "when password input is empty" do | ||
it "does not login the user" do | ||
visit_login_route | ||
|
||
fill_in "Email", with: user.email | ||
fill_in "Password", with: "" | ||
click_on "Log in" | ||
|
||
expect(page.current_path).to eq(sign_in_url) | ||
expect(page.status_code).to eq(422) | ||
end | ||
end | ||
|
||
context "when email and password inputs are empty" do | ||
it "does not login the user" do | ||
visit_login_route | ||
|
||
fill_in "Email", with: "" | ||
fill_in "Password", with: "" | ||
click_on "Log in" | ||
|
||
expect(page.current_path).to eq(sign_in_url) | ||
expect(page.status_code).to eq(422) | ||
end | ||
end | ||
end | ||
|
||
describe "forgot password flow" do | ||
context "when email is correct" do | ||
it "does send a password reset email" do | ||
visit_login_route | ||
|
||
click_link "Forgot your password?" | ||
fill_in "Email", with: user.email | ||
|
||
expect { click_on "Send me reset password instructions" }.to change(ActionMailer::Base.deliveries, :count).by(1) | ||
expect(page.current_path).to eq(sign_in_url) | ||
end | ||
end | ||
|
||
context "when the email address does not exist in the db" do | ||
it "does not send the password reset email" do | ||
visit_login_route | ||
|
||
click_link "Forgot your password?" | ||
fill_in "Email", with: "[email protected]" | ||
|
||
expect { click_on "Send me reset password instructions" }.not_to change(ActionMailer::Base.deliveries, :count) | ||
expect(page).to have_content("Email not found") | ||
end | ||
end | ||
|
||
context "when the email address input is empty" do | ||
it "does not send the password reset email" do | ||
visit_login_route | ||
|
||
click_link "Forgot your password?" | ||
fill_in "Email", with: "" | ||
|
||
expect { click_on "Send me reset password instructions" }.not_to change(ActionMailer::Base.deliveries, :count) | ||
expect(page).to have_content("Email can't be blank") | ||
end | ||
end | ||
end | ||
end |