diff options
author | Abhay Nikam <nikam.abhay1@gmail.com> | 2019-02-18 21:42:09 +0530 |
---|---|---|
committer | Abhay Nikam <nikam.abhay1@gmail.com> | 2019-02-19 16:57:49 +0530 |
commit | 5c8d4c3466cbfa850a89f718ec358ed3a352c34e (patch) | |
tree | e5629e9d01480426fd8ee1599fbd4efc8564b28c /activerecord/test | |
parent | 84bd9adafde36d0192849649b86ffcd4e59e5e11 (diff) | |
download | rails-5c8d4c3466cbfa850a89f718ec358ed3a352c34e.tar.gz rails-5c8d4c3466cbfa850a89f718ec358ed3a352c34e.tar.bz2 rails-5c8d4c3466cbfa850a89f718ec358ed3a352c34e.zip |
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 |