From 994b5c99c295cea1f9fe48b39d5e4a72c972e09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 25 Sep 2019 23:35:01 +0200 Subject: [PATCH] Simplify taggings creation in specs --- spec/factories/classifications.rb | 8 ++++++++ spec/models/tag_spec.rb | 6 ++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/factories/classifications.rb b/spec/factories/classifications.rb index bea7599ca..df2ba4456 100644 --- a/spec/factories/classifications.rb +++ b/spec/factories/classifications.rb @@ -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 diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index 95dea8cb8..59dad7137 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -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)