-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Spec:
- spec/models/view_spec.rb
require "spec_helper"
class Account
include Mongoid::Document
#this is correct, account has many users, not has many views
has_many :users, as: :account
end
class User
include Mongoid::Document
embeds_many :views
end
class View
include Mongoid::Document
embedded_in :user
#this is correct, view belongs to account, not user belongs to account
belongs_to :account , polymorphic: true
attr_accessible :account, :account_id, :account_type
validates :account, :presence => true
end
describe View do
let!(:account)
{ Account.create! }let!(:user)
{ User.create! } let!(:view) do
user.views.build(
:account_id => account.id,
:account_type => account.class.name
)
end
it "works" do
user.save!
end
it "works" do
view.save!(:validate => false)
end
it "doesn't work" do
view.save!
end
end
Failure:
$ rspec spec -f d -b
View
works
works
doesn't work (FAILED - 1)
Failures:
1) View doesn't work
Failure/Error: view.save!
NoMethodError:
undefined method `insert_modifier' for #<Mongoid::Atomic::Paths::Root:0x00000003aa9058>
- mongoid-2.3.4/lib/mongoid/atomic.rb:71:in `atomic_insert_modifier'
- mongoid-2.3.4/lib/mongoid/persistence/operations.rb:65:in `inserts'
- mongoid-2.3.4/lib/mongoid/persistence/operations/embedded/insert.rb:34:in `block in persist'
- mongoid-2.3.4/lib/mongoid/persistence/insertion.rb:26:in `block (3 levels) in prepare'
- activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_create_callbacks'
- activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
- mongoid-2.3.4/lib/mongoid/callbacks.rb:42:in `block in run_callbacks'
- mongoid-2.3.4/lib/mongoid/callbacks.rb:67:in `call'
- mongoid-2.3.4/lib/mongoid/callbacks.rb:67:in `run_cascading_callbacks'
- mongoid-2.3.4/lib/mongoid/callbacks.rb:41:in `run_callbacks'
- mongoid-2.3.4/lib/mongoid/persistence/insertion.rb:25:in `block (2 levels) in prepare'
- activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_save_callbacks'
- activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
- mongoid-2.3.4/lib/mongoid/callbacks.rb:42:in `block in run_callbacks'
- mongoid-2.3.4/lib/mongoid/callbacks.rb:67:in `call'
- mongoid-2.3.4/lib/mongoid/callbacks.rb:67:in `run_cascading_callbacks'
- mongoid-2.3.4/lib/mongoid/callbacks.rb:41:in `run_callbacks'
- mongoid-2.3.4/lib/mongoid/persistence/insertion.rb:24:in `block in prepare'
- mongoid-2.3.4/lib/mongoid/persistence/insertion.rb:22:in `tap'
- mongoid-2.3.4/lib/mongoid/persistence/insertion.rb:22:in `prepare'
- mongoid-2.3.4/lib/mongoid/persistence/operations/embedded/insert.rb:30:in `persist'
- mongoid-2.3.4/lib/mongoid/persistence.rb:44:in `insert'
- mongoid-2.3.4/lib/mongoid/persistence.rb:149:in `upsert'
- mongoid-2.3.4/lib/mongoid/persistence.rb:70:in `save!'
- ./spec/models/view_spec.rb:47:in `block (2 levels) in <top (required)>'
- ... rspec cli/runner methods ...
Finished in 2.68 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/models/view_spec.rb:46 # View doesn't work