Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Save grandparents when saving a parent association
Browse files Browse the repository at this point in the history
[#940 state:resolved]
  • Loading branch information
dkubb committed Jul 1, 2009
1 parent 169ee0e commit cb4301e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dm-core/resource.rb
Expand Up @@ -614,7 +614,7 @@ def save_self
def save_parents
parent_relationships.all? do |relationship|
parent = relationship.get!(self)
if parent.save_self
if parent.save_parents && parent.save_self
relationship.set(self, parent) # set the FK values
end
end
Expand Down
44 changes: 44 additions & 0 deletions spec/public/shared/resource_shared_spec.rb
Expand Up @@ -702,6 +702,50 @@

end

describe 'on a new object with unsaved parent and grandparent' do
before :all do
@grandparent = @user_model.new(:name => 'dkubb', :comment => @comment)
@parent = @user_model.new(:name => 'ashleymoran', :comment => @comment, :referrer => @grandparent)
@child = @user_model.new(:name => 'mrship', :comment => @comment, :referrer => @parent)

@response = @child.save
end

it 'should return true' do
@response.should be_true
end

it 'should save the child' do
@child.should be_saved
end

it 'should save the parent' do
@parent.should be_saved
end

it 'should save the grandparent' do
@grandparent.should be_saved
end

it 'should relate the child to the parent' do
pending_if 'TODO', @one_to_one_through do
@child.model.get(*@child.key).referrer.should == @parent
end
end

it 'should relate the parent to the grandparent' do
pending_if 'TODO', @one_to_one_through do
@parent.model.get(*@parent.key).referrer.should == @grandparent
end
end

it 'should relate the grandparent to nothing' do
pending_if 'TODO', @one_to_one_through do
@grandparent.model.get(*@grandparent.key).referrer.should be_nil
end
end
end

end

it { @user.should respond_to(:saved?) }
Expand Down

0 comments on commit cb4301e

Please sign in to comment.