Sha256: b67c9a818d09976faebb0d2d56494ec5251feea6e0b218b1aace1d32a57090a5

Contents?: true

Size: 1.32 KB

Versions: 13

Compression:

Stored size: 1.32 KB

Contents

# A global trait for setting created_by and updated_by.
#
# When a model includes the Accountable concern, it adds a #by attributes and this
# can be set as a shorthand for setting both created_by and updated_by.
# Similarly, any factory defined against such a model therefore naturally has a by
# attribute available, so we can for example do
#
#    create(:patient, by: user_a)
#
# which is equivalent to
#
#    create(:patient, created_by: user_a, updated_by: user_a)
#
# However if you don't call `create` with a `by` or `*_by` arguments, the default `association` we
# define here in this global trait ensures only one user - accountable_actor is created and assigned
# to both created_by and updated_by. Previously each had its own `user` association and two users
# were created each time any model (that included Accountable) was created by FactoryBot.
# If you need to use the same user for any other attribute in a factory, you can do for instance
#
#     factory :audit do
#       accountable
#       requested_by { accountable_actor }
#     end
#
#  Which create one user and assign them to updated_by, createed_by and requested_by.
#
FactoryBot.define do
  trait :accountable do
    transient do
      accountable_actor { by || create(:user) }
    end
    created_by { accountable_actor }
    updated_by { accountable_actor }
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc11 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc10 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc9 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc8 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc7 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc6 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc5 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc4 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc3 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.rc1 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.beta12 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.beta11 spec/factories/shared/accountable.rb
renalware-core-2.0.0.pre.beta10 spec/factories/shared/accountable.rb