From dd067768fd921c2a39bdaec92e3858095231b427 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 9 Feb 2022 10:30:46 +1100 Subject: [PATCH] FIX: use request_store properly --- extensions/discourse_tagging.rb | 3 ++- extensions/tags_controller.rb | 3 ++- spec/extensions/tags_controller_spec.rb | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/discourse_tagging.rb b/extensions/discourse_tagging.rb index 6c4d6040..3c81bbb3 100644 --- a/extensions/discourse_tagging.rb +++ b/extensions/discourse_tagging.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true +require 'request_store' module CustomWizardDiscourseTagging def filter_allowed_tags(guardian, opts = {}) - if tag_groups = RequestStore.store[:tag_groups] + if tag_groups = ::RequestStore.store[:tag_groups] tag_group_array = tag_groups.split(",") filtered_tags = TagGroup.includes(:tags).where(name: tag_group_array).map do |tag_group| tag_group.tags.pluck(:name) diff --git a/extensions/tags_controller.rb b/extensions/tags_controller.rb index e9618733..0ddacb5f 100644 --- a/extensions/tags_controller.rb +++ b/extensions/tags_controller.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true +require 'request_store' module CustomWizardTagsController def search - RequestStore.store[:tag_groups] = params[:tag_groups] if params[:tag_groups].present? + ::RequestStore.store[:tag_groups] = params[:tag_groups] if params[:tag_groups].present? super end end diff --git a/spec/extensions/tags_controller_spec.rb b/spec/extensions/tags_controller_spec.rb index 455990c6..6df00d9a 100644 --- a/spec/extensions/tags_controller_spec.rb +++ b/spec/extensions/tags_controller_spec.rb @@ -12,9 +12,13 @@ describe ::TagsController, type: :request do fab!(:tag_group_1) { Fabricate(:tag_group, tags: [tag_1, tag_2]) } fab!(:tag_group_2) { Fabricate(:tag_group, tags: [tag_3, tag_4]) } + before do + ::RequestStore.store[:tag_groups] = nil + end + describe "#search" do context "tag group param present" do - it "returns tags only only in the tag group" do + it "returns tags only in the tag group" do get "/tags/filter/search.json", params: { q: '', tag_groups: [tag_group_1.name, tag_group_2.name] } expect(response.status).to eq(200) results = response.parsed_body['results'] @@ -24,6 +28,7 @@ describe ::TagsController, type: :request do .includes(:tags) .where(id: [tag_group_1.id, tag_group_2.id]) .map { |tag_group| tag_group.tags.pluck(:name) }.flatten + expect(names).to contain_exactly(*expected_tag_names) end end