From f9e33fc09a6731ad56ff8cfe24b49532ed65039c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 2 Nov 2010 15:13:10 +0100 Subject: create_dummy_app method that allows to easily create dummy application from template --- .../rails/plugin_new/plugin_new_generator.rb | 61 +++++++++++----------- .../generators/rails/plugin_new/templates/Rakefile | 6 --- .../rails/plugin_new/templates/script/rails.tt | 2 +- 3 files changed, 32 insertions(+), 37 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 29a92c9388..eac4f76510 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -37,13 +37,19 @@ module Rails def test template "test/test_helper.rb" template "test/%name%_test.rb" + append_file "Rakefile", <<-EOF +#{rakefile_test_tasks} + +task :default => :test + EOF if full? template "test/integration/navigation_test.rb" end end - def generate_test_dummy + def generate_test_dummy(force = false) opts = (options || {}).slice(:skip_active_record, :skip_javascript, :database, :javascript) + opts[:force] = force invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts @@ -70,33 +76,12 @@ module Rails end end - def script - directory "script" do |content| + def script(force = false) + directory "script", :force => force do |content| "#{shebang}\n" + content end chmod "script", 0755, :verbose => false end - - def rakefile_test_tasks - <<-RUBY -require 'rake/testtask' - -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.libs << 'test' - t.pattern = 'test/**/*_test.rb' - t.verbose = false -end - RUBY - end - - def dummy_path - "#{test_path}/dummy" - end - - def test_path - "test" - end end module Generators @@ -143,7 +128,7 @@ end def create_test_dummy_files return if options[:skip_test_unit] - create_test_dummy(dummy_path) + create_dummy_app end def finish_template @@ -153,13 +138,17 @@ end public_task :apply_rails_template, :bundle_if_dev_or_edge protected - def create_test_dummy(dummy_path) + def create_dummy_app(path = nil) + dummy_path(path) if path + say_status :vendor_app, dummy_path mute do build(:generate_test_dummy) store_application_definition! build(:test_dummy_config) build(:test_dummy_clean) + # ensure that script/rails has proper dummy_path + build(:script, true) end end @@ -205,10 +194,22 @@ end defined?(::PluginBuilder) ? ::PluginBuilder : Rails::PluginBuilder end - [:test_path, :dummy_path, :rakefile_test_tasks].each do |name| - define_method name do - builder.send(name) if builder.respond_to?(name) - end + def rakefile_test_tasks + <<-RUBY +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = false +end + RUBY + end + + def dummy_path(path = nil) + @dummy_path = path if path + @dummy_path || "test/dummy" end def mute(&block) diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile index dd7c11622d..88f50f9f04 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile @@ -9,12 +9,6 @@ end require 'rake' require 'rake/rdoctask' -<% unless options[:skip_test_unit] -%> -<%= rakefile_test_tasks %> - -task :default => :test -<% end -%> - Rake::RDocTask.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = '<%= camelized %>' diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt index 91d9cf079d..ebd5a77dd5 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +++ b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt @@ -2,4 +2,4 @@ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. ENGINE_PATH = File.expand_path('../..', __FILE__) -load File.expand_path('../../<%= test_path %>/dummy/script/rails', __FILE__) +load File.expand_path('../../<%= dummy_path %>/script/rails', __FILE__) -- cgit v1.2.3