diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-06-05 03:47:02 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-06-05 03:47:02 +0000 |
commit | 673daeabca18a3d96171c86bcdd03fd3d0091a73 (patch) | |
tree | 4c1c1a0e8a100716192be6a74679baff743651a5 /activerecord/lib | |
parent | d6785e967433470cfe5eba72a72f6f01682282c0 (diff) | |
download | rails-673daeabca18a3d96171c86bcdd03fd3d0091a73.tar.gz rails-673daeabca18a3d96171c86bcdd03fd3d0091a73.tar.bz2 rails-673daeabca18a3d96171c86bcdd03fd3d0091a73.zip |
Fixtures: people(:technomancy, :josh) returns both fixtures. Closes #7880.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6940 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 47a77e4249..0a8b75e014 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -501,20 +501,26 @@ module Test #:nodoc: end end - def self.setup_fixture_accessors(table_names=nil) + def self.setup_fixture_accessors(table_names = nil) (table_names || fixture_table_names).each do |table_name| - table_name = table_name.to_s.tr('.','_') + table_name = table_name.to_s.tr('.', '_') + + define_method(table_name) do |*fixtures| + force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload - define_method(table_name) do |fixture, *optionals| - force_reload = optionals.shift @fixture_cache[table_name] ||= Hash.new - @fixture_cache[table_name][fixture] = nil if force_reload - if @loaded_fixtures[table_name][fixture.to_s] - @fixture_cache[table_name][fixture] ||= @loaded_fixtures[table_name][fixture.to_s].find - else - raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'" + instances = fixtures.map do |fixture| + @fixture_cache[table_name].delete(fixture) if force_reload + + if @loaded_fixtures[table_name][fixture.to_s] + @fixture_cache[table_name][fixture] ||= @loaded_fixtures[table_name][fixture.to_s].find + else + raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'" + end end + + instances.size == 1 ? instances.first : instances end end end |