-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6d1087
commit fbe7645
Showing
2 changed files
with
82 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "/session", type: :request do | ||
describe "GET /session/new" do | ||
it "should return 200" do | ||
get "/session/new" | ||
|
||
expect(response.status).to eq 200 | ||
end | ||
end | ||
|
||
describe "POST /session" do | ||
context "when user is not authenticated" do | ||
context "when no user data in database" do | ||
it "should redirect to /session/new" do | ||
post "/session", params: { | ||
email_address: "[email protected]", | ||
password: "activity-pub-relay-pass" | ||
} | ||
|
||
expect(response).to redirect_to new_session_path | ||
end | ||
end | ||
|
||
context "when user data in database" do | ||
before do | ||
create(:user, email_address: "[email protected]", password: "activity-pub-relay-pass") | ||
end | ||
|
||
context "when wrong user email address given" do | ||
it "should redirect to /session/new" do | ||
post "/session", params: { | ||
email_address: "[email protected]", | ||
password: "activity-pub-relay-pass" | ||
} | ||
|
||
expect(response).to redirect_to new_session_path | ||
end | ||
end | ||
|
||
context "when wrong user password given" do | ||
it "should redirect to /session/new" do | ||
post "/session", params: { | ||
email_address: "[email protected]", | ||
password: "wrong-pass" | ||
} | ||
|
||
expect(response).to redirect_to new_session_path | ||
end | ||
end | ||
|
||
context "when correct user email address and password given" do | ||
it "should redirect to /dashboard" do | ||
post "/session", params: { | ||
email_address: "[email protected]", | ||
password: "activity-pub-relay-pass" | ||
} | ||
|
||
expect(response).to redirect_to dashboard_path | ||
end | ||
end | ||
end | ||
end | ||
|
||
context "when user is authenticated" do | ||
let(:user) { create(:user) } | ||
|
||
before do | ||
login_as(user) | ||
end | ||
|
||
it "should redirect /dashboard" do | ||
post "/session", params: { | ||
email_address: "[email protected]", | ||
password: "activity-pub-relay-pass" | ||
} | ||
|
||
expect(response).to redirect_to dashboard_path | ||
end | ||
end | ||
end | ||
end |