diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-15 15:52:27 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-15 15:52:27 -0800 |
commit | 8276a240207ab6906fa2a6d4635f093906fa3c10 (patch) | |
tree | b1916c9e8651f670985815698a6bc9d27b7aa944 /activerecord/lib | |
parent | 8c4c07e4cb3ea00767aa584afac9f7730fe2f7b1 (diff) | |
download | rails-8276a240207ab6906fa2a6d4635f093906fa3c10.tar.gz rails-8276a240207ab6906fa2a6d4635f093906fa3c10.tar.bz2 rails-8276a240207ab6906fa2a6d4635f093906fa3c10.zip |
fixture methods can be overridden and super() is useful
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index a5931b2232..b9e591e633 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -874,28 +874,31 @@ module ActiveRecord def setup_fixture_accessors(fixture_names = nil) fixture_names = Array.wrap(fixture_names || fixture_table_names) - fixture_names.each do |fixture_name| - fixture_name = fixture_name.to_s.tr('./', '_') + methods = Module.new do + fixture_names.each do |fixture_name| + fixture_name = fixture_name.to_s.tr('./', '_') - redefine_method(fixture_name) do |*fixtures| - force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload + define_method(fixture_name) do |*fixtures| + force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload - @fixture_cache[fixture_name] ||= {} + @fixture_cache[fixture_name] ||= {} - instances = fixtures.map do |fixture| - @fixture_cache[fixture_name].delete(fixture) if force_reload + instances = fixtures.map do |fixture| + @fixture_cache[fixture_name].delete(fixture) if force_reload - if @loaded_fixtures[fixture_name][fixture.to_s] - @fixture_cache[fixture_name][fixture] ||= @loaded_fixtures[fixture_name][fixture.to_s].find - else - raise StandardError, "No fixture with name '#{fixture}' found for table '#{fixture_name}'" + if @loaded_fixtures[fixture_name][fixture.to_s] + @fixture_cache[fixture_name][fixture] ||= @loaded_fixtures[fixture_name][fixture.to_s].find + else + raise StandardError, "No fixture with name '#{fixture}' found for table '#{fixture_name}'" + end end - end - instances.size == 1 ? instances.first : instances + instances.size == 1 ? instances.first : instances + end + private fixture_name end - private fixture_name end + include methods end def uses_transaction(*methods) |