2017年12月12日 星期二

RSpec 原來還可以在 factory 下面再用 factory

RSpec 原來還可以在 factory 下面再用 factory

這樣就可以用

```
create(:tiny_btc_account)
```

```
FactoryGirl.define do
  factory :account do
    locked { "0.0".to_d }
    balance { "0.0".to_d }

    trait :usd do
      currency :usd
    end

    trait :btc do
      currency :btc
    end

    trait :small do
      after :create do |account|
        account.plus_funds 10, reason: Account::DEPOSIT
      end
    end

    trait :tiny do
      after :create do |account|
        account.plus_funds 1, reason: Account::DEPOSIT
      end
    end

    factory :tiny_btc_account, traits: [:tiny, :btc]
    factory :tiny_usd_account, traits: [:tiny, :usd]

    factory :small_btc_account, traits: [:small, :btc]
    factory :small_usd_account, traits: [:small, :usd]
  end
end

```


沒有留言:

張貼留言