|
2 | 2 | require "models/author"
|
3 | 3 | require "models/binary"
|
4 | 4 | require "models/cake_designer"
|
| 5 | +require "models/category" |
5 | 6 | require "models/chef"
|
6 | 7 | require "models/comment"
|
7 | 8 | require "models/edge"
|
|
14 | 15 |
|
15 | 16 | module ActiveRecord
|
16 | 17 | class WhereTest < ActiveRecord::TestCase
|
17 |
| - fixtures :posts, :edges, :authors, :binaries, :essays |
| 18 | + fixtures :posts, :edges, :authors, :categories, :binaries, :essays |
18 | 19 |
|
19 | 20 | def test_where_copies_bind_params
|
20 | 21 | author = authors(:david)
|
@@ -207,35 +208,70 @@ def test_where_with_blank_conditions
|
207 | 208 | end
|
208 | 209 |
|
209 | 210 | def test_where_on_association_with_custom_primary_key
|
| 211 | + category = categories(:general) |
| 212 | + essay = Essay.where(category: category).first |
| 213 | + |
| 214 | + assert_equal essays(:david_modest_proposal), essay |
| 215 | + end |
| 216 | + |
| 217 | + def test_where_on_association_with_custom_primary_key_with_relation |
| 218 | + category = categories(:general) |
| 219 | + essay = Essay.where(category: Category.where(id: category.id)).first |
| 220 | + |
| 221 | + assert_equal essays(:david_modest_proposal), essay |
| 222 | + end |
| 223 | + |
| 224 | + def test_where_on_association_with_relation_performs_subselect_not_two_queries |
| 225 | + category = categories(:general) |
| 226 | + |
| 227 | + assert_queries(1) do |
| 228 | + Essay.where(category: Category.where(id: category.id)).to_a |
| 229 | + end |
| 230 | + end |
| 231 | + |
| 232 | + def test_where_on_association_with_custom_primary_key_with_array_of_base |
| 233 | + category = categories(:general) |
| 234 | + essay = Essay.where(category: [category]).first |
| 235 | + |
| 236 | + assert_equal essays(:david_modest_proposal), essay |
| 237 | + end |
| 238 | + |
| 239 | + def test_where_on_association_with_custom_primary_key_with_array_of_ids |
| 240 | + essay = Essay.where(category: ["General"]).first |
| 241 | + |
| 242 | + assert_equal essays(:david_modest_proposal), essay |
| 243 | + end |
| 244 | + |
| 245 | + def test_where_on_polymorphic_association_with_custom_primary_key |
210 | 246 | author = authors(:david)
|
211 | 247 | essay = Essay.where(writer: author).first
|
212 | 248 |
|
213 | 249 | assert_equal essays(:david_modest_proposal), essay
|
214 | 250 | end
|
215 | 251 |
|
216 |
| - def test_where_on_association_with_custom_primary_key_with_relation |
| 252 | + def test_where_on_polymorphic_association_with_custom_primary_key_with_relation |
217 | 253 | author = authors(:david)
|
218 | 254 | essay = Essay.where(writer: Author.where(id: author.id)).first
|
219 | 255 |
|
220 | 256 | assert_equal essays(:david_modest_proposal), essay
|
221 | 257 | end
|
222 | 258 |
|
223 |
| - def test_where_on_association_with_relation_performs_subselect_not_two_queries |
| 259 | + def test_where_on_polymorphic_association_with_relation_performs_subselect_not_two_queries |
224 | 260 | author = authors(:david)
|
225 | 261 |
|
226 | 262 | assert_queries(1) do
|
227 | 263 | Essay.where(writer: Author.where(id: author.id)).to_a
|
228 | 264 | end
|
229 | 265 | end
|
230 | 266 |
|
231 |
| - def test_where_on_association_with_custom_primary_key_with_array_of_base |
| 267 | + def test_where_on_polymorphic_association_with_custom_primary_key_with_array_of_base |
232 | 268 | author = authors(:david)
|
233 | 269 | essay = Essay.where(writer: [author]).first
|
234 | 270 |
|
235 | 271 | assert_equal essays(:david_modest_proposal), essay
|
236 | 272 | end
|
237 | 273 |
|
238 |
| - def test_where_on_association_with_custom_primary_key_with_array_of_ids |
| 274 | + def test_where_on_polymorphic_association_with_custom_primary_key_with_array_of_ids |
239 | 275 | essay = Essay.where(writer: ["David"]).first
|
240 | 276 |
|
241 | 277 | assert_equal essays(:david_modest_proposal), essay
|
|
0 commit comments