Skip to content

Commit

Permalink
When inserting stub instantiations, set new_record to true before set…
Browse files Browse the repository at this point in the history
…ting has_many associations
  • Loading branch information
lawrencepit committed Jun 17, 2008
1 parent 004da7c commit cc1543a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/model_stubbing/stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc1543a

Please sign in to comment.