rails--rails/railties/test/application/generators_test.rb

130 lines
3.9 KiB
Ruby
Raw Normal View History

require "isolation/abstract_unit"
module ApplicationTests
class GeneratorsTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
build_app
boot_rails
end
def teardown
teardown_app
end
2009-11-30 23:58:38 +00:00
def app_const
@app_const ||= Class.new(Rails::Application)
end
def with_config
require "rails/all"
require "rails/generators"
2009-11-30 23:58:38 +00:00
yield app_const.config
end
2010-01-28 01:39:11 +00:00
def with_bare_config
require "rails"
require "rails/generators"
yield app_const.config
end
test "allow running plugin new generator inside Rails app directory" do
2010-11-17 22:31:29 +00:00
FileUtils.cd(rails_root){ `ruby script/rails plugin new vendor/plugins/bukkits` }
assert File.exist?(File.join(rails_root, "vendor/plugins/bukkits/test/dummy/config/application.rb"))
Do not allow to use plugin_new generator directly, you should use Usage: rails new APP_PATH [options] Options: -G, [--skip-git] # Skip Git ignores and keeps -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: /Users/drogus/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -b, [--builder=BUILDER] # Path to an application builder (can be a filesystem path or URL) [--edge] # Setup the application with Gemfile pointing to Rails repository [--dev] # Setup the application with Gemfile pointing to your Rails checkout [--skip-gemfile] # Don't create a Gemfile -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db) # Default: sqlite3 -O, [--skip-active-record] # Skip Active Record files -m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL) -J, [--skip-prototype] # Skip Prototype files -T, [--skip-test-unit] # Skip Test::Unit files Runtime options: -s, [--skip] # Skip files that already exist -p, [--pretend] # Run but do not make any changes -f, [--force] # Overwrite files that already exist -q, [--quiet] # Supress status output Rails options: -v, [--version] # Show Rails version number and quit -h, [--help] # Show this help message and quit Description: The 'rails new' command creates a new Rails application with a default directory structure and configuration at the path you specify. Example: rails new ~/Code/Ruby/weblog This generates a skeletal Rails installation in ~/Code/Ruby/weblog. See the README in the newly created application to get going. command
2010-11-15 19:09:39 +00:00
end
test "generators default values" do
2010-01-28 01:39:11 +00:00
with_bare_config do |c|
assert_equal(true, c.generators.colorize_logging)
assert_equal({}, c.generators.aliases)
assert_equal({}, c.generators.options)
2010-02-01 09:48:59 +00:00
assert_equal({}, c.generators.fallbacks)
end
end
test "generators set rails options" do
with_bare_config do |c|
c.generators.orm = :datamapper
c.generators.test_framework = :rspec
c.generators.helper = false
expected = { :rails => { :orm => :datamapper, :test_framework => :rspec, :helper => false } }
assert_equal(expected, c.generators.options)
end
end
test "generators set rails aliases" do
2009-11-30 23:58:38 +00:00
with_config do |c|
c.generators.aliases = { :rails => { :test_framework => "-w" } }
expected = { :rails => { :test_framework => "-w" } }
assert_equal expected, c.generators.aliases
end
end
test "generators aliases, options, templates and fallbacks on initialization" do
add_to_config <<-RUBY
config.generators.rails :aliases => { :test_framework => "-w" }
config.generators.orm :datamapper
config.generators.test_framework :rspec
2010-02-01 09:48:59 +00:00
config.generators.fallbacks[:shoulda] = :test_unit
config.generators.templates << "some/where"
RUBY
# Initialize the application
2010-01-12 16:48:09 +00:00
require "#{app_path}/config/environment"
2011-05-25 07:30:41 +00:00
Rails.application.load_generators
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
assert_equal Hash[:shoulda => :test_unit], Rails::Generators.fallbacks
assert_equal ["some/where"], Rails::Generators.templates_path
end
test "generators no color on initialization" do
add_to_config <<-RUBY
config.generators.colorize_logging = false
RUBY
# Initialize the application
require "#{app_path}/config/environment"
2011-05-25 07:30:41 +00:00
Rails.application.load_generators
assert_equal Thor::Base.shell, Thor::Shell::Basic
end
test "generators with hashes for options and aliases" do
2010-01-28 01:39:11 +00:00
with_bare_config do |c|
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
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
end
end