Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/models/prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions spec/models/prompt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,68 @@
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
signup = build(:challenge_signup, collection: collection)
prompt = build(:offer,
tag_set: create(:tag_set, tags: [fandom, fandom_character]),
collection_id: collection.id,
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: 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
signup = build(:challenge_signup, collection: collection)
prompt = build(:offer,
tag_set: create(:tag_set, tags: [fandom, fandom_character]),
collection_id: collection.id,
challenge_signup: signup)
expect(prompt).to be_valid
end
end
end
end
Loading