1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Pass more options to test/dummy in 'plugin new' generator

This commit is contained in:
Piotr Sarnacki 2010-10-27 00:16:57 +02:00
parent 671d1469c6
commit 46fdb3197d
4 changed files with 29 additions and 16 deletions

View file

@ -8,6 +8,9 @@ require 'uri'
module Rails
module Generators
class AppBase < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
JAVASCRIPTS = %w( prototype jquery )
attr_accessor :rails_template
add_shebang_option!
@ -26,10 +29,17 @@ module Rails
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
:desc => "Skip Git ignores and keeps"
skip_active_record_desc = "Skip Active Record files"
skip_active_record_desc << " for dummy application" if name == "plugin"
class_option :skip_active_record, :type => :boolean, :aliases => "-O", :default => false,
:desc => skip_active_record_desc
:desc => "Skip Active Record files"
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
class_option :javascript, :type => :string, :aliases => "-j", :default => "prototype",
:desc => "Preconfigure for selected javascript library (options: #{JAVASCRIPTS.join('/')})"
class_option :skip_javascript, :type => :boolean, :aliases => "-J", :default => false,
:desc => "Skip javascript files"
class_option :dev, :type => :boolean, :default => false,
:desc => "Setup the #{name} with Gemfile pointing to your Rails checkout"

View file

@ -154,23 +154,11 @@ module Rails
plugin runner test]
class AppGenerator < AppBase
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
JAVASCRIPTS = %w( prototype jquery )
add_shared_options_for "application"
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
class_option :javascript, :type => :string, :aliases => "-j", :default => "prototype",
:desc => "Preconfigure for selected javascript library (options: #{JAVASCRIPTS.join('/')})"
class_option :skip_test_unit, :type => :boolean, :aliases => "-T", :default => false,
:desc => "Skip Test::Unit files"
class_option :skip_javascript, :type => :boolean, :aliases => "-J", :default => false,
:desc => "Skip javascript files"
# Add bin/rails options
class_option :version, :type => :boolean, :aliases => "-v", :group => :rails,
:desc => "Show Rails version number and quit"

View file

@ -45,7 +45,7 @@ module Rails
end
def generate_test_dummy
opts = (options || {}).slice("skip_active_record")
opts = (options || {}).slice(:skip_active_record, :skip_javascript, :database, :javascript)
invoke Rails::Generators::AppGenerator,
[ File.expand_path(dummy_path, destination_root) ], opts

View file

@ -63,6 +63,21 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_no_file "test/dummy/config/database.yml"
end
def test_ensure_that_database_option_is_passed_to_app_generator
run_generator [destination_root, "--database", "postgresql"]
assert_file "test/dummy/config/database.yml", /postgres/
end
def test_ensure_that_javascript_option_is_passed_to_app_generator
run_generator [destination_root, "--javascript", "jquery"]
assert_file "test/dummy/public/javascripts/jquery.js"
end
def test_ensure_that_skip_javascript_option_is_passed_to_app_generator
run_generator [destination_root, "--skip_javascript"]
assert_no_file "test/dummy/public/javascripts/prototype.js"
end
def test_template_from_dir_pwd
FileUtils.cd(Rails.root)
assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])