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

Add session request spec #53

Merged
merged 1 commit into from
Dec 1, 2024
Merged
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: 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