aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/console_test.rb4
-rw-r--r--railties/test/application/initializer_test.rb15
-rw-r--r--railties/test/application/notifications_test.rb27
-rw-r--r--railties/test/generators/plugin_generator_test.rb2
-rw-r--r--railties/test/initializable_test.rb28
-rw-r--r--railties/test/initializer/initialize_i18n_test.rb55
-rw-r--r--railties/test/initializer/path_test.rb23
-rw-r--r--railties/test/paths_test.rb27
-rw-r--r--railties/test/plugins/configuration_test.rb6
-rw-r--r--railties/test/plugins/vendored_test.rb154
10 files changed, 208 insertions, 133 deletions
diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb
index e8a4a4e158..22ab60f4a0 100644
--- a/railties/test/application/console_test.rb
+++ b/railties/test/application/console_test.rb
@@ -9,8 +9,8 @@ class ConsoleTest < Test::Unit::TestCase
# Load steps taken from rails/commands/console.rb
require "#{rails_root}/config/environment"
- require 'rails/console_app'
- require 'rails/console_with_helpers'
+ require 'rails/console/app'
+ require 'rails/console/helpers'
end
def test_app_method_should_return_integration_session
diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb
index 754c0f1839..053757979b 100644
--- a/railties/test/application/initializer_test.rb
+++ b/railties/test/application/initializer_test.rb
@@ -29,7 +29,7 @@ module ApplicationTests
add_to_config <<-RUBY
config.root = "#{app_path}"
- config.eager_load_paths = "#{app_path}/lib"
+ config.eager_load_paths << "#{app_path}/lib"
RUBY
require "#{app_path}/config/environment"
@@ -38,13 +38,24 @@ module ApplicationTests
end
test "load environment with global" do
- app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'"
+ app_file "config/environments/development.rb", <<-RUBY
+ $initialize_test_set_from_env = 'success'
+ AppTemplate::Application.configure do
+ config.cache_classes = true
+ config.time_zone = "Brasilia"
+ end
+ RUBY
+
assert_nil $initialize_test_set_from_env
add_to_config <<-RUBY
config.root = "#{app_path}"
+ config.time_zone = "UTC"
RUBY
+
require "#{app_path}/config/environment"
assert_equal "success", $initialize_test_set_from_env
+ assert AppTemplate::Application.config.cache_classes
+ assert_equal "Brasilia", AppTemplate::Application.config.time_zone
end
test "action_controller load paths set only if action controller in use" do
diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb
index db8605edbe..061bb34c19 100644
--- a/railties/test/application/notifications_test.rb
+++ b/railties/test/application/notifications_test.rb
@@ -1,17 +1,6 @@
require "isolation/abstract_unit"
module ApplicationTests
- class MyQueue
- def publish(name, *args)
- raise name
- end
-
- # Not a full queue implementation
- def method_missing(name, *args, &blk)
- self
- end
- end
-
class MockLogger
def method_missing(*args)
@logged ||= []
@@ -39,22 +28,6 @@ module ApplicationTests
ActiveSupport::Notifications.notifier.wait
end
- test "new queue is set" do
- # We don't want to load all frameworks, so remove them and clean up environments.
- use_frameworks []
- FileUtils.rm_rf("#{app_path}/config/environments")
-
- add_to_config <<-RUBY
- config.notifications.notifier = ActiveSupport::Notifications::Notifier.new(ApplicationTests::MyQueue.new)
- RUBY
-
- require "#{app_path}/config/environment"
-
- assert_raise RuntimeError do
- ActiveSupport::Notifications.publish('foo')
- end
- end
-
test "rails subscribers are added" do
add_to_config <<-RUBY
config.colorize_logging = false
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index 0a79e2cfb8..065dbe1423 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -48,7 +48,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase
def test_creates_tasks_if_required
run_generator ["plugin_fu", "--tasks"]
- assert_file "vendor/plugins/plugin_fu/tasks/plugin_fu_tasks.rake"
+ assert_file "vendor/plugins/plugin_fu/lib/tasks/plugin_fu_tasks.rake"
end
def test_creates_generator_if_required
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb
index e308cbcb0e..0c7378cb64 100644
--- a/railties/test/initializable_test.rb
+++ b/railties/test/initializable_test.rb
@@ -10,14 +10,14 @@ module InitializableTests
attr_accessor :foo, :bar
end
- initializer :omg, :global => true do
+ initializer :omg do
@foo ||= 0
@foo += 1
end
end
class Bar < Foo
- initializer :bar, :global => true do
+ initializer :bar do
@bar ||= 0
@bar += 1
end
@@ -26,7 +26,7 @@ module InitializableTests
module Word
include Rails::Initializable
- initializer :word, :global => true do
+ initializer :word do
$word = "bird"
end
end
@@ -34,11 +34,11 @@ module InitializableTests
class Parent
include Rails::Initializable
- initializer :one, :global => true do
+ initializer :one do
$arr << 1
end
- initializer :two, :global => true do
+ initializer :two do
$arr << 2
end
end
@@ -46,17 +46,17 @@ module InitializableTests
class Child < Parent
include Rails::Initializable
- initializer :three, :before => :one, :global => true do
+ initializer :three, :before => :one do
$arr << 3
end
- initializer :four, :after => :one, :global => true do
+ initializer :four, :after => :one do
$arr << 4
end
end
class Parent
- initializer :five, :before => :one, :global => true do
+ initializer :five, :before => :one do
$arr << 5
end
end
@@ -72,11 +72,11 @@ module InitializableTests
$arr << 2
end
- initializer :three, :global => true do
+ initializer :three do
$arr << 3
end
- initializer :four, :global => true do
+ initializer :four do
$arr << 4
end
end
@@ -181,13 +181,7 @@ module InitializableTests
$arr = []
instance = Instance.new
instance.run_initializers
- assert_equal [1, 2], $arr
- end
-
- test "running globals" do
- $arr = []
- Instance.run_initializers
- assert_equal [3, 4], $arr
+ assert_equal [1, 2, 3, 4], $arr
end
end
diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb
deleted file mode 100644
index 472566378d..0000000000
--- a/railties/test/initializer/initialize_i18n_test.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-require "isolation/abstract_unit"
-
-module InitializerTests
- class InitializeI18nTest < Test::Unit::TestCase
- include ActiveSupport::Testing::Isolation
-
- def setup
- build_app
- boot_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
- 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(
- #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml
- #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml
- #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml
- #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml
- #{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml
- my/other/locale.yml
- ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) }
- end
-
- test "i18n finds locale files in engines" do
- # app_file "vendor/plugins/engine/init.rb", ""
- # app_file "vendor/plugins/engine/app/models/hellos.rb", "class Hello ; end"
- # app_file "vendor/plugins/engine/lib/omg.rb", "puts 'omg'"
- # app_file "vendor/plugins/engine/config/locales/en.yml", "hello:"
- #
- # Rails::Initializer.run do |c|
- # c.root = app_path
- # c.i18n.load_path << "my/other/locale.yml"
- # end
- # Rails.initialize!
- #
- # #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml
- # assert_equal %W(
- # #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml
- # #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml
- # #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml
- # #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml
- # #{app_path}/config/locales/en.yml
- # my/other/locale.yml
- # #{app_path}/vendor/plugins/engine/config/locales/en.yml
- # ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) }
- end
- end
-end \ No newline at end of file
diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb
index 328dda6d2c..7a40d7fa6e 100644
--- a/railties/test/initializer/path_test.rb
+++ b/railties/test/initializer/path_test.rb
@@ -8,6 +8,7 @@ module InitializerTests
build_app
boot_rails
FileUtils.rm_rf("#{app_path}/config/environments")
+ app_file "config/environments/development.rb", ""
add_to_config <<-RUBY
config.root = "#{app_path}"
config.after_initialize do
@@ -36,19 +37,17 @@ module InitializerTests
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.app.views, "app", "views"
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_path @paths.config.locales, "config", "locales", "en.yml"
+ assert_path @paths.config.environment, "config", "environments", "development.rb"
assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first
assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path,
@@ -56,27 +55,23 @@ module InitializerTests
end
test "booting up Rails yields a list of paths that are eager" do
- assert @paths.app.models.eager_load?
+ assert @paths.app.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
+ assert_equal "#{Rails.env}.rb", @paths.config.environment.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"
@@ -86,17 +81,17 @@ module InitializerTests
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/ }
+ assert Rails::Application::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/ }
+ assert !Rails::Application::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/ }
+ assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
end
diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb
index d60d6177f6..92c7b2ba0e 100644
--- a/railties/test/paths_test.rb
+++ b/railties/test/paths_test.rb
@@ -3,22 +3,23 @@ require 'rails/paths'
class PathsTest < ActiveSupport::TestCase
def setup
- @root = Rails::Application::Root.new("/foo/bar")
+ File.stubs(:exists?).returns(true)
+ @root = Rails::Paths::Root.new("/foo/bar")
end
test "the paths object is initialized with the root path" do
- root = Rails::Application::Root.new("/fiz/baz")
+ root = Rails::Paths::Root.new("/fiz/baz")
assert_equal "/fiz/baz", root.path
end
test "the paths object can be initialized with nil" do
assert_nothing_raised do
- Rails::Application::Root.new(nil)
+ Rails::Paths::Root.new(nil)
end
end
test "a paths object initialized with nil can be updated" do
- root = Rails::Application::Root.new(nil)
+ root = Rails::Paths::Root.new(nil)
root.app = "app"
root.path = "/root"
assert_equal ["/root/app"], root.app.to_a
@@ -30,7 +31,7 @@ class PathsTest < ActiveSupport::TestCase
end
test "raises exception if root path never set" do
- root = Rails::Application::Root.new(nil)
+ root = Rails::Paths::Root.new(nil)
root.app = "app"
assert_raises RuntimeError do
root.app.to_a
@@ -110,7 +111,7 @@ class PathsTest < ActiveSupport::TestCase
end
test "the root can only have one physical path" do
- assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) }
+ assert_raise(RuntimeError) { Rails::Paths::Root.new(["/fiz", "/biz"]) }
assert_raise(RuntimeError) { @root.push "/biz" }
assert_raise(RuntimeError) { @root.unshift "/biz" }
assert_raise(RuntimeError) { @root.concat ["/biz"]}
@@ -193,12 +194,7 @@ class PathsTest < ActiveSupport::TestCase
assert_equal 2, @root.eager_load.size
end
- test "a path should have a glob that defaults to **/*.rb" do
- @root.app = "/app"
- assert_equal "**/*.rb", @root.app.glob
- end
-
- test "it should be possible to override a path's default glob" do
+ test "it should be possible to add a path's default glob" do
@root.app = "/app"
@root.app.glob = "*.rb"
assert_equal "*.rb", @root.app.glob
@@ -227,4 +223,11 @@ class PathsTest < ActiveSupport::TestCase
@root.app.eager_load!
assert_equal ["/foo/bar/app"], @root.load_paths
end
+
+ test "adding a path to the load once paths also adds it to the load path" do
+ @root.app = "app"
+ @root.app.load_once!
+ assert_equal ["/foo/bar/app"], @root.load_paths
+ end
+
end
diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb
index 09f8943af9..c59040c712 100644
--- a/railties/test/plugins/configuration_test.rb
+++ b/railties/test/plugins/configuration_test.rb
@@ -26,11 +26,11 @@ module PluginsTest
test "plugin config merges are deep" do
class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end
- class MyApp < Rails::Application
+ class Bar < Rails::Railtie
config.foo.bar = "bar"
end
- assert_equal "hello", MyApp.config.foo.greetings
- assert_equal "bar", MyApp.config.foo.bar
+ assert_equal "hello", Bar.config.foo.greetings
+ assert_equal "bar", Bar.config.foo.bar
end
test "plugin can add subscribers" do
diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb
index b3b85891b2..05c01846e1 100644
--- a/railties/test/plugins/vendored_test.rb
+++ b/railties/test/plugins/vendored_test.rb
@@ -17,6 +17,10 @@ module PluginsTest
require "#{app_path}/config/environment"
end
+ def app
+ @app ||= Rails.application
+ end
+
test "it loads the plugin's init.rb file" do
boot_rails
assert_equal "loaded", BUKKITS
@@ -145,6 +149,156 @@ module PluginsTest
response = Rails.application.call(Rack::MockRequest.env_for("/sprokkit"))
assert_equal "I am a Sprokkit", response[2].join
end
+
+ test "tasks are loaded by default" do
+ $executed = false
+ @plugin.write "lib/tasks/foo.rake", <<-RUBY
+ task :foo do
+ $executed = true
+ end
+ RUBY
+
+ boot_rails
+ require 'rake'
+ require 'rake/rdoctask'
+ require 'rake/testtask'
+ Rails.application.load_tasks
+ Rake::Task[:foo].invoke
+ assert $executed
+ end
+
+ test "deprecated tasks are also loaded" do
+ $executed = false
+ @plugin.write "tasks/foo.rake", <<-RUBY
+ task :foo do
+ $executed = true
+ end
+ RUBY
+
+ boot_rails
+ require 'rake'
+ require 'rake/rdoctask'
+ require 'rake/testtask'
+ Rails.application.load_tasks
+ Rake::Task[:foo].invoke
+ assert $executed
+ end
+
+ test "i18n files are added with lower priority than application ones" do
+ add_to_config <<-RUBY
+ config.i18n.load_path << "#{app_path}/app/locales/en.yml"
+ RUBY
+
+ app_file 'app/locales/en.yml', <<-YAML
+en:
+ bar: "1"
+YAML
+
+ app_file 'config/locales/en.yml', <<-YAML
+en:
+ foo: "2"
+ bar: "2"
+YAML
+
+ @plugin.write 'config/locales/en.yml', <<-YAML
+en:
+ foo: "3"
+YAML
+
+ boot_rails
+
+ assert_equal %W(
+ #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml
+ #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml
+ #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml
+ #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml
+ #{app_path}/vendor/plugins/bukkits/config/locales/en.yml
+ #{app_path}/config/locales/en.yml
+ #{app_path}/app/locales/en.yml
+ ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) }
+
+ assert_equal "2", I18n.t(:foo)
+ assert_equal "1", I18n.t(:bar)
+ end
+
+ test "plugin metals are added to the middleware stack" do
+ @plugin.write 'app/metal/foo_metal.rb', <<-RUBY
+ class FooMetal
+ def self.call(env)
+ [200, { "Content-Type" => "text/html"}, ["FooMetal"]]
+ end
+ end
+ RUBY
+
+ boot_rails
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ get "/"
+ assert_equal 200, last_response.status
+ assert_equal "FooMetal", last_response.body
+ end
+
+ test "namespaced controllers with namespaced routes" do
+ @plugin.write "config/routes.rb", <<-RUBY
+ ActionController::Routing::Routes.draw do
+ namespace :admin do
+ match "index", :to => "admin/foo#index"
+ end
+ end
+ RUBY
+
+ @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY
+ class Admin::FooController < ApplicationController
+ def index
+ render :text => "Rendered from namespace"
+ end
+ end
+ RUBY
+
+ boot_rails
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ get "/admin/index"
+ assert_equal 200, last_response.status
+ assert_equal "Rendered from namespace", last_response.body
+ end
+
+ test "plugin with initializers" do
+ $plugin_initializer = false
+ @plugin.write "config/initializers/foo.rb", <<-RUBY
+ $plugin_initializer = true
+ RUBY
+
+ boot_rails
+ assert $plugin_initializer
+ end
+
+ test "plugin cannot declare an engine for it" do
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ class Bukkits
+ class Engine < Rails::Engine
+ end
+ end
+ RUBY
+
+ @plugin.write "init.rb", <<-RUBY
+ require "bukkits"
+ RUBY
+
+ rescued = false
+
+ begin
+ boot_rails
+ rescue Exception => e
+ rescued = true
+ assert_equal '"bukkits" is a Railtie/Engine and cannot be installed as plugin', e.message
+ end
+
+ assert rescued, "Expected boot rails to fail"
+ end
end
class VendoredOrderingTest < Test::Unit::TestCase