Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

dont cache instantiated stubs with :id => :new

  • Loading branch information...
commit 287558d1ba9e9e112656381f5bf0e1412481aaa2 1 parent 3382c02
@technoweenie authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 lib/model_stubbing/stub.rb
View
7 lib/model_stubbing/stub.rb
@@ -39,7 +39,11 @@ def default?
# pass :id => :new to specify you want a new record, not one in the database
def record(attributes = {})
this_record_key = record_key(attributes)
- ModelStubbing.records[this_record_key] ||= instantiate(this_record_key, attributes)
+ if attributes[:id] != :new && ModelStubbing.records.key?(this_record_key)
+ ModelStubbing.records[this_record_key]
+ else
+ ModelStubbing.records[this_record_key] = instantiate(this_record_key, attributes)
+ end
end
def inspect
@@ -157,7 +161,6 @@ def stubbed_attributes(attributes)
def record_key(attributes)
return @record_key if @record_key && attributes.empty?
key = [model.model_class.name, @global_key, @attributes.merge(attributes).inspect] * ":"
- key << model.model_class.base_class.mock_id.to_s if attributes[:id] == :new
@record_key = key if attributes.empty?
key
end
Please sign in to comment.
Something went wrong with that request. Please try again.