在控制台中我这样做:
board = FactoryGirl.build(:board_with_source)
board.sources
=> [#<Board id: 6, name: "Free Ruby Books", description: "Ruby Books - Free and Paid ones", created_at: "2013-06-21 12:21:34", updated_at: "2013-06-21 12:21:34", user_id: nil>]
board.sources.count
=> 0
为什么它显示 0 ?
FactoryGirl 设置:
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :board do
name "Ruby Books"
description "Ruby Books - Free and Paid ones"
end
factory :board_with_source, parent: :board do
after :build do |board|
board.sources << FactoryGirl.create(:board, name: "Free Ruby Books")
end
end
end