Commit a3c2dd3
committed
Fix tests passing with false positives
The arguments to a Rails path helper should be either an object such as
a record that implements ActiveModel::Naming ActiveModel::Conversions,
or a keyword argument [[1]]; if an object `o` is passed as an argument
then `o.model_name.route_key` will be used to work out what parameter in
the path `o.to_param` should be used for, and if a keyword argument is
given then the name of that keyword will be used for the path parameter.
If an object is given as a keyword argument, the model name is not used
for the path parameter; only the keyword argument name is used.
These tests have a subtle bug, where the record objects were mistakenly
passed as keyword arguments to path helpers in the spec expectations.
The tests passed because the value of `#to_param` was `nil`, because the
records were not persisted (see the definition of
ActiveModel::Conversion#to_param [[2]]), and thus were ignored by the path
helper, but the correct path parameters were accessible from the
request. If the records had been persisted then a URL parameter named
after the keyword would have been appended as a query parameter; not the
desired behaviour.
This commit changes these tests so that they all use keyword arguments
for path helpers; they are more explicit and allow the tests to pass
for the right reason.
Note that there is one test failing after this change; it is failing
correctly now, previously the bug was causing it to pass incorrectly.
[1]: https://guides.rubyonrails.org/routing.html#creating-paths-and-urls-from-objects
[2]: https://api.rubyonrails.org/classes/ActiveModel/Conversion.html#method-i-to_param1 parent ff1705b commit a3c2dd3
1 file changed
Lines changed: 12 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | | - | |
| 279 | + | |
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
| 304 | + | |
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
| 345 | + | |
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
357 | | - | |
| 357 | + | |
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | | - | |
| 421 | + | |
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
| |||
548 | 548 | | |
549 | 549 | | |
550 | 550 | | |
551 | | - | |
| 551 | + | |
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
558 | | - | |
| 558 | + | |
559 | 559 | | |
560 | 560 | | |
561 | 561 | | |
| |||
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
590 | | - | |
| 590 | + | |
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
| |||
0 commit comments