diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2014-05-08 07:55:12 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2014-05-08 07:55:12 -0300 |
commit | 33fcdffff285f43ba5f8787cbf193a1b7f9b582b (patch) | |
tree | 4bba724d80c525b61c7fcc64be87d7a232a1ad4f /activerecord/test | |
parent | 7f1fd0265cb11544ae7cc94fb417c6abddcf2ee3 (diff) | |
parent | f045663dfc879b9516904255fb555f048c394b7b (diff) | |
download | rails-33fcdffff285f43ba5f8787cbf193a1b7f9b582b.tar.gz rails-33fcdffff285f43ba5f8787cbf193a1b7f9b582b.tar.bz2 rails-33fcdffff285f43ba5f8787cbf193a1b7f9b582b.zip |
Merge pull request #14992 from fredwu/habtm_relation_size_calculation_fix
Habtm relation size calculation fix. Fixes #14913, Fixes #14914.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb | 18 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index 5d33634da2..c166fe87e8 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -217,6 +217,24 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase 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_habtm_collection_size_from_params + devel = Developer.new({ + projects_attributes: { + '0' => {} + } + }) + + assert_equal 1, devel.projects.size + end + def test_build devel = Developer.find(1) proj = assert_no_queries { devel.projects.build("name" => "Projekt") } diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 762259ffa3..0a614c3bfd 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -13,6 +13,8 @@ class Developer < ActiveRecord::Base end end + accepts_nested_attributes_for :projects + has_and_belongs_to_many :projects_extended_by_name, -> { extending(DeveloperProjectsAssociationExtension) }, :class_name => "Project", |