提交 6468ff41 编写于 作者: A Alexey Muranov 提交者: Alexey Muranov

Test fixtures with custom model and table names

Test using fixtures with random names and model names, that is not following naming conventions but using set_fixture_class instead.

It is expected that the table name be defined in the model, but this is not explicitly tested here.  This will need to be fixed.
上级 e43b2b35
require 'cases/helper'
require 'models/admin'
require 'models/admin/account'
require 'models/admin/randomly_named_c1'
require 'models/admin/user'
require 'models/binary'
require 'models/book'
......@@ -14,6 +15,7 @@
require 'models/parrot'
require 'models/pirate'
require 'models/post'
require 'models/randomly_named_c1'
require 'models/reply'
require 'models/ship'
require 'models/task'
......@@ -745,3 +747,29 @@ def test_does_not_logs_message_for_successful_dependency_load
ActiveRecord::TestCase.try_to_load_dependency(:works_out_fine)
end
end
class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
ActiveRecord::Fixtures.reset_cache
set_fixture_class :randomly_named_a9 =>
ClassNameThatDoesNotFollowCONVENTIONS,
:'admin/randomly_named_a9' =>
Admin::ClassNameThatDoesNotFollowCONVENTIONS,
'admin/randomly_named_b0' =>
Admin::ClassNameThatDoesNotFollowCONVENTIONS
fixtures :randomly_named_a9, 'admin/randomly_named_a9',
:'admin/randomly_named_b0'
def test_named_accessor_for_randomly_named_fixture_and_class
assert_kind_of ClassNameThatDoesNotFollowCONVENTIONS,
randomly_named_a9(:first_instance)
end
def test_named_accessor_for_randomly_named_namespaced_fixture_and_class
assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS,
admin_randomly_named_a9(:first_instance)
assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS,
admin_randomly_named_b0(:second_instance)
end
end
first_instance:
some_attribute: AAA
another_attribute: 000
second_instance:
some_attribute: BBB
another_attribute: 999
first_instance:
some_attribute: AAA
another_attribute: 000
second_instance:
some_attribute: BBB
another_attribute: 999
first_instance:
some_attribute: AAA
another_attribute: 000
second_instance:
some_attribute: BBB
another_attribute: 999
class Admin::ClassNameThatDoesNotFollowCONVENTIONS < ActiveRecord::Base
self.table_name = :randomly_named_table
end
class ClassNameThatDoesNotFollowCONVENTIONS < ActiveRecord::Base
self.table_name = :randomly_named_table
end
......@@ -505,6 +505,11 @@ def create_table(*args, &block)
t.string :type
end
create_table :randomly_named_table, :force => true do |t|
t.string :some_attribute
t.integer :another_attribute
end
create_table :ratings, :force => true do |t|
t.integer :comment_id
t.integer :value
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册