From 64e557474544f197994621002a71193806c69439 Mon Sep 17 00:00:00 2001 From: Pablo Monfort Date: Sat, 25 Apr 2026 00:04:17 -0300 Subject: [PATCH 1/2] AO3-5713 Add tests for tag set fandom only validation --- spec/models/prompt_spec.rb | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/spec/models/prompt_spec.rb b/spec/models/prompt_spec.rb index ab5254441b0..5866a06a54a 100644 --- a/spec/models/prompt_spec.rb +++ b/spec/models/prompt_spec.rb @@ -43,5 +43,65 @@ expect(prompt.errors[:base][0]).to include("not in the selected fandom") end end + + context "when restrict_to_fandom and restrict_to_tag_set are both enabled" do + let(:fandom_character) { create(:character, canonical: true) } + + before do + create(:common_tagging, filterable: fandom, common_tag: fandom_character) + create(:common_tagging, filterable: fandom, common_tag: non_fandom_character) + create(:tag_set_association, tag: fandom_character, parent_tag: fandom, owned_tag_set: owned_tag_set) + end + + let!(:challenge) do + create(:gift_exchange, + offer_restriction: create(:prompt_restriction, + character_restrict_to_fandom: true, + character_restrict_to_tag_set: true, + owned_tag_sets: [owned_tag_set])) + end + + it "marks the prompt as valid when the character is in the tag set" do + prompt = build(:offer, + tag_set: create(:tag_set, tags: [fandom, fandom_character]), + collection_id: collection.id, + challenge_signup: create(:challenge_signup)) + expect(prompt).to be_valid + end + + it "marks the prompt as invalid when the character is canonical in the fandom but not in the tag set" do + other_character = create(:character, canonical: true) + create(:common_tagging, filterable: fandom, common_tag: other_character) + prompt = build(:offer, + tag_set: create(:tag_set, tags: [fandom, other_character]), + collection_id: collection.id, + challenge_signup: create(:challenge_signup)) + expect(prompt).not_to be_valid + end + end + + context "when only restrict_to_fandom is enabled (not restrict_to_tag_set)" do + let(:fandom_character) { create(:character, canonical: true) } + + before do + create(:common_tagging, filterable: fandom, common_tag: fandom_character) + end + + let!(:challenge) do + create(:gift_exchange, + offer_restriction: create(:prompt_restriction, + character_restrict_to_fandom: true, + character_restrict_to_tag_set: false, + owned_tag_sets: [owned_tag_set])) + end + + it "marks the prompt as valid when the character is canonical in the fandom even if not in the tag set" do + prompt = build(:offer, + tag_set: create(:tag_set, tags: [fandom, fandom_character]), + collection_id: collection.id, + challenge_signup: create(:challenge_signup)) + expect(prompt).to be_valid + end + end end end From bcc9db4cb6a184687759b91ab09ebc90e4461f1a Mon Sep 17 00:00:00 2001 From: Pablo Monfort Date: Wed, 6 May 2026 00:26:47 -0300 Subject: [PATCH 2/2] AO3-5713 Validate tag set fandom only restriction --- app/models/prompt.rb | 7 +++++++ spec/models/prompt_spec.rb | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/prompt.rb b/app/models/prompt.rb index cdae4bb6a4a..9a2ed13cd49 100755 --- a/app/models/prompt.rb +++ b/app/models/prompt.rb @@ -175,6 +175,13 @@ def restricted_tags # tag_type is one of a set set so we know it is safe for constantize allowed_tags = tag_type.classify.constantize.with_parents(tag_set.fandom_taglist).canonical + + if restriction.send("#{tag_type}_restrict_to_tag_set") + allowed_tags = allowed_tags.where( + id: tag_set_associations.where(parent_tag_id: tag_set.fandom_taglist).select(:tag_id) + ) + end + disallowed_taglist = tag_set ? tag_set.send("#{tag_type}_taglist") - allowed_tags : [] # check for tag set associations diff --git a/spec/models/prompt_spec.rb b/spec/models/prompt_spec.rb index 5866a06a54a..a61ee888633 100644 --- a/spec/models/prompt_spec.rb +++ b/spec/models/prompt_spec.rb @@ -62,20 +62,22 @@ end it "marks the prompt as valid when the character is in the tag set" do + signup = build(:challenge_signup, collection: collection) prompt = build(:offer, tag_set: create(:tag_set, tags: [fandom, fandom_character]), collection_id: collection.id, - challenge_signup: create(:challenge_signup)) + challenge_signup: signup) expect(prompt).to be_valid end it "marks the prompt as invalid when the character is canonical in the fandom but not in the tag set" do other_character = create(:character, canonical: true) create(:common_tagging, filterable: fandom, common_tag: other_character) + signup = build(:challenge_signup, collection: collection) prompt = build(:offer, tag_set: create(:tag_set, tags: [fandom, other_character]), collection_id: collection.id, - challenge_signup: create(:challenge_signup)) + challenge_signup: signup) expect(prompt).not_to be_valid end end @@ -96,10 +98,11 @@ end it "marks the prompt as valid when the character is canonical in the fandom even if not in the tag set" do + signup = build(:challenge_signup, collection: collection) prompt = build(:offer, tag_set: create(:tag_set, tags: [fandom, fandom_character]), collection_id: collection.id, - challenge_signup: create(:challenge_signup)) + challenge_signup: signup) expect(prompt).to be_valid end end