Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 24 16:03

    brimatteng on main

    (compare)

  • Jul 06 09:37
    ThaDaVos commented #385
  • Jun 24 20:15
    georgebrock added as member
  • May 24 00:20
    brandoncordell commented #384
  • May 11 17:50
    jjb commented #384
  • May 11 17:48
    jjb commented #384
  • Apr 28 22:01
    jjb commented #384
  • Apr 19 17:45
    ThaDaVos commented #386
  • Apr 19 13:01
    georgebrock closed #386
  • Apr 19 13:01
    georgebrock commented #386
  • Apr 19 12:59
    georgebrock commented #385
  • Apr 16 07:24
    ThaDaVos opened #386
  • Mar 31 16:18
    ThaDaVos opened #385
  • Mar 06 20:57
    brandoncordell opened #384
  • Mar 02 13:40
    chiangs commented #383
  • Mar 02 13:39
    chiangs closed #383
  • Mar 02 11:47
    chiangs edited #383
  • Mar 02 11:39
    chiangs edited #383
  • Mar 02 11:38
    chiangs edited #383
  • Mar 02 11:37
    chiangs edited #383
totrash
@totrash

Hi.

It is possible to define factory with nested traits ?

This is working in example:

create(:cart, :with_address,  :with_patients,  traits: [:with_products])

I want to predefined factory for it like

factory :order_ready_cart, traits: [:with_address, with_patients: [:with_products]]
totrash
@totrash

oh and I forgot my trait :with_patients looks like this:

 trait :with_patients do
      transient do
          count { 1 }
          traits { [] }
      end
     after(:create) do |cart, evaluator|
        create_list(:carts_patient, evaluator.count, *evaluator.traits, cart: cart)
        cart.reload
      end
   end

so thats why my first example works.
(transient => traits is an array)
Any way to do it better ?

totrash
@totrash

This also doesn`t work:

    factory :order_ready_cart do
      with_address     
      with_patients { with_products }
    end

=> undefined method :with_products

totrash
@totrash
This message was deleted

At least wrap this :

create(:cart, :with_address,  :with_patients,  traits: [:with_products])

in to something like that:

  factory :order_ready_cart do
       create(:cart, :with_address,  :with_patients,  traits: [:with_products])
   end