@@ -24,29 +24,41 @@ def test_merge_in_clause
24
24
25
25
assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) )
26
26
assert_equal [ mary ] , david_and_mary . merge ( Author . rewhere ( id : mary ) )
27
- assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) , rewhere : true )
27
+ assert_deprecated do
28
+ assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) , rewhere : true )
29
+ end
28
30
29
31
assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) )
30
32
assert_equal [ bob ] , david_and_mary . merge ( Author . rewhere ( id : bob ) )
31
- assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) , rewhere : true )
33
+ assert_deprecated do
34
+ assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) , rewhere : true )
35
+ end
32
36
33
37
assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) )
34
- assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) , rewhere : true )
38
+ assert_deprecated do
39
+ assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) , rewhere : true )
40
+ end
35
41
36
42
assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob )
37
- assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob , rewhere : true )
43
+ assert_deprecated do
44
+ assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob , rewhere : true )
45
+ end
38
46
assert_equal [ mary ] , david_and_mary . and ( mary_and_bob )
39
47
assert_equal authors , david_and_mary . or ( mary_and_bob )
40
48
41
49
assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary )
42
- assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary , rewhere : true )
50
+ assert_deprecated do
51
+ assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary , rewhere : true )
52
+ end
43
53
assert_equal [ mary ] , david_and_mary . and ( mary_and_bob )
44
54
assert_equal authors , david_and_mary . or ( mary_and_bob )
45
55
46
56
david_and_bob = Author . where ( id : david ) . or ( Author . where ( name : "Bob" ) )
47
57
48
58
assert_equal [ david ] , david_and_mary . merge ( david_and_bob )
49
- assert_equal [ david ] , david_and_mary . merge ( david_and_bob , rewhere : true )
59
+ assert_deprecated do
60
+ assert_equal [ david ] , david_and_mary . merge ( david_and_bob , rewhere : true )
61
+ end
50
62
assert_equal [ david ] , david_and_mary . and ( david_and_bob )
51
63
assert_equal authors , david_and_mary . or ( david_and_bob )
52
64
end
@@ -62,29 +74,41 @@ def test_merge_between_clause
62
74
63
75
assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) )
64
76
assert_equal [ mary ] , david_and_mary . merge ( Author . rewhere ( id : mary ) )
65
- assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) , rewhere : true )
77
+ assert_deprecated do
78
+ assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) , rewhere : true )
79
+ end
66
80
67
81
assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) )
68
82
assert_equal [ bob ] , david_and_mary . merge ( Author . rewhere ( id : bob ) )
69
- assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) , rewhere : true )
83
+ assert_deprecated do
84
+ assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) , rewhere : true )
85
+ end
70
86
71
87
assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) )
72
- assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) , rewhere : true )
88
+ assert_deprecated do
89
+ assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) , rewhere : true )
90
+ end
73
91
74
92
assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob )
75
- assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob , rewhere : true )
93
+ assert_deprecated do
94
+ assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob , rewhere : true )
95
+ end
76
96
assert_equal [ mary ] , david_and_mary . and ( mary_and_bob )
77
97
assert_equal authors , david_and_mary . or ( mary_and_bob )
78
98
79
99
assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary )
80
- assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary , rewhere : true )
100
+ assert_deprecated do
101
+ assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary , rewhere : true )
102
+ end
81
103
assert_equal [ mary ] , david_and_mary . and ( mary_and_bob )
82
104
assert_equal authors , david_and_mary . or ( mary_and_bob )
83
105
84
106
david_and_bob = Author . where ( id : david ) . or ( Author . where ( name : "Bob" ) )
85
107
86
108
assert_equal [ david ] , david_and_mary . merge ( david_and_bob )
87
- assert_equal [ david ] , david_and_mary . merge ( david_and_bob , rewhere : true )
109
+ assert_deprecated do
110
+ assert_equal [ david ] , david_and_mary . merge ( david_and_bob , rewhere : true )
111
+ end
88
112
assert_equal [ david ] , david_and_mary . and ( david_and_bob )
89
113
assert_equal authors , david_and_mary . or ( david_and_bob )
90
114
end
@@ -100,30 +124,42 @@ def test_merge_or_clause
100
124
101
125
assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) )
102
126
assert_equal [ mary ] , david_and_mary . merge ( Author . rewhere ( id : mary ) )
103
- assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) , rewhere : true )
127
+ assert_deprecated do
128
+ assert_equal [ mary ] , david_and_mary . merge ( Author . where ( id : mary ) , rewhere : true )
129
+ end
104
130
105
131
assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) )
106
132
assert_equal [ bob ] , david_and_mary . merge ( Author . rewhere ( id : bob ) )
107
- assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) , rewhere : true )
133
+ assert_deprecated do
134
+ assert_equal [ bob ] , david_and_mary . merge ( Author . where ( id : bob ) , rewhere : true )
135
+ end
108
136
109
137
assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) )
110
- assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) , rewhere : true )
138
+ assert_deprecated do
139
+ assert_equal [ david , bob ] , mary_and_bob . merge ( Author . where ( id : [ david , bob ] ) , rewhere : true )
140
+ end
111
141
112
142
113
143
assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob )
114
- assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob , rewhere : true )
144
+ assert_deprecated do
145
+ assert_equal [ mary , bob ] , david_and_mary . merge ( mary_and_bob , rewhere : true )
146
+ end
115
147
assert_equal [ mary ] , david_and_mary . and ( mary_and_bob )
116
148
assert_equal authors , david_and_mary . or ( mary_and_bob )
117
149
118
150
assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary )
119
- assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary , rewhere : true )
151
+ assert_deprecated do
152
+ assert_equal [ david , mary ] , mary_and_bob . merge ( david_and_mary , rewhere : true )
153
+ end
120
154
assert_equal [ mary ] , david_and_mary . and ( mary_and_bob )
121
155
assert_equal authors , david_and_mary . or ( mary_and_bob )
122
156
123
157
david_and_bob = Author . where ( id : david ) . or ( Author . where ( name : "Bob" ) )
124
158
125
159
assert_equal [ david ] , david_and_mary . merge ( david_and_bob )
126
- assert_equal [ david ] , david_and_mary . merge ( david_and_bob , rewhere : true )
160
+ assert_deprecated do
161
+ assert_equal [ david ] , david_and_mary . merge ( david_and_bob , rewhere : true )
162
+ end
127
163
assert_equal [ david ] , david_and_mary . and ( david_and_bob )
128
164
assert_equal authors , david_and_mary . or ( david_and_bob )
129
165
end
@@ -136,10 +172,14 @@ def test_merge_not_in_clause
136
172
assert_equal [ david ] , non_mary_and_bob
137
173
138
174
assert_equal [ david ] , Author . where ( id : david ) . merge ( non_mary_and_bob )
139
- assert_equal [ david ] , Author . where ( id : david ) . merge ( non_mary_and_bob , rewhere : true )
175
+ assert_deprecated do
176
+ assert_equal [ david ] , Author . where ( id : david ) . merge ( non_mary_and_bob , rewhere : true )
177
+ end
140
178
141
179
assert_equal [ david ] , Author . where ( id : mary ) . merge ( non_mary_and_bob )
142
- assert_equal [ david ] , Author . where ( id : mary ) . merge ( non_mary_and_bob , rewhere : true )
180
+ assert_deprecated do
181
+ assert_equal [ david ] , Author . where ( id : mary ) . merge ( non_mary_and_bob , rewhere : true )
182
+ end
143
183
end
144
184
145
185
def test_merge_not_range_clause
@@ -150,10 +190,14 @@ def test_merge_not_range_clause
150
190
assert_equal [ david , mary ] , less_than_bob
151
191
152
192
assert_equal [ david , mary ] , Author . where ( id : david ) . merge ( less_than_bob )
153
- assert_equal [ david , mary ] , Author . where ( id : david ) . merge ( less_than_bob , rewhere : true )
193
+ assert_deprecated do
194
+ assert_equal [ david , mary ] , Author . where ( id : david ) . merge ( less_than_bob , rewhere : true )
195
+ end
154
196
155
197
assert_equal [ david , mary ] , Author . where ( id : mary ) . merge ( less_than_bob )
156
- assert_equal [ david , mary ] , Author . where ( id : mary ) . merge ( less_than_bob , rewhere : true )
198
+ assert_deprecated do
199
+ assert_equal [ david , mary ] , Author . where ( id : mary ) . merge ( less_than_bob , rewhere : true )
200
+ end
157
201
end
158
202
159
203
def test_merge_doesnt_duplicate_same_clauses
@@ -174,15 +218,19 @@ def test_merge_doesnt_duplicate_same_clauses
174
218
end
175
219
176
220
assert_sql ( /WHERE \( #{ Regexp . escape ( author_id ) } IN \( '1'\) \) \z / ) do
177
- assert_equal [ david ] , only_david . merge ( only_david , rewhere : true )
221
+ assert_deprecated do
222
+ assert_equal [ david ] , only_david . merge ( only_david , rewhere : true )
223
+ end
178
224
end
179
225
else
180
226
assert_sql ( /WHERE \( #{ Regexp . escape ( author_id ) } IN \( 1\) \) \z / ) do
181
227
assert_equal [ david ] , only_david . merge ( only_david )
182
228
end
183
229
184
230
assert_sql ( /WHERE \( #{ Regexp . escape ( author_id ) } IN \( 1\) \) \z / ) do
185
- assert_equal [ david ] , only_david . merge ( only_david , rewhere : true )
231
+ assert_deprecated do
232
+ assert_equal [ david ] , only_david . merge ( only_david , rewhere : true )
233
+ end
186
234
end
187
235
end
188
236
end
@@ -207,7 +255,9 @@ def test_relation_merging_with_arel_equalities_keeps_last_equality
207
255
devs = Developer . where ( salary_attr . eq ( 80000 ) ) . merge ( Developer . where ( salary_attr . eq ( 9000 ) ) )
208
256
assert_equal [ developers ( :poor_jamis ) ] , devs . to_a
209
257
210
- devs = Developer . where ( salary_attr . eq ( 80000 ) ) . merge ( Developer . where ( salary_attr . eq ( 9000 ) ) , rewhere : true )
258
+ assert_deprecated do
259
+ devs = Developer . where ( salary_attr . eq ( 80000 ) ) . merge ( Developer . where ( salary_attr . eq ( 9000 ) ) , rewhere : true )
260
+ end
211
261
assert_equal [ developers ( :poor_jamis ) ] , devs . to_a
212
262
213
263
devs = Developer . where ( salary_attr . eq ( 80000 ) ) . rewhere ( salary_attr . eq ( 9000 ) )
@@ -221,7 +271,9 @@ def test_relation_merging_with_arel_equalities_keeps_last_equality_with_non_attr
221
271
devs = Developer . where ( abs_salary . eq ( 80000 ) ) . merge ( Developer . where ( abs_salary . eq ( 9000 ) ) )
222
272
assert_equal [ developers ( :poor_jamis ) ] , devs . to_a
223
273
224
- devs = Developer . where ( abs_salary . eq ( 80000 ) ) . merge ( Developer . where ( abs_salary . eq ( 9000 ) ) , rewhere : true )
274
+ assert_deprecated do
275
+ devs = Developer . where ( abs_salary . eq ( 80000 ) ) . merge ( Developer . where ( abs_salary . eq ( 9000 ) ) , rewhere : true )
276
+ end
225
277
assert_equal [ developers ( :poor_jamis ) ] , devs . to_a
226
278
227
279
devs = Developer . where ( abs_salary . eq ( 80000 ) ) . rewhere ( abs_salary . eq ( 9000 ) )
@@ -347,6 +399,24 @@ def test_merging_duplicated_annotations
347
399
Post . annotate ( "bar" ) . merge ( Post . annotate ( "foo" ) ) . merge ( posts ) . to_a
348
400
end
349
401
end
402
+
403
+ def test_rewhere_true_is_deprecated
404
+ message = <<-MSG . squish
405
+ Specifying `Relation#merge(rewhere: true)` is deprecated
406
+ MSG
407
+ assert_deprecated ( message ) do
408
+ Author . where ( id : 1 ) . merge ( Author . where ( id : 2 ) , rewhere : true )
409
+ end
410
+ end
411
+
412
+ def test_rewhere_false_is_deprecated
413
+ message = <<-MSG . squish
414
+ Relation#merge(rewhere: false)` is deprecated without replacement
415
+ MSG
416
+ assert_deprecated ( message ) do
417
+ Author . where ( id : 1 ) . merge ( Author . where ( id : 2 ) , rewhere : false )
418
+ end
419
+ end
350
420
end
351
421
352
422
class MergingDifferentRelationsTest < ActiveRecord ::TestCase
0 commit comments