Skip to content
Browse files

Handles stubbing many-to-many relationships

  • Loading branch information...
1 parent 7b3cdda commit ea65221d389bb673dff15e71dd6ac31cbc852e23 @lawrencepit lawrencepit committed Jun 17, 2008
Showing with 5 additions and 1 deletion.
  1. +1 −1 lib/model_stubbing/model.rb
  2. +4 −0 lib/model_stubbing/stub.rb
View
2 lib/model_stubbing/model.rb
@@ -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
View
4 lib/model_stubbing/stub.rb
@@ -51,6 +51,7 @@ def inspect
def insert(attributes = {})
object = record(attributes)
+ object.id = nil
object.new_record = true
object.save!
end
@@ -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

0 comments on commit ea65221

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