Permalink
Browse files

best solution?

Signed-off-by: Steven Soroka <ssoroka78@gmail.com>
  • Loading branch information...
ssoroka authored and dhh committed May 1, 2008
1 parent c353794 commit 9c20391bbe6ec1c56f8c8ed4aefb31a93576f76a
@@ -10,14 +10,14 @@ def initialize(owner, reflection)
def create!(attrs = nil)
@reflection.klass.transaction do
- self << (object = @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! })
+ self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! } : @reflection.klass.create!)
object
end
end
def create(attrs = nil)
@reflection.klass.transaction do
- self << (object = @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create })
+ self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create } : @reflection.klass.create)
object
end
end
@@ -115,6 +115,18 @@ def test_associate_with_create
assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Jeb")
end
+ def test_associate_with_create_and_no_options
+ peeps = posts(:thinking).people.count
+ posts(:thinking).people.create
+ assert_equal peeps + 1, posts(:thinking).people.count
+ end
+
+ def test_associate_with_create_exclaimation_and_no_options
+ peeps = posts(:thinking).people.count
+ posts(:thinking).people.create!
+ assert_equal peeps + 1, posts(:thinking).people.count
+ end
+
def test_clear_associations
assert_queries(2) { posts(:welcome);posts(:welcome).people(true) }

0 comments on commit 9c20391

Please sign in to comment.