2022-07-03 12:12:18 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe Settings::MutesController, type: :controller do
|
|
|
|
describe "#index" do
|
|
|
|
subject { get :index }
|
|
|
|
|
|
|
|
context "user signed in" do
|
2022-07-03 12:32:43 -07:00
|
|
|
let(:user) { FactoryBot.create(:user) }
|
2022-07-03 12:12:18 -07:00
|
|
|
|
2022-07-03 12:32:43 -07:00
|
|
|
before { sign_in user }
|
2022-07-03 12:12:18 -07:00
|
|
|
|
2022-07-03 12:32:43 -07:00
|
|
|
it "shows the index page" do
|
2022-07-03 12:12:18 -07:00
|
|
|
subject
|
2022-07-03 12:32:43 -07:00
|
|
|
expect(response).to have_rendered(:index)
|
2022-07-03 12:12:18 -07:00
|
|
|
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
|
2022-07-03 12:12:18 -07:00
|
|
|
end
|