Add tests for reacting to comments while blocked/blocking
This commit is contained in:
parent
e64d4f3ca7
commit
6a15a323cf
|
@ -6,6 +6,10 @@ class Ajax::SmileController < AjaxController
|
|||
|
||||
begin
|
||||
current_user.smile answer
|
||||
rescue Errors::Base => e
|
||||
@response[:status] = e.code
|
||||
@response[:message] = e.locale_tag
|
||||
return
|
||||
rescue => e
|
||||
Sentry.capture_exception(e)
|
||||
@response[:status] = :fail
|
||||
|
@ -44,6 +48,10 @@ class Ajax::SmileController < AjaxController
|
|||
|
||||
begin
|
||||
current_user.smile_comment comment
|
||||
rescue Errors::Base => e
|
||||
@response[:status] = e.code
|
||||
@response[:message] = e.locale_tag
|
||||
return
|
||||
rescue => e
|
||||
Sentry.capture_exception(e)
|
||||
@response[:status] = :fail
|
||||
|
|
|
@ -81,15 +81,19 @@ module Errors
|
|||
end
|
||||
|
||||
class ReactingSelfBlockedOther < SelfBlockedOther
|
||||
@locale_tag = "errors.self_blocked_other"
|
||||
end
|
||||
|
||||
class ReactingOtherBlockedSelf < OtherBlockedSelf
|
||||
@locale_tag = "errors.other_blocked_self"
|
||||
end
|
||||
|
||||
class ListingSelfBlockedOther < SelfBlockedOther
|
||||
@locale_tag = "errors.self_blocked_other"
|
||||
end
|
||||
|
||||
class ListingOtherBlockedSelf < OtherBlockedSelf
|
||||
@locale_tag = "errors.other_blocked_self"
|
||||
end
|
||||
# endregion
|
||||
end
|
||||
|
|
|
@ -81,6 +81,54 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
|||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
|
||||
context "when blocked by the answer's author" do
|
||||
let(:other_user) { FactoryBot.create(:user) }
|
||||
let(:answer) { FactoryBot.create(:answer, user: other_user) }
|
||||
let(:answer_id) { answer.id }
|
||||
|
||||
before do
|
||||
other_user.block(user)
|
||||
end
|
||||
|
||||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "fail",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
||||
it "does not create a smile" do
|
||||
expect { subject }.not_to(change { Smile.count })
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
|
||||
context "when blocking the answer's author" do
|
||||
let(:other_user) { FactoryBot.create(:user) }
|
||||
let(:answer) { FactoryBot.create(:answer, user: user) }
|
||||
let(:answer_id) { answer.id }
|
||||
|
||||
before do
|
||||
user.block(other_user)
|
||||
end
|
||||
|
||||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "fail",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
||||
it "does not create a smile" do
|
||||
expect { subject }.not_to(change { Smile.count })
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
|
|
Loading…
Reference in New Issue