0
我真的想圍繞如何用Factory Girl創建複雜的工廠,而且它是不是容易。使用特質來建立工廠的語法是什麼?
我有以下幾點:
認購belongs_to的用戶
認購belongs_to的計劃
我想測試不同Plans
。這是我如何設置它:
FactoryGirl.define do
factory :plan do
trait :copper do
name { "Copper" }
amount { 5 }
stripe_id { "Economy" }
listing_limit { 10 }
repositories_allowed { 1 }
end
trait :copper_multi do
name { "Copper Multi" }
amount { 10 }
stripe_id { "Copper_Multi" }
listing_limit { 10 }
repositories_allowed { 5 }
end
trait :bronze do
name { "Bronze" }
amount { 5 }
stripe_id { "Basic" }
listing_limit { 10 }
repositories_allowed { 1 }
end
trait :bronze_multi do
name { "Bronze Multi" }
amount { 10 }
stripe_id { "Basic_Multi" }
listing_limit { 10 }
repositories_allowed { 5 }
end
end
end
Subscription
廠是:
FactoryGirl.define do
factory :subscription do
association :user
association :plan
start_date { Time.now }
end_date { 365.days.from_now }
end
end
當然,這失敗,因爲Plan
工廠不能同時沒有指定一個特性來使用。這是設計。
此外,之間有什麼區別:
factory :subscription do
association :user
end
和:
factory :subscription do
user
end