Permalink
Browse files

Merge pull request #14995 from fredwu/habtm_relation_size_calculation…

…_fix-4-0-stable

Habtm relation size calculation fix for 4.0 branch
  • Loading branch information...
carlosantoniodasilva committed May 8, 2014
2 parents 3d057a0 + 9d4e2ab commit bb136488e16665321b7bc474538cf058ed2995b9
@@ -1,3 +1,12 @@
+* Fixed HABTM's CollectionAssociation size calculation.
+
+ HABTM should not include new records as part of #count_records as new
+ records are already counted.
+
+ Fixes #14914.
+
+ *Fred Wu*
+
* Keep track of dirty attributes after transaction is rollback.
Related #13166.
@@ -35,7 +35,7 @@ def insert_record(record, validate = true, raise = false)
private
def count_records
- load_target.size
+ load_target.reject { |r| r.new_record? }.size
end
def delete_records(records, method)
@@ -228,6 +228,14 @@ def test_habtm_unique_order_preserved
assert_equal developers(:poor_jamis, :jamis, :david), projects(:active_record).developers
end
+ def test_habtm_collection_size_from_build
+ devel = Developer.create("name" => "Fred Wu")
+ devel.projects << Project.create("name" => "Grimetime")
+ devel.projects.build
+
+ assert_equal 2, devel.projects.size
+ end
+
def test_build
devel = Developer.find(1)
proj = assert_no_queries { devel.projects.build("name" => "Projekt") }

0 comments on commit bb13648

Please sign in to comment.