@@ -1120,6 +1120,40 @@ def test_update_all_doesnt_ignore_order_coerced
11201120 _ ( david . reload . name ) . must_equal "David"
11211121 _ ( mary . reload . name ) . must_equal "Test"
11221122 end
1123+
1124+ # SELECT columns must be in the GROUP clause.
1125+ coerce_tests! :test_update_all_with_group_by
1126+ def test_update_all_with_group_by_coerced
1127+ minimum_comments_count = 2
1128+
1129+ Post . most_commented ( minimum_comments_count ) . update_all ( title : "ig" )
1130+ posts = Post . select ( :id , :title ) . group ( :title ) . most_commented ( minimum_comments_count ) . all . to_a
1131+
1132+ assert_operator posts . length , :> , 0
1133+ assert posts . all? { |post | post . comments . length >= minimum_comments_count }
1134+ assert posts . all? { |post | "ig" == post . title }
1135+
1136+ post = Post . select ( :id , :title ) . group ( :title ) . joins ( :comments ) . group ( "posts.id" ) . having ( "count(comments.id) < #{ minimum_comments_count } " ) . first
1137+ assert_not_equal "ig" , post . title
1138+ end
1139+ end
1140+
1141+ class DeleteAllTest < ActiveRecord ::TestCase
1142+ # SELECT columns must be in the GROUP clause.
1143+ coerce_tests! :test_delete_all_with_group_by_and_having
1144+ def test_delete_all_with_group_by_and_having_coerced
1145+ minimum_comments_count = 2
1146+ posts_to_be_deleted = Post . select ( :id ) . most_commented ( minimum_comments_count ) . all . to_a
1147+ assert_operator posts_to_be_deleted . length , :> , 0
1148+
1149+ assert_difference ( "Post.count" , -posts_to_be_deleted . length ) do
1150+ Post . most_commented ( minimum_comments_count ) . delete_all
1151+ end
1152+
1153+ posts_to_be_deleted . each do |deleted_post |
1154+ assert_raise ( ActiveRecord ::RecordNotFound ) { deleted_post . reload }
1155+ end
1156+ end
11231157end
11241158
11251159require "models/topic"
0 commit comments