Files
grecia/spec/factories/notifications.rb
rgarcia 68a2281203 Refactor segment constant into a class method
We're going to make it dynamic using the geozones. Besides, class
methods can be overwritten using custom models, while constants can't be
overwritten without getting a warning [1].

Makes the definition of segments with geozones a little cleaner. I
think it’s worth it, compared to the slight memory gain of using a
constant [2].

[1] warning: already initialized constant UserSegments::SEGMENTS

[2] https://stackoverflow.com/questions/15903835/class-method-vs-constant-in-ruby-rails#answer-15903970
2021-12-20 15:07:25 +01:00

37 lines
862 B
Ruby

FactoryBot.define do
factory :notification do
user
association :notifiable, factory: :proposal
trait :read do
read_at { Time.current }
end
trait :for_proposal_notification do
association :notifiable, factory: :proposal_notification
end
trait :for_comment do
association :notifiable, factory: :comment
end
trait :for_poll_question do
association :notifiable, factory: :poll_question
end
end
factory :admin_notification do
sequence(:title) { |n| "Admin Notification title #{n}" }
sequence(:body) { |n| "Admin Notification body #{n}" }
link { nil }
segment_recipient { UserSegments.segments.sample }
recipients_count { nil }
sent_at { nil }
trait :sent do
recipients_count { 1 }
sent_at { Time.current }
end
end
end