
Updating parent object fires a hook on associated objects
Reported by Marcin Kulik | May 7th, 2009 @ 08:45 AM
I've noticed a bug in (probably) dm-observer causing firing hooks on associated objects. If you set up "after :update" observer for Comment model and then you update some Post record the hooks are being fired on all comments objects. Following spec is reproducing the problem on DM 0.9.11
require 'rubygems'
require 'spec'
require 'dm-core'
require 'dm-observer'
DataMapper.setup(:default, 'sqlite3::memory:')
class Post
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :comments
end
class Comment
include DataMapper::Resource
property :id, Serial
property :body, String
belongs_to :post
end
class CommentObserver
include DataMapper::Observer
observe Comment
after :update do
raise RuntimeError
end
end
DataMapper.auto_migrate!
describe Post do
before(:all) do
post = Post.create(:name => "Jola")
post.comments.create(:body => "A comment")
end
it "should not fire hooks on associated objects after updating (association not loaded)" do
post = Post.first
lambda do
post.update_attributes(:name => "Misio")
end.should_not raise_error
end
it "should not fire hooks on associated objects after updating (association loaded)" do
post = Post.first
post.comments
lambda do
post.update_attributes(:name => "Misio")
end.should_not raise_error
end
end
Comments and changes to this ticket
-
Dan Kubb (dkubb) May 28th, 2009 @ 07:21 PM
- State changed from unconfirmed to accepted
- Assigned user set to Dan Kubb (dkubb)
-
Dan Kubb (dkubb) June 7th, 2009 @ 01:57 AM
- State changed from accepted to resolved
I can confirm these specs now pass with dm-core/next.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »