diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-04-10 17:43:59 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-04-10 17:44:32 -0300 |
commit | a7a180bd8158a0a2151f0711b874a7495820d6e0 (patch) | |
tree | 826babcdecdf06bda24b56b10543422596d9140c /activerecord/test | |
parent | 632d9d22375dd79614ce731eb42875b65112b987 (diff) | |
parent | ec0928076529e8f0b5a4ad58c95cfa1fe6ed5b60 (diff) | |
download | rails-a7a180bd8158a0a2151f0711b874a7495820d6e0.tar.gz rails-a7a180bd8158a0a2151f0711b874a7495820d6e0.tar.bz2 rails-a7a180bd8158a0a2151f0711b874a7495820d6e0.zip |
Merge pull request #12829 from iantropov/issue_insert_via_hmt_scope_3548
Fix insertion of records for hmt association with scope
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 14 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/club.rb | 2 |
3 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 026a7fe635..6675e19dd9 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -1102,7 +1102,19 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal [posts(:thinking)], person.reload.first_posts end - def test_has_many_through_with_includes_in_through_association_scope + test "has many through with includes in through association scope" do assert_not_empty posts(:welcome).author_address_extra_with_address end + + test "insert records via has_many_through association with scope" do + club = Club.create! + member = Member.create! + Membership.create!(club: club, member: member) + + club.favourites << member + assert_equal [member], club.favourites + + club.reload + assert_equal [member], club.favourites + end end diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 15611656fd..fb0b906c07 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -16,6 +16,10 @@ module ActiveRecord def self.connection Post.connection end + + def self.table_name + 'fake_table' + end end def test_construction diff --git a/activerecord/test/models/club.rb b/activerecord/test/models/club.rb index 566e0873f1..a762ad4bb5 100644 --- a/activerecord/test/models/club.rb +++ b/activerecord/test/models/club.rb @@ -6,6 +6,8 @@ class Club < ActiveRecord::Base has_one :sponsored_member, :through => :sponsor, :source => :sponsorable, :source_type => "Member" belongs_to :category + has_many :favourites, -> { where(memberships: { favourite: true }) }, through: :memberships, source: :member + private def private_method |