Skip to content

Commit

Permalink
Add session request spec
Browse files Browse the repository at this point in the history
  • Loading branch information
S-H-GAMELINKS committed Dec 1, 2024
1 parent f6d1087 commit fbe7645
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
add_filter "app/controllers/application_controller.rb"
add_filter "app/channels/application_cable/connection.rb"
add_filter "app/controllers/passwords_controller.rb"
add_filter "app/controllers/sessions_controller.rb"
add_filter "app/controllers/concerns/authentication.rb"
add_filter "app/mailers/application_mailer.rb"
add_filter "app/mailers/passwords_mailer.rb"
Expand Down
82 changes: 82 additions & 0 deletions spec/requests/session_controller_spec.rb
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

0 comments on commit fbe7645

Please sign in to comment.