63 lines
1.8 KiB
Ruby
63 lines
1.8 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe "DayLogs", type: :request do
|
|
let(:user) { create(:user) }
|
|
let(:day) { Date.new(2026, 1, 15) }
|
|
|
|
describe "GET /day_logs/new" do
|
|
context "when not authenticated" do
|
|
it "redirects to the login page" do
|
|
get new_day_log_path
|
|
expect(response).to redirect_to(new_session_path)
|
|
end
|
|
end
|
|
|
|
context "when authenticated" do
|
|
before { login_as(user) }
|
|
|
|
it "returns http success" do
|
|
get new_day_log_path
|
|
expect(response).to have_http_status(:success)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "POST /day_logs" do
|
|
context "when not authenticated" do
|
|
it "redirects to the login page" do
|
|
post day_logs_path, params: { day_log: { day: day, info: "Une info" } }
|
|
expect(response).to redirect_to(new_session_path)
|
|
end
|
|
end
|
|
|
|
context "when authenticated" do
|
|
before { login_as(user) }
|
|
|
|
context "with valid params" do
|
|
it "creates a day_log" do
|
|
expect {
|
|
post day_logs_path, params: { day_log: { day: day, info: "Une info" } }
|
|
}.to change(DayLog, :count).by(1)
|
|
end
|
|
|
|
it "redirects after creation" do
|
|
post day_logs_path, params: { day_log: { day: day, info: "Une info" } }
|
|
expect(response).to have_http_status(:redirect)
|
|
end
|
|
end
|
|
|
|
context "with invalid params" do
|
|
it "does not create a day_log" do
|
|
expect {
|
|
post day_logs_path, params: { day_log: { day: nil, info: nil } }
|
|
}.not_to change(DayLog, :count)
|
|
end
|
|
|
|
it "returns unprocessable entity" do
|
|
post day_logs_path, params: { day_log: { day: nil, info: nil } }
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|