1) BuildsController has a valid factory
Failure/Error: FactoryGirl.create(:app).should be_valid
Mongoid::Errors::MixedRelations:
Problem:
Referencing a(n) Build document from the App document via a relational association is not allowed since the Build is embedded.
Summary:
In order to properly access a(n) Build from App the reference would need to go through the root document of Build. In a simple case this would require Mongoid to store an extra foreign key for the root, in more complex cases where Build is multiple levels deep a key would need to be stored for each parent up the hierarchy.
Resolution:
Consider not embedding Build, or do the key storage and access in a custom manner in the application code.
# ./spec/controllers/builds_controller_spec.rb:12:in `block (2 levels) in <top (required)>'
构建.rb
class Build
include Mongoid::Document
include Mongoid::Timestamps
field :note
embedded_in :own_app, :class_name => "App", :inverse_of => :last_build
belongs_to :app
end
应用程序.rb
class App
include Mongoid::Document
include Mongoid::Timestamps
has_many :builds
embeds_one :last_build, :class_name => "Build", :inverse_of => :own_app
end
规格/工厂/apps.rb
FactoryGirl.define do
factory :app do |f|
#fields
last_build { FactoryGirl.build(:build) }
builds {|b| [ b = FactoryGirl.build(:build) ] }
end
end
当我运行 rsepc 时,控制台会抛出此异常。我的英语很差,所以我希望代码会告诉我。谢谢 !