Skip to content
Browse files

When assigning has_many instantiated stubs, temporarily act as new ot…

…herwise AR inserts rows
  • Loading branch information...
1 parent 5f5c55a commit fa19833747dd574be9c9e7dd7ec69bece72503c7 @lawrencepit lawrencepit committed Jun 19, 2008
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/model_stubbing/stub.rb
View
6 lib/model_stubbing/stub.rb
@@ -123,8 +123,12 @@ def instantiate(this_record_key, attributes)
meta.send :attr_accessor, key unless record.respond_to?("#{key}=")
record.send("#{key}=", value.is_a?(Stub) ? value.record : value)
elsif value.is_a? Array
+ # when assigning has_many instantiated stubs, temporarily act as new
+ # otherwise AR inserts rows
value.collect! { |v| v.is_a?(Stub) ? v.record : v }
- record.send("#{key}=", value.compact)
+ nr, record.new_record = record.new_record?, true
+ record.send("#{key}=", value.compact)
+ record.new_record = nr
else
record.send("#{key}=", value)
end

0 comments on commit fa19833

Please sign in to comment.
Something went wrong with that request. Please try again.