Add tests announcement failure cases

This commit is contained in:
Andreas Nedbal 2022-01-25 22:08:10 +01:00 committed by Andreas Nedbal
parent 6565805ef5
commit a28f581aed
1 changed files with 43 additions and 0 deletions

View File

@ -72,6 +72,25 @@ describe AnnouncementController, type: :controller do
expect(response).to redirect_to(:announcement_index) expect(response).to redirect_to(:announcement_index)
end end
end end
context "submitting a malformed announcement" do
before(:each) { sign_in(user) }
let :announcement_params do
{
announcement: {
content: "I like dogs!",
starts_at: Time.current,
ends_at: Time.current - 2.days
}
}
end
it "stays in the new view when a malformed announcement is submitted" do
post :create, params: announcement_params
expect(response).to render_template(:new)
end
end
end end
describe "#edit" do describe "#edit" do
@ -129,6 +148,30 @@ describe AnnouncementController, type: :controller do
expect(response).to redirect_to(:announcement_index) expect(response).to redirect_to(:announcement_index)
end end
end end
context "submitting a malformed announcement" do
before(:each) { sign_in(user) }
let :announcement_params do
{
content: "I like dogs!",
starts_at: Time.current,
ends_at: Time.current - 2.days
}
end
subject do
patch :update, params: {
id: announcement.id,
announcement: announcement_params
}
end
it "stays in the edit view when a malformed announcement is submitted" do
subject
expect(response).to render_template(:edit)
end
end
end end
describe "#destroy" do describe "#destroy" do