2011-11-26 13:57:51 -05:00
|
|
|
require "generators/generators_test_helper"
|
|
|
|
require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
|
|
|
|
|
|
|
|
# Mock out two ORMs
|
|
|
|
module ORMWithGenerators
|
|
|
|
module Generators
|
|
|
|
class ActiveModel
|
|
|
|
def initialize(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ORMWithoutGenerators
|
|
|
|
# No generators
|
|
|
|
end
|
|
|
|
|
|
|
|
class OrmTest < Rails::Generators::TestCase
|
|
|
|
include GeneratorsTestHelper
|
|
|
|
tests Rails::Generators::ScaffoldControllerGenerator
|
|
|
|
|
|
|
|
def test_orm_class_returns_custom_generator_if_supported_custom_orm_set
|
2012-10-14 06:03:39 -04:00
|
|
|
g = generator ["Foo"], orm: "ORMWithGenerators"
|
2011-11-26 13:57:51 -05:00
|
|
|
assert_equal ORMWithGenerators::Generators::ActiveModel, g.send(:orm_class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_orm_class_returns_rails_generator_if_unsupported_custom_orm_set
|
2012-10-14 06:03:39 -04:00
|
|
|
g = generator ["Foo"], orm: "ORMWithoutGenerators"
|
2011-11-26 13:57:51 -05:00
|
|
|
assert_equal Rails::Generators::ActiveModel, g.send(:orm_class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_orm_instance_returns_orm_class_instance_with_name
|
|
|
|
g = generator ["Foo"]
|
|
|
|
orm_instance = g.send(:orm_instance)
|
|
|
|
assert g.send(:orm_class) === orm_instance
|
|
|
|
assert_equal "foo", orm_instance.name
|
|
|
|
end
|
|
|
|
end
|