Simplify taggings creation in specs

This commit is contained in:
Javi Martín
2019-09-25 23:35:01 +02:00
parent 3b5cbc2150
commit 994b5c99c2
2 changed files with 10 additions and 4 deletions

View File

@@ -9,6 +9,14 @@ FactoryBot.define do
trait :milestone do
kind { "milestone" }
end
transient { taggables { [] } }
after(:create) do |tag, evaluator|
evaluator.taggables.each do |taggable|
create(:tagging, tag: tag, taggable: taggable)
end
end
end
factory :tagging, class: "ActsAsTaggableOn::Tagging" do

View File

@@ -4,8 +4,7 @@ describe Tag do
it "decreases tag_count when a debate is hidden" do
debate = create(:debate)
tag = create(:tag)
tagging = create(:tagging, tag: tag, taggable: debate)
tag = create(:tag, taggables: [debate])
expect(tag.taggings_count).to eq(1)
@@ -17,8 +16,7 @@ describe Tag do
it "decreases tag_count when a proposal is hidden" do
proposal = create(:proposal)
tag = create(:tag)
tagging = create(:tagging, tag: tag, taggable: proposal)
tag = create(:tag, taggables: [proposal])
expect(tag.taggings_count).to eq(1)