mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix lookup of fixtures with non-string label
- Fixtures with non-string labels such as integers should be accessed using integer label as key. For eg. pirates(1) or pirates(42). - But this results in NotFound error because the label is converted into string before looking up into the fixtures hash. - After this commit, the label is converted into string only if its a symbol. - This issue was fount out while adding a test case for https://github.com/rails/rails/commit/7b910917.
This commit is contained in:
parent
de4f40826e
commit
8da936a5d3
4 changed files with 13 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
* Fix accessing of fixtures having non-string labels like Fixnum by converting
|
||||
the label into string only if its a symbol.
|
||||
|
||||
*Prathamesh Sonpatki*
|
||||
|
||||
* Remove deprecated support to preload instance-dependent associations.
|
||||
|
||||
*Yves Senn*
|
||||
|
|
|
@ -882,7 +882,7 @@ module ActiveRecord
|
|||
@fixture_cache[fs_name] ||= {}
|
||||
|
||||
instances = fixture_names.map do |f_name|
|
||||
f_name = f_name.to_s
|
||||
f_name = f_name.to_s if f_name.is_a?(Symbol)
|
||||
@fixture_cache[fs_name].delete(f_name) if force_reload
|
||||
|
||||
if @loaded_fixtures[fs_name][f_name]
|
||||
|
|
|
@ -792,6 +792,10 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|||
assert_equal("X marks the spot!", pirates(:mark).catchphrase)
|
||||
end
|
||||
|
||||
def test_supports_label_interpolation_for_fixnum_label
|
||||
assert_equal("#1 pirate!", pirates(1).catchphrase)
|
||||
end
|
||||
|
||||
def test_supports_polymorphic_belongs_to
|
||||
assert_equal(pirates(:redbeard), treasures(:sapphire).looter)
|
||||
assert_equal(parrots(:louis), treasures(:ruby).looter)
|
||||
|
|
3
activerecord/test/fixtures/pirates.yml
vendored
3
activerecord/test/fixtures/pirates.yml
vendored
|
@ -10,3 +10,6 @@ redbeard:
|
|||
|
||||
mark:
|
||||
catchphrase: "X $LABELs the spot!"
|
||||
|
||||
1:
|
||||
catchphrase: "#$LABEL pirate!"
|
||||
|
|
Loading…
Reference in a new issue