aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-10-26 22:22:15 +0200
committerPiotr Sarnacki <drogus@gmail.com>2010-11-02 17:14:51 +0100
commit671d1469c6f70abb7cbd373bb37f18268ed7069c (patch)
tree10a8f231b09510f33931313b1e408344e586bbf2 /railties
parentfdbd9df21e0063da4b34346c54fbe21ac9583ca6 (diff)
downloadrails-671d1469c6f70abb7cbd373bb37f18268ed7069c.tar.gz
rails-671d1469c6f70abb7cbd373bb37f18268ed7069c.tar.bz2
rails-671d1469c6f70abb7cbd373bb37f18268ed7069c.zip
Add --full option to 'plugin new' generator, which generates rails engine
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/app_base.rb5
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb3
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb25
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/Gemfile5
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb6
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb4
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb8
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb (renamed from railties/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb.tt)0
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb7
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/test/support/integration_case.rb5
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb16
-rw-r--r--railties/test/generators/plugin_new_generator_test.rb28
13 files changed, 105 insertions, 9 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index a355f3b055..1b3673e96e 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -26,6 +26,11 @@ 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
+
class_option :dev, :type => :boolean, :default => false,
:desc => "Setup the #{name} with Gemfile pointing to your Rails checkout"
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 04c2e3738a..6fdc51bd94 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -165,9 +165,6 @@ module Rails
class_option :javascript, :type => :string, :aliases => "-j", :default => "prototype",
:desc => "Preconfigure for selected javascript library (options: #{JAVASCRIPTS.join('/')})"
- class_option :skip_active_record, :type => :boolean, :aliases => "-O", :default => false,
- :desc => "Skip Active Record files"
-
class_option :skip_test_unit, :type => :boolean, :aliases => "-T", :default => false,
:desc => "Skip Test::Unit files"
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 8c4ddc822a..d361c490a3 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
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/hash/slice'
require 'rails/generators/app_base'
require "rails/generators/rails/app/app_generator"
@@ -28,16 +29,26 @@ module Rails
end
def lib
- directory "lib"
+ template "lib/%name%.rb"
+ if full?
+ template "lib/%name%/engine.rb"
+ end
end
def test
- directory "test"
+ template "test/test_helper.rb"
+ template "test/%name%_test.rb"
+ if full?
+ template "test/integration/navigation_test.rb"
+ template "test/support/integration_case.rb"
+ end
end
def generate_test_dummy
+ opts = (options || {}).slice("skip_active_record")
+
invoke Rails::Generators::AppGenerator,
- [ File.expand_path(dummy_path, destination_root) ], {}
+ [ File.expand_path(dummy_path, destination_root) ], opts
end
def test_dummy_config
@@ -96,6 +107,9 @@ end
alias_method :plugin_path, :app_path
+ class_option :full, :type => :boolean, :default => false,
+ :desc => "Generate rails engine with integration tests"
+
def initialize(*args)
raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank?
@@ -159,6 +173,10 @@ end
protected
+ def full?
+ options[:full]
+ end
+
def self.banner
"rails plugin new #{self.arguments.map(&:usage).join(' ')} [options]"
end
@@ -183,6 +201,7 @@ end
def application_definition
@application_definition ||= begin
+
dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
unless options[:pretend] || !File.exists?(dummy_application_path)
contents = File.read(dummy_application_path)
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
index 53a925d976..7ce44a3d52 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
@@ -2,6 +2,11 @@ source "http://rubygems.org"
<%= rails_gemfile_entry -%>
+<% if full? -%>
+ gem "capybara", ">= 0.3.9"
+ gem "sqlite3-ruby", :require => "sqlite3"
+<% end -%>
+
if RUBY_VERSION < '1.9'
gem "ruby-debug", ">= 0.10.3"
end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb
new file mode 100644
index 0000000000..805ba008c3
--- /dev/null
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb
@@ -0,0 +1,6 @@
+<% if full? %>
+require "<%= name %>/engine"
+
+<% end -%>
+module <%= camelized %>
+end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb.tt b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb.tt
deleted file mode 100644
index cf77a0b4d3..0000000000
--- a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb.tt
+++ /dev/null
@@ -1,2 +0,0 @@
-module <%= camelized %>
-end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb
new file mode 100644
index 0000000000..779bd1cfd3
--- /dev/null
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb
@@ -0,0 +1,4 @@
+module <%= camelized %>
+ class Engine < Rails::Engine
+ end
+end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb b/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb
index ce655ba7e5..8b68280a5e 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb
@@ -1,6 +1,14 @@
require File.expand_path('../boot', __FILE__)
+<% unless options[:skip_active_record] -%>
require 'rails/all'
+<% else -%>
+# require "active_record/railtie"
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "active_resource/railtie"
+require "rails/test_unit/railtie"
+<% end -%>
Bundler.require
require "<%= name %>"
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb.tt b/railties/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb
index 0a8bbd4aaf..0a8bbd4aaf 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb.tt
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb b/railties/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb
new file mode 100644
index 0000000000..42721899c8
--- /dev/null
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class NagivationTest < ActiveSupport::IntegrationCase
+ test "truth" do
+ assert_kind_of Dummy::Application, Rails.application
+ end
+end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/test/support/integration_case.rb b/railties/lib/rails/generators/rails/plugin_new/templates/test/support/integration_case.rb
new file mode 100644
index 0000000000..4cfe3f0e71
--- /dev/null
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/test/support/integration_case.rb
@@ -0,0 +1,5 @@
+# Define a bare test case to use with Capybara
+class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
+ include Capybara
+ include Rails.application.routes.url_helpers
+end \ No newline at end of file
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb
index 791b901593..d821079b91 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb
@@ -6,5 +6,21 @@ require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
+<% if full? -%>
+ActionMailer::Base.delivery_method = :test
+ActionMailer::Base.perform_deliveries = true
+ActionMailer::Base.default_url_options[:host] = "test.com"
+
+# Configure capybara for integration testing
+require "capybara/rails"
+Capybara.default_driver = :rack_test
+Capybara.default_selector = :css
+
+# Run any available migration from application
+ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
+# and from engine
+ActiveRecord::Migrator.migrate File.expand_path("../../db/migrate/", __FILE__)
+<% end -%>
+
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index bf395749e5..f833411e3a 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -41,15 +41,28 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
def test_generating_test_files
run_generator
assert_file "test/test_helper.rb"
-
assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/
end
+ def test_generating_test_files_in_full_mode
+ run_generator [destination_root, "--full"]
+ assert_directory "test/support/"
+ assert_directory "test/integration/"
+
+ assert_file "test/integration/navigation_test.rb", /assert_kind_of Dummy::Application, Rails.application/
+ assert_file "test/support/integration_case.rb", /class ActiveSupport::IntegrationCase/
+ end
+
def test_ensure_that_plugin_options_are_not_passed_to_app_generator
FileUtils.cd(Rails.root)
assert_no_match /It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"])
end
+ def test_ensure_that_skip_active_record_option_is_passed_to_app_generator
+ run_generator [destination_root, "--skip_active_record"]
+ assert_no_file "test/dummy/config/database.yml"
+ 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"])
@@ -62,6 +75,19 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`
end
+ def test_ensure_that_tests_works_in_full_mode
+ run_generator [destination_root, "--full"]
+ FileUtils.cd destination_root
+ `bundle install`
+ assert_match /2 tests, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test`
+ end
+
+ def test_creating_engine_in_full_mode
+ run_generator [destination_root, "--full"]
+ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < Rails::Engine\n end\nend/
+ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/
+ end
+
protected
def action(*args, &block)