From 25ed1e46052b0ad143167afb6f63e8ced09c5b2a Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 12 Jun 2022 22:39:28 +0200 Subject: [PATCH] Add tests for commenting on answers while blocked --- config/locales/errors.en.yml | 2 ++ .../ajax/comment_controller_spec.rb | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/config/locales/errors.en.yml b/config/locales/errors.en.yml index 7f9aed2f..8a0e8aab 100644 --- a/config/locales/errors.en.yml +++ b/config/locales/errors.en.yml @@ -15,6 +15,8 @@ en: following_self_blocked_other: "You cannot follow a user who you are currently blocking" answering_self_blocked_other: "You cannot answer a question from a user who you are currently blocking" answering_other_blocked_self: "You cannot answer this question as you have been blocked its author" + commenting_self_blocked_other: "You cannot comment on this answer as you have blocked its author" + commenting_other_blocked_self: "You cannot comment on this answer as you have been blocked by its author" self_action: "You cannot do this to yourself" following_self: "You cannot follow yourself" blocking_self: "You cannot block yourself" diff --git a/spec/controllers/ajax/comment_controller_spec.rb b/spec/controllers/ajax/comment_controller_spec.rb index d1e1b0be..332659dd 100644 --- a/spec/controllers/ajax/comment_controller_spec.rb +++ b/spec/controllers/ajax/comment_controller_spec.rb @@ -66,6 +66,40 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do include_examples "does not create the comment" end + + context "when the user is blocked by the answer's author" do + before do + answer.user.block(user) + end + + let(:comment) { ">:3" } + let(:expected_response) do + { + "success" => false, + "status" => "commenting_other_blocked_self", + "message" => I18n.t("errors.commenting_other_blocked_self") + } + end + + include_examples "does not create the comment" + end + + context "when the user is blocking the answer's author" do + before do + user.block(answer.user) + end + + let(:comment) { "heast" } + let(:expected_response) do + { + "success" => false, + "status" => "commenting_self_blocked_other", + "message" => I18n.t("errors.commenting_self_blocked_other") + } + end + + include_examples "does not create the comment" + end end context "when answer does not exist" do