aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-04 03:24:39 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-04 03:24:39 +0530
commitcda36a0731f14b33a920bf7e32255661e06f890a (patch)
tree79ccba37953f9fe3055503be42b1610faa6d64ad /railties/test
parentbd4a3cce4ecd8e648179a91e26506e3622ac2162 (diff)
parenta115b5d79a850bb56cd3c9db9a05d6da35e3d7be (diff)
downloadrails-cda36a0731f14b33a920bf7e32255661e06f890a.tar.gz
rails-cda36a0731f14b33a920bf7e32255661e06f890a.tar.bz2
rails-cda36a0731f14b33a920bf7e32255661e06f890a.zip
Merge remote branch 'mainstream/master'
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/abstract_unit.rb6
-rw-r--r--railties/test/application/configuration_test.rb106
-rw-r--r--railties/test/application/generators_test.rb46
-rw-r--r--railties/test/application/initializer_test.rb183
-rw-r--r--railties/test/application/load_test.rb30
-rw-r--r--railties/test/application/notifications_test.rb51
-rw-r--r--railties/test/application/routing_test.rb180
-rw-r--r--railties/test/fixtures/plugins/engines/engine/config/routes.rb2
-rw-r--r--railties/test/fixtures/vendor/plugins/mspec/lib/rails_generators/mspec_generator.rb (renamed from railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb)0
-rw-r--r--railties/test/generators/actions_test.rb14
-rw-r--r--railties/test/generators/app_generator_test.rb55
-rw-r--r--railties/test/generators/controller_generator_test.rb15
-rw-r--r--railties/test/generators/generator_generator_test.rb9
-rw-r--r--railties/test/generators/generators_test_helper.rb94
-rw-r--r--railties/test/generators/helper_generator_test.rb9
-rw-r--r--railties/test/generators/integration_test_generator_test.rb9
-rw-r--r--railties/test/generators/mailer_generator_test.rb9
-rw-r--r--railties/test/generators/metal_generator_test.rb9
-rw-r--r--railties/test/generators/migration_generator_test.rb41
-rw-r--r--railties/test/generators/model_generator_test.rb15
-rw-r--r--railties/test/generators/named_base_test.rb8
-rw-r--r--railties/test/generators/observer_generator_test.rb9
-rw-r--r--railties/test/generators/performance_test_generator_test.rb9
-rw-r--r--railties/test/generators/plugin_generator_test.rb9
-rw-r--r--railties/test/generators/resource_generator_test.rb19
-rw-r--r--railties/test/generators/scaffold_controller_generator_test.rb27
-rw-r--r--railties/test/generators/scaffold_generator_test.rb32
-rw-r--r--railties/test/generators/session_migration_generator_test.rb9
-rw-r--r--railties/test/generators/stylesheets_generator_test.rb11
-rw-r--r--railties/test/generators_test.rb24
-rw-r--r--railties/test/initializable_test.rb10
-rw-r--r--railties/test/initializer/check_ruby_version_test.rb56
-rw-r--r--railties/test/initializer/initialize_i18n_test.rb11
-rw-r--r--railties/test/initializer/path_test.rb174
-rw-r--r--railties/test/isolation/abstract_unit.rb19
-rw-r--r--railties/test/metal_test.rb1
-rw-r--r--railties/test/paths_test.rb3
-rw-r--r--railties/test/plugins/configuration_test.rb36
-rw-r--r--railties/test/plugins/framework_extension_test.rb52
-rw-r--r--railties/test/rails_info_controller_test.rb8
40 files changed, 762 insertions, 648 deletions
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index 47013d7797..2d6983076a 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -20,8 +20,10 @@ require 'active_support/core_ext/logger'
require 'active_support/test_case'
require 'action_controller'
-require 'rails'
+require 'rails/all'
-Rails::Initializer.run do |config|
+# TODO: Remove these hacks
+class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
end
+Rails.application = TestApp
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index a3e1916494..79dfacdcdb 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -4,9 +4,19 @@ module ApplicationTests
class InitializerTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
+ def new_app
+ File.expand_path("#{app_path}/../new_app")
+ end
+
+ def copy_app
+ FileUtils.cp_r(app_path, new_app)
+ end
+
def setup
+ FileUtils.rm_rf(new_app) if File.directory?(new_app)
build_app
boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
end
test "the application root is set correctly" do
@@ -14,35 +24,103 @@ module ApplicationTests
assert_equal Pathname.new(app_path), Rails.application.root
end
+ test "the application root can be seen from the application singleton" do
+ require "#{app_path}/config/environment"
+ assert_equal Pathname.new(app_path), AppTemplate::Application.root
+ end
+
test "the application root can be set" do
- FileUtils.mkdir_p("#{app_path}/hello")
+ copy_app
add_to_config <<-RUBY
- config.frameworks = []
- config.root = '#{app_path}/hello'
+ config.root = '#{new_app}'
RUBY
+
+ use_frameworks []
+
+ require "#{app_path}/config/environment"
+ assert_equal Pathname.new(new_app), Rails.application.root
+ end
+
+ test "the application root is Dir.pwd if there is no config.ru" do
+ File.delete("#{app_path}/config.ru")
+
+ use_frameworks []
+
+ Dir.chdir("#{app_path}") do
+ require "#{app_path}/config/environment"
+ assert_equal Pathname.new("#{app_path}"), Rails.application.root
+ end
+ end
+
+ test "if there's no config.active_support.bare, all of ActiveSupport is required" do
+ use_frameworks []
require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root
+ assert_nothing_raised { [1,2,3].rand }
end
- test "the application root is detected as where config.ru is located" do
+ test "config.active_support.bare does not require all of ActiveSupport" do
+ add_to_config "config.active_support.bare = true"
+
+ use_frameworks []
+
+ Dir.chdir("#{app_path}/app") do
+ require "#{app_path}/config/environment"
+ assert_raises(NoMethodError) { [1,2,3].rand }
+ end
+ end
+
+ test "marking the application as threadsafe sets the correct config variables" do
add_to_config <<-RUBY
- config.frameworks = []
+ config.threadsafe!
RUBY
- FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru"
+
+ require "#{app_path}/config/application"
+ assert AppTemplate::Application.config.action_controller.allow_concurrency
+ end
+
+ test "the application can be marked as threadsafe when there are no frameworks" do
+ FileUtils.rm_rf("#{app_path}/config/environments")
+ add_to_config <<-RUBY
+ config.threadsafe!
+ RUBY
+
+ use_frameworks []
+
+ assert_nothing_raised do
+ require "#{app_path}/config/application"
+ end
+ end
+
+ test "Frameworks are not preloaded by default" do
require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/config"), Rails.application.root
+
+ assert ActionController.autoload?(:RecordIdentifier)
end
- test "the application root is Dir.pwd if there is no config.ru" do
- File.delete("#{app_path}/config.ru")
+ test "frameworks are preloaded with config.preload_frameworks is set" do
add_to_config <<-RUBY
- config.frameworks = []
+ config.preload_frameworks = true
RUBY
- Dir.chdir("#{app_path}/app") do
+ require "#{app_path}/config/environment"
+
+ assert !ActionController.autoload?(:RecordIdentifier)
+ end
+
+ test "runtime error is raised if config.frameworks= is used" do
+ add_to_config "config.frameworks = []"
+
+ assert_raises RuntimeError do
+ require "#{app_path}/config/environment"
+ end
+ end
+
+ test "runtime error is raised if config.frameworks is used" do
+ add_to_config "config.frameworks -= []"
+
+ assert_raises RuntimeError do
require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/app"), Rails.application.root
end
end
end
-end \ No newline at end of file
+end
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index ccbcd84176..0c858d6394 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -7,12 +7,20 @@ module ApplicationTests
def setup
build_app
boot_rails
- require "rails"
+ end
+
+ def app_const
+ @app_const ||= Class.new(Rails::Application)
+ end
+
+ def with_config
+ require "rails/all"
require "rails/generators"
+ yield app_const.config
end
test "generators default values" do
- Rails::Initializer.run do |c|
+ with_config do |c|
assert_equal(true, c.generators.colorize_logging)
assert_equal({}, c.generators.aliases)
assert_equal({}, c.generators.options)
@@ -20,7 +28,7 @@ module ApplicationTests
end
test "generators set rails options" do
- Rails::Initializer.run do |c|
+ with_config do |c|
c.generators.orm = :datamapper
c.generators.test_framework = :rspec
c.generators.helper = false
@@ -30,7 +38,7 @@ module ApplicationTests
end
test "generators set rails aliases" do
- Rails::Initializer.run do |c|
+ with_config do |c|
c.generators.aliases = { :rails => { :test_framework => "-w" } }
expected = { :rails => { :test_framework => "-w" } }
assert_equal expected, c.generators.aliases
@@ -38,14 +46,15 @@ module ApplicationTests
end
test "generators aliases and options on initialization" do
- Rails::Initializer.run do |c|
- c.frameworks = []
- c.generators.rails :aliases => { :test_framework => "-w" }
- c.generators.orm :datamapper
- c.generators.test_framework :rspec
- end
+ add_to_config <<-RUBY
+ config.generators.rails :aliases => { :test_framework => "-w" }
+ config.generators.orm :datamapper
+ config.generators.test_framework :rspec
+ RUBY
+
+ require "#{app_path}/config/environment"
# Initialize the application
- Rails.initialize!
+ require "rails/generators"
Rails::Generators.configure!
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
@@ -53,19 +62,20 @@ module ApplicationTests
end
test "generators no color on initialization" do
- Rails::Initializer.run do |c|
- c.frameworks = []
- c.generators.colorize_logging = false
- end
+ add_to_config <<-RUBY
+ config.generators.colorize_logging = false
+ RUBY
+
# Initialize the application
- Rails.initialize!
+ require "#{app_path}/config/environment"
+ require "rails/generators"
Rails::Generators.configure!
assert_equal Thor::Base.shell, Thor::Shell::Basic
end
test "generators with hashes for options and aliases" do
- Rails::Initializer.run do |c|
+ with_config do |c|
c.generators do |g|
g.orm :datamapper, :migration => false
g.plugin :aliases => { :generator => "-g" },
@@ -84,7 +94,7 @@ module ApplicationTests
end
test "generators with hashes are deep merged" do
- Rails::Initializer.run do |c|
+ with_config do |c|
c.generators do |g|
g.orm :datamapper, :migration => false
g.plugin :aliases => { :generator => "-g" },
diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb
index 719520bf68..3fd0b0e5df 100644
--- a/railties/test/application/initializer_test.rb
+++ b/railties/test/application/initializer_test.rb
@@ -7,45 +7,18 @@ module ApplicationTests
def setup
build_app
boot_rails
- require "rails"
- end
-
- test "initializing an application initializes rails" do
- Rails::Initializer.run do |config|
- config.root = app_path
- end
-
- if RUBY_VERSION < '1.9'
- $KCODE = ''
- Rails.initialize!
- assert_equal 'UTF8', $KCODE
- else
- Encoding.default_external = Encoding::US_ASCII
- Rails.initialize!
- assert_equal Encoding::UTF_8, Encoding.default_external
- end
+ FileUtils.rm_rf "#{app_path}/config/environments"
end
test "initializing an application adds the application paths to the load path" do
- Rails::Initializer.run do |config|
- config.root = app_path
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
- Rails.initialize!
+ require "#{app_path}/config/environment"
assert $:.include?("#{app_path}/app/models")
end
- test "adding an unknown framework raises an error" do
- Rails::Initializer.run do |config|
- config.root = app_path
- config.frameworks << :action_foo
- end
-
- assert_raises RuntimeError do
- Rails.initialize!
- end
- end
-
test "eager loading loads parent classes before children" do
app_file "lib/zoo.rb", <<-ZOO
class Zoo ; include ReptileHouse ; end
@@ -54,12 +27,12 @@ module ApplicationTests
module Zoo::ReptileHouse ; end
ZOO
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.eager_load_paths = "#{app_path}/lib"
- end
+ RUBY
- Rails.initialize!
+ require "#{app_path}/config/environment"
assert Zoo
end
@@ -67,41 +40,44 @@ module ApplicationTests
test "load environment with global" do
app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'"
assert_nil $initialize_test_set_from_env
- Rails::Initializer.run { |config| config.root = app_path }
- Rails.initialize!
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal "success", $initialize_test_set_from_env
end
test "action_controller load paths set only if action controller in use" do
assert_nothing_raised NameError do
- Rails::Initializer.run do |config|
- config.root = app_path
- config.frameworks = []
- end
- Rails.initialize!
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+
+ use_frameworks []
+ require "#{app_path}/config/environment"
end
end
test "after_initialize block works correctly" do
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.after_initialize { $test_after_initialize_block1 = "success" }
config.after_initialize { $test_after_initialize_block2 = "congratulations" }
- end
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal "success", $test_after_initialize_block1
assert_equal "congratulations", $test_after_initialize_block2
end
test "after_initialize block works correctly when no block is passed" do
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.after_initialize { $test_after_initialize_block1 = "success" }
config.after_initialize # don't pass a block, this is what we're testing!
config.after_initialize { $test_after_initialize_block2 = "congratulations" }
- end
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal "success", $test_after_initialize_block1
assert_equal "congratulations", $test_after_initialize_block2
@@ -109,35 +85,40 @@ module ApplicationTests
# i18n
test "setting another default locale" do
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.i18n.default_locale = :de
- end
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal :de, I18n.default_locale
end
test "no config locales dir present should return empty load path" do
FileUtils.rm_rf "#{app_path}/config/locales"
- Rails::Initializer.run do |c|
- c.root = app_path
- assert_equal [], c.i18n.load_path
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+ require "#{app_path}/config/environment"
+
+ assert_equal [], Rails.application.config.i18n.load_path
end
test "config locales dir present should be added to load path" do
- Rails::Initializer.run do |c|
- c.root = app_path
- assert_equal ["#{app_path}/config/locales/en.yml"], c.i18n.load_path
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+
+ require "#{app_path}/config/environment"
+ assert_equal ["#{app_path}/config/locales/en.yml"], Rails.application.config.i18n.load_path
end
test "config defaults should be added with config settings" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.i18n.load_path << "my/other/locale.yml"
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ config.i18n.load_path << "my/other/locale.yml"
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal [
"#{app_path}/config/locales/en.yml", "my/other/locale.yml"
@@ -146,64 +127,48 @@ module ApplicationTests
# DB middleware
test "database middleware doesn't initialize when session store is not active_record" do
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.action_controller.session_store = :cookie_store
- end
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
end
- test "database middleware doesn't initialize when activerecord is not in frameworks" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.frameworks = []
- end
- assert_equal [], Rails.application.config.middleware
- end
-
test "database middleware initializes when session store is active record" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.action_controller.session_store = :active_record_store
- end
- Rails.initialize!
+ add_to_config "config.action_controller.session_store = :active_record_store"
+
+ require "#{app_path}/config/environment"
expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
assert_equal expects, middleware & expects
end
- test "ensure database middleware doesn't use action_controller on initializing" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.frameworks -= [:action_controller]
- c.action_controller.session_store = :active_record_store
- end
- Rails.initialize!
-
- assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
+ test "Rails.root should be a Pathname" do
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+ require "#{app_path}/config/environment"
+ assert_instance_of Pathname, Rails.root
end
+ end
- # Pathview test
- test "load view paths doesn't perform anything when action_view not in frameworks" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.frameworks -= [:action_view]
- end
- Rails.initialize!
+ class InitializerCustomFrameworkExtensionsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
- assert_equal nil, ActionMailer::Base.template_root
- assert_equal [], ActionController::Base.view_paths
+ def setup
+ build_app
+ boot_rails
+ FileUtils.rm_rf "#{app_path}/config/environments"
end
- test "Rails.root should be a Pathname" do
- Rails::Initializer.run do |c|
- c.root = app_path
- end
- Rails.initialize!
- assert_instance_of Pathname, Rails.root
+ test "database middleware doesn't initialize when activerecord is not in frameworks" do
+ use_frameworks []
+ require "#{app_path}/config/environment"
+
+ assert_nil defined?(ActiveRecord)
end
end
-end \ No newline at end of file
+end
diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb
index 3da51c4355..1c5811b07a 100644
--- a/railties/test/application/load_test.rb
+++ b/railties/test/application/load_test.rb
@@ -1,27 +1,13 @@
require "isolation/abstract_unit"
-# require "rails"
-# require 'action_dispatch'
module ApplicationTests
class LoadTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def rackup
- config = "#{app_path}/config.ru"
- # Copied from ActionDispatch::Utils.parse_config
- # ActionDispatch is not necessarily available at this point.
- require 'rack'
- if config =~ /\.ru$/
- cfgfile = ::File.read(config)
- if cfgfile[/^#\\(.*)/]
- opts.parse! $1.split(/\s+/)
- end
- inner_app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
- nil, config
- else
- require config
- inner_app = Object.const_get(::File.basename(config, '.rb').capitalize)
- end
+ require "rack"
+ app, options = Rack::Builder.parse_file("#{app_path}/config.ru")
+ app
end
def setup
@@ -34,20 +20,22 @@ module ApplicationTests
end
test "config.ru can be racked up" do
- @app = rackup
- assert_welcome get("/")
+ Dir.chdir app_path do
+ @app = rackup
+ assert_welcome get("/")
+ end
end
test "Rails.application is available after config.ru has been racked up" do
rackup
- assert Rails.application < Rails::Application
+ assert Rails.application.is_a?(Rails::Application)
end
# Passenger still uses AC::Dispatcher, so we need to
# keep it working for now
test "deprecated ActionController::Dispatcher still works" do
rackup
- assert ActionController::Dispatcher.new < Rails::Application
+ assert ActionController::Dispatcher.new.is_a?(Rails::Application)
end
test "the config object is available on the application object" do
diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb
index 62ed4f4ad4..b57e829cca 100644
--- a/railties/test/application/notifications_test.rb
+++ b/railties/test/application/notifications_test.rb
@@ -1,46 +1,39 @@
require "isolation/abstract_unit"
module ApplicationTests
- class NotificationsTest < Test::Unit::TestCase
- include ActiveSupport::Testing::Isolation
-
- class MyQueue
- attr_reader :events, :subscribers
-
- def initialize
- @events = []
- @subscribers = []
- end
-
- def publish(name, *args)
- @events << name
- end
+ class MyQueue
+ def publish(name, *args)
+ raise name
+ end
- def subscribe(pattern=nil, &block)
- @subscribers << pattern
- end
+ # Not a full queue implementation
+ def method_missing(name, *args, &blk)
+ self
end
+ end
+
+ class NotificationsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
def setup
build_app
boot_rails
- require "rails"
+ FileUtils.rm_rf("#{app_path}/config/environments")
require "active_support/notifications"
- Rails::Initializer.run do |c|
- c.notifications.queue = MyQueue.new
- c.notifications.subscribe(/listening/) do
- puts "Cool"
- end
- end
+ @events = []
+
+ add_to_config <<-RUBY
+ config.notifications.notifier = ActiveSupport::Notifications::Notifier.new(ApplicationTests::MyQueue.new)
+ RUBY
end
test "new queue is set" do
- ActiveSupport::Notifications.instrument(:foo)
- assert_equal :foo, ActiveSupport::Notifications.queue.events.first
- end
+ use_frameworks []
+ require "#{app_path}/config/environment"
- test "configuration subscribers are loaded" do
- assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == /listening/ }
+ assert_raise RuntimeError do
+ ActiveSupport::Notifications.publish('foo')
+ end
end
end
end
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
new file mode 100644
index 0000000000..725dd06929
--- /dev/null
+++ b/railties/test/application/routing_test.rb
@@ -0,0 +1,180 @@
+require 'isolation/abstract_unit'
+
+module ApplicationTests
+ class RoutingTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ require 'rack/test'
+ extend Rack::Test::Methods
+ end
+
+ def app
+ @app ||= begin
+ require "#{app_path}/config/environment"
+
+ Rails.application
+ end
+ end
+
+ test "rails/info/properties" do
+ get "/rails/info/properties"
+ assert_equal 200, last_response.status
+ end
+
+ test "simple controller" do
+ controller :foo, <<-RUBY
+ class FooController < ActionController::Base
+ def index
+ render :text => "foo"
+ end
+ end
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match ':controller(/:action)'
+ end
+ RUBY
+
+ get '/foo'
+ assert_equal 'foo', last_response.body
+ end
+
+ test "multiple controllers" do
+ controller :foo, <<-RUBY
+ class FooController < ActionController::Base
+ def index
+ render :text => "foo"
+ end
+ end
+ RUBY
+
+ controller :bar, <<-RUBY
+ class BarController < ActionController::Base
+ def index
+ render :text => "bar"
+ end
+ end
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match ':controller(/:action)'
+ end
+ RUBY
+
+ get '/foo'
+ assert_equal 'foo', last_response.body
+
+ get '/bar'
+ assert_equal 'bar', last_response.body
+ end
+
+ test "nested controller" do
+ controller 'foo', <<-RUBY
+ class FooController < ActionController::Base
+ def index
+ render :text => "foo"
+ end
+ end
+ RUBY
+
+ controller 'admin/foo', <<-RUBY
+ module Admin
+ class FooController < ActionController::Base
+ def index
+ render :text => "admin::foo"
+ end
+ end
+ end
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match ':controller(/:action)'
+ end
+ RUBY
+
+ get '/foo'
+ assert_equal 'foo', last_response.body
+
+ get '/admin/foo'
+ assert_equal 'admin::foo', last_response.body
+ end
+
+ test "merges with plugin routes" do
+ controller 'foo', <<-RUBY
+ class FooController < ActionController::Base
+ def index
+ render :text => "foo"
+ end
+ end
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match 'foo', :to => 'foo#index'
+ end
+ RUBY
+
+ plugin 'bar', 'require File.dirname(__FILE__) + "/app/controllers/bar"' do |plugin|
+ plugin.write 'app/controllers/bar.rb', <<-RUBY
+ class BarController < ActionController::Base
+ def index
+ render :text => "bar"
+ end
+ end
+ RUBY
+
+ plugin.write 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match 'bar', :to => 'bar#index'
+ end
+ RUBY
+ end
+
+ get '/foo'
+ assert_equal 'foo', last_response.body
+
+ get '/bar'
+ assert_equal 'bar', last_response.body
+ end
+
+ test "reloads routes when configuration is changed" do
+ controller :foo, <<-RUBY
+ class FooController < ActionController::Base
+ def bar
+ render :text => "bar"
+ end
+
+ def baz
+ render :text => "baz"
+ end
+ end
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match 'foo', :to => 'foo#bar'
+ end
+ RUBY
+
+ get '/foo'
+ assert_equal 'bar', last_response.body
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match 'foo', :to => 'foo#baz'
+ end
+ RUBY
+
+ sleep 0.1
+
+ get '/foo'
+ assert_equal 'baz', last_response.body
+ end
+ end
+end
diff --git a/railties/test/fixtures/plugins/engines/engine/config/routes.rb b/railties/test/fixtures/plugins/engines/engine/config/routes.rb
index cca8d1b146..da44595693 100644
--- a/railties/test/fixtures/plugins/engines/engine/config/routes.rb
+++ b/railties/test/fixtures/plugins/engines/engine/config/routes.rb
@@ -1,3 +1,3 @@
ActionController::Routing::Routes.draw do |map|
- map.connect '/engine', :controller => "engine"
+ match '/engine', :to => "engine"
end
diff --git a/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb b/railties/test/fixtures/vendor/plugins/mspec/lib/rails_generators/mspec_generator.rb
index 191bdbf2fc..191bdbf2fc 100644
--- a/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb
+++ b/railties/test/fixtures/vendor/plugins/mspec/lib/rails_generators/mspec_generator.rb
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index 7d03a37f2a..27b6a49566 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -1,8 +1,10 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/app/app_generator'
class ActionsTest < GeneratorsTestCase
+ tests Rails::Generators::AppGenerator
+ arguments [destination_root]
+
def setup
super
@git_plugin_uri = 'git://github.com/technoweenie/restful-authentication.git'
@@ -171,21 +173,13 @@ class ActionsTest < GeneratorsTestCase
def test_route_should_add_data_to_the_routes_block_in_config_routes
run_generator
- route_command = "map.route '/login', :controller => 'sessions', :action => 'new'"
+ route_command = "route '/login', :controller => 'sessions', :action => 'new'"
action :route, route_command
assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/
end
protected
- def run_generator
- silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root] }
- end
-
- def generator(config={})
- @generator ||= Rails::Generators::Base.new([], {}, { :destination_root => destination_root }.merge!(config))
- end
-
def action(*args, &block)
silence(:stdout){ generator.send(*args, &block) }
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 10d0bc6bc2..7dd798db75 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -3,6 +3,7 @@ require 'generators/generators_test_helper'
require 'rails/generators/rails/app/app_generator'
class AppGeneratorTest < GeneratorsTestCase
+ arguments [destination_root]
def setup
super
@@ -49,24 +50,35 @@ class AppGeneratorTest < GeneratorsTestCase
end
def test_invalid_database_option_raises_an_error
- content = capture(:stderr){ run_generator(["-d", "unknown"]) }
+ content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) }
assert_match /Invalid value for \-\-database option/, content
end
+ def test_invalid_application_name_raises_an_error
+ content = capture(:stderr){ Rails::Generators::AppGenerator.start [File.join(destination_root, "43-things")] }
+ assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content
+ end
+
+ def test_invalid_application_name_is_fixed
+ silence(:stdout){ Rails::Generators::AppGenerator.start [File.join(destination_root, "things-43")] }
+ assert_file "things-43/config/environment.rb", /Things43::Application/
+ end
+
def test_config_database_is_added_by_default
run_generator
assert_file "config/database.yml", /sqlite3/
end
def test_config_database_is_not_added_if_skip_activerecord_is_given
- run_generator ["--skip-activerecord"]
+ run_generator [destination_root, "--skip-activerecord"]
assert_no_file "config/database.yml"
end
- def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given
- run_generator ["--skip-activerecord"]
- assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/
- end
+ # TODO: Bring this back using requires
+ # def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given
+ # run_generator ["--skip-activerecord"]
+ # assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/
+ # end
def test_prototype_and_test_unit_are_added_by_default
run_generator
@@ -75,13 +87,13 @@ class AppGeneratorTest < GeneratorsTestCase
end
def test_prototype_and_test_unit_are_skipped_if_required
- run_generator ["--skip-prototype", "--skip-testunit"]
+ run_generator [destination_root, "--skip-prototype", "--skip-testunit"]
assert_no_file "public/javascripts/prototype.js"
assert_no_file "test"
end
def test_shebang_is_added_to_files
- run_generator ["--ruby", "foo/bar/baz"]
+ run_generator [destination_root, "--ruby", "foo/bar/baz"]
%w(
about
@@ -96,7 +108,7 @@ class AppGeneratorTest < GeneratorsTestCase
end
def test_shebang_when_is_the_same_as_default_use_env
- run_generator ["--ruby", Thor::Util.ruby_command]
+ run_generator [destination_root, "--ruby", Thor::Util.ruby_command]
%w(
about
@@ -112,11 +124,11 @@ class AppGeneratorTest < GeneratorsTestCase
def test_template_from_dir_pwd
FileUtils.cd(Rails.root)
- assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"])
+ assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])
end
def test_template_raises_an_error_with_invalid_path
- content = capture(:stderr){ run_generator(["-m", "non/existant/path"]) }
+ content = capture(:stderr){ run_generator([destination_root, "-m", "non/existant/path"]) }
assert_match /The template \[.*\] could not be loaded/, content
assert_match /non\/existant\/path/, content
end
@@ -126,7 +138,7 @@ class AppGeneratorTest < GeneratorsTestCase
template = %{ say "It works!" }
template.instance_eval "def read; self; end" # Make the string respond to read
- generator(:template => path, :database => "sqlite3").expects(:open).with(path).returns(template)
+ generator([destination_root], :template => path, :database => "sqlite3").expects(:open).with(path).returns(template)
assert_match /It works!/, silence(:stdout){ generator.invoke }
end
@@ -149,15 +161,20 @@ class AppGeneratorTest < GeneratorsTestCase
assert_file 'lib/test_file.rb', 'heres test data'
end
- protected
+ def test_dev_option
+ run_generator [destination_root, "--dev"]
+ rails_path = File.expand_path('../../..', Rails.root)
+ dev_gem = %(gem "rails", :path => #{rails_path.inspect})
+ assert_file 'Gemfile', /^#{Regexp.escape(dev_gem)}$/
+ end
- def run_generator(args=[])
- silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root].concat(args) }
- end
+ def test_edge_option
+ run_generator [destination_root, "--edge"]
+ edge_gem = %(gem "rails", :git => "git://github.com/rails/rails.git")
+ assert_file 'Gemfile', /^#{Regexp.escape(edge_gem)}$/
+ end
- def generator(options={})
- @generator ||= Rails::Generators::AppGenerator.new([destination_root], options, :destination_root => destination_root)
- end
+ protected
def action(*args, &block)
silence(:stdout){ generator.send(*args, &block) }
diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb
index 56bc688ad0..8e2fd3b9ed 100644
--- a/railties/test/generators/controller_generator_test.rb
+++ b/railties/test/generators/controller_generator_test.rb
@@ -1,12 +1,12 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/controller/controller_generator'
class ControllerGeneratorTest < GeneratorsTestCase
+ arguments %w(Account foo bar)
def test_help_does_not_show_invoked_generators_options_if_they_already_exist
content = run_generator ["--help"]
- assert_no_match /Helper options:/, content
+ assert_no_match /Helper options\:/, content
end
def test_controller_skeleton_is_created
@@ -66,15 +66,8 @@ class ControllerGeneratorTest < GeneratorsTestCase
run_generator
assert_file "app/controllers/account_controller.rb" do |controller|
- assert_instance_method controller, :foo
- assert_instance_method controller, :bar
+ assert_instance_method :foo, controller
+ assert_instance_method :bar, controller
end
end
-
- protected
-
- def run_generator(args=["Account", "foo", "bar"])
- silence(:stdout) { Rails::Generators::ControllerGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/generator_generator_test.rb b/railties/test/generators/generator_generator_test.rb
index aea3f4da51..28377f23b0 100644
--- a/railties/test/generators/generator_generator_test.rb
+++ b/railties/test/generators/generator_generator_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/generator/generator_generator'
class GeneratorGeneratorTest < GeneratorsTestCase
+ arguments %w(awesome)
def test_generator_skeleton_is_created
run_generator
@@ -16,11 +16,4 @@ class GeneratorGeneratorTest < GeneratorsTestCase
assert_file "lib/generators/awesome/awesome_generator.rb",
/class AwesomeGenerator < Rails::Generators::NamedBase/
end
-
- protected
-
- def run_generator(args=["awesome"], config={})
- silence(:stdout) { Rails::Generators::GeneratorGenerator.start args, config.merge(:destination_root => destination_root) }
- end
-
end
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index 4ce48a453b..fcd0989fd7 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -10,93 +10,19 @@ end
Rails.application.config.root = Rails.root
require 'rails/generators'
+require 'rails/generators/test_case'
+
require 'rubygems'
require 'active_record'
require 'action_dispatch'
-CURRENT_PATH = File.expand_path(Dir.pwd)
-Rails::Generators.no_color!
-
-class GeneratorsTestCase < ActiveSupport::TestCase
- include FileUtils
-
- def destination_root
- File.join(Rails.root, "tmp")
- end
-
- def setup
- cd CURRENT_PATH
- rm_rf(destination_root)
- mkdir_p(destination_root)
- end
-
- def test_truth
- # don't complain, test/unit
- end
-
- def capture(stream)
- begin
- stream = stream.to_s
- eval "$#{stream} = StringIO.new"
- yield
- result = eval("$#{stream}").string
- ensure
- eval("$#{stream} = #{stream.upcase}")
- end
+class GeneratorsTestCase < Rails::Generators::TestCase
+ destination File.join(Rails.root, "tmp")
+ setup :prepare_destination
- result
+ def self.inherited(base)
+ base.tests Rails::Generators.const_get(base.name.sub(/Test$/, ''))
+ rescue
+ # Do nothing.
end
- alias :silence :capture
-
- def assert_file(relative, *contents)
- absolute = File.join(destination_root, relative)
- assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
-
- read = File.read(absolute) if block_given? || !contents.empty?
- yield read if block_given?
-
- contents.each do |content|
- case content
- when String
- assert_equal content, read
- when Regexp
- assert_match content, read
- end
- end
- end
-
- def assert_no_file(relative)
- absolute = File.join(destination_root, relative)
- assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does"
- end
-
- def assert_migration(relative, *contents, &block)
- file_name = migration_file_name(relative)
- assert file_name, "Expected migration #{relative} to exist, but was not found"
- assert_file File.join(File.dirname(relative), file_name), *contents, &block
- end
-
- def assert_no_migration(relative)
- file_name = migration_file_name(relative)
- assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}"
- end
-
- def assert_class_method(content, method, &block)
- assert_instance_method content, "self.#{method}", &block
- end
-
- def assert_instance_method(content, method)
- assert content =~ /def #{method}(\(.+\))?(.*?)\n end/m, "Expected to have method #{method}"
- yield $2.strip if block_given?
- end
-
- protected
-
- def migration_file_name(relative)
- absolute = File.join(destination_root, relative)
- dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
-
- migration = Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
- File.basename(migration) if migration
- end
-end
+end \ No newline at end of file
diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb
index f8bfc517a2..cf18782986 100644
--- a/railties/test/generators/helper_generator_test.rb
+++ b/railties/test/generators/helper_generator_test.rb
@@ -1,4 +1,3 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/helper/helper_generator'
@@ -6,6 +5,7 @@ ObjectHelper = Class.new
AnotherObjectHelperTest = Class.new
class HelperGeneratorTest < GeneratorsTestCase
+ arguments %w(admin)
def test_helper_skeleton_is_created
run_generator
@@ -50,11 +50,4 @@ class HelperGeneratorTest < GeneratorsTestCase
end
end
end
-
- protected
-
- def run_generator(args=["admin"])
- silence(:stdout) { Rails::Generators::HelperGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/integration_test_generator_test.rb b/railties/test/generators/integration_test_generator_test.rb
index 6a504ceea2..88e18be5b2 100644
--- a/railties/test/generators/integration_test_generator_test.rb
+++ b/railties/test/generators/integration_test_generator_test.rb
@@ -1,18 +1,11 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/integration_test/integration_test_generator'
class IntegrationTestGeneratorTest < GeneratorsTestCase
+ arguments %w(integration)
def test_integration_test_skeleton_is_created
run_generator
assert_file "test/integration/integration_test.rb", /class IntegrationTest < ActionController::IntegrationTest/
end
-
- protected
-
- def run_generator(args=["integration"])
- silence(:stdout) { Rails::Generators::IntegrationTestGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb
index 251474ad16..ee4346eb71 100644
--- a/railties/test/generators/mailer_generator_test.rb
+++ b/railties/test/generators/mailer_generator_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/mailer/mailer_generator'
class MailerGeneratorTest < GeneratorsTestCase
+ arguments %w(notifier foo bar)
def test_mailer_skeleton_is_created
run_generator
@@ -42,11 +42,4 @@ class MailerGeneratorTest < GeneratorsTestCase
assert_file "app/models/notifier.rb", /def foo/
assert_file "app/models/notifier.rb", /def bar/
end
-
- protected
-
- def run_generator(args=["notifier", "foo", "bar"])
- silence(:stdout) { Rails::Generators::MailerGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/metal_generator_test.rb b/railties/test/generators/metal_generator_test.rb
index 80bf342892..5d6a277561 100644
--- a/railties/test/generators/metal_generator_test.rb
+++ b/railties/test/generators/metal_generator_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/metal/metal_generator'
class MetalGeneratorTest < GeneratorsTestCase
+ arguments %w(foo)
def test_metal_skeleton_is_created
run_generator
@@ -13,11 +13,4 @@ class MetalGeneratorTest < GeneratorsTestCase
content = capture(:stderr){ run_generator ["object"] }
assert_match /The name 'Object' is either already used in your application or reserved/, content
end
-
- protected
-
- def run_generator(args=["foo"])
- silence(:stdout) { Rails::Generators::MetalGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb
index 35172a8be4..2fd3e5c056 100644
--- a/railties/test/generators/migration_generator_test.rb
+++ b/railties/test/generators/migration_generator_test.rb
@@ -1,32 +1,30 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/migration/migration_generator'
class MigrationGeneratorTest < GeneratorsTestCase
-
def test_migration
- @migration = "change_title_body_from_posts"
- run_generator
- assert_migration "db/migrate/#{@migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/
+ migration = "change_title_body_from_posts"
+ run_generator [migration]
+ assert_migration "db/migrate/#{migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/
end
def test_migration_with_class_name
- @migration = "ChangeTitleBodyFromPosts"
- run_generator
- assert_migration "db/migrate/change_title_body_from_posts.rb", /class #{@migration} < ActiveRecord::Migration/
+ migration = "ChangeTitleBodyFromPosts"
+ run_generator [migration]
+ assert_migration "db/migrate/change_title_body_from_posts.rb", /class #{migration} < ActiveRecord::Migration/
end
def test_add_migration_with_attributes
- @migration = "add_title_body_to_posts"
- run_generator [@migration, "title:string", "body:text"]
+ migration = "add_title_body_to_posts"
+ run_generator [migration, "title:string", "body:text"]
- assert_migration "db/migrate/#{@migration}.rb" do |content|
- assert_class_method content, :up do |up|
+ assert_migration "db/migrate/#{migration}.rb" do |content|
+ assert_class_method :up, content do |up|
assert_match /add_column :posts, :title, :string/, up
assert_match /add_column :posts, :body, :text/, up
end
- assert_class_method content, :down do |down|
+ assert_class_method :down, content do |down|
assert_match /remove_column :posts, :title/, down
assert_match /remove_column :posts, :body/, down
end
@@ -34,26 +32,19 @@ class MigrationGeneratorTest < GeneratorsTestCase
end
def test_remove_migration_with_attributes
- @migration = "remove_title_body_from_posts"
- run_generator [@migration, "title:string", "body:text"]
+ migration = "remove_title_body_from_posts"
+ run_generator [migration, "title:string", "body:text"]
- assert_migration "db/migrate/#{@migration}.rb" do |content|
- assert_class_method content, :up do |up|
+ assert_migration "db/migrate/#{migration}.rb" do |content|
+ assert_class_method :up, content do |up|
assert_match /remove_column :posts, :title/, up
assert_match /remove_column :posts, :body/, up
end
- assert_class_method content, :down do |down|
+ assert_class_method :down, content do |down|
assert_match /add_column :posts, :title, :string/, down
assert_match /add_column :posts, :body, :text/, down
end
end
end
-
- protected
-
- def run_generator(args=[@migration])
- silence(:stdout) { Rails::Generators::MigrationGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb
index e073b11e1e..051a43706b 100644
--- a/railties/test/generators/model_generator_test.rb
+++ b/railties/test/generators/model_generator_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/model/model_generator'
class ModelGeneratorTest < GeneratorsTestCase
+ arguments %w(Account name:string age:integer)
def test_help_shows_invoked_generators_options
content = run_generator ["--help"]
@@ -84,13 +84,13 @@ class ModelGeneratorTest < GeneratorsTestCase
run_generator ["product", "name:string", "supplier_id:integer"]
assert_migration "db/migrate/create_products.rb" do |m|
- assert_class_method m, :up do |up|
+ assert_class_method :up, m do |up|
assert_match /create_table :products/, up
assert_match /t\.string :name/, up
assert_match /t\.integer :supplier_id/, up
end
- assert_class_method m, :down do |down|
+ assert_class_method :down, m do |down|
assert_match /drop_table :products/, down
end
end
@@ -126,7 +126,7 @@ class ModelGeneratorTest < GeneratorsTestCase
run_generator ["account", "--no-timestamps"]
assert_migration "db/migrate/create_accounts.rb" do |m|
- assert_class_method m, :up do |up|
+ assert_class_method :up, m do |up|
assert_no_match /t.timestamps/, up
end
end
@@ -171,11 +171,4 @@ class ModelGeneratorTest < GeneratorsTestCase
content = capture(:stderr){ run_generator ["object"] }
assert_match /The name 'Object' is either already used in your application or reserved/, content
end
-
- protected
-
- def run_generator(args=["Account", "name:string", "age:integer"], config={})
- silence(:stdout) { Rails::Generators::ModelGenerator.start args, config.merge(:destination_root => destination_root) }
- end
-
end
diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb
index 98cbf9b8f6..8c1df3b992 100644
--- a/railties/test/generators/named_base_test.rb
+++ b/railties/test/generators/named_base_test.rb
@@ -1,4 +1,3 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
@@ -13,9 +12,10 @@ module ActiveRecord
end
class NamedBaseTest < GeneratorsTestCase
+ tests Rails::Generators::ScaffoldControllerGenerator
def test_named_generator_attributes
- g = Rails::Generators::ScaffoldControllerGenerator.new ["admin/foo"]
+ g = generator ["admin/foo"]
assert_equal 'admin/foo', g.name
assert_equal %w(admin), g.class_path
assert_equal 1, g.class_nesting_depth
@@ -28,12 +28,12 @@ class NamedBaseTest < GeneratorsTestCase
def test_named_generator_attributes_without_pluralized
ActiveRecord::Base.pluralize_table_names = false
- g = Rails::Generators::ScaffoldControllerGenerator.new ["admin/foo"]
+ g = generator ["admin/foo"]
assert_equal "admin_#{g.singular_name}", g.table_name
end
def test_scaffold_plural_names
- g = Rails::Generators::ScaffoldControllerGenerator.new ["ProductLine"]
+ g = generator ["ProductLine"]
assert_equal "ProductLines", g.controller_name
assert_equal "ProductLines", g.controller_class_name
assert_equal "product_lines", g.controller_file_name
diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb
index 6fed2998dd..44d9e4a9f3 100644
--- a/railties/test/generators/observer_generator_test.rb
+++ b/railties/test/generators/observer_generator_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/observer/observer_generator'
class ObserverGeneratorTest < GeneratorsTestCase
+ arguments %w(account)
def test_invokes_default_orm
run_generator
@@ -23,11 +23,4 @@ class ObserverGeneratorTest < GeneratorsTestCase
content = run_generator ["account", "--test-framework=rspec"]
assert_match /rspec \[not found\]/, content
end
-
- protected
-
- def run_generator(args=["account"])
- silence(:stdout) { Rails::Generators::ObserverGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/performance_test_generator_test.rb b/railties/test/generators/performance_test_generator_test.rb
index d19128f79a..099575ea1d 100644
--- a/railties/test/generators/performance_test_generator_test.rb
+++ b/railties/test/generators/performance_test_generator_test.rb
@@ -1,18 +1,11 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/performance_test/performance_test_generator'
class PerformanceTestGeneratorTest < GeneratorsTestCase
+ arguments %w(performance)
def test_performance_test_skeleton_is_created
run_generator
assert_file "test/performance/performance_test.rb", /class PerformanceTest < ActionController::PerformanceTest/
end
-
- protected
-
- def run_generator(args=["performance"])
- silence(:stdout) { Rails::Generators::PerformanceTestGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index f5b8b6ffb6..f84b8b6d50 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/plugin/plugin_generator'
class PluginGeneratorTest < GeneratorsTestCase
+ arguments %w(plugin_fu)
def test_plugin_skeleton_is_created
run_generator
@@ -46,11 +46,4 @@ class PluginGeneratorTest < GeneratorsTestCase
run_generator
run_generator ["plugin_fu"], :behavior => :revoke
end
-
- protected
-
- def run_generator(args=["plugin_fu"], config={})
- silence(:stdout) { Rails::Generators::PluginGenerator.start args, config.merge(:destination_root => destination_root) }
- end
-
end
diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb
index 886af01b22..15c0ca0f01 100644
--- a/railties/test/generators/resource_generator_test.rb
+++ b/railties/test/generators/resource_generator_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/resource/resource_generator'
class ResourceGeneratorTest < GeneratorsTestCase
+ arguments %w(account)
def setup
super
@@ -50,8 +50,8 @@ class ResourceGeneratorTest < GeneratorsTestCase
run_generator ["account", "--actions", "index", "new"]
assert_file "app/controllers/accounts_controller.rb" do |controller|
- assert_instance_method controller, :index
- assert_instance_method controller, :new
+ assert_instance_method :index, controller
+ assert_instance_method :new, controller
end
assert_file "app/views/accounts/index.html.erb"
@@ -62,7 +62,7 @@ class ResourceGeneratorTest < GeneratorsTestCase
run_generator
assert_file "config/routes.rb" do |route|
- assert_match /map\.resources :accounts$/, route
+ assert_match /resources :accounts$/, route
end
end
@@ -70,7 +70,7 @@ class ResourceGeneratorTest < GeneratorsTestCase
run_generator ["account", "--singleton"]
assert_file "config/routes.rb" do |route|
- assert_match /map\.resource :account$/, route
+ assert_match /resource :account$/, route
end
end
@@ -93,14 +93,7 @@ class ResourceGeneratorTest < GeneratorsTestCase
run_generator ["account"], :behavior => :revoke
assert_file "config/routes.rb" do |route|
- assert_no_match /map\.resources :accounts$/, route
+ assert_no_match /resources :accounts$/, route
end
end
-
- protected
-
- def run_generator(args=["account"], config={})
- silence(:stdout) { Rails::Generators::ResourceGenerator.start args, config.merge(:destination_root => destination_root) }
- end
-
end
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb
index 02155c295c..7593c14dd9 100644
--- a/railties/test/generators/scaffold_controller_generator_test.rb
+++ b/railties/test/generators/scaffold_controller_generator_test.rb
@@ -1,4 +1,3 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
@@ -8,6 +7,7 @@ module Unknown
end
class ScaffoldControllerGeneratorTest < GeneratorsTestCase
+ arguments %w(User name:string age:integer)
def test_controller_skeleton_is_created
run_generator
@@ -15,35 +15,35 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase
assert_file "app/controllers/users_controller.rb" do |content|
assert_match /class UsersController < ApplicationController/, content
- assert_instance_method content, :index do |m|
+ assert_instance_method :index, content do |m|
assert_match /@users = User\.all/, m
end
- assert_instance_method content, :show do |m|
+ assert_instance_method :show, content do |m|
assert_match /@user = User\.find\(params\[:id\]\)/, m
end
- assert_instance_method content, :new do |m|
+ assert_instance_method :new, content do |m|
assert_match /@user = User\.new/, m
end
- assert_instance_method content, :edit do |m|
+ assert_instance_method :edit, content do |m|
assert_match /@user = User\.find\(params\[:id\]\)/, m
end
- assert_instance_method content, :create do |m|
+ assert_instance_method :create, content do |m|
assert_match /@user = User\.new\(params\[:user\]\)/, m
assert_match /@user\.save/, m
assert_match /@user\.errors/, m
end
- assert_instance_method content, :update do |m|
+ assert_instance_method :update, content do |m|
assert_match /@user = User\.find\(params\[:id\]\)/, m
assert_match /@user\.update_attributes\(params\[:user\]\)/, m
assert_match /@user\.errors/, m
end
- assert_instance_method content, :destroy do |m|
+ assert_instance_method :destroy, content do |m|
assert_match /@user = User\.find\(params\[:id\]\)/, m
assert_match /@user\.destroy/, m
end
@@ -108,7 +108,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase
assert_file "app/controllers/users_controller.rb" do |content|
assert_match /class UsersController < ApplicationController/, content
- assert_instance_method content, :index do |m|
+ assert_instance_method :index, content do |m|
assert_match /@users = User\.all/, m
end
end
@@ -127,7 +127,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase
assert_file "app/controllers/users_controller.rb" do |content|
assert_match /class UsersController < ApplicationController/, content
- assert_instance_method content, :index do |m|
+ assert_instance_method :index, content do |m|
assert_match /@users = User\.find\(:all\)/, m
assert_no_match /@users = User\.all/, m
end
@@ -135,11 +135,4 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase
ensure
Unknown::Generators.send :remove_const, :ActiveModel
end
-
- protected
-
- def run_generator(args=["User", "name:string", "age:integer"])
- silence(:stdout) { Rails::Generators::ScaffoldControllerGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index c0652c034f..4ddc7b1c89 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/scaffold/scaffold_generator'
class ScaffoldGeneratorTest < GeneratorsTestCase
+ arguments %w(product_line title:string price:integer)
def setup
super
@@ -25,42 +25,42 @@ class ScaffoldGeneratorTest < GeneratorsTestCase
# Route
assert_file "config/routes.rb" do |route|
- assert_match /map\.resources :product_lines$/, route
+ assert_match /resources :product_lines$/, route
end
# Controller
assert_file "app/controllers/product_lines_controller.rb" do |content|
assert_match /class ProductLinesController < ApplicationController/, content
- assert_instance_method content, :index do |m|
+ assert_instance_method :index, content do |m|
assert_match /@product_lines = ProductLine\.all/, m
end
- assert_instance_method content, :show do |m|
+ assert_instance_method :show, content do |m|
assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m
end
- assert_instance_method content, :new do |m|
+ assert_instance_method :new, content do |m|
assert_match /@product_line = ProductLine\.new/, m
end
- assert_instance_method content, :edit do |m|
+ assert_instance_method :edit, content do |m|
assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m
end
- assert_instance_method content, :create do |m|
+ assert_instance_method :create, content do |m|
assert_match /@product_line = ProductLine\.new\(params\[:product_line\]\)/, m
assert_match /@product_line\.save/, m
assert_match /@product_line\.errors/, m
end
- assert_instance_method content, :update do |m|
+ assert_instance_method :update, content do |m|
assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m
assert_match /@product_line\.update_attributes\(params\[:product_line\]\)/, m
assert_match /@product_line\.errors/, m
end
- assert_instance_method content, :destroy do |m|
+ assert_instance_method :destroy, content do |m|
assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m
assert_match /@product_line\.destroy/, m
end
@@ -89,7 +89,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase
def test_scaffold_on_revoke
run_generator
- run_generator :behavior => :revoke
+ run_generator ["product_line"], :behavior => :revoke
# Model
assert_no_file "app/models/product_line.rb"
@@ -99,7 +99,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase
# Route
assert_file "config/routes.rb" do |route|
- assert_no_match /map\.resources :product_lines$/, route
+ assert_no_match /resources :product_lines$/, route
end
# Controller
@@ -117,14 +117,4 @@ class ScaffoldGeneratorTest < GeneratorsTestCase
# Stylesheets (should not be removed)
assert_file "public/stylesheets/scaffold.css"
end
-
- protected
-
- def run_generator(config={})
- silence(:stdout) do
- Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"],
- config.merge(:destination_root => destination_root)
- end
- end
-
end
diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb
index 34fb996b7f..251ffb19ed 100644
--- a/railties/test/generators/session_migration_generator_test.rb
+++ b/railties/test/generators/session_migration_generator_test.rb
@@ -1,9 +1,7 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/session_migration/session_migration_generator'
class SessionMigrationGeneratorTest < GeneratorsTestCase
-
def test_session_migration_with_default_name
run_generator
assert_migration "db/migrate/add_sessions_table.rb", /class AddSessionsTable < ActiveRecord::Migration/
@@ -24,11 +22,4 @@ class SessionMigrationGeneratorTest < GeneratorsTestCase
ensure
ActiveRecord::SessionStore::Session.table_name = "sessions"
end
-
- protected
-
- def run_generator(args=[])
- silence(:stdout) { Rails::Generators::SessionMigrationGenerator.start args, :destination_root => destination_root }
- end
-
end
diff --git a/railties/test/generators/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb
index 15263d4bb8..d9079327ba 100644
--- a/railties/test/generators/stylesheets_generator_test.rb
+++ b/railties/test/generators/stylesheets_generator_test.rb
@@ -1,9 +1,7 @@
-require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/stylesheets/stylesheets_generator'
class StylesheetsGeneratorTest < GeneratorsTestCase
-
def test_copy_stylesheets
run_generator
assert_file "public/stylesheets/scaffold.css"
@@ -11,14 +9,7 @@ class StylesheetsGeneratorTest < GeneratorsTestCase
def test_stylesheets_are_not_deleted_on_revoke
run_generator
- run_generator :behavior => :revoke
+ run_generator [], :behavior => :revoke
assert_file "public/stylesheets/scaffold.css"
end
-
- protected
-
- def run_generator(config={})
- silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config.merge(:destination_root => destination_root) }
- end
-
end
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index a8716d9992..2df218debc 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -9,6 +9,11 @@ class GeneratorsTest < GeneratorsTestCase
Gem.stubs(:respond_to?).with(:loaded_specs).returns(false)
end
+ def test_invoke_add_generators_to_raw_lookups
+ TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {})
+ Rails::Generators.invoke("test_unit:model", ["Account"])
+ end
+
def test_invoke_when_generator_is_not_found
output = capture(:stdout){ Rails::Generators.invoke :unknown }
assert_equal "Could not find generator unknown.\n", output
@@ -51,12 +56,6 @@ class GeneratorsTest < GeneratorsTestCase
assert_equal "foobar:foobar", klass.namespace
end
- def test_find_by_namespace_add_generators_to_raw_lookups
- klass = Rails::Generators.find_by_namespace("test_unit:model")
- assert klass
- assert_equal "test_unit:generators:model", klass.namespace
- end
-
def test_find_by_namespace_lookup_to_the_rails_root_folder
klass = Rails::Generators.find_by_namespace(:fixjour)
assert klass
@@ -96,7 +95,7 @@ class GeneratorsTest < GeneratorsTestCase
end
def test_builtin_generators
- assert Rails::Generators.builtin.include? %w(rails model)
+ assert Rails::Generators.builtin.include?("rails:model")
end
def test_rails_generators_help_with_builtin_information
@@ -107,7 +106,7 @@ class GeneratorsTest < GeneratorsTestCase
def test_rails_generators_with_others_information
output = capture(:stdout){ Rails::Generators.help }.split("\n").last
- assert_equal "Others: active_record:fixjour, fixjour, foobar, mspec, rails:javascripts.", output
+ assert_equal "Others: active_record:fixjour, fixjour, foobar:foobar, mspec, rails:javascripts, xspec.", output
end
def test_warning_is_shown_if_generator_cant_be_loaded
@@ -150,6 +149,13 @@ class GeneratorsTest < GeneratorsTestCase
assert_equal "test_unit:generators:plugin", klass.namespace
end
+ def test_fallbacks_for_generators_on_find_by_namespace_with_context
+ Rails::Generators.fallbacks[:remarkable] = :test_unit
+ klass = Rails::Generators.find_by_namespace(:remarkable, :rails, :plugin)
+ assert klass
+ assert_equal "test_unit:generators:plugin", klass.namespace
+ end
+
def test_fallbacks_for_generators_on_invoke
Rails::Generators.fallbacks[:shoulda] = :test_unit
TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {})
@@ -171,6 +177,8 @@ class GeneratorsTest < GeneratorsTestCase
end
assert_equal false, klass.class_options[:generate].default
+ ensure
+ Rails::Generators.subclasses.delete(klass)
end
def test_source_paths_for_not_namespaced_generators
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb
index a9e60680ac..e308cbcb0e 100644
--- a/railties/test/initializable_test.rb
+++ b/railties/test/initializable_test.rb
@@ -150,6 +150,16 @@ module InitializableTests
Word.run_initializers
assert_equal "bird", $word
end
+
+ test "creating initializer without a block raises an error" do
+ assert_raise(ArgumentError) do
+ Class.new do
+ include Rails::Initializable
+
+ initializer :foo
+ end
+ end
+ end
end
class BeforeAfter < ActiveSupport::TestCase
diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb
index 97d884e1be..311f19a28a 100644
--- a/railties/test/initializer/check_ruby_version_test.rb
+++ b/railties/test/initializer/check_ruby_version_test.rb
@@ -1,66 +1,32 @@
require "isolation/abstract_unit"
module InitializerTests
- class PathsTest < Test::Unit::TestCase
+ class CheckRubyVersionTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
build_app
boot_rails
- require "rails"
end
- test "rails does not initialize with ruby version 1.8.1" do
- assert_rails_does_not_boot "1.8.1"
- end
-
- test "rails does not initialize with ruby version 1.8.2" do
- assert_rails_does_not_boot "1.8.2"
- end
-
- test "rails does not initialize with ruby version 1.8.3" do
- assert_rails_does_not_boot "1.8.3"
- end
-
- test "rails does not initialize with ruby version 1.8.4" do
- assert_rails_does_not_boot "1.8.4"
- end
-
- test "rails does not initializes with ruby version 1.8.5" do
- assert_rails_does_not_boot "1.8.5"
- end
-
- test "rails does not initialize with ruby version 1.8.6" do
- assert_rails_does_not_boot "1.8.6"
- end
-
- test "rails initializes with ruby version 1.8.7" do
- assert_rails_boots "1.8.7"
- end
-
- test "rails initializes with the current version of Ruby" do
- assert_rails_boots
- end
-
- def set_ruby_version(version)
- $-w = nil
- Object.const_set(:RUBY_VERSION, version.freeze)
+ test "rails initializes with ruby 1.8.7 or later" do
+ if RUBY_VERSION < '1.8.7'
+ assert_rails_does_not_boot
+ else
+ assert_rails_boots
+ end
end
- def assert_rails_boots(version = nil)
- set_ruby_version(version) if version
+ def assert_rails_boots
assert_nothing_raised "It appears that rails does not boot" do
- Rails::Initializer.run { |c| c.frameworks = [] }
- Rails.initialize!
+ require "rails/all"
end
end
- def assert_rails_does_not_boot(version)
- set_ruby_version(version)
+ def assert_rails_does_not_boot
$stderr = File.open("/dev/null", "w")
assert_raises(SystemExit) do
- Rails::Initializer.run { |c| c.frameworks = [] }
- Rails.initialize!
+ require "rails/all"
end
end
end
diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb
index 076816d73b..472566378d 100644
--- a/railties/test/initializer/initialize_i18n_test.rb
+++ b/railties/test/initializer/initialize_i18n_test.rb
@@ -7,16 +7,15 @@ module InitializerTests
def setup
build_app
boot_rails
- require "rails"
end
# test_config_defaults_and_settings_should_be_added_to_i18n_defaults
test "i18n config defaults and settings should be added to i18n defaults" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.i18n.load_path << "my/other/locale.yml"
- end
- Rails.initialize!
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ config.i18n.load_path << "my/other/locale.yml"
+ RUBY
+ require "#{app_path}/config/environment"
#{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml
assert_equal %W(
diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb
index 1b58a58555..bfb1887d11 100644
--- a/railties/test/initializer/path_test.rb
+++ b/railties/test/initializer/path_test.rb
@@ -1,101 +1,103 @@
require "isolation/abstract_unit"
-class PathsTest < Test::Unit::TestCase
- include ActiveSupport::Testing::Isolation
-
- def setup
- build_app
- boot_rails
- require "rails"
- Rails::Initializer.run do |config|
- config.root = app_path
- config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record]
- config.after_initialize do
- ActionController::Base.session_store = nil
- end
+module InitializerTests
+ class PathTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ config.after_initialize do
+ ActionController::Base.session_store = nil
+ end
+ RUBY
+ use_frameworks [:action_controller, :action_view, :action_mailer, :active_record]
+ require "#{app_path}/config/environment"
+ @paths = Rails.application.config.paths
end
- Rails.initialize!
- @paths = Rails.application.config.paths
- end
- def root(*path)
- app_path(*path).to_s
- end
+ def root(*path)
+ app_path(*path).to_s
+ end
- def assert_path(paths, *dir)
- assert_equal [root(*dir)], paths.paths
- end
+ def assert_path(paths, *dir)
+ assert_equal [root(*dir)], paths.paths
+ end
- def assert_in_load_path(*path)
- assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----"
- end
+ def assert_in_load_path(*path)
+ assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----"
+ end
- def assert_not_in_load_path(*path)
- assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----"
- end
+ def assert_not_in_load_path(*path)
+ assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----"
+ end
- test "booting up Rails yields a valid paths object" do
- assert_path @paths.app, "app"
- assert_path @paths.app.metals, "app", "metal"
- assert_path @paths.app.models, "app", "models"
- assert_path @paths.app.helpers, "app", "helpers"
- assert_path @paths.app.services, "app", "services"
- assert_path @paths.lib, "lib"
- assert_path @paths.vendor, "vendor"
- assert_path @paths.vendor.plugins, "vendor", "plugins"
- assert_path @paths.tmp, "tmp"
- assert_path @paths.tmp.cache, "tmp", "cache"
- assert_path @paths.config, "config"
- assert_path @paths.config.locales, "config", "locales"
- assert_path @paths.config.environments, "config", "environments"
-
- assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first
- assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path,
- Pathname.new(@paths.app.controllers.to_a[1]).expand_path
- end
+ test "booting up Rails yields a valid paths object" do
+ assert_path @paths.app, "app"
+ assert_path @paths.app.metals, "app", "metal"
+ assert_path @paths.app.models, "app", "models"
+ assert_path @paths.app.helpers, "app", "helpers"
+ assert_path @paths.app.services, "app", "services"
+ assert_path @paths.lib, "lib"
+ assert_path @paths.vendor, "vendor"
+ assert_path @paths.vendor.plugins, "vendor", "plugins"
+ assert_path @paths.tmp, "tmp"
+ assert_path @paths.tmp.cache, "tmp", "cache"
+ assert_path @paths.config, "config"
+ assert_path @paths.config.locales, "config", "locales"
+ assert_path @paths.config.environments, "config", "environments"
+
+ assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first
+ assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path,
+ Pathname.new(@paths.app.controllers.to_a[1]).expand_path
+ end
- test "booting up Rails yields a list of paths that are eager" do
- assert @paths.app.models.eager_load?
- assert @paths.app.controllers.eager_load?
- assert @paths.app.helpers.eager_load?
- assert @paths.app.metals.eager_load?
- end
+ test "booting up Rails yields a list of paths that are eager" do
+ assert @paths.app.models.eager_load?
+ assert @paths.app.controllers.eager_load?
+ assert @paths.app.helpers.eager_load?
+ assert @paths.app.metals.eager_load?
+ end
- test "environments has a glob equal to the current environment" do
- assert_equal "#{RAILS_ENV}.rb", @paths.config.environments.glob
- end
+ test "environments has a glob equal to the current environment" do
+ assert_equal "#{RAILS_ENV}.rb", @paths.config.environments.glob
+ end
- test "load path includes each of the paths in config.paths as long as the directories exist" do
- assert_in_load_path "app"
- assert_in_load_path "app", "controllers"
- assert_in_load_path "app", "models"
- assert_in_load_path "app", "helpers"
- assert_in_load_path "lib"
- assert_in_load_path "vendor"
-
- assert_not_in_load_path "app", "views"
- assert_not_in_load_path "app", "metal"
- assert_not_in_load_path "app", "services"
- assert_not_in_load_path "config"
- assert_not_in_load_path "config", "locales"
- assert_not_in_load_path "config", "environments"
- assert_not_in_load_path "tmp"
- assert_not_in_load_path "tmp", "cache"
- end
+ test "load path includes each of the paths in config.paths as long as the directories exist" do
+ assert_in_load_path "app"
+ assert_in_load_path "app", "controllers"
+ assert_in_load_path "app", "models"
+ assert_in_load_path "app", "helpers"
+ assert_in_load_path "lib"
+ assert_in_load_path "vendor"
+
+ assert_not_in_load_path "app", "views"
+ assert_not_in_load_path "app", "metal"
+ assert_not_in_load_path "app", "services"
+ assert_not_in_load_path "config"
+ assert_not_in_load_path "config", "locales"
+ assert_not_in_load_path "config", "environments"
+ assert_not_in_load_path "tmp"
+ assert_not_in_load_path "tmp", "cache"
+ end
- test "controller paths include builtin in development mode" do
- RAILS_ENV.replace "development"
- assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
- end
+ test "controller paths include builtin in development mode" do
+ RAILS_ENV.replace "development"
+ assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
+ end
- test "controller paths does not have builtin_directories in test mode" do
- RAILS_ENV.replace "test"
- assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
- end
+ test "controller paths does not have builtin_directories in test mode" do
+ RAILS_ENV.replace "test"
+ assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
+ end
- test "controller paths does not have builtin_directories in production mode" do
- RAILS_ENV.replace "production"
- assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
- end
+ test "controller paths does not have builtin_directories in production mode" do
+ RAILS_ENV.replace "production"
+ assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
+ end
-end \ No newline at end of file
+ end
+end
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index ba8b35d5cc..dc5fddb19d 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -89,6 +89,13 @@ module TestHelpers
end
end
+ routes = File.read("#{app_path}/config/routes.rb")
+ if routes =~ /(\n\s*end\s*)\Z/
+ File.open("#{app_path}/config/routes.rb", 'w') do |f|
+ f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)'\n" + $1
+ end
+ end
+
add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }'
end
@@ -128,7 +135,7 @@ module TestHelpers
def add_to_config(str)
environment = File.read("#{app_path}/config/application.rb")
- if environment =~ /(\n\s*end\s*)\Z/
+ if environment =~ /(\n\s*end\s*end\s*)\Z/
File.open("#{app_path}/config/application.rb", 'w') do |f|
f.puts $` + "\n#{str}\n" + $1
end
@@ -146,6 +153,14 @@ module TestHelpers
app_file("app/controllers/#{name}_controller.rb", contents)
end
+ def use_frameworks(arr)
+ to_remove = [:actionmailer,
+ :activemodel,
+ :activerecord,
+ :activeresource] - arr
+ $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' }
+ end
+
def boot_rails
root = File.expand_path('../../../..', __FILE__)
begin
@@ -192,6 +207,6 @@ Module.new do
`#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f|
f.puts "require '#{environment}'" if require_environment
- f.puts "require 'rails'"
+ f.puts "require 'rails/all'"
end
end
diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb
index 2256b191e2..91f55c2b5e 100644
--- a/railties/test/metal_test.rb
+++ b/railties/test/metal_test.rb
@@ -1,5 +1,4 @@
require 'abstract_unit'
-require 'rails/initializer'
class MetalTest < Test::Unit::TestCase
def test_metals_should_return_list_of_found_metal_apps
diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb
index c724799d64..d60d6177f6 100644
--- a/railties/test/paths_test.rb
+++ b/railties/test/paths_test.rb
@@ -2,7 +2,6 @@ require 'abstract_unit'
require 'rails/paths'
class PathsTest < ActiveSupport::TestCase
-
def setup
@root = Rails::Application::Root.new("/foo/bar")
end
@@ -228,4 +227,4 @@ class PathsTest < ActiveSupport::TestCase
@root.app.eager_load!
assert_equal ["/foo/bar/app"], @root.load_paths
end
-end \ No newline at end of file
+end
diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb
new file mode 100644
index 0000000000..25bf24eb3b
--- /dev/null
+++ b/railties/test/plugins/configuration_test.rb
@@ -0,0 +1,36 @@
+require "isolation/abstract_unit"
+
+module PluginsTest
+ class ConfigurationTest < Test::Unit::TestCase
+ def setup
+ build_app
+ boot_rails
+ require "rails/all"
+ end
+
+ test "config is available to plugins" do
+ class Foo < Rails::Railtie ; end
+ assert_nil Foo.config.action_controller.foo
+ end
+
+ test "a config name is available for the plugin" do
+ class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
+ assert_equal "hello", Foo.config.foo.greetings
+ end
+
+ test "plugin configurations are available in the application" do
+ class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
+ require "#{app_path}/config/application"
+ assert_equal "hello", AppTemplate::Application.config.foo.greetings
+ end
+
+ test "plugin config merges are deep" do
+ class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end
+ class MyApp < Rails::Application
+ config.foo.bar = "bar"
+ end
+ assert_equal "hello", MyApp.config.foo.greetings
+ assert_equal "bar", MyApp.config.foo.bar
+ end
+ end
+end
diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb
new file mode 100644
index 0000000000..c920db77aa
--- /dev/null
+++ b/railties/test/plugins/framework_extension_test.rb
@@ -0,0 +1,52 @@
+require "isolation/abstract_unit"
+
+module PluginsTest
+ class FrameworkExtensionTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
+ require "rails/all"
+ end
+
+ test "rake_tasks block is executed when MyApp.load_tasks is called" do
+ $ran_block = false
+
+ class MyTie < Rails::Railtie
+ rake_tasks do
+ $ran_block = true
+ end
+ end
+
+ require "#{app_path}/config/environment"
+
+ assert !$ran_block
+ require 'rake'
+ require 'rake/testtask'
+ require 'rake/rdoctask'
+
+ AppTemplate::Application.load_tasks
+ assert $ran_block
+ end
+ end
+
+ class ActiveRecordExtensionTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
+ end
+
+ test "active_record extensions are applied to ActiveRecord" do
+ add_to_config "config.active_record.table_name_prefix = 'tbl_'"
+
+ require "#{app_path}/config/environment"
+
+ assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index a0484c0868..435bd34925 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'action_controller'
+require 'action_controller/test_case'
require 'rails/info'
require 'rails/info_controller'
@@ -14,17 +15,12 @@ class InfoControllerTest < ActionController::TestCase
tests Rails::InfoController
def setup
- ActionController::Routing.use_controllers!(['rails/info'])
ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
+ match ':controller/:action'
end
@controller.stubs(:consider_all_requests_local => false, :local_request? => true)
end
- def teardown
- ActionController::Routing.use_controllers! nil
- end
-
test "info controller does not allow remote requests" do
@controller.stubs(:consider_all_requests_local => false, :local_request? => false)
get :properties