2013-05-03 45 views
2

我使用Mongoid作爲數據庫,並且我有兩個模型,如下所示。我無法斷言has_many和belongs_to的關係。我可以在MiniTest中聲明這種關係。has_many和belongs_to在使用Mongoid的MiniTest中聲明

Event.rb

class Event 
    include Schizo::Data 
    include Mongoid::Document 

    field :name 
    field :start_at 
    field :finish_at 
    field :status 
    field :location 

    has_many :participations 
end 

Participation.rb

class Participation 
    include Mongoid::Document 

    belongs_to :event 
    belongs_to :participant 

end 

回答

0

考慮使用mongoid-minitest寶石爲。查看詳情here

您的規格看起來像下面則:

describe Event do 
    subject { Event } 

    it { must have_many(:participations) } 
end 

describe Participation do 
    subject { Participation } 

    it { must belong_to(:participations) } 
end