2013-01-09 39 views
0

我有一個團隊模型文件爲:如何在mongoDB測試中爲嵌入數據創建FactoryGirl?

class Team 
    include Mongoid::Document 
    field :short_name, type: String 
    field :sdi_team_id, type: Integer 
    embeds_many :history, :class_name => "History" 
end 

class History 
    include Mongoid::Document 
    field :short_name, type: String 
    field :sdi_team_id, type: Integer 
    embedded_in :teams, :class_name => "Team" 
end 

爲此,我必須寫測試在一個單一的規範文件team_spec.rb

在該文件中我寫了創建團隊和歷史factorygirl:

team = FactoryGirl.create(:team, sdi_team_id:team_d['sdi_team_id']) 

它創造的球隊,但我試過同爲歷史它不...

在我factories.rb我寫的是:

factory :team do 
    history { FactoryGirl.build(:history)} 
end 

factory :history do 

end 

我想創建相同的spec文件的歷史可以任何一個幫助。對軌道是新的。 我使用mongodb作爲我的後端。當我正在從XML數據...

回答

0

最後我得到了,

它只是做簡單的只是修改我的factories.rb文件

factory :team do 
    # team data 
    factory :history do 
    #history data 
    end 

end 
相關問題