From 5f2b044d8063600da7fa389735d1b9431b4cabfa Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Fri, 18 Nov 2022 21:50:28 +0100 Subject: [PATCH] Add tests for mute rules --- .../settings/mutes_controller_spec.rb | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/controllers/settings/mutes_controller_spec.rb b/spec/controllers/settings/mutes_controller_spec.rb index 796965fd..95a25b78 100644 --- a/spec/controllers/settings/mutes_controller_spec.rb +++ b/spec/controllers/settings/mutes_controller_spec.rb @@ -17,4 +17,36 @@ describe Settings::MutesController, type: :controller do end end end + + describe "#create" do + subject { post :create, params: { muted_phrase: "foo" } } + + context "user signed in" do + let(:user) { FactoryBot.create(:user) } + + before { sign_in user } + + it "creates a mute rule" do + expect { subject }.to(change { MuteRule.count }.by(1)) + end + end + end + + describe "#destroy" do + subject { delete :destroy, params: } + + context "user signed in" do + let(:user) { FactoryBot.create(:user) } + let(:rule) { MuteRule.create(user:, muted_phrase: "foo") } + let(:params) { { id: rule.id } } + + before { sign_in user } + + it "destroys a mute rule" do + subject + + expect(MuteRule.exists?(rule.id)).to eq(false) + end + end + end end