2009-10-08 21:12:28 -04:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
class GeneratorsTest < Test::Unit::TestCase
|
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
boot_rails
|
|
|
|
end
|
|
|
|
|
2009-11-30 18:58:38 -05:00
|
|
|
def app_const
|
|
|
|
@app_const ||= Class.new(Rails::Application)
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_config
|
2009-12-31 15:28:48 -05:00
|
|
|
require "rails/all"
|
2009-12-22 20:03:23 -05:00
|
|
|
require "rails/generators"
|
2009-11-30 18:58:38 -05:00
|
|
|
yield app_const.config
|
|
|
|
end
|
|
|
|
|
2010-01-27 20:39:11 -05:00
|
|
|
def with_bare_config
|
|
|
|
require "rails"
|
|
|
|
require "rails/generators"
|
|
|
|
yield app_const.config
|
|
|
|
end
|
|
|
|
|
2009-10-08 21:12:28 -04:00
|
|
|
test "generators default values" do
|
2010-01-27 20:39:11 -05:00
|
|
|
with_bare_config do |c|
|
2009-10-08 21:12:28 -04:00
|
|
|
assert_equal(true, c.generators.colorize_logging)
|
|
|
|
assert_equal({}, c.generators.aliases)
|
|
|
|
assert_equal({}, c.generators.options)
|
2010-02-01 04:48:59 -05:00
|
|
|
assert_equal({}, c.generators.fallbacks)
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "generators set rails options" do
|
2010-01-28 13:45:25 -05:00
|
|
|
with_bare_config do |c|
|
2009-10-08 21:12:28 -04:00
|
|
|
c.generators.orm = :datamapper
|
|
|
|
c.generators.test_framework = :rspec
|
2009-11-03 21:14:44 -05:00
|
|
|
c.generators.helper = false
|
|
|
|
expected = { :rails => { :orm => :datamapper, :test_framework => :rspec, :helper => false } }
|
2009-10-08 21:12:28 -04:00
|
|
|
assert_equal(expected, c.generators.options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "generators set rails aliases" do
|
2009-11-30 18:58:38 -05:00
|
|
|
with_config do |c|
|
2009-10-08 21:12:28 -04:00
|
|
|
c.generators.aliases = { :rails => { :test_framework => "-w" } }
|
|
|
|
expected = { :rails => { :test_framework => "-w" } }
|
|
|
|
assert_equal expected, c.generators.aliases
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-06 11:32:06 -05:00
|
|
|
test "generators aliases, options, templates and fallbacks on initialization" do
|
2009-12-22 20:03:23 -05:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.generators.rails :aliases => { :test_framework => "-w" }
|
|
|
|
config.generators.orm :datamapper
|
|
|
|
config.generators.test_framework :rspec
|
2010-02-01 04:48:59 -05:00
|
|
|
config.generators.fallbacks[:shoulda] = :test_unit
|
2010-02-06 11:32:06 -05:00
|
|
|
config.generators.templates << "some/where"
|
2009-12-22 20:03:23 -05:00
|
|
|
RUBY
|
|
|
|
|
2009-10-15 17:50:02 -04:00
|
|
|
# Initialize the application
|
2010-01-12 11:48:09 -05:00
|
|
|
require "#{app_path}/config/environment"
|
2009-12-22 20:03:23 -05:00
|
|
|
require "rails/generators"
|
2010-06-09 02:37:24 -04:00
|
|
|
Rails::Generators.configure!
|
2009-10-08 21:12:28 -04:00
|
|
|
|
|
|
|
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
|
|
|
|
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
|
2010-02-06 11:32:06 -05:00
|
|
|
assert_equal Hash[:shoulda => :test_unit], Rails::Generators.fallbacks
|
2010-10-06 11:18:59 -04:00
|
|
|
assert_equal ["some/where"], Rails::Generators.templates_path
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "generators no color on initialization" do
|
2009-12-22 20:03:23 -05:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.generators.colorize_logging = false
|
|
|
|
RUBY
|
|
|
|
|
2009-10-15 17:50:02 -04:00
|
|
|
# Initialize the application
|
2009-12-22 20:03:23 -05:00
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
require "rails/generators"
|
2009-11-03 21:58:40 -05:00
|
|
|
Rails::Generators.configure!
|
2009-10-08 21:12:28 -04:00
|
|
|
|
|
|
|
assert_equal Thor::Base.shell, Thor::Shell::Basic
|
|
|
|
end
|
|
|
|
|
|
|
|
test "generators with hashes for options and aliases" do
|
2010-01-27 20:39:11 -05:00
|
|
|
with_bare_config do |c|
|
2009-10-08 21:12:28 -04:00
|
|
|
c.generators do |g|
|
|
|
|
g.orm :datamapper, :migration => false
|
|
|
|
g.plugin :aliases => { :generator => "-g" },
|
|
|
|
:generator => true
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = {
|
|
|
|
:rails => { :orm => :datamapper },
|
|
|
|
:plugin => { :generator => true },
|
|
|
|
:datamapper => { :migration => false }
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal expected, c.generators.options
|
|
|
|
assert_equal({ :plugin => { :generator => "-g" } }, c.generators.aliases)
|
|
|
|
end
|
|
|
|
end
|
2010-07-21 10:37:03 -04:00
|
|
|
|
|
|
|
test "generators with string and hash for options should generate symbol keys" do
|
|
|
|
with_bare_config do |c|
|
|
|
|
c.generators do |g|
|
|
|
|
g.orm 'datamapper', :migration => false
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = {
|
|
|
|
:rails => { :orm => :datamapper },
|
|
|
|
:datamapper => { :migration => false }
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal expected, c.generators.options
|
|
|
|
end
|
|
|
|
end
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
2009-11-03 21:14:44 -05:00
|
|
|
end
|