Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-24 02:10:29 +01:00
FIX: use request_store properly
Dieser Commit ist enthalten in:
Ursprung
5360cef214
Commit
ec78229ba0
3 geänderte Dateien mit 10 neuen und 3 gelöschten Zeilen
|
@ -1,8 +1,9 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
require 'request_store'
|
||||||
|
|
||||||
module CustomWizardDiscourseTagging
|
module CustomWizardDiscourseTagging
|
||||||
def filter_allowed_tags(guardian, opts = {})
|
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(",")
|
tag_group_array = tag_groups.split(",")
|
||||||
filtered_tags = TagGroup.includes(:tags).where(name: tag_group_array).map do |tag_group|
|
filtered_tags = TagGroup.includes(:tags).where(name: tag_group_array).map do |tag_group|
|
||||||
tag_group.tags.pluck(:name)
|
tag_group.tags.pluck(:name)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
require 'request_store'
|
||||||
|
|
||||||
module CustomWizardTagsController
|
module CustomWizardTagsController
|
||||||
def search
|
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
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,9 +12,13 @@ describe ::TagsController, type: :request do
|
||||||
fab!(:tag_group_1) { Fabricate(:tag_group, tags: [tag_1, tag_2]) }
|
fab!(:tag_group_1) { Fabricate(:tag_group, tags: [tag_1, tag_2]) }
|
||||||
fab!(:tag_group_2) { Fabricate(:tag_group, tags: [tag_3, tag_4]) }
|
fab!(:tag_group_2) { Fabricate(:tag_group, tags: [tag_3, tag_4]) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
::RequestStore.store[:tag_groups] = nil
|
||||||
|
end
|
||||||
|
|
||||||
describe "#search" do
|
describe "#search" do
|
||||||
context "tag group param present" 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] }
|
get "/tags/filter/search.json", params: { q: '', tag_groups: [tag_group_1.name, tag_group_2.name] }
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
results = response.parsed_body['results']
|
results = response.parsed_body['results']
|
||||||
|
@ -24,6 +28,7 @@ describe ::TagsController, type: :request do
|
||||||
.includes(:tags)
|
.includes(:tags)
|
||||||
.where(id: [tag_group_1.id, tag_group_2.id])
|
.where(id: [tag_group_1.id, tag_group_2.id])
|
||||||
.map { |tag_group| tag_group.tags.pluck(:name) }.flatten
|
.map { |tag_group| tag_group.tags.pluck(:name) }.flatten
|
||||||
|
|
||||||
expect(names).to contain_exactly(*expected_tag_names)
|
expect(names).to contain_exactly(*expected_tag_names)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren