diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-19 21:47:22 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-19 21:52:49 +0900 |
commit | 64ef5e2f9e854a7f988227d629a699f11a998b17 (patch) | |
tree | ef239f8f8df88a6d200c94385f17fdb95681dac9 /activerecord/test | |
parent | 30016df82f892f621c4937f3aec397f8d4cb30f2 (diff) | |
parent | 5c8d4c3466cbfa850a89f718ec358ed3a352c34e (diff) | |
download | rails-64ef5e2f9e854a7f988227d629a699f11a998b17.tar.gz rails-64ef5e2f9e854a7f988227d629a699f11a998b17.tar.bz2 rails-64ef5e2f9e854a7f988227d629a699f11a998b17.zip |
Merge pull request #35316 from abhaynikam/35304-add-delete_by_and_destroy_by
Introduce delete_by and destroy_by methods to ActiveRecord::Relation
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index c82f93a3f0..adc50a694e 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1686,6 +1686,24 @@ class RelationTest < ActiveRecord::TestCase assert_predicate topics, :loaded? end + def test_delete_by + david = authors(:david) + + assert_difference("Post.count", -3) { david.posts.delete_by(body: "hello") } + + deleted = Author.delete_by(id: david.id) + assert_equal 1, deleted + end + + def test_destroy_by + david = authors(:david) + + assert_difference("Post.count", -3) { david.posts.destroy_by(body: "hello") } + + destroyed = Author.destroy_by(id: david.id) + assert_equal [david], destroyed + end + test "find_by with hash conditions returns the first matching record" do assert_equal posts(:eager_other), Post.order(:id).find_by(author_id: 2) end |