2018-05-08 10:10:19 +00:00
|
|
|
FactoryBot.define do
|
|
|
|
factory :recent_view do
|
2018-09-10 12:38:33 +00:00
|
|
|
transient do
|
|
|
|
type { :ticket }
|
|
|
|
user_role { :agent }
|
|
|
|
end
|
|
|
|
|
|
|
|
recent_view_object_id { ObjectLookup.by_name(type.to_s.camelcase) }
|
|
|
|
|
|
|
|
# select a random record of the given object class
|
|
|
|
o_id do
|
2018-09-11 06:46:10 +00:00
|
|
|
random_function = case ActiveRecord::Base.connection_config[:adapter]
|
|
|
|
when 'mysql2'
|
|
|
|
'RAND'
|
|
|
|
when 'postgresql'
|
|
|
|
'RANDOM'
|
|
|
|
end
|
|
|
|
|
|
|
|
type.to_s.camelcase.constantize.order("#{random_function}()").first.id
|
2018-09-10 12:38:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# assign to an existing user, if possible
|
|
|
|
created_by_id do
|
|
|
|
User.find { |u| u.role?(user_role.capitalize) }&.id ||
|
|
|
|
create("#{user_role}_user").id
|
|
|
|
end
|
2018-05-08 10:10:19 +00:00
|
|
|
end
|
|
|
|
end
|