diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-14 20:29:30 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-14 20:29:30 -0300 |
commit | ec6bb3320991df57c00a30c61a03cb5b44942404 (patch) | |
tree | 233b1231971a823734981e4416d2c2597e43431e /activerecord/test | |
parent | f2bff250a017b6da76b7587a164643db31ffbf9b (diff) | |
parent | 1d316ac1fd68962782762b02694a1bf9fd4ef44e (diff) | |
download | rails-ec6bb3320991df57c00a30c61a03cb5b44942404.tar.gz rails-ec6bb3320991df57c00a30c61a03cb5b44942404.tar.bz2 rails-ec6bb3320991df57c00a30c61a03cb5b44942404.zip |
Merge pull request #15078 from nbudin/fix_merger_filter_binds_comparison_master
Make filter_binds filter out symbols that are equal to strings
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relation/merging_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/comment.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 9 |
3 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation/merging_test.rb b/activerecord/test/cases/relation/merging_test.rb index 48f45d45b1..2b5c2fd5a4 100644 --- a/activerecord/test/cases/relation/merging_test.rb +++ b/activerecord/test/cases/relation/merging_test.rb @@ -108,6 +108,11 @@ class RelationMergingTest < ActiveRecord::TestCase merged = left.merge(right) assert_equal post, merged.first end + + def test_merging_compares_symbols_and_strings_as_equal + post = PostThatLoadsCommentsInAnAfterSaveHook.create!(title: "First Post", body: "Blah blah blah.") + assert_equal "First comment!", post.comments.where(body: "First comment!").first_or_create.body + end end class MergingDifferentRelationsTest < ActiveRecord::TestCase diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb index f82df417ce..bf0162d09b 100644 --- a/activerecord/test/models/comment.rb +++ b/activerecord/test/models/comment.rb @@ -40,3 +40,11 @@ end class VerySpecialComment < Comment end + +class CommentThatAutomaticallyAltersPostBody < Comment + belongs_to :post, class_name: "PostThatLoadsCommentsInAnAfterSaveHook", foreign_key: :post_id + + after_save do |comment| + comment.post.update_attributes(body: "Automatically altered") + end +end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index b1e56c14d1..5f01ab0a82 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -208,3 +208,12 @@ class SpecialPostWithDefaultScope < ActiveRecord::Base self.table_name = 'posts' default_scope { where(:id => [1, 5,6]) } end + +class PostThatLoadsCommentsInAnAfterSaveHook < ActiveRecord::Base + self.table_name = 'posts' + has_many :comments, class_name: "CommentThatAutomaticallyAltersPostBody", foreign_key: :post_id + + after_save do |post| + post.comments.load + end +end |