Permalink
Browse files

When inserting stub instantiations, set new_record to true before set…

…ting has_many associations
  • Loading branch information...
lawrencepit committed Jun 17, 2008
1 parent 004da7c commit cc1543ab53825fd3e3f15e7da5cbe7b6e1c81194
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/model_stubbing/stub.rb
@@ -50,9 +50,10 @@ def inspect
end
def insert(attributes = {})
+ @inserting = true
object = record(attributes)
- object.new_record = true
object.save!
+ @inserting = false
end
def with(attributes)
@@ -111,6 +112,7 @@ def instantiate(this_record_key, attributes)
record.new_record = false
record.id = ModelStubbing.record_ids[this_record_key] ||= attributes[:id] || @model.model_class.base_class.mock_id
end
+ record.new_record = true if @inserting
record.stubbed_attributes = stubbed_attributes.merge(:id => record.id)
stubbed_attributes.each do |key, value|
if value.is_a? Stub

0 comments on commit cc1543a

Please sign in to comment.