public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
best solution?

Signed-off-by: Steven Soroka <ssoroka78@gmail.com>
Steven Soroka (author)
Thu May 01 12:09:12 -0700 2008
dhh (committer)
Thu May 01 12:22:55 -0700 2008
commit  9c20391bbe6ec1c56f8c8ed4aefb31a93576f76a
tree    fb66a893a06c0a0f452748d808f10a5d74faf61f
parent  c353794dff580c8aa63b357b2857c1fadff3104b
...
10
11
12
13
 
14
15
16
17
18
19
20
 
21
22
23
...
10
11
12
 
13
14
15
16
17
18
19
 
20
21
22
23
0
@@ -10,14 +10,14 @@ module ActiveRecord
0
 
0
       def create!(attrs = nil)
0
         @reflection.klass.transaction do
0
-          self << (object = @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! })
0
+          self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! } : @reflection.klass.create!)
0
           object
0
         end
0
       end
0
 
0
       def create(attrs = nil)
0
         @reflection.klass.transaction do
0
-          self << (object = @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create })
0
+          self << (object = attrs ? @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create } : @reflection.klass.create)
0
           object
0
         end
0
       end
...
115
116
117
 
 
 
 
 
 
 
 
 
 
 
 
118
119
120
...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
0
@@ -115,6 +115,18 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
0
     assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Jeb")
0
   end
0
 
0
+  def test_associate_with_create_and_no_options
0
+    peeps = posts(:thinking).people.count
0
+    posts(:thinking).people.create
0
+    assert_equal peeps + 1, posts(:thinking).people.count
0
+  end
0
+
0
+  def test_associate_with_create_exclaimation_and_no_options
0
+    peeps = posts(:thinking).people.count
0
+    posts(:thinking).people.create!
0
+    assert_equal peeps + 1, posts(:thinking).people.count
0
+  end
0
+
0
   def test_clear_associations
0
     assert_queries(2) { posts(:welcome);posts(:welcome).people(true) }
0
     

Comments