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
|
begin
|
||||||
current_user.smile answer
|
current_user.smile answer
|
||||||
|
rescue Errors::Base => e
|
||||||
|
@response[:status] = e.code
|
||||||
|
@response[:message] = e.locale_tag
|
||||||
|
return
|
||||||
rescue => e
|
rescue => e
|
||||||
Sentry.capture_exception(e)
|
Sentry.capture_exception(e)
|
||||||
@response[:status] = :fail
|
@response[:status] = :fail
|
||||||
|
@ -44,6 +48,10 @@ class Ajax::SmileController < AjaxController
|
||||||
|
|
||||||
begin
|
begin
|
||||||
current_user.smile_comment comment
|
current_user.smile_comment comment
|
||||||
|
rescue Errors::Base => e
|
||||||
|
@response[:status] = e.code
|
||||||
|
@response[:message] = e.locale_tag
|
||||||
|
return
|
||||||
rescue => e
|
rescue => e
|
||||||
Sentry.capture_exception(e)
|
Sentry.capture_exception(e)
|
||||||
@response[:status] = :fail
|
@response[:status] = :fail
|
||||||
|
|
|
@ -81,15 +81,19 @@ module Errors
|
||||||
end
|
end
|
||||||
|
|
||||||
class ReactingSelfBlockedOther < SelfBlockedOther
|
class ReactingSelfBlockedOther < SelfBlockedOther
|
||||||
|
@locale_tag = "errors.self_blocked_other"
|
||||||
end
|
end
|
||||||
|
|
||||||
class ReactingOtherBlockedSelf < OtherBlockedSelf
|
class ReactingOtherBlockedSelf < OtherBlockedSelf
|
||||||
|
@locale_tag = "errors.other_blocked_self"
|
||||||
end
|
end
|
||||||
|
|
||||||
class ListingSelfBlockedOther < SelfBlockedOther
|
class ListingSelfBlockedOther < SelfBlockedOther
|
||||||
|
@locale_tag = "errors.self_blocked_other"
|
||||||
end
|
end
|
||||||
|
|
||||||
class ListingOtherBlockedSelf < OtherBlockedSelf
|
class ListingOtherBlockedSelf < OtherBlockedSelf
|
||||||
|
@locale_tag = "errors.other_blocked_self"
|
||||||
end
|
end
|
||||||
# endregion
|
# endregion
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,6 +81,54 @@ describe Ajax::SmileController, :ajax_controller, type: :controller do
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
include_examples "returns the expected response"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "#destroy" do
|
describe "#destroy" do
|
||||||
|
|
Loading…
Reference in New Issue