Retrospring/spec/controllers/settings/mutes_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "rails_helper"
describe Settings::MutesController, type: :controller do
describe "#index" do
subject { get :index }
context "user signed in" do
let(:user) { FactoryBot.create(:user) }
before { sign_in user }
it "shows the index page" do
subject
expect(response).to have_rendered(:index)
end
end
end
2022-11-18 12:50:28 -08:00
describe "#create" do
2023-02-11 17:23:43 -08:00
subject { post :create, params: { muted_phrase: "foo" }, format: :turbo_stream }
2022-11-18 12:50:28 -08:00
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
2023-02-11 17:23:43 -08:00
it "contains a turbo stream append tag" do
subject
expect(response.body).to include "turbo-stream action=\"append\" target=\"rules\""
end
2022-11-18 12:50:28 -08:00
end
end
describe "#destroy" do
2023-02-11 17:23:43 -08:00
subject { delete :destroy, params:, format: :turbo_stream }
2022-11-18 12:50:28 -08:00
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
2023-02-11 17:23:43 -08:00
it "contains a turbo stream remove tag" do
subject
expect(response.body).to include "turbo-stream action=\"remove\" target=\"rule_#{rule.id}\""
end
2022-11-18 12:50:28 -08:00
end
end
end