From a28f581aedd2548197602c4ce6562d410aafbd05 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 25 Jan 2022 22:08:10 +0100 Subject: [PATCH] Add tests announcement failure cases --- .../announcement_controller_spec.rb | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/spec/controllers/announcement_controller_spec.rb b/spec/controllers/announcement_controller_spec.rb index 4af41374..1d2dcd66 100644 --- a/spec/controllers/announcement_controller_spec.rb +++ b/spec/controllers/announcement_controller_spec.rb @@ -72,6 +72,25 @@ describe AnnouncementController, type: :controller do expect(response).to redirect_to(:announcement_index) 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 describe "#edit" do @@ -129,6 +148,30 @@ describe AnnouncementController, type: :controller do expect(response).to redirect_to(:announcement_index) 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 describe "#destroy" do