提交 b52d9d0f 编写于 作者: A Alexey Muranov

Fixes for TestFixtures::setup_fixture_accessors

Renamed "fixture_name" to "accessor_name" and made fixture names in the form "admin/users" be used as the key for the hashes @fixture_cache and @loaded_fixtures.

Previously the variable "fixture_name" here was getting a value of the form "admin_user", and this value was then used as the hash key.
上级 7162ea2a
......@@ -511,8 +511,7 @@ def self.identify(label)
def initialize(connection, fixture_name, class_name, fixture_path)
@connection = connection
@fixture_path = fixture_path
@name = fixture_name.tr('/', '_') # preserve fixture base name
# TODO: see how it is used and if the substitution can be avoided
@name = fixture_name
@class_name = class_name
@fixtures = ActiveSupport::OrderedHash.new
......@@ -790,9 +789,9 @@ def setup_fixture_accessors(fixture_names = nil)
fixture_names = Array.wrap(fixture_names || fixture_table_names)
methods = Module.new do
fixture_names.each do |fixture_name|
fixture_name = fixture_name.to_s.tr('./', '_') # TODO: use fixture_name variable for only one form of fixture names ("admin/users" for example)
accessor_name = fixture_name.tr('/', '_').to_sym
define_method(fixture_name) do |*fixtures|
define_method(accessor_name) do |*fixtures|
force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload
@fixture_cache[fixture_name] ||= {}
......@@ -805,13 +804,13 @@ def setup_fixture_accessors(fixture_names = nil)
@fixture_cache[fixture_name][fixture] ||= @loaded_fixtures[fixture_name][fixture.to_s].find
end
else
raise StandardError, "No fixture with name '#{fixture}' found for table '#{fixture_name}'"
raise StandardError, "No entry named '#{fixture}' found for fixture collection '#{fixture_name}'"
end
end
instances.size == 1 ? instances.first : instances
end
private fixture_name
private accessor_name
end
end
include methods
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册