From 2df1810cf3cde71fb15594eac022cab27d6497a1 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Thu, 21 Jan 2010 23:30:17 +0700 Subject: Add test case for load initializers before routing behavior. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/test/application/routing_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 725dd06929..50cb9e3acc 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -176,5 +176,33 @@ module ApplicationTests get '/foo' assert_equal 'baz', last_response.body end + + test 'resource routing with irrigular inflection' do + app_file 'config/initializers/inflection.rb', <<-RUBY + ActiveSupport::Inflector.inflections do |inflect| + inflect.irregular 'yazi', 'yazilar' + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do |map| + resources :yazilar + end + RUBY + + controller 'yazilar', <<-RUBY + class YazilarController < ActionController::Base + def index + render :text => 'yazilar#index' + end + end + RUBY + + get '/yazilars' + assert_equal 404, last_response.status + + get '/yazilar' + assert_equal 200, last_response.status + end end end -- cgit v1.2.3 From 02c5137eadbb3530033d919b7aebeb6f4f389b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 01:10:31 +0100 Subject: Add view paths to Engine setup. --- railties/test/application/configuration_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 6968e87986..2c842eb096 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -34,9 +34,9 @@ module ApplicationTests add_to_config <<-RUBY config.root = '#{new_app}' RUBY - + use_frameworks [] - + require "#{app_path}/config/environment" assert_equal Pathname.new(new_app), Rails.application.root end -- cgit v1.2.3 From 4ae79367277954bf6616151b03cbe0660808f9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 16:24:44 +0100 Subject: Got tests working once again. --- railties/test/application/configuration_test.rb | 4 ++-- railties/test/initializer/path_test.rb | 23 ++++++++--------------- railties/test/paths_test.rb | 7 +------ 3 files changed, 11 insertions(+), 23 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 2c842eb096..6968e87986 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -34,9 +34,9 @@ module ApplicationTests add_to_config <<-RUBY config.root = '#{new_app}' RUBY - + use_frameworks [] - + require "#{app_path}/config/environment" assert_equal Pathname.new(new_app), Rails.application.root end diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 328dda6d2c..76eb29bdf4 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,11 +37,8 @@ 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" @@ -48,7 +46,7 @@ module InitializerTests 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.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 +54,22 @@ 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 +79,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::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::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::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..001282bb0d 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -193,12 +193,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 -- cgit v1.2.3 From 98240c49b05093d6d14b9384a9bd695b58eefb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 01:29:29 +0100 Subject: Get rid of initializers global and create i18n railtie. --- railties/test/application/initializer_test.rb | 4 ++-- railties/test/application/notifications_test.rb | 27 ---------------------- railties/test/initializable_test.rb | 28 +++++++++-------------- railties/test/initializer/initialize_i18n_test.rb | 3 ++- railties/test/initializer/path_test.rb | 2 +- 5 files changed, 16 insertions(+), 48 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 754c0f1839..205840360c 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" @@ -132,7 +132,7 @@ module ApplicationTests require "#{app_path}/config/environment" assert_equal [ - "#{app_path}/config/locales/en.yml", "my/other/locale.yml" + "my/other/locale.yml", "#{app_path}/config/locales/en.yml" ], Rails.application.config.i18n.load_path end 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/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 index 472566378d..904d2a6566 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -15,6 +15,7 @@ module InitializerTests 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 @@ -23,8 +24,8 @@ module InitializerTests #{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 + #{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } end diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 76eb29bdf4..4f475fae11 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -45,7 +45,7 @@ module InitializerTests 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.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 -- cgit v1.2.3 From 4eab3aad8d256b868390b739b075bd38661339b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 02:03:11 +0100 Subject: Ensure user set load paths have higher preference and move Bootstrap inside Application. --- railties/test/application/initializer_test.rb | 2 +- railties/test/initializer/initialize_i18n_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 205840360c..6686d82f19 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -132,7 +132,7 @@ module ApplicationTests require "#{app_path}/config/environment" assert_equal [ - "my/other/locale.yml", "#{app_path}/config/locales/en.yml" + "#{app_path}/config/locales/en.yml", "my/other/locale.yml" ], Rails.application.config.i18n.load_path end diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index 904d2a6566..64396bddb4 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -24,8 +24,8 @@ module InitializerTests #{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 - my/other/locale.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 -- cgit v1.2.3 From 924fa084e81b8b2f5ae9eab93d6b711c2b6b89d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 17:13:25 +0100 Subject: First steps into making Plugin < Engine. --- railties/test/paths_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index 001282bb0d..343926340a 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -222,4 +222,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 -- cgit v1.2.3 From b17e358e3df34c03019e357f693611618092e1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 22:30:17 +0100 Subject: Move configuration to subfolders. --- railties/test/initializer/path_test.rb | 6 +++--- railties/test/paths_test.rb | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 4f475fae11..54bdddbdf2 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -79,17 +79,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 343926340a..eafe7a64e1 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -3,22 +3,22 @@ require 'rails/paths' class PathsTest < ActiveSupport::TestCase def setup - @root = Rails::Application::Root.new("/foo/bar") + @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 +30,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 +110,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"]} -- cgit v1.2.3 From d3c40242a58a8863cd216f6639f93df5fdb0c075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 23:02:43 +0100 Subject: Move console stuff to its own directory. --- railties/test/application/console_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') 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 -- cgit v1.2.3 From 2fde9d774b322fc708990675671231c64c691a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 09:00:18 +0100 Subject: Solve some pendencies. --- railties/test/paths_test.rb | 1 + railties/test/plugins/configuration_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index eafe7a64e1..92c7b2ba0e 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -3,6 +3,7 @@ require 'rails/paths' class PathsTest < ActiveSupport::TestCase def setup + File.stubs(:exists?).returns(true) @root = Rails::Paths::Root.new("/foo/bar") 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 -- cgit v1.2.3 From 5b26fa48755c461619f7d48f4cd28faa9db442f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 09:42:28 +0100 Subject: Make plugin generator compatible with new schema. --- railties/test/generators/plugin_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') 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 -- cgit v1.2.3 From 25724c664d8af6c50903709da69a5871475383fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 09:47:55 +0100 Subject: Load deprecated tasks for plugins. --- railties/test/plugins/vendored_test.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'railties/test') diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index b3b85891b2..eae73ee5d8 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -145,6 +145,40 @@ 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 end class VendoredOrderingTest < Test::Unit::TestCase -- cgit v1.2.3 From 5cd9aad4fdf55c591fe8e12657008e83315251d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 10:27:42 +0100 Subject: Add I18n tests to engines. --- railties/test/initializer/initialize_i18n_test.rb | 56 ----------------------- railties/test/plugins/vendored_test.rb | 38 +++++++++++++++ 2 files changed, 38 insertions(+), 56 deletions(-) delete mode 100644 railties/test/initializer/initialize_i18n_test.rb (limited to 'railties/test') diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb deleted file mode 100644 index 64396bddb4..0000000000 --- a/railties/test/initializer/initialize_i18n_test.rb +++ /dev/null @@ -1,56 +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/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index eae73ee5d8..6207cd13c1 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -179,6 +179,44 @@ module PluginsTest 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 + require "#{app_path}/config/environment" + + 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 end class VendoredOrderingTest < Test::Unit::TestCase -- cgit v1.2.3 From e0bdc4f446686a498c3117e27ed8561f5c6d34f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 11:06:06 +0100 Subject: Ensure namespaced controllers in engines work. --- railties/test/plugins/vendored_test.rb | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 6207cd13c1..1fc8766def 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 @@ -202,7 +206,6 @@ en: YAML boot_rails - require "#{app_path}/config/environment" assert_equal %W( #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml @@ -217,6 +220,33 @@ YAML assert_equal "2", I18n.t(:foo) assert_equal "1", I18n.t(:bar) 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 end class VendoredOrderingTest < Test::Unit::TestCase -- cgit v1.2.3 From b92608770e20618ab6a6c67099dd19ae4533689e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 12:15:46 +0100 Subject: Ensure environment config has higher priority than application ones. --- railties/test/application/initializer_test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 6686d82f19..053757979b 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -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 -- cgit v1.2.3 From dd05b6c543f48050f494214da7803da6f5655292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 12:49:12 +0100 Subject: Add tests for plugin sanity check. --- railties/test/plugins/vendored_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'railties/test') diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 1fc8766def..86f3ecd1f7 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -247,6 +247,30 @@ YAML assert_equal 200, last_response.status assert_equal "Rendered from namespace", last_response.body 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 -- cgit v1.2.3 From 84ebfa4550b2325c6c89bc13aa6f904ff88d0db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 14:48:00 +0100 Subject: Ensure metals and initializers in plugins are loaded. --- railties/test/initializer/path_test.rb | 4 +++- railties/test/plugins/vendored_test.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 54bdddbdf2..7a40d7fa6e 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -38,6 +38,7 @@ module InitializerTests test "booting up Rails yields a valid paths object" do assert_path @paths.app.metals, "app", "metal" + assert_path @paths.app.helpers, "app", "helpers" assert_path @paths.app.views, "app", "views" assert_path @paths.lib, "lib" assert_path @paths.vendor, "vendor" @@ -56,7 +57,7 @@ module InitializerTests test "booting up Rails yields a list of paths that are eager" do assert @paths.app.eager_load? assert @paths.app.controllers.eager_load? - assert @paths.app.metals.eager_load? + assert @paths.app.helpers.eager_load? end test "environments has a glob equal to the current environment" do @@ -70,6 +71,7 @@ module InitializerTests assert_in_load_path "lib" assert_in_load_path "vendor" + assert_not_in_load_path "app", "metal" assert_not_in_load_path "config" assert_not_in_load_path "config", "locales" assert_not_in_load_path "config", "environments" diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 86f3ecd1f7..05c01846e1 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -221,6 +221,24 @@ YAML 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 @@ -248,6 +266,16 @@ YAML 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 -- cgit v1.2.3