Skip to content

Commit dd06776

Browse files
committed
FIX: use request_store properly
1 parent ba7e8d7 commit dd06776

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

extensions/discourse_tagging.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# frozen_string_literal: true
2+
require 'request_store'
23

34
module CustomWizardDiscourseTagging
45
def filter_allowed_tags(guardian, opts = {})
5-
if tag_groups = RequestStore.store[:tag_groups]
6+
if tag_groups = ::RequestStore.store[:tag_groups]
67
tag_group_array = tag_groups.split(",")
78
filtered_tags = TagGroup.includes(:tags).where(name: tag_group_array).map do |tag_group|
89
tag_group.tags.pluck(:name)

extensions/tags_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# frozen_string_literal: true
2+
require 'request_store'
23

34
module CustomWizardTagsController
45
def search
5-
RequestStore.store[:tag_groups] = params[:tag_groups] if params[:tag_groups].present?
6+
::RequestStore.store[:tag_groups] = params[:tag_groups] if params[:tag_groups].present?
67
super
78
end
89
end

spec/extensions/tags_controller_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
fab!(:tag_group_1) { Fabricate(:tag_group, tags: [tag_1, tag_2]) }
1313
fab!(:tag_group_2) { Fabricate(:tag_group, tags: [tag_3, tag_4]) }
1414

15+
before do
16+
::RequestStore.store[:tag_groups] = nil
17+
end
18+
1519
describe "#search" do
1620
context "tag group param present" do
17-
it "returns tags only only in the tag group" do
21+
it "returns tags only in the tag group" do
1822
get "/tags/filter/search.json", params: { q: '', tag_groups: [tag_group_1.name, tag_group_2.name] }
1923
expect(response.status).to eq(200)
2024
results = response.parsed_body['results']
@@ -24,6 +28,7 @@
2428
.includes(:tags)
2529
.where(id: [tag_group_1.id, tag_group_2.id])
2630
.map { |tag_group| tag_group.tags.pluck(:name) }.flatten
31+
2732
expect(names).to contain_exactly(*expected_tag_names)
2833
end
2934
end

0 commit comments

Comments
 (0)