Static attributes are deprecated since factory bot 4.11; we haven't upgraded yet but now we're ready to do so: https://thoughtbot.com/blog/deprecating-static-attributes-in-factory_bot-4-11
40 lines
894 B
Ruby
40 lines
894 B
Ruby
FactoryBot.define do
|
|
factory :comment do
|
|
association :commentable, factory: :debate
|
|
user
|
|
sequence(:body) { |n| "Comment body #{n}" }
|
|
|
|
trait :hidden do
|
|
hidden_at { Time.current }
|
|
end
|
|
|
|
trait :with_ignored_flag do
|
|
ignored_flag_at { Time.current }
|
|
end
|
|
|
|
trait :with_confirmed_hide do
|
|
confirmed_hide_at { Time.current }
|
|
end
|
|
|
|
trait :flagged do
|
|
after :create do |debate|
|
|
Flag.flag(create(:user), debate)
|
|
end
|
|
end
|
|
|
|
trait :with_confidence_score do
|
|
before(:save) { |d| d.calculate_confidence_score }
|
|
end
|
|
|
|
trait :valuation do
|
|
valuation { true }
|
|
association :commentable, factory: :budget_investment
|
|
before :create do |valuation|
|
|
valuator = create(:valuator)
|
|
valuation.author = valuator.user
|
|
valuation.commentable.valuators << valuator
|
|
end
|
|
end
|
|
end
|
|
end
|