Refactor consumer factory

This commit is contained in:
Sebastian Serth
2022-09-22 13:33:54 +02:00
committed by Sebastian Serth
parent 6ad5274e67
commit e3018c1847
2 changed files with 28 additions and 8 deletions

View File

@ -3,12 +3,15 @@
FactoryBot.define do
factory :consumer do
name { 'openHPI' }
oauth_key { SecureRandom.hex }
oauth_secret { SecureRandom.hex }
singleton_consumer
end
trait :singleton_consumer do
initialize_with { Consumer.where(name: name).first_or_create }
initialize_with do
Consumer.find_or_initialize_by(name: name) do |consumer|
consumer.oauth_key = SecureRandom.hex
consumer.oauth_secret = SecureRandom.hex
end
end
end
end