mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
fixture methods can be overridden and super() is useful
This commit is contained in:
parent
8c4c07e4cb
commit
8276a24020
2 changed files with 32 additions and 14 deletions
|
@ -874,10 +874,11 @@ module ActiveRecord
|
|||
|
||||
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('./', '_')
|
||||
|
||||
redefine_method(fixture_name) do |*fixtures|
|
||||
define_method(fixture_name) do |*fixtures|
|
||||
force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload
|
||||
|
||||
@fixture_cache[fixture_name] ||= {}
|
||||
|
@ -897,6 +898,8 @@ module ActiveRecord
|
|||
private fixture_name
|
||||
end
|
||||
end
|
||||
include methods
|
||||
end
|
||||
|
||||
def uses_transaction(*methods)
|
||||
@uses_transaction = [] unless defined?(@uses_transaction)
|
||||
|
|
|
@ -378,6 +378,21 @@ class ForeignKeyFixturesTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class OverRideFixtureMethodTest < ActiveRecord::TestCase
|
||||
fixtures :topics
|
||||
|
||||
def topics(name)
|
||||
topic = super
|
||||
topic.title = 'omg'
|
||||
topic
|
||||
end
|
||||
|
||||
def test_fixture_methods_can_be_overridden
|
||||
x = topics :first
|
||||
assert_equal 'omg', x.title
|
||||
end
|
||||
end
|
||||
|
||||
class CheckSetTableNameFixturesTest < ActiveRecord::TestCase
|
||||
set_fixture_class :funny_jokes => 'Joke'
|
||||
fixtures :funny_jokes
|
||||
|
|
Loading…
Reference in a new issue