Appease the robot dog

This commit is contained in:
Andreas Nedbal 2022-09-02 20:08:11 +02:00
parent 13c275b189
commit c979a7211d
1 changed files with 17 additions and 18 deletions

View File

@ -1,20 +1,21 @@
require 'rails_helper' # frozen_string_literal: true
require "rails_helper"
describe Ajax::MuteRuleController, :ajax_controller, type: :controller do describe Ajax::MuteRuleController, :ajax_controller, type: :controller do
describe "#create" do describe "#create" do
subject { post(:create, params: params) } subject { post(:create, params:) }
context "when user is signed in" do context "when user is signed in" do
before(:each) { sign_in(user) } before(:each) { sign_in(user) }
let(:params) { { muted_phrase: 'test' } } let(:params) { { muted_phrase: "test" } }
let(:expected_response) do let(:expected_response) do
{ {
"success" => true, "success" => true,
"status" => "okay", "status" => "okay",
"id" => MuteRule.last.id.to_s, "id" => MuteRule.last.id.to_s,
"message" => "Rule added successfully.", "message" => "Rule added successfully."
} }
end end
@ -24,7 +25,7 @@ describe Ajax::MuteRuleController, :ajax_controller, type: :controller do
rule = MuteRule.first rule = MuteRule.first
expect(rule.user_id).to eq(user.id) expect(rule.user_id).to eq(user.id)
expect(rule.muted_phrase).to eq('test') expect(rule.muted_phrase).to eq("test")
end end
include_examples "returns the expected response" include_examples "returns the expected response"
@ -32,17 +33,17 @@ describe Ajax::MuteRuleController, :ajax_controller, type: :controller do
end end
describe "#update" do describe "#update" do
subject { post(:update, params: params) } subject { post(:update, params:) }
context "when user is signed in" do context "when user is signed in" do
before(:each) { sign_in(user) } before(:each) { sign_in(user) }
let(:rule) { MuteRule.create(user: user, muted_phrase: 'test') } let(:rule) { MuteRule.create(user:, muted_phrase: "test") }
let(:params) { { id: rule.id, muted_phrase: 'dogs' } } let(:params) { { id: rule.id, muted_phrase: "dogs" } }
let(:expected_response) do let(:expected_response) do
{ {
"success" => true, "success" => true,
"status" => "okay", "status" => "okay",
"message" => "Rule updated successfully." "message" => "Rule updated successfully."
} }
end end
@ -51,7 +52,7 @@ describe Ajax::MuteRuleController, :ajax_controller, type: :controller do
subject subject
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
expect(rule.reload.muted_phrase).to eq('dogs') expect(rule.reload.muted_phrase).to eq("dogs")
end end
include_examples "returns the expected response" include_examples "returns the expected response"
@ -59,17 +60,17 @@ describe Ajax::MuteRuleController, :ajax_controller, type: :controller do
end end
describe "#destroy" do describe "#destroy" do
subject { delete(:destroy, params: params) } subject { delete(:destroy, params:) }
context "when user is signed in" do context "when user is signed in" do
before(:each) { sign_in(user) } before(:each) { sign_in(user) }
let(:rule) { MuteRule.create(user: user, muted_phrase: 'test') } let(:rule) { MuteRule.create(user:, muted_phrase: "test") }
let(:params) { { id: rule.id } } let(:params) { { id: rule.id } }
let(:expected_response) do let(:expected_response) do
{ {
"success" => true, "success" => true,
"status" => "okay", "status" => "okay",
"message" => "Rule deleted successfully." "message" => "Rule deleted successfully."
} }
end end
@ -79,11 +80,9 @@ describe Ajax::MuteRuleController, :ajax_controller, type: :controller do
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
expect(MuteRule.exists?(rule.id)).to eq(false) expect(MuteRule.exists?(rule.id)).to eq(false)
end end
include_examples "returns the expected response" include_examples "returns the expected response"
end end
end end
end end