Permalink
Browse files

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.
  • Loading branch information...
1 parent 748f0b3 commit 428dd54ff2c7d86990d6553596f4c72f70a2a4ac @alexeymuranov committed Dec 29, 2011
Showing with 5 additions and 6 deletions.
  1. +5 −6 activerecord/lib/active_record/fixtures.rb
@@ -536,8 +536,7 @@ def self.identify(label)
def initialize(connection, fixture_name, class_name, fixture_path)
@fixtures = ActiveSupport::OrderedHash.new
- @name = fixture_name.tr('/', '_') # preserve fixture base name
- # TODO: see how it is used and if the substitution can be avoided
+ @name = fixture_name
@fixture_path = fixture_path
@class_name = class_name # TODO: this variable is not used, should it be removed?
@@ -810,9 +809,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] ||= {}
@@ -825,13 +824,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

0 comments on commit 428dd54

Please sign in to comment.