Skip to content

Commit

Permalink
Handles stubbing many-to-many relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencepit committed Jun 17, 2008
1 parent 7b3cdda commit ea65221
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/model_stubbing/model.rb
Expand Up @@ -30,7 +30,7 @@ def initialize(definition, klass, options = {}, &block)
unless @model_class.respond_to?(:mock_id)
class << @model_class
define_method :mock_id do
@mock_id ||= 999
@mock_id ||= 9999
@mock_id += 1
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/model_stubbing/stub.rb
Expand Up @@ -51,6 +51,7 @@ def inspect

def insert(attributes = {})
object = record(attributes)
object.id = nil
object.new_record = true
object.save!
end
Expand Down Expand Up @@ -119,6 +120,9 @@ def instantiate(this_record_key, attributes)
# set association
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
value.collect! { |v| v.is_a?(Stub) ? v.record : v }
record.send("#{key}=", value.compact)
else
record.send("#{key}=", value)
end
Expand Down

0 comments on commit ea65221

Please sign in to comment.