我正在嘗試爲我的用戶模型及其關聯創建一個工廠。但是,我似乎無法在Factory Girl代碼中獲得正確的語法。我已閱讀了Factory Girl文檔,但似乎無法找到任何有關我的特定用例的幫助。當我運行我的測試套件,我目前收到的錯誤是:工廠女孩 - 如何爲具有關聯的模型創建工廠?
undefined method `subscription_args' for #<FactoryGirl::SyntaxRunner...
和
Trait not registered: valid_card_data
這裏是我的模型和協會:
User.rb
has_one :subscription
has_one :plan, :through => :subscription
has_many :projects
Project.rb
belongs_to :user
Plan.rb
has_many :subscriptions
Subscription.rb
belongs_to :plan
belongs_to :user
和
這裏是我的工廠女孩代碼:
FactoryGirl.define do
factory :user do
first_name "Joel"
last_name "Brewer"
email { "#{first_name}.#{last_name}@example.com".downcase }
password "foobar"
password_confirmation "foobar"
user_type "entrepreneur"
subscription { build(:subscription, subscription_args) }
after(:create) do |user|
user.subscription.save!
end
end
factory :subscription do
user
plan_id '4'
## I am trying to access a helper method from support/utilities ##
## This call to valid_card_data doesn't seem to be working... ##
stripe_card_token valid_card_data
email "[email protected]"
end
factory :project do
title "Sample Project"
user
end
end
查看關聯下的https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md。 – kddeisz
我試過通過文檔閱讀,我似乎無法得到它爲我的用例工作... –