2009-10-08 21:12:28 -04:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
|
|
|
|
module ApplicationTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class GeneratorsTest < ActiveSupport::TestCase
|
2009-10-08 21:12:28 -04:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
boot_rails
|
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
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
|
|
|
|
|
2010-11-15 14:09:05 -05:00
|
|
|
test "allow running plugin new generator inside Rails app directory" do
|
2010-11-17 17:31:29 -05: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 14:09:39 -05:00
|
|
|
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|
|
2011-10-18 09:29:16 -04:00
|
|
|
c.generators.orm = :data_mapper
|
2009-10-08 21:12:28 -04:00
|
|
|
c.generators.test_framework = :rspec
|
2009-11-03 21:14:44 -05:00
|
|
|
c.generators.helper = false
|
2012-10-14 06:03:39 -04:00
|
|
|
expected = { rails: { orm: :data_mapper, 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|
|
2012-10-14 06:03:39 -04:00
|
|
|
c.generators.aliases = { rails: { test_framework: "-w" } }
|
|
|
|
expected = { rails: { test_framework: "-w" } }
|
2009-10-08 21:12:28 -04:00
|
|
|
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
|
2012-10-14 06:03:39 -04:00
|
|
|
config.generators.rails aliases: { test_framework: "-w" }
|
2011-10-18 09:29:16 -04:00
|
|
|
config.generators.orm :data_mapper
|
2009-12-22 20:03:23 -05:00
|
|
|
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"
|
2011-05-25 03:30:41 -04:00
|
|
|
Rails.application.load_generators
|
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]
|
2012-10-14 06:03:39 -04: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"
|
2011-05-25 03:30:41 -04:00
|
|
|
Rails.application.load_generators
|
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|
|
2012-10-14 06:03:39 -04:00
|
|
|
g.orm :data_mapper, migration: false
|
|
|
|
g.plugin aliases: { generator: "-g" },
|
|
|
|
generator: true
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expected = {
|
2012-10-14 06:03:39 -04:00
|
|
|
rails: { orm: :data_mapper },
|
|
|
|
plugin: { generator: true },
|
|
|
|
data_mapper: { migration: false }
|
2009-10-08 21:12:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal expected, c.generators.options
|
2012-10-14 06:03:39 -04:00
|
|
|
assert_equal({ plugin: { generator: "-g" } }, c.generators.aliases)
|
2009-10-08 21:12:28 -04:00
|
|
|
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|
|
2012-10-14 06:03:39 -04:00
|
|
|
g.orm 'data_mapper', migration: false
|
2010-07-21 10:37:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expected = {
|
2012-10-14 06:03:39 -04:00
|
|
|
rails: { orm: :data_mapper },
|
|
|
|
data_mapper: { migration: false }
|
2010-07-21 10:37:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|