diff --git a/app/controllers/ajax/question_controller.rb b/app/controllers/ajax/question_controller.rb index 66ed7d58..f91ca17a 100644 --- a/app/controllers/ajax/question_controller.rb +++ b/app/controllers/ajax/question_controller.rb @@ -83,8 +83,8 @@ class Ajax::QuestionController < AjaxController return end - unless MuteRule.where(user: target_user).any? { |rule| rule.applies_to? question } || - (author_is_anonymous && AnonymousBlock.where(identifier: AnonymousBlock.get_identifier(request.ip)).any?) + unless target_user.mute_rules.any? { |rule| rule.applies_to? question } || + (author_is_anonymous && target_user.anonymous_blocks.where(identifier: AnonymousBlock.get_identifier(request.ip)).any?) Inbox.create!(user_id: target_user.id, question_id: question.id, new: true) end end diff --git a/spec/controllers/ajax/question_controller_spec.rb b/spec/controllers/ajax/question_controller_spec.rb index d4eb9f43..bf79958c 100644 --- a/spec/controllers/ajax/question_controller_spec.rb +++ b/spec/controllers/ajax/question_controller_spec.rb @@ -274,6 +274,24 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do end end + context "when the sender is blocked by another user" do + let(:user_allows_anonymous_questions) { true } + let(:expected_question_user) { nil } + let(:expected_question_direct) { true } + + before do + identifier = AnonymousBlock.get_identifier("0.0.0.0") + dummy_question = FactoryBot.create(:question, author_is_anonymous: true, author_identifier: identifier) + AnonymousBlock.create( + user: FactoryBot.create(:user), + identifier: identifier, + question: dummy_question + ) + end + + include_examples "creates the question" + end + context "when user does not allow anonymous questions" do let(:user_allows_anonymous_questions) { false } let(:expected_response) do