Skip to content

Commit

Permalink
Fixes issue where calling make_unsaved inside a blueprint forces a ma…
Browse files Browse the repository at this point in the history
…ke_unsaved instance of the top-level blueprint to be saved.
  • Loading branch information
fosrias authored and notahat committed Jul 9, 2010
1 parent 7eb4b05 commit 49038a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/machinist.rb
Expand Up @@ -105,11 +105,12 @@ def generate_attribute_value(attribute, *args)
# that calls to make from within a blueprint don't create
# anything inside make_unsaved.
def self.with_save_nerfed
prior_nerfed = @@nerfed
begin
@@nerfed = true
yield
ensure
@@nerfed = false
@@nerfed = prior_nerfed
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/active_record_spec.rb
Expand Up @@ -193,6 +193,13 @@ class Comment < ActiveRecord::Base
post = Post.make_unsaved { comment = Comment.make }
post.should be_new_record
comment.should_not be_new_record
end

it "should not save constructed object when objects are constructed within blueprint" do
Comment.blueprint { }
Post.blueprint { comment = Comment.make_unsaved }
post = Post.make_unsaved
post.should be_new_record
end
end

Expand Down

0 comments on commit 49038a9

Please sign in to comment.