@@ -22,6 +22,37 @@ def test_result_set_does_not_include_collection_of_excluded_records
22
22
assert_not_includes relation , posts ( :thinking )
23
23
end
24
24
25
+ def test_result_set_does_not_include_collection_of_excluded_records_from_a_query
26
+ query = Post . where ( id : @post )
27
+
28
+ assert_sql ( /SELECT #{ Regexp . escape Post . connection . quote_table_name ( "posts.id" ) } FROM/ ) do
29
+ records = Post . excluding ( query ) . to_a
30
+
31
+ assert_not_includes records , @post
32
+ end
33
+ end
34
+
35
+ def test_result_set_does_not_include_collection_of_excluded_records_from_a_loaded_query
36
+ query = Post . where ( id : @post ) . load
37
+
38
+ records = assert_queries 1 do
39
+ Post . excluding ( query ) . to_a
40
+ end
41
+
42
+ assert_not_includes records , @post
43
+ end
44
+
45
+ def test_result_set_does_not_include_collection_of_excluded_records_and_queries
46
+ thinking = posts ( :thinking )
47
+
48
+ records = assert_queries 2 do
49
+ Post . excluding ( @post , Post . where ( id : thinking ) ) . to_a
50
+ end
51
+
52
+ assert_not_includes records , @post
53
+ assert_not_includes records , thinking
54
+ end
55
+
25
56
def test_result_set_through_association_does_not_include_single_excluded_record
26
57
comment_greetings , comment_more_greetings = comments ( :greetings , :more_greetings )
27
58
@@ -38,6 +69,30 @@ def test_result_set_through_association_does_not_include_collection_of_excluded_
38
69
assert_not_includes relation , comment_more_greetings
39
70
end
40
71
72
+ def test_result_set_through_association_does_not_include_collection_of_excluded_records_from_a_relation
73
+ relation = @post . comments
74
+
75
+ assert_sql ( /SELECT #{ Regexp . escape Comment . connection . quote_table_name ( "comments.id" ) } FROM/ ) do
76
+ records = Comment . excluding ( relation ) . to_a
77
+
78
+ assert_not_empty records
79
+ assert_not_empty @post . comments
80
+ assert_empty records . intersection ( @post . comments . to_a )
81
+ end
82
+ end
83
+
84
+ def test_result_set_through_association_does_not_include_collection_of_excluded_records_from_a_loaded_relation
85
+ relation = @post . comments . load
86
+
87
+ records = assert_queries 1 do
88
+ Comment . excluding ( relation ) . to_a
89
+ end
90
+
91
+ assert_not_empty records
92
+ assert_not_empty @post . comments
93
+ assert_empty records . intersection ( @post . comments . to_a )
94
+ end
95
+
41
96
def test_does_not_exclude_records_when_no_arguments
42
97
assert_no_excludes Post . excluding
43
98
assert_no_excludes Post . excluding ( nil )
0 commit comments