From d56984c01696348913b298bb65483534035304f0 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 13 Oct 2009 17:47:18 -0700 Subject: Make rails configuration's path object's root lazy --- railties/test/paths_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index d50882110f..c724799d64 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -12,11 +12,32 @@ class PathsTest < ActiveSupport::TestCase 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) + end + end + + test "a paths object initialized with nil can be updated" do + root = Rails::Application::Root.new(nil) + root.app = "app" + root.path = "/root" + assert_equal ["/root/app"], root.app.to_a + end + test "creating a root level path" do @root.app = "/foo/bar" assert_equal ["/foo/bar"], @root.app.to_a end + test "raises exception if root path never set" do + root = Rails::Application::Root.new(nil) + root.app = "app" + assert_raises RuntimeError do + root.app.to_a + end + end + test "creating a root level path without assignment" do @root.app "/foo/bar" assert_equal ["/foo/bar"], @root.app.to_a -- cgit v1.2.3 From ff8be66f249d49e82c8e1d04cb8cfbbc128deabe Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 8 Oct 2009 18:12:28 -0700 Subject: Finish porting over the initializers to the app object and fix all the tests --- railties/test/application/configuration_test.rb | 17 +++++++++++++++++ railties/test/application/generators_test.rb | 2 +- railties/test/generators/generators_test_helper.rb | 9 +++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 railties/test/application/configuration_test.rb (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb new file mode 100644 index 0000000000..1bf59c2b8e --- /dev/null +++ b/railties/test/application/configuration_test.rb @@ -0,0 +1,17 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class InitializerTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + test "the application root is set correctly" do + # require "#{app_path}/config/environment" + # assert_equal app_path, Rails.application.root + end + end +end \ No newline at end of file diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 0d6eb4147a..0edb29483d 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -5,9 +5,9 @@ module ApplicationTests include ActiveSupport::Testing::Isolation def setup - require "rails/generators" build_app boot_rails + require "rails/generators" end test "generators default values" do diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index d917812383..7599bda8a2 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -8,12 +8,17 @@ else RAILS_ROOT = fixtures end +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activemodel/lib" +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib" +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib" $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" +# TODO: Fix this RAILS_ENV stuff +RAILS_ENV = 'test' +require "rails/core" require 'rails/generators' require 'rubygems' -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib" -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib" + require 'active_record' require 'action_dispatch' -- cgit v1.2.3 From bf9819f73d74e19052b7b8a7a9885972a27e8876 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 14 Oct 2009 16:13:45 -0700 Subject: Have Rails.root be based off of config.ru --- railties/test/application/configuration_test.rb | 36 +++++++++++++++++++++++-- railties/test/isolation/abstract_unit.rb | 10 +++++-- 2 files changed, 42 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 1bf59c2b8e..d90582d3db 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -7,11 +7,43 @@ module ApplicationTests def setup build_app boot_rails + Object.send(:remove_const, :RAILS_ROOT) end test "the application root is set correctly" do - # require "#{app_path}/config/environment" - # assert_equal app_path, Rails.application.root + require "#{app_path}/config/environment" + assert_equal app_path, Rails.application.root + end + + test "the application root can be set" do + FileUtils.mkdir_p("#{app_path}/hello") + add_to_config <<-RUBY + config.frameworks = [] + config.root = '#{app_path}/hello' + RUBY + require "#{app_path}/config/environment" + assert_equal "#{app_path}/hello", Rails.application.root + end + + test "the application root is detected as where config.ru is located" do + add_to_config <<-RUBY + config.frameworks = [] + RUBY + FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru" + require "#{app_path}/config/environment" + assert_equal "#{app_path}/config", Rails.application.root + end + + test "the application root is Dir.pwd if there is no config.ru" do + File.delete("#{app_path}/config.ru") + add_to_config <<-RUBY + config.frameworks = [] + RUBY + + Dir.chdir("#{app_path}/app") do + require "#{app_path}/config/environment" + assert_equal "#{app_path}/app", Rails.application.root + end end end end \ No newline at end of file diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index f83e0151a4..245577e8c0 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -25,8 +25,10 @@ module TestHelpers module Paths module_function + TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp])) + def tmp_path(*args) - File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp] + args)) + File.join(TMP_PATH, *args) end def app_path(*args) @@ -88,10 +90,14 @@ module TestHelpers end end + add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' + end + + def add_to_config(str) environment = File.read("#{app_path}/config/environment.rb") if environment =~ /(\n\s*end\s*)\Z/ File.open("#{app_path}/config/environment.rb", 'w') do |f| - f.puts $` + %'\nconfig.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }\n' + $1 + f.puts $` + "\n#{str}\n" + $1 end end end -- cgit v1.2.3 From aeaabc6d2d6f9faaa98057f33c0635d8add54461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 9 Oct 2009 09:17:08 -0300 Subject: Configure Orchestra on initialization. --- railties/test/application/orchestra_test.rb | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 railties/test/application/orchestra_test.rb (limited to 'railties/test') diff --git a/railties/test/application/orchestra_test.rb b/railties/test/application/orchestra_test.rb new file mode 100644 index 0000000000..38a06be741 --- /dev/null +++ b/railties/test/application/orchestra_test.rb @@ -0,0 +1,49 @@ +require "isolation/abstract_unit" +require "active_support/orchestra" + +module ApplicationTests + class OrchestraTest < Test::Unit::TestCase + + class MyQueue + attr_reader :events, :subscribers + + def initialize + @events = [] + @subscribers = [] + end + + def publish(name, payload=nil) + @events << name + end + + def subscribe(pattern=nil, &block) + @subscribers << pattern + end + end + + def setup + build_app + boot_rails + + Rails::Initializer.run do |c| + c.orchestra.queue = MyQueue.new + c.orchestra.subscribe(/listening/) do + puts "Cool" + end + end + end + + test "new queue is set" do + ActiveSupport::Orchestra.instrument(:foo) + assert_equal :foo, ActiveSupport::Orchestra.queue.events.first + end + + test "frameworks subscribers are loaded" do + assert_equal 1, ActiveSupport::Orchestra.queue.subscribers.count { |s| s == "sql" } + end + + test "configuration subscribers are loaded" do + assert_equal 1, ActiveSupport::Orchestra.queue.subscribers.count { |s| s == /listening/ } + end + end +end -- cgit v1.2.3 From 11f9f556b83f90e33ae516cc7a74177a9befdb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 9 Oct 2009 22:22:17 -0300 Subject: Make Orchestra specs run on isolation. --- railties/test/application/orchestra_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/orchestra_test.rb b/railties/test/application/orchestra_test.rb index 38a06be741..fcf073bd6f 100644 --- a/railties/test/application/orchestra_test.rb +++ b/railties/test/application/orchestra_test.rb @@ -1,8 +1,8 @@ require "isolation/abstract_unit" -require "active_support/orchestra" module ApplicationTests class OrchestraTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation class MyQueue attr_reader :events, :subscribers @@ -25,6 +25,7 @@ module ApplicationTests build_app boot_rails + require "active_support/orchestra" Rails::Initializer.run do |c| c.orchestra.queue = MyQueue.new c.orchestra.subscribe(/listening/) do -- cgit v1.2.3 From 2d7abe245e7a2b1717e48ef550e4083318fd7ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Oct 2009 18:51:51 -0300 Subject: Renamed Orchestra to Notifications once again [#3321 state:resolved] --- railties/test/application/notifications_test.rb | 50 +++++++++++++++++++++++++ railties/test/application/orchestra_test.rb | 50 ------------------------- 2 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 railties/test/application/notifications_test.rb delete mode 100644 railties/test/application/orchestra_test.rb (limited to 'railties/test') diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb new file mode 100644 index 0000000000..c861d10c35 --- /dev/null +++ b/railties/test/application/notifications_test.rb @@ -0,0 +1,50 @@ +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, payload=nil) + @events << name + end + + def subscribe(pattern=nil, &block) + @subscribers << pattern + end + end + + def setup + build_app + boot_rails + + require "active_support/notifications" + Rails::Initializer.run do |c| + c.notifications.queue = MyQueue.new + c.notifications.subscribe(/listening/) do + puts "Cool" + end + end + end + + test "new queue is set" do + ActiveSupport::Notifications.instrument(:foo) + assert_equal :foo, ActiveSupport::Notifications.queue.events.first + end + + test "frameworks subscribers are loaded" do + assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == "sql" } + end + + test "configuration subscribers are loaded" do + assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == /listening/ } + end + end +end diff --git a/railties/test/application/orchestra_test.rb b/railties/test/application/orchestra_test.rb deleted file mode 100644 index fcf073bd6f..0000000000 --- a/railties/test/application/orchestra_test.rb +++ /dev/null @@ -1,50 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class OrchestraTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - class MyQueue - attr_reader :events, :subscribers - - def initialize - @events = [] - @subscribers = [] - end - - def publish(name, payload=nil) - @events << name - end - - def subscribe(pattern=nil, &block) - @subscribers << pattern - end - end - - def setup - build_app - boot_rails - - require "active_support/orchestra" - Rails::Initializer.run do |c| - c.orchestra.queue = MyQueue.new - c.orchestra.subscribe(/listening/) do - puts "Cool" - end - end - end - - test "new queue is set" do - ActiveSupport::Orchestra.instrument(:foo) - assert_equal :foo, ActiveSupport::Orchestra.queue.events.first - end - - test "frameworks subscribers are loaded" do - assert_equal 1, ActiveSupport::Orchestra.queue.subscribers.count { |s| s == "sql" } - end - - test "configuration subscribers are loaded" do - assert_equal 1, ActiveSupport::Orchestra.queue.subscribers.count { |s| s == /listening/ } - end - end -end -- cgit v1.2.3 From 97296b11e2c4011ea5522c4de0153f7ffa6a47ae Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 15 Oct 2009 14:50:02 -0700 Subject: Have config/application.rb contain the application definition and require that file instead of config/boot.rb or config/environment.rb in script/*. --- railties/test/abstract_unit.rb | 1 + railties/test/application/generators_test.rb | 4 ++++ railties/test/application/initializer_test.rb | 15 +++++++++++++++ railties/test/application/plugins_test.rb | 15 ++++++++++++--- railties/test/generators/actions_test.rb | 10 +++++----- railties/test/generators/app_generator_test.rb | 2 +- railties/test/initializer/check_ruby_version_test.rb | 2 ++ railties/test/initializer/initialize_i18n_test.rb | 2 ++ railties/test/initializer/path_test.rb | 1 + railties/test/isolation/abstract_unit.rb | 4 ++-- 10 files changed, 45 insertions(+), 11 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 6c6af0b2bf..551468b3e8 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -16,6 +16,7 @@ require 'stringio' require 'test/unit' require 'active_support' +require 'active_support/core_ext/logger' require 'active_support/test_case' require 'action_controller' diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 0edb29483d..c664b61137 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -41,6 +41,8 @@ module ApplicationTests c.generators.orm :datamapper c.generators.test_framework :rspec end + # Initialize the application + Rails.application.new assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] @@ -50,6 +52,8 @@ module ApplicationTests Rails::Initializer.run do |c| c.generators.colorize_logging = false end + # Initialize the application + Rails.application.new assert_equal Thor::Base.shell, Thor::Shell::Basic end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index f46bf2b656..76486d8f2c 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -52,6 +52,8 @@ module ApplicationTests config.eager_load_paths = "#{app_path}/lib" end + Rails.application.new + assert Zoo end @@ -59,6 +61,7 @@ module ApplicationTests app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'" assert_nil $initialize_test_set_from_env Rails::Initializer.run { } + Rails.application.new assert_equal "success", $initialize_test_set_from_env end @@ -67,6 +70,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.frameworks = [] end + Rails.application.new end end @@ -74,6 +78,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.frameworks = [:action_controller] end + Rails.application.new assert $:.include?("#{framework_path}/actionpack/lib") end @@ -82,6 +87,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.frameworks = [:action_view] end + Rails.application.new assert $:.include?("#{framework_path}/actionpack/lib") end @@ -91,6 +97,7 @@ module ApplicationTests config.after_initialize { $test_after_initialize_block1 = "success" } config.after_initialize { $test_after_initialize_block2 = "congratulations" } end + Rails.application.new assert_equal "success", $test_after_initialize_block1 assert_equal "congratulations", $test_after_initialize_block2 @@ -102,6 +109,7 @@ module ApplicationTests config.after_initialize # don't pass a block, this is what we're testing! config.after_initialize { $test_after_initialize_block2 = "congratulations" } end + Rails.application.new assert_equal "success", $test_after_initialize_block1 assert_equal "congratulations", $test_after_initialize_block2 @@ -112,6 +120,8 @@ module ApplicationTests Rails::Initializer.run do |config| config.i18n.default_locale = :de end + Rails.application.new + assert_equal :de, I18n.default_locale end @@ -143,6 +153,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.action_controller.session_store = :cookie_store end + Rails.application.new assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) end @@ -158,6 +169,7 @@ module ApplicationTests Rails::Initializer.run do |c| c.action_controller.session_store = :active_record_store end + Rails.application.new expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] middleware = Rails.application.config.middleware.map { |m| m.klass } @@ -169,6 +181,7 @@ module ApplicationTests c.frameworks -= [:action_controller] c.action_controller.session_store = :active_record_store end + Rails.application.new assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) end @@ -178,6 +191,8 @@ module ApplicationTests Rails::Initializer.run do |c| c.frameworks -= [:action_view] end + Rails.application.new + assert_equal nil, ActionMailer::Base.template_root assert_equal [], ActionController::Base.view_paths end diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb index 81e7f4d88c..a4cf322139 100644 --- a/railties/test/application/plugins_test.rb +++ b/railties/test/application/plugins_test.rb @@ -18,6 +18,7 @@ module ApplicationTests test "all plugins are loaded when registered plugin list is untouched" do Rails::Initializer.run { } + Rails.application.new assert_plugins [ :a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby ], Rails.application.config.loaded_plugins, @failure_tip @@ -31,6 +32,7 @@ module ApplicationTests test "only the specified plugins are located in the order listed" do plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon] Rails::Initializer.run { |c| c.plugins = plugin_names } + Rails.application.new assert_plugins plugin_names, Rails.application.config.loaded_plugins end @@ -38,6 +40,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.plugins = [:stubby, :all, :acts_as_chunky_bacon] end + Rails.application.new assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], Rails.application.config.loaded_plugins, @failure_tip end @@ -46,6 +49,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] end + Rails.application.new assert_plugins plugin_names, Rails.application.config.loaded_plugins, @failure_tip end @@ -54,6 +58,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.plugins = [:stubby, :acts_as_chunky_bacon, :all] end + Rails.application.new assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], Rails.application.config.loaded_plugins, @failure_tip end @@ -62,16 +67,19 @@ module ApplicationTests Rails::Initializer.run do |config| config.plugins = [:stubby, :acts_as_chunky_bacon] end + Rails.application.new assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/stubby/lib") assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/acts/acts_as_chunky_bacon/lib") end test "registering a plugin name that does not exist raises a load error" do + Rails::Initializer.run do |config| + config.plugins = [:stubby, :acts_as_a_non_existant_plugin] + end + assert_raise(LoadError) do - Rails::Initializer.run do |config| - config.plugins = [:stubby, :acts_as_a_non_existant_plugin] - end + Rails.application.new end end @@ -83,6 +91,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2] end + Rails.application.new flunk "Expected a LoadError but did not get one" rescue LoadError => e assert_plugins valid_plugins, Rails.application.config.loaded_plugins, @failure_tip diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index f226e184d1..adc61f6d8a 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -57,7 +57,7 @@ class ActionsTest < GeneratorsTestCase def test_gem_should_put_gem_dependency_in_enviroment run_generator action :gem, 'will-paginate' - assert_file 'config/environment.rb', /config\.gem 'will\-paginate'/ + assert_file 'config/application.rb', /config\.gem 'will\-paginate'/ end def test_gem_with_options_should_include_options_in_gem_dependency_in_environment @@ -65,7 +65,7 @@ class ActionsTest < GeneratorsTestCase action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com' regexp = /#{Regexp.escape("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'")}/ - assert_file 'config/environment.rb', regexp + assert_file 'config/application.rb', regexp end def test_gem_with_env_string_should_put_gem_dependency_in_specified_environment @@ -84,14 +84,14 @@ class ActionsTest < GeneratorsTestCase def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly run_generator action :gem, 'mislav-will-paginate', :lib => false - assert_file 'config/environment.rb', /config\.gem 'mislav\-will\-paginate'\, :lib => false/ + assert_file 'config/application.rb', /config\.gem 'mislav\-will\-paginate'\, :lib => false/ end def test_environment_should_include_data_in_environment_initializer_block run_generator load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]' action :environment, load_paths - assert_file 'config/environment.rb', /#{Regexp.escape(load_paths)}/ + assert_file 'config/application.rb', /#{Regexp.escape(load_paths)}/ end def test_environment_with_block_should_include_block_contents_in_environment_initializer_block @@ -102,7 +102,7 @@ class ActionsTest < GeneratorsTestCase '# This will be added' end - assert_file 'config/environment.rb' do |content| + assert_file 'config/application.rb' do |content| assert_match /# This will be added/, content assert_no_match /# This wont be added/, content end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 6e46c4ddc0..5d6a9f6de9 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -65,7 +65,7 @@ class AppGeneratorTest < GeneratorsTestCase def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given run_generator ["--skip-activerecord"] - assert_file "config/environment.rb", /config\.frameworks \-= \[ :active_record \]/ + assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/ end def test_prototype_and_test_unit_are_added_by_default diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 1852fea4df..6c32f5635b 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -42,6 +42,7 @@ module InitializerTests set_ruby_version(version) assert_nothing_raised "It appears that rails does not boot" do Rails::Initializer.run { |c| c.frameworks = [] } + Rails.application.new end end @@ -50,6 +51,7 @@ module InitializerTests $stderr = File.open("/dev/null", "w") assert_raises(SystemExit) do Rails::Initializer.run { |c| c.frameworks = [] } + Rails.application.new end end end diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index e909688817..f952d06f94 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -14,6 +14,7 @@ module InitializerTests Rails::Initializer.run do |c| c.i18n.load_path << "my/other/locale.yml" end + Rails.application.new #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml assert_equal %W( @@ -35,6 +36,7 @@ module InitializerTests Rails::Initializer.run do |c| c.i18n.load_path << "my/other/locale.yml" end + Rails.application.new #{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 72ff8d88e0..ce8fc4b8b0 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -12,6 +12,7 @@ class PathsTest < Test::Unit::TestCase ActionController::Base.session_store = nil end end + Rails.application.new @paths = Rails.application.config.paths end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 245577e8c0..5bc878b3be 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -94,9 +94,9 @@ module TestHelpers end def add_to_config(str) - environment = File.read("#{app_path}/config/environment.rb") + environment = File.read("#{app_path}/config/application.rb") if environment =~ /(\n\s*end\s*)\Z/ - File.open("#{app_path}/config/environment.rb", 'w') do |f| + File.open("#{app_path}/config/application.rb", 'w') do |f| f.puts $` + "\n#{str}\n" + $1 end end -- cgit v1.2.3 From b0f55dc1f82b3d4fc56d44133b10926be3efa607 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 15 Oct 2009 21:51:24 -0700 Subject: Remove framework subscriber tests which depends on AR, which isn't loaded --- railties/test/application/notifications_test.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index c861d10c35..0fdb4a083a 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -39,10 +39,6 @@ module ApplicationTests assert_equal :foo, ActiveSupport::Notifications.queue.events.first end - test "frameworks subscribers are loaded" do - assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == "sql" } - end - test "configuration subscribers are loaded" do assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == /listening/ } end -- cgit v1.2.3 From 2110a524a4913815d036786aa01319fd67db0ee2 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 16 Oct 2009 12:49:39 -0700 Subject: Deprecate RAILS_ROOT in favor of Rails.root (which proxies to the application's object root) --- railties/test/abstract_unit.rb | 10 ++--- railties/test/application/configuration_test.rb | 8 ++-- railties/test/application/generators_test.rb | 2 + railties/test/application/initializer_test.rb | 45 +++++++++++++++------- railties/test/application/plugins_test.rb | 12 ++++-- railties/test/backtrace_cleaner_test.rb | 2 - railties/test/boot_test.rb | 1 - railties/test/generators/generators_test_helper.rb | 20 ++-------- railties/test/initializer/initialize_i18n_test.rb | 2 + railties/test/initializer/path_test.rb | 1 + railties/test/initializer_test.rb | 20 ---------- 11 files changed, 58 insertions(+), 65 deletions(-) delete mode 100644 railties/test/initializer_test.rb (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 551468b3e8..8010481609 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -14,15 +14,15 @@ $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" require 'stringio' require 'test/unit' +require 'fileutils' require 'active_support' require 'active_support/core_ext/logger' require 'active_support/test_case' require 'action_controller' +require 'rails' -if defined?(RAILS_ROOT) - RAILS_ROOT.replace File.dirname(__FILE__) -else - RAILS_ROOT = File.dirname(__FILE__) -end +Rails::Initializer.run do |config| + config.root = File.dirname(__FILE__) +end \ No newline at end of file diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index d90582d3db..0452208cae 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -12,7 +12,7 @@ module ApplicationTests test "the application root is set correctly" do require "#{app_path}/config/environment" - assert_equal app_path, Rails.application.root + assert_equal Pathname.new(app_path), Rails.application.root end test "the application root can be set" do @@ -22,7 +22,7 @@ module ApplicationTests config.root = '#{app_path}/hello' RUBY require "#{app_path}/config/environment" - assert_equal "#{app_path}/hello", Rails.application.root + assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root end test "the application root is detected as where config.ru is located" do @@ -31,7 +31,7 @@ module ApplicationTests RUBY FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru" require "#{app_path}/config/environment" - assert_equal "#{app_path}/config", Rails.application.root + assert_equal Pathname.new("#{app_path}/config"), Rails.application.root end test "the application root is Dir.pwd if there is no config.ru" do @@ -42,7 +42,7 @@ module ApplicationTests Dir.chdir("#{app_path}/app") do require "#{app_path}/config/environment" - assert_equal "#{app_path}/app", Rails.application.root + assert_equal Pathname.new("#{app_path}/app"), Rails.application.root end end end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index c664b61137..25c82578a3 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -37,6 +37,7 @@ module ApplicationTests 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 @@ -50,6 +51,7 @@ module ApplicationTests test "generators no color on initialization" do Rails::Initializer.run do |c| + c.frameworks = [] c.generators.colorize_logging = false end # Initialize the application diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 76486d8f2c..805ff8b6be 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -10,33 +10,38 @@ module ApplicationTests end test "initializing an application initializes rails" do - class MyApp < Rails::Application ; end + Rails::Initializer.run do |config| + config.root = app_path + end if RUBY_VERSION < '1.9' $KCODE = '' - MyApp.new + Rails.application.new assert_equal 'UTF8', $KCODE else Encoding.default_external = Encoding::US_ASCII - MyApp.new + Rails.application.new assert_equal Encoding::UTF_8, Encoding.default_external end end test "initializing an application adds the application paths to the load path" do - class MyApp < Rails::Application ; end + Rails::Initializer.run do |config| + config.root = app_path + end - MyApp.new + Rails.application.new assert $:.include?("#{app_path}/app/models") end test "adding an unknown framework raises an error" do - class MyApp < Rails::Application + Rails::Initializer.run do |config| + config.root = app_path config.frameworks << :action_foo end assert_raises RuntimeError do - MyApp.new + Rails.application.new end end @@ -49,6 +54,7 @@ module ApplicationTests ZOO Rails::Initializer.run do |config| + config.root = app_path config.eager_load_paths = "#{app_path}/lib" end @@ -60,7 +66,7 @@ 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 { } + Rails::Initializer.run { |config| config.root = app_path } Rails.application.new assert_equal "success", $initialize_test_set_from_env end @@ -68,6 +74,7 @@ module ApplicationTests 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.application.new @@ -76,6 +83,7 @@ module ApplicationTests test "action_pack is added to the load path if action_controller is required" do Rails::Initializer.run do |config| + config.root = app_path config.frameworks = [:action_controller] end Rails.application.new @@ -85,6 +93,7 @@ module ApplicationTests test "action_pack is added to the load path if action_view is required" do Rails::Initializer.run do |config| + config.root = app_path config.frameworks = [:action_view] end Rails.application.new @@ -94,6 +103,7 @@ module ApplicationTests test "after_initialize block works correctly" do Rails::Initializer.run do |config| + config.root = app_path config.after_initialize { $test_after_initialize_block1 = "success" } config.after_initialize { $test_after_initialize_block2 = "congratulations" } end @@ -105,6 +115,7 @@ module ApplicationTests test "after_initialize block works correctly when no block is passed" do Rails::Initializer.run do |config| + 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" } @@ -118,6 +129,7 @@ module ApplicationTests # i18n test "setting another default locale" do Rails::Initializer.run do |config| + config.root = app_path config.i18n.default_locale = :de end Rails.application.new @@ -128,18 +140,21 @@ module ApplicationTests 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 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 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 @@ -151,6 +166,7 @@ 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 config.action_controller.session_store = :cookie_store end Rails.application.new @@ -160,6 +176,7 @@ module ApplicationTests 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 @@ -167,6 +184,7 @@ module ApplicationTests 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.application.new @@ -178,6 +196,7 @@ module ApplicationTests 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 @@ -189,6 +208,7 @@ module ApplicationTests # 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.application.new @@ -197,12 +217,11 @@ module ApplicationTests assert_equal [], ActionController::Base.view_paths end - # Rails root test - test "Rails.root == RAILS_ROOT" do - assert_equal RAILS_ROOT, Rails.root.to_s - end - test "Rails.root should be a Pathname" do + Rails::Initializer.run do |c| + c.root = app_path + end + Rails.application.new assert_instance_of Pathname, Rails.root end end diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb index a4cf322139..6ea6d49460 100644 --- a/railties/test/application/plugins_test.rb +++ b/railties/test/application/plugins_test.rb @@ -17,7 +17,7 @@ module ApplicationTests end test "all plugins are loaded when registered plugin list is untouched" do - Rails::Initializer.run { } + Rails::Initializer.run { |c| c.root = app_path } Rails.application.new assert_plugins [ :a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby @@ -25,19 +25,20 @@ module ApplicationTests end test "no plugins are loaded if the configuration has an empty plugin list" do - Rails::Initializer.run { |c| c.plugins = [] } + Rails::Initializer.run { |c| c.root = app_path; c.plugins = [] } assert_plugins [], Rails.application.config.loaded_plugins end test "only the specified plugins are located in the order listed" do plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon] - Rails::Initializer.run { |c| c.plugins = plugin_names } + Rails::Initializer.run { |c| c.root = app_path; c.plugins = plugin_names } Rails.application.new assert_plugins plugin_names, Rails.application.config.loaded_plugins end test "all plugins loaded after all" do Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :all, :acts_as_chunky_bacon] end Rails.application.new @@ -47,6 +48,7 @@ module ApplicationTests test "plugin names may be strings" do plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] Rails::Initializer.run do |config| + config.root = app_path config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] end Rails.application.new @@ -56,6 +58,7 @@ module ApplicationTests test "all plugins loaded when all is used" do Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon, :all] end Rails.application.new @@ -65,6 +68,7 @@ module ApplicationTests test "all loaded plugins are added to the load paths" do Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon] end Rails.application.new @@ -75,6 +79,7 @@ module ApplicationTests test "registering a plugin name that does not exist raises a load error" do Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :acts_as_a_non_existant_plugin] end @@ -89,6 +94,7 @@ module ApplicationTests begin Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2] end Rails.application.new diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index c3e4f970fe..f9b9d3168d 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -1,6 +1,4 @@ require 'abstract_unit' - -require 'rails/initializer' require 'rails/backtrace_cleaner' if defined? Test::Unit::Util::BacktraceFilter diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb index 1280d27ffe..46ef01f54c 100644 --- a/railties/test/boot_test.rb +++ b/railties/test/boot_test.rb @@ -57,7 +57,6 @@ class VendorBootTest < Test::Unit::TestCase boot = VendorBoot.new boot.expects(:require).with("rails") boot.expects(:install_gem_spec_stubs) - Rails::GemDependency.expects(:add_frozen_gem_path) boot.load_initializer end end diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index 7599bda8a2..ccf08c347c 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -1,24 +1,10 @@ -require 'test/unit' -require 'fileutils' - -fixtures = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) -if defined?(RAILS_ROOT) - RAILS_ROOT.replace fixtures -else - RAILS_ROOT = fixtures -end - -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activemodel/lib" -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib" -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib" -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" # TODO: Fix this RAILS_ENV stuff RAILS_ENV = 'test' -require "rails/core" -require 'rails/generators' +require 'abstract_unit' +Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) +require 'rails/generators' require 'rubygems' - require 'active_record' require 'action_dispatch' diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index f952d06f94..5d921cb21a 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -12,6 +12,7 @@ module InitializerTests # 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.application.new @@ -34,6 +35,7 @@ module InitializerTests 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.application.new diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index ce8fc4b8b0..29acbdbd25 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -7,6 +7,7 @@ class PathsTest < Test::Unit::TestCase build_app boot_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 diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb deleted file mode 100644 index 80e774b7b7..0000000000 --- a/railties/test/initializer_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'abstract_unit' -require 'rails/initializer' -require 'rails/generators' - -require 'action_view' -require 'action_mailer' -require 'active_record' - -require 'plugin_test_helper' - -class RailsRootTest < Test::Unit::TestCase - def test_rails_dot_root_equals_rails_root - assert_equal RAILS_ROOT, Rails.root.to_s - end - - def test_rails_dot_root_should_be_a_pathname - assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s - end -end - -- cgit v1.2.3 From c296b33ef1ca9f2d576104e3938bd21afba02377 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 16 Oct 2009 16:31:05 -0700 Subject: Make the railties tests pass --- railties/test/boot_test.rb | 171 ------------------------------- railties/test/isolation/abstract_unit.rb | 2 +- 2 files changed, 1 insertion(+), 172 deletions(-) delete mode 100644 railties/test/boot_test.rb (limited to 'railties/test') diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb deleted file mode 100644 index 46ef01f54c..0000000000 --- a/railties/test/boot_test.rb +++ /dev/null @@ -1,171 +0,0 @@ -require 'abstract_unit' -require 'rails/initializer' -require "#{File.dirname(__FILE__)}/../lib/rails/generators/rails/app/templates/config/boot" -require 'rails/gem_dependency' - -class BootTest < Test::Unit::TestCase - def test_boot_returns_if_booted - Rails.expects(:booted?).returns(true) - Rails.expects(:pick_boot).never - assert_nil Rails.boot! - end - - def test_boot_preinitializes_then_picks_and_runs_if_not_booted - Rails.expects(:booted?).returns(false) - Rails.expects(:preinitialize) - Rails.expects(:pick_boot).returns(mock(:run => 'result')) - assert_equal 'result', Rails.boot! - end - - def test_preinitialize_does_not_raise_exception_if_preinitializer_file_does_not_exist - Rails.stubs(:preinitializer_path).returns('/there/is/no/such/file') - - assert_nothing_raised { Rails.preinitialize } - end - - def test_load_preinitializer_loads_preinitializer_file - Rails.stubs(:preinitializer_path).returns("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb") - - assert_nil $initialize_test_set_from_env - Rails.preinitialize - assert_equal "success", $initialize_test_set_from_env - ensure - $initialize_test_set_from_env = nil - end - - def test_boot_vendor_rails_by_default - Rails.expects(:booted?).returns(false) - Rails.expects(:preinitialize) - File.expects(:exist?).with("#{RAILS_ROOT}/vendor/rails").returns(true) - Rails::VendorBoot.any_instance.expects(:run).returns('result') - assert_equal 'result', Rails.boot! - end - - def test_boot_gem_rails_otherwise - Rails.expects(:booted?).returns(false) - Rails.expects(:preinitialize) - File.expects(:exist?).with("#{RAILS_ROOT}/vendor/rails").returns(false) - Rails::GemBoot.any_instance.expects(:run).returns('result') - assert_equal 'result', Rails.boot! - end -end - -class VendorBootTest < Test::Unit::TestCase - include Rails - - def test_load_initializer_requires_from_vendor_rails - boot = VendorBoot.new - boot.expects(:require).with("rails") - boot.expects(:install_gem_spec_stubs) - boot.load_initializer - end -end - -class GemBootTest < Test::Unit::TestCase - include Rails - - def test_load_initializer_loads_rubygems_and_the_rails_gem - boot = GemBoot.new - GemBoot.expects(:load_rubygems) - boot.expects(:load_rails_gem) - boot.expects(:require).with('rails') - boot.load_initializer - end - - def test_load_rubygems_exits_with_error_if_missing - GemBoot.expects(:require).with('rubygems').raises(LoadError, 'missing rubygems') - STDERR.expects(:puts) - GemBoot.expects(:exit).with(1) - GemBoot.load_rubygems - end - - def test_load_rubygems_exits_with_error_if_too_old - GemBoot.stubs(:rubygems_version).returns('0.0.1') - GemBoot.expects(:require).with('rubygems').returns(true) - STDERR.expects(:puts) - GemBoot.expects(:exit).with(1) - GemBoot.load_rubygems - end - - def test_load_rails_gem_activates_specific_gem_if_version_given - GemBoot.stubs(:gem_version).returns('0.0.1') - - boot = GemBoot.new - boot.expects(:gem).with('rails', '0.0.1') - boot.load_rails_gem - end - - def test_load_rails_gem_activates_latest_gem_if_no_version_given - GemBoot.stubs(:gem_version).returns(nil) - - boot = GemBoot.new - boot.expects(:gem).with('rails') - boot.load_rails_gem - end - - def test_load_rails_gem_exits_with_error_if_missing - GemBoot.stubs(:gem_version).returns('0.0.1') - - boot = GemBoot.new - boot.expects(:gem).with('rails', '0.0.1').raises(Gem::LoadError, 'missing rails 0.0.1 gem') - STDERR.expects(:puts) - boot.expects(:exit).with(1) - boot.load_rails_gem - end -end - -class ParseGemVersionTest < Test::Unit::TestCase - def test_should_return_nil_if_no_lines_are_passed - assert_equal nil, parse('') - assert_equal nil, parse(nil) - end - - def test_should_accept_either_single_or_double_quotes - assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'") - assert_equal "1.2.3", parse('RAILS_GEM_VERSION = "1.2.3"') - end - - def test_should_return_nil_if_no_lines_match - assert_equal nil, parse('nothing matches on this line\nor on this line') - end - - def test_should_parse_with_no_leading_space - assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION") - assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'") - end - - def test_should_parse_with_any_number_of_leading_spaces - assert_equal nil, parse([]) - assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION") - assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION") - assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3'") - assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3'") - end - - def test_should_ignore_unrelated_comments - assert_equal "1.2.3", parse("# comment\nRAILS_GEM_VERSION = '1.2.3'\n# comment") - end - - def test_should_ignore_commented_version_lines - assert_equal "1.2.3", parse("#RAILS_GEM_VERSION = '9.8.7'\nRAILS_GEM_VERSION = '1.2.3'") - assert_equal "1.2.3", parse("# RAILS_GEM_VERSION = '9.8.7'\nRAILS_GEM_VERSION = '1.2.3'") - assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'\n# RAILS_GEM_VERSION = '9.8.7'") - end - - def test_should_allow_advanced_rubygems_version_specifications - # See http://rubygems.org/read/chapter/16 - assert_equal "=1.2.3", parse("RAILS_GEM_VERSION = '=1.2.3'") # equal sign - assert_equal "= 1.2.3", parse("RAILS_GEM_VERSION = '= 1.2.3'") # with space - assert_equal "!=1.2.3", parse("RAILS_GEM_VERSION = '!=1.2.3'") # not equal - assert_equal ">1.2.3", parse("RAILS_GEM_VERSION = '>1.2.3'") # greater than - assert_equal "<1.2.3", parse("RAILS_GEM_VERSION = '<1.2.3'") # less than - assert_equal ">=1.2.3", parse("RAILS_GEM_VERSION = '>=1.2.3'") # greater than or equal - assert_equal "<=1.2.3", parse("RAILS_GEM_VERSION = '<=1.2.3'") # less than or equal - assert_equal "~>1.2.3.0", parse("RAILS_GEM_VERSION = '~>1.2.3.0'") # approximately greater than - end - - private - def parse(text) - Rails::GemBoot.parse_gem_version(text) - end -end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 5bc878b3be..750ec5d319 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -120,7 +120,7 @@ module TestHelpers Initializer = 'lol' require "#{app_path}/config/boot" remove_const(:Initializer) - booter = VendorBoot.new + booter = VendorBoot.new('#{app_path}') booter.run end RUBY -- cgit v1.2.3 From 3971d972c304272dbbd88d5d5df14b5739e801a2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 16 Oct 2009 18:42:55 -0500 Subject: Expand paths in i18n initializer tests --- railties/test/initializer/initialize_i18n_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index 5d921cb21a..92ac1312bf 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -25,7 +25,7 @@ module InitializerTests #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml my/other/locale.yml - ), I18n.load_path + ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } end test "i18n finds locale files in engines" do @@ -49,7 +49,7 @@ module InitializerTests #{app_path}/config/locales/en.yml my/other/locale.yml #{app_path}/vendor/plugins/engine/config/locales/en.yml - ), I18n.load_path + ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } end end end \ No newline at end of file -- cgit v1.2.3 From d8594026962704b6b51e188a29406fbd22bb31ce Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 16 Oct 2009 18:58:35 -0500 Subject: Use Rails.initialize! where we just want to run the initializers and aren't concerned about the config --- railties/test/application/generators_test.rb | 4 +-- railties/test/application/initializer_test.rb | 34 +++++++++++----------- railties/test/application/plugins_test.rb | 18 ++++++------ .../test/initializer/check_ruby_version_test.rb | 4 +-- railties/test/initializer/initialize_i18n_test.rb | 4 +-- railties/test/initializer/path_test.rb | 2 +- 6 files changed, 33 insertions(+), 33 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 25c82578a3..03fecffdd0 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -43,7 +43,7 @@ module ApplicationTests c.generators.test_framework :rspec end # Initialize the application - Rails.application.new + Rails.initialize! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] @@ -55,7 +55,7 @@ module ApplicationTests c.generators.colorize_logging = false end # Initialize the application - Rails.application.new + Rails.initialize! assert_equal Thor::Base.shell, Thor::Shell::Basic end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 805ff8b6be..c2e64374d0 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -16,11 +16,11 @@ module ApplicationTests if RUBY_VERSION < '1.9' $KCODE = '' - Rails.application.new + Rails.initialize! assert_equal 'UTF8', $KCODE else Encoding.default_external = Encoding::US_ASCII - Rails.application.new + Rails.initialize! assert_equal Encoding::UTF_8, Encoding.default_external end end @@ -30,7 +30,7 @@ module ApplicationTests config.root = app_path end - Rails.application.new + Rails.initialize! assert $:.include?("#{app_path}/app/models") end @@ -41,7 +41,7 @@ module ApplicationTests end assert_raises RuntimeError do - Rails.application.new + Rails.initialize! end end @@ -58,7 +58,7 @@ module ApplicationTests config.eager_load_paths = "#{app_path}/lib" end - Rails.application.new + Rails.initialize! assert Zoo end @@ -67,7 +67,7 @@ module ApplicationTests 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.application.new + Rails.initialize! assert_equal "success", $initialize_test_set_from_env end @@ -77,7 +77,7 @@ module ApplicationTests config.root = app_path config.frameworks = [] end - Rails.application.new + Rails.initialize! end end @@ -86,7 +86,7 @@ module ApplicationTests config.root = app_path config.frameworks = [:action_controller] end - Rails.application.new + Rails.initialize! assert $:.include?("#{framework_path}/actionpack/lib") end @@ -96,7 +96,7 @@ module ApplicationTests config.root = app_path config.frameworks = [:action_view] end - Rails.application.new + Rails.initialize! assert $:.include?("#{framework_path}/actionpack/lib") end @@ -107,7 +107,7 @@ module ApplicationTests config.after_initialize { $test_after_initialize_block1 = "success" } config.after_initialize { $test_after_initialize_block2 = "congratulations" } end - Rails.application.new + Rails.initialize! assert_equal "success", $test_after_initialize_block1 assert_equal "congratulations", $test_after_initialize_block2 @@ -120,7 +120,7 @@ module ApplicationTests config.after_initialize # don't pass a block, this is what we're testing! config.after_initialize { $test_after_initialize_block2 = "congratulations" } end - Rails.application.new + Rails.initialize! assert_equal "success", $test_after_initialize_block1 assert_equal "congratulations", $test_after_initialize_block2 @@ -132,7 +132,7 @@ module ApplicationTests config.root = app_path config.i18n.default_locale = :de end - Rails.application.new + Rails.initialize! assert_equal :de, I18n.default_locale end @@ -169,7 +169,7 @@ module ApplicationTests config.root = app_path config.action_controller.session_store = :cookie_store end - Rails.application.new + Rails.initialize! assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) end @@ -187,7 +187,7 @@ module ApplicationTests c.root = app_path c.action_controller.session_store = :active_record_store end - Rails.application.new + Rails.initialize! expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] middleware = Rails.application.config.middleware.map { |m| m.klass } @@ -200,7 +200,7 @@ module ApplicationTests c.frameworks -= [:action_controller] c.action_controller.session_store = :active_record_store end - Rails.application.new + Rails.initialize! assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) end @@ -211,7 +211,7 @@ module ApplicationTests c.root = app_path c.frameworks -= [:action_view] end - Rails.application.new + Rails.initialize! assert_equal nil, ActionMailer::Base.template_root assert_equal [], ActionController::Base.view_paths @@ -221,7 +221,7 @@ module ApplicationTests Rails::Initializer.run do |c| c.root = app_path end - Rails.application.new + Rails.initialize! assert_instance_of Pathname, Rails.root end end diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb index 6ea6d49460..0926ed106b 100644 --- a/railties/test/application/plugins_test.rb +++ b/railties/test/application/plugins_test.rb @@ -18,7 +18,7 @@ module ApplicationTests test "all plugins are loaded when registered plugin list is untouched" do Rails::Initializer.run { |c| c.root = app_path } - Rails.application.new + Rails.initialize! assert_plugins [ :a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby ], Rails.application.config.loaded_plugins, @failure_tip @@ -32,7 +32,7 @@ module ApplicationTests test "only the specified plugins are located in the order listed" do plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon] Rails::Initializer.run { |c| c.root = app_path; c.plugins = plugin_names } - Rails.application.new + Rails.initialize! assert_plugins plugin_names, Rails.application.config.loaded_plugins end @@ -41,7 +41,7 @@ module ApplicationTests config.root = app_path config.plugins = [:stubby, :all, :acts_as_chunky_bacon] end - Rails.application.new + Rails.initialize! assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], Rails.application.config.loaded_plugins, @failure_tip end @@ -51,7 +51,7 @@ module ApplicationTests config.root = app_path config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] end - Rails.application.new + Rails.initialize! assert_plugins plugin_names, Rails.application.config.loaded_plugins, @failure_tip end @@ -61,8 +61,8 @@ module ApplicationTests config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon, :all] end - Rails.application.new - + Rails.initialize! + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], Rails.application.config.loaded_plugins, @failure_tip end @@ -71,7 +71,7 @@ module ApplicationTests config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon] end - Rails.application.new + Rails.initialize! assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/stubby/lib") assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/acts/acts_as_chunky_bacon/lib") @@ -84,7 +84,7 @@ module ApplicationTests end assert_raise(LoadError) do - Rails.application.new + Rails.initialize! end end @@ -97,7 +97,7 @@ module ApplicationTests config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2] end - Rails.application.new + Rails.initialize! flunk "Expected a LoadError but did not get one" rescue LoadError => e assert_plugins valid_plugins, Rails.application.config.loaded_plugins, @failure_tip diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 6c32f5635b..0c725311ad 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -42,7 +42,7 @@ module InitializerTests set_ruby_version(version) assert_nothing_raised "It appears that rails does not boot" do Rails::Initializer.run { |c| c.frameworks = [] } - Rails.application.new + Rails.initialize! end end @@ -51,7 +51,7 @@ module InitializerTests $stderr = File.open("/dev/null", "w") assert_raises(SystemExit) do Rails::Initializer.run { |c| c.frameworks = [] } - Rails.application.new + Rails.initialize! end end end diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index 92ac1312bf..04b44cedd0 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -15,7 +15,7 @@ module InitializerTests c.root = app_path c.i18n.load_path << "my/other/locale.yml" end - Rails.application.new + Rails.initialize! #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml assert_equal %W( @@ -38,7 +38,7 @@ module InitializerTests c.root = app_path c.i18n.load_path << "my/other/locale.yml" end - Rails.application.new + Rails.initialize! #{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 29acbdbd25..9c36bb2000 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -13,7 +13,7 @@ class PathsTest < Test::Unit::TestCase ActionController::Base.session_store = nil end end - Rails.application.new + Rails.initialize! @paths = Rails.application.config.paths end -- cgit v1.2.3 From c1261b5484c10930be9f737abfc164f9ba072629 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 16 Oct 2009 19:04:28 -0500 Subject: Use Rails.application where we want a valid rack app --- railties/test/application/load_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb index 5c3d35fb16..3da51c4355 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/load_test.rb @@ -40,7 +40,7 @@ module ApplicationTests test "Rails.application is available after config.ru has been racked up" do rackup - assert Rails.application.new < Rails::Application + assert Rails.application < Rails::Application end # Passenger still uses AC::Dispatcher, so we need to -- cgit v1.2.3 From e1fdc8bba3e427435927685e77937b3a478aa416 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 16 Oct 2009 18:10:12 -0700 Subject: Remove config.gem in favor of using the bundler. This makes config/boot.rb obsolete. The bundler library is at: http://github.com/wycats/bundler/ and is a rubygem. --- railties/test/application/configuration_test.rb | 1 - railties/test/application/generators_test.rb | 1 + railties/test/application/initializer_test.rb | 1 + railties/test/application/notifications_test.rb | 2 +- railties/test/application/plugins_test.rb | 1 + railties/test/backtrace_cleaner_test.rb | 6 ------ railties/test/generators_test.rb | 3 ++- .../test/initializer/check_ruby_version_test.rb | 1 + railties/test/initializer/initialize_i18n_test.rb | 1 + railties/test/initializer/path_test.rb | 1 + railties/test/isolation/abstract_unit.rb | 23 ++++++++++++---------- 11 files changed, 22 insertions(+), 19 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 0452208cae..a3e1916494 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -7,7 +7,6 @@ module ApplicationTests def setup build_app boot_rails - Object.send(:remove_const, :RAILS_ROOT) end test "the application root is set correctly" do diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 03fecffdd0..445a867c85 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -7,6 +7,7 @@ module ApplicationTests def setup build_app boot_rails + require "rails" require "rails/generators" end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index c2e64374d0..f42954079b 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -7,6 +7,7 @@ module ApplicationTests def setup build_app boot_rails + require "rails" end test "initializing an application initializes rails" do diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index 0fdb4a083a..83c18be057 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -24,7 +24,7 @@ module ApplicationTests def setup build_app boot_rails - + require "rails" require "active_support/notifications" Rails::Initializer.run do |c| c.notifications.queue = MyQueue.new diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb index 0926ed106b..80a19856d7 100644 --- a/railties/test/application/plugins_test.rb +++ b/railties/test/application/plugins_test.rb @@ -11,6 +11,7 @@ module ApplicationTests def setup build_app boot_rails + require "rails" @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" # Tmp hax to get tests working FileUtils.cp_r "#{File.dirname(__FILE__)}/../fixtures/plugins", "#{app_path}/vendor" diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index f9b9d3168d..0319d5f38c 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -50,10 +50,4 @@ class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase end end - test "should format vendor gems correctly" do - @backtrace = [ "#{Rails::GemDependency.unpacked_path}/nosuchgem-1.2.3/lib/foo.rb" ] - @result = @cleaner.clean(@backtrace) - assert_equal "nosuchgem (1.2.3) [v] lib/foo.rb", @result[0] - end - end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 7e6b7b183c..2e19169d3d 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -101,10 +101,11 @@ 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, mspec, rails:javascripts, wrong.", output + assert_equal "Others: active_record:fixjour, fixjour, mspec, rails:javascripts.", output end def test_warning_is_shown_if_generator_cant_be_loaded + Rails::Generators.load_paths << File.expand_path("../fixtures/vendor/gems/gems/wrong", __FILE__) output = capture(:stderr){ Rails::Generators.find_by_namespace(:wrong) } assert_match /\[WARNING\] Could not load generator at/, output assert_match /Error: uninitialized constant Rails::Generator/, output diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 0c725311ad..cf956e68fb 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -7,6 +7,7 @@ module InitializerTests def setup build_app boot_rails + require "rails" end test "rails does not initialize with ruby version 1.8.1" do diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index 04b44cedd0..d664f96ad1 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -7,6 +7,7 @@ module InitializerTests def setup build_app boot_rails + require "rails" end # test_config_defaults_and_settings_should_be_added_to_i18n_defaults diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 9c36bb2000..1b58a58555 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -6,6 +6,7 @@ class PathsTest < Test::Unit::TestCase 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] diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 750ec5d319..aafc9f68bb 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -114,16 +114,19 @@ module TestHelpers end def boot_rails - # TMP mega hax to prevent boot.rb from actually booting - Object.class_eval <<-RUBY, __FILE__, __LINE__+1 - module Rails - Initializer = 'lol' - require "#{app_path}/config/boot" - remove_const(:Initializer) - booter = VendorBoot.new('#{app_path}') - booter.run - end - RUBY + %w( + actionmailer/lib + actionpack/lib + activemodel/lib + activerecord/lib + activeresource/lib + activesupport/lib + railties/lib + railties + ).reverse_each do |path| + path = File.expand_path("../../../../#{path}", __FILE__) + $:.unshift(path) + end end end end -- cgit v1.2.3 From 03c5a0e5c4c9888c54265d6ef97136854e0ff9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 17 Oct 2009 15:54:58 -0300 Subject: Make app generatoor specs green once again. --- railties/test/generators/app_generator_test.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 5d6a9f6de9..20f2a24e6d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -114,11 +114,18 @@ class AppGeneratorTest < GeneratorsTestCase generator(:freeze => true, :database => "sqlite3").expects(:run). with("rake rails:freeze:edge", :verbose => false) silence(:stdout){ generator.invoke } - assert_file 'config/environment.rb', /# RAILS_GEM_VERSION/ + + assert_file 'Gemfile' do |content| + flag = %(gem "rails", "#{Rails::VERSION::STRING}", :git => "git://github.com/rails/rails.git") + assert_match /^#{Regexp.escape(flag)}$/, content + + flag = %(# gem "rails", "#{Rails::VERSION::STRING}") + assert_match /^#{Regexp.escape(flag)}$/, content + end end def test_template_from_dir_pwd - FileUtils.cd(RAILS_ROOT) + FileUtils.cd(Rails.root) assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"]) end -- cgit v1.2.3 From 1f9d234a6b567e68d97e71da6f19bd126e7f7058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 17 Oct 2009 15:56:44 -0300 Subject: By default use ActiveModel API in controller generators, unless otherwise specified [#3123 status:resolved] --- .../scaffold_controller_generator_test.rb | 41 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index f555725eb8..02155c295c 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -2,6 +2,11 @@ require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' +module Unknown + module Generators + end +end + class ScaffoldControllerGeneratorTest < GeneratorsTestCase def test_controller_skeleton_is_created @@ -97,10 +102,38 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase assert_no_file "app/views/layouts/users.html.erb" end - def test_error_is_shown_if_orm_does_not_provide_interface - error = capture(:stderr){ run_generator ["User", "--orm=unknown"] } - assert_equal "Could not load Unknown::Generators::ActiveModel, skipping controller. " << - "Error: no such file to load -- rails/generators/unknown.\n", error + def test_default_orm_is_used + run_generator ["User", "--orm=unknown"] + + assert_file "app/controllers/users_controller.rb" do |content| + assert_match /class UsersController < ApplicationController/, content + + assert_instance_method content, :index do |m| + assert_match /@users = User\.all/, m + end + end + end + + def test_customized_orm_is_used + klass = Class.new(Rails::Generators::ActiveModel) do + def self.all(klass) + "#{klass}.find(:all)" + end + end + + Unknown::Generators.const_set(:ActiveModel, klass) + run_generator ["User", "--orm=unknown"] + + assert_file "app/controllers/users_controller.rb" do |content| + assert_match /class UsersController < ApplicationController/, content + + assert_instance_method content, :index do |m| + assert_match /@users = User\.find\(:all\)/, m + assert_no_match /@users = User\.all/, m + end + end + ensure + Unknown::Generators.send :remove_const, :ActiveModel end protected -- cgit v1.2.3 From d0f4d93df823d5124d8f2cc740471d458633c338 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Sat, 17 Oct 2009 14:38:21 -0700 Subject: Remove some remnants of config.gem --- railties/test/gem_dependency_test.rb | 220 ----------------------------------- 1 file changed, 220 deletions(-) delete mode 100644 railties/test/gem_dependency_test.rb (limited to 'railties/test') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb deleted file mode 100644 index 92132be992..0000000000 --- a/railties/test/gem_dependency_test.rb +++ /dev/null @@ -1,220 +0,0 @@ -require 'plugin_test_helper' -require 'rails/gem_dependency' - -class Rails::GemDependency - public :install_command, :unpack_command -end - -Rails::VendorGemSourceIndex.silence_spec_warnings = true - -class GemDependencyTest < Test::Unit::TestCase - def setup - @gem = Rails::GemDependency.new "xhpricotx" - @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net" - @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6" - @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3" - @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false - end - - def test_configuration_adds_gem_dependency - config = Rails::Configuration.new - config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0" - assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect { |g| g.install_command } - end - - def test_gem_creates_install_command - assert_equal %w(install xhpricotx), @gem.install_command - end - - def test_gem_with_source_creates_install_command - assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command - end - - def test_gem_with_version_creates_install_command - assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command - end - - def test_gem_creates_unpack_command - assert_equal %w(unpack xhpricotx), @gem.unpack_command - end - - def test_gem_with_version_unpack_install_command - # stub out specification method, or else test will fail if hpricot 0.6 isn't installed - mock_spec = mock() - mock_spec.stubs(:version).returns('0.6') - @gem_with_version.stubs(:specification).returns(mock_spec) - assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command - end - - def test_gem_adds_load_paths - @gem.expects(:gem).with(@gem) - @gem.add_load_paths - end - - def test_gem_with_version_adds_load_paths - @gem_with_version.expects(:gem).with(@gem_with_version) - @gem_with_version.add_load_paths - assert @gem_with_version.load_paths_added? - end - - def test_gem_loading - @gem.expects(:gem).with(@gem) - @gem.expects(:require).with(@gem.name) - @gem.add_load_paths - @gem.load - assert @gem.loaded? - end - - def test_gem_with_lib_loading - @gem_with_lib.expects(:gem).with(@gem_with_lib) - @gem_with_lib.expects(:require).with(@gem_with_lib.lib) - @gem_with_lib.add_load_paths - @gem_with_lib.load - assert @gem_with_lib.loaded? - end - - def test_gem_without_lib_loading - @gem_without_load.expects(:gem).with(@gem_without_load) - @gem_without_load.expects(:require).with(@gem_without_load.lib).never - @gem_without_load.add_load_paths - @gem_without_load.load - end - - def test_gem_dependencies_compare_for_uniq - gem1 = Rails::GemDependency.new "gem1" - gem1a = Rails::GemDependency.new "gem1" - gem2 = Rails::GemDependency.new "gem2" - gem2a = Rails::GemDependency.new "gem2" - gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1" - gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1" - gem4 = Rails::GemDependency.new "gem3" - gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4] - assert_equal 4, gems.uniq.size - end - - def test_gem_load_frozen - dummy_gem = Rails::GemDependency.new "dummy-gem-a" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_A_VERSION - end - - def test_gem_load_frozen_specific_version - dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0' - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_B_VERSION - assert_equal '0.4.0', DUMMY_GEM_B_VERSION - end - - def test_gem_load_frozen_minimum_version - dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0' - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_C_VERSION - assert_equal '0.6.0', DUMMY_GEM_C_VERSION - end - - def test_gem_load_missing_specification - dummy_gem = Rails::GemDependency.new "dummy-gem-d" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_D_VERSION - assert_equal '1.0.0', DUMMY_GEM_D_VERSION - assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files - end - - def test_gem_load_bad_specification - dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_E_VERSION - assert_equal '1.0.0', DUMMY_GEM_E_VERSION - end - - def test_gem_handle_missing_dependencies - dummy_gem = Rails::GemDependency.new "dummy-gem-g" - dummy_gem.add_load_paths - dummy_gem.load - assert_equal 1, dummy_gem.dependencies.size - assert_equal 1, dummy_gem.dependencies.first.dependencies.size - assert_nothing_raised do - dummy_gem.dependencies.each do |g| - g.dependencies - end - end - end - - def test_gem_ignores_development_dependencies - dummy_gem = Rails::GemDependency.new "dummy-gem-k" - dummy_gem.add_load_paths - dummy_gem.load - assert_equal 1, dummy_gem.dependencies.size - end - - def test_gem_guards_against_duplicate_unpacks - dummy_gem = Rails::GemDependency.new "dummy-gem-a" - dummy_gem.stubs(:frozen?).returns(true) - dummy_gem.expects(:unpack_base).never - dummy_gem.unpack - end - - def test_gem_does_not_unpack_framework_gems - dummy_gem = Rails::GemDependency.new "dummy-gem-a" - dummy_gem.stubs(:framework_gem?).returns(true) - dummy_gem.expects(:unpack_base).never - dummy_gem.unpack - end - - def test_gem_from_directory_name_attempts_to_load_specification - assert_raises RuntimeError do - dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1') - end - end - - def test_gem_from_directory_name - dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1', false) - assert_equal 'dummy-gem', dummy_gem.name - assert_equal '= 1.1', dummy_gem.version_requirements.to_s - end - - def test_gem_from_directory_name_loads_specification_successfully - assert_nothing_raised do - dummy_gem = Rails::GemDependency.from_directory_name(File.join(Rails::GemDependency.unpacked_path, 'dummy-gem-g-1.0.0')) - assert_not_nil dummy_gem.specification - end - end - - def test_gem_from_invalid_directory_name - assert_raises RuntimeError do - dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem') - end - assert_raises RuntimeError do - dummy_gem = Rails::GemDependency.from_directory_name('dummy') - end - end - - def test_gem_determines_build_status - assert_equal true, Rails::GemDependency.new("dummy-gem-a").built? - assert_equal true, Rails::GemDependency.new("dummy-gem-i").built? - assert_equal false, Rails::GemDependency.new("dummy-gem-j").built? - end - - def test_gem_determines_build_status_only_on_vendor_gems - framework_gem = Rails::GemDependency.new('dummy-framework-gem') - framework_gem.stubs(:framework_gem?).returns(true) # already loaded - framework_gem.stubs(:vendor_rails?).returns(false) # but not in vendor/rails - framework_gem.stubs(:vendor_gem?).returns(false) # and not in vendor/gems - framework_gem.add_load_paths # freeze framework gem early - assert framework_gem.built? - end - - def test_gem_build_passes_options_to_dependencies - start_gem = Rails::GemDependency.new("dummy-gem-g") - dep_gem = Rails::GemDependency.new("dummy-gem-f") - start_gem.stubs(:dependencies).returns([dep_gem]) - dep_gem.expects(:build).with({ :force => true }).once - start_gem.build(:force => true) - end - -end -- cgit v1.2.3 From f74e04c21d9930c863ef92639050c0434be8dd0c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 18 Oct 2009 10:44:05 -0500 Subject: RAILS_GEM_VERSION is obsolete --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 5d6a9f6de9..e0b4e97952 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -114,7 +114,7 @@ class AppGeneratorTest < GeneratorsTestCase generator(:freeze => true, :database => "sqlite3").expects(:run). with("rake rails:freeze:edge", :verbose => false) silence(:stdout){ generator.invoke } - assert_file 'config/environment.rb', /# RAILS_GEM_VERSION/ + assert_file 'config/environment.rb' end def test_template_from_dir_pwd -- cgit v1.2.3 From 01e04a446c801af88a1bb0315efffc775a00eedf Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 18 Oct 2009 10:53:43 -0500 Subject: Use Rails.root in railties tests --- railties/test/generators/actions_test.rb | 2 +- railties/test/generators/app_generator_test.rb | 2 +- railties/test/generators_test.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index adc61f6d8a..199b5fa8b4 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -89,7 +89,7 @@ class ActionsTest < GeneratorsTestCase def test_environment_should_include_data_in_environment_initializer_block run_generator - load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]' + load_paths = 'config.load_paths += %w["#{Rails.root}/app/extras"]' action :environment, load_paths assert_file 'config/application.rb', /#{Regexp.escape(load_paths)}/ end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index e0b4e97952..3eefaf9b02 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -118,7 +118,7 @@ class AppGeneratorTest < GeneratorsTestCase end def test_template_from_dir_pwd - FileUtils.cd(RAILS_ROOT) + FileUtils.cd(Rails.root) assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"]) end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 2e19169d3d..178b5ef6de 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -80,7 +80,7 @@ class GeneratorsTest < GeneratorsTestCase Rails::Generators.instance_variable_set(:@load_paths, nil) spec = Gem::Specification.new - spec.expects(:full_gem_path).returns(File.join(RAILS_ROOT, 'vendor', 'another_gem_path', 'xspec')) + spec.expects(:full_gem_path).returns(File.join(Rails.root, 'vendor', 'another_gem_path', 'xspec')) Gem.expects(:respond_to?).with(:loaded_specs).returns(true) Gem.expects(:loaded_specs).returns(:spec => spec) @@ -119,7 +119,7 @@ class GeneratorsTest < GeneratorsTestCase end def test_rails_root_templates - template = File.join(RAILS_ROOT, "lib", "templates", "active_record", "model", "model.rb") + template = File.join(Rails.root, "lib", "templates", "active_record", "model", "model.rb") # Create template mkdir_p(File.dirname(template)) @@ -171,6 +171,6 @@ class GeneratorsTest < GeneratorsTestCase def test_source_paths_for_not_namespaced_generators mspec = Rails::Generators.find_by_namespace :mspec - assert mspec.source_paths.include?(File.join(RAILS_ROOT, "lib", "templates", "mspec")) + assert mspec.source_paths.include?(File.join(Rails.root, "lib", "templates", "mspec")) end end -- cgit v1.2.3 From 51e1260b182b7fd5fda0c3f6b97bb166a578d0e6 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 18 Oct 2009 11:13:57 -0500 Subject: Rails info tests needs use_controllers --- railties/test/rails_info_controller_test.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 99cf9168e1..a0484c0868 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -4,10 +4,6 @@ require 'action_controller' require 'rails/info' require 'rails/info_controller' -ActionController::Routing::Routes.draw do |map| - map.connect ':controller/:action/:id' -end - module ActionController class Base include ActionController::Testing @@ -18,9 +14,17 @@ 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' + 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 -- cgit v1.2.3 From 77bb129fdb3b1da8365931a6313b5e7ef4c91de0 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Wed, 23 Sep 2009 06:41:22 -0500 Subject: Fix bad assumption in BacktraceCleaner test [#3249 state:resolved] Signed-off-by: Pratik Naik --- railties/test/backtrace_cleaner_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 0319d5f38c..64a47712b7 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -35,7 +35,7 @@ class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase end test "should format installed gems correctly" do - @backtrace = [ "#{Gem.default_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] + @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ] @result = @cleaner.clean(@backtrace) assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0] end -- cgit v1.2.3 From 4f6d8ceb0436cf7eea435bdfed87ecf5aba050c1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 19 Oct 2009 19:22:23 -0700 Subject: Bundle for railties tests too --- railties/test/abstract_unit.rb | 18 +++++++++--------- railties/test/isolation/abstract_unit.rb | 32 ++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 21 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 8010481609..7977b45a57 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,14 +1,14 @@ ORIG_ARGV = ARGV.dup -require 'rubygems' -gem 'rack', '~> 1.0.0' -gem 'rack-test', '~> 0.5.0' +bundled = "#{File.dirname(__FILE__)}/../vendor/gems/environment" +if File.exist?("#{bundled}.rb") + require bundled +else + %w(activesupport activemodel activerecord actionpack actionmailer activeresource).each do |lib| + $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../#{lib}/lib" + end +end -$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" -$:.unshift File.dirname(__FILE__) + "/../../activerecord/lib" -$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" -$:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib" -$:.unshift File.dirname(__FILE__) + "/../../activeresource/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" @@ -25,4 +25,4 @@ require 'rails' Rails::Initializer.run do |config| config.root = File.dirname(__FILE__) -end \ No newline at end of file +end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index aafc9f68bb..557292e7d3 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -114,18 +114,26 @@ module TestHelpers end def boot_rails - %w( - actionmailer/lib - actionpack/lib - activemodel/lib - activerecord/lib - activeresource/lib - activesupport/lib - railties/lib - railties - ).reverse_each do |path| - path = File.expand_path("../../../../#{path}", __FILE__) - $:.unshift(path) + bundled = "#{File.dirname(__FILE__)}/../../vendor/gems/environment" + if File.exist?("#{bundled}.rb") + require bundled + %w(railties railties/lib).each do |path| + $LOAD_PATH.unshift File.expand_path("../../../../#{path}", __FILE__) + end + else + %w( + actionmailer/lib + actionpack/lib + activemodel/lib + activerecord/lib + activeresource/lib + activesupport/lib + railties/lib + railties + ).reverse_each do |path| + path = File.expand_path("../../../../#{path}", __FILE__) + $:.unshift(path) + end end end end -- cgit v1.2.3 From fa1926ddaa7ad481c55b76d1f2c1952721b7b586 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 20 Oct 2009 09:32:26 -0500 Subject: Exclude gem backtrace filter if rubygems is not loaded --- railties/test/backtrace_cleaner_test.rb | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'railties/test') diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 64a47712b7..4e273852e0 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -29,25 +29,26 @@ else $stderr.puts 'No BacktraceFilter for minitest' end -class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase - def setup - @cleaner = Rails::BacktraceCleaner.new - end - - test "should format installed gems correctly" do - @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ] - @result = @cleaner.clean(@backtrace) - assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0] - end +if defined? Gem + class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase + def setup + @cleaner = Rails::BacktraceCleaner.new + end - test "should format installed gems not in Gem.default_dir correctly" do - @target_dir = Gem.path.detect { |p| p != Gem.default_dir } - # skip this test if default_dir is the only directory on Gem.path - if @target_dir - @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] + test "should format installed gems correctly" do + @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ] @result = @cleaner.clean(@backtrace) assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0] end - end + test "should format installed gems not in Gem.default_dir correctly" do + @target_dir = Gem.path.detect { |p| p != Gem.default_dir } + # skip this test if default_dir is the only directory on Gem.path + if @target_dir + @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] + @result = @cleaner.clean(@backtrace) + assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0] + end + end + end end -- cgit v1.2.3 From 4f6d6f7031a88b647814fc0154e6b69b636dc912 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 20 Oct 2009 16:33:54 -0700 Subject: Have all the tests running off a single Gemfile --- railties/test/abstract_unit.rb | 15 +++++++-------- railties/test/application/initializer_test.rb | 20 -------------------- railties/test/isolation/abstract_unit.rb | 19 ++++++++----------- 3 files changed, 15 insertions(+), 39 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 7977b45a57..47013d7797 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,16 +1,15 @@ ORIG_ARGV = ARGV.dup -bundled = "#{File.dirname(__FILE__)}/../vendor/gems/environment" -if File.exist?("#{bundled}.rb") - require bundled -else - %w(activesupport activemodel activerecord actionpack actionmailer activeresource).each do |lib| - $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../#{lib}/lib" +root = File.expand_path('../../..', __FILE__) +begin + require "#{root}/vendor/gems/environment" +rescue LoadError + %w(activesupport activemodel activerecord actionpack actionmailer activeresource railties).each do |lib| + $:.unshift "#{root}/#{lib}/lib" end end -$:.unshift File.dirname(__FILE__) + "/../lib" -$:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" +$:.unshift "#{root}/railties/builtin/rails_info" require 'stringio' require 'test/unit' diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index f42954079b..719520bf68 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -82,26 +82,6 @@ module ApplicationTests end end - test "action_pack is added to the load path if action_controller is required" do - Rails::Initializer.run do |config| - config.root = app_path - config.frameworks = [:action_controller] - end - Rails.initialize! - - assert $:.include?("#{framework_path}/actionpack/lib") - end - - test "action_pack is added to the load path if action_view is required" do - Rails::Initializer.run do |config| - config.root = app_path - config.frameworks = [:action_view] - end - Rails.initialize! - - assert $:.include?("#{framework_path}/actionpack/lib") - end - test "after_initialize block works correctly" do Rails::Initializer.run do |config| config.root = app_path diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 557292e7d3..11cabb2c0b 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -6,7 +6,6 @@ # # It is also good to know what is the bare minimum to get # Rails booted up. - require 'fileutils' # TODO: Remove rubygems when possible @@ -82,6 +81,7 @@ module TestHelpers def build_app(options = {}) FileUtils.rm_rf(app_path) FileUtils.cp_r(tmp_path('app_template'), app_path) + FileUtils.ln_s(RAILS_FRAMEWORK_ROOT, app_path('vendor/rails')) # Delete the initializers unless requested unless options[:initializers] @@ -114,13 +114,10 @@ module TestHelpers end def boot_rails - bundled = "#{File.dirname(__FILE__)}/../../vendor/gems/environment" - if File.exist?("#{bundled}.rb") - require bundled - %w(railties railties/lib).each do |path| - $LOAD_PATH.unshift File.expand_path("../../../../#{path}", __FILE__) - end - else + root = File.expand_path('../../../..', __FILE__) + begin + require "#{root}/vendor/gems/environment" + rescue LoadError %w( actionmailer/lib actionpack/lib @@ -131,8 +128,7 @@ module TestHelpers railties/lib railties ).reverse_each do |path| - path = File.expand_path("../../../../#{path}", __FILE__) - $:.unshift(path) + $:.unshift "#{root}/#{path}" end end end @@ -155,5 +151,6 @@ Module.new do end FileUtils.mkdir(tmp_path) - `#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` + root = File.expand_path('../../../..', __FILE__) + `#{Gem.ruby} -r #{root}/vendor/gems/environment #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` end -- cgit v1.2.3 From 8a0f4564432bef9dde815dd6b768d088cfad16ed Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 21 Oct 2009 15:45:11 -0700 Subject: Refactored railties' isolation tests to be able to run script/* scripts. --- railties/test/isolation/abstract_unit.rb | 17 +++++++++++++---- railties/test/plugins/vendored_test.rb | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 railties/test/plugins/vendored_test.rb (limited to 'railties/test') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 11cabb2c0b..462a4d8dea 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -81,7 +81,6 @@ module TestHelpers def build_app(options = {}) FileUtils.rm_rf(app_path) FileUtils.cp_r(tmp_path('app_template'), app_path) - FileUtils.ln_s(RAILS_FRAMEWORK_ROOT, app_path('vendor/rails')) # Delete the initializers unless requested unless options[:initializers] @@ -93,6 +92,12 @@ module TestHelpers add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' end + def script(script) + Dir.chdir(app_path) do + `#{Gem.ruby} #{app_path}/script/#{script}` + end + end + def add_to_config(str) environment = File.read("#{app_path}/config/application.rb") if environment =~ /(\n\s*end\s*)\Z/ @@ -149,8 +154,12 @@ Module.new do if File.exist?(tmp_path) FileUtils.rm_rf(tmp_path) end - FileUtils.mkdir(tmp_path) - root = File.expand_path('../../../..', __FILE__) - `#{Gem.ruby} -r #{root}/vendor/gems/environment #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` + + environment = File.expand_path('../../../../vendor/gems/environment', __FILE__) + + `#{Gem.ruby} -r #{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}' ; require 'rails'" + end end diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb new file mode 100644 index 0000000000..71de542ff7 --- /dev/null +++ b/railties/test/plugins/vendored_test.rb @@ -0,0 +1,19 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class PluginTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + test "generates the plugin" do + script "generate plugin my_plugin" + File.open("#{app_path}/vendor/plugins/my_plugin/init.rb", 'w') do |f| + f.puts "OMG = 'hello'" + end + require "#{app_path}/config/environment" + end + end +end \ No newline at end of file -- cgit v1.2.3 From b30294b54ab019b0e53402c6927981f8c306e976 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 27 Oct 2009 09:34:17 -0700 Subject: Fix broken tests --- railties/test/application/notifications_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index 83c18be057..62ed4f4ad4 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -12,7 +12,7 @@ module ApplicationTests @subscribers = [] end - def publish(name, payload=nil) + def publish(name, *args) @events << name end -- cgit v1.2.3 From df95f165708b6baf93dcc6eff6911ee159cab34c Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 27 Oct 2009 16:48:35 -0700 Subject: Update initializable --- railties/test/initializable_test.rb | 95 +++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 10 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index 7c8aed00c9..a1306adb60 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -31,38 +31,113 @@ module InitializableTests end end + class Parent + extend Rails::Initializable + + initializer :one do + $arr << 1 + end + + initializer :two do + $arr << 2 + end + end + + class Child < Parent + extend Rails::Initializable + + initializer :three, :before => :one do + $arr << 3 + end + + initializer :four, :after => :one do + $arr << 4 + end + end + + class Parent + initializer :five, :before => :one do + $arr << 5 + end + end + + class Instance + include Rails::Initializable + + initializer :one do + $arr << 1 + end + + initializer :two do + $arr << 2 + end + + initializer :three, :global => true do + $arr << 3 + end + + initializer :four, :global => true do + $arr << 4 + end + end + class Basic < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation test "initializers run" do - Foo.initializers.run + Foo.initialize! assert_equal 1, Foo.foo end test "initializers are inherited" do - Bar.initializers.run + Bar.initialize! assert_equal [1, 1], [Bar.foo, Bar.bar] end test "initializers only get run once" do - Foo.initializers.run - Foo.initializers.run + Foo.initialize! + Foo.initialize! assert_equal 1, Foo.foo end test "running initializers on children does not effect the parent" do - Bar.initializers.run + Bar.initialize! assert_nil Foo.foo assert_nil Foo.bar end - test "inherited initializers are the same objects" do - assert Foo.initializers[:foo].eql?(Bar.initializers[:foo]) - end - test "initializing with modules" do - Word.initializers.run + Word.initialize! assert_equal "bird", $word end end + + class BeforeAfter < ActiveSupport::TestCase + test "running on parent" do + $arr = [] + Parent.initialize! + assert_equal [5, 1, 2], $arr + end + + test "running on child" do + $arr = [] + Child.initialize! + assert_equal [5, 3, 1, 4, 2], $arr + end + end + + class InstanceTest < ActiveSupport::TestCase + test "running locals" do + $arr = [] + instance = Instance.new + instance.initialize! + assert_equal [1, 2], $arr + end + + test "running globals" do + $arr = [] + Instance.initialize! + assert_equal [3, 4], $arr + end + end end \ No newline at end of file -- cgit v1.2.3 From 86596975be45fa9088fba4db99b67518434f3afc Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Tue, 27 Oct 2009 19:05:29 -0700 Subject: Tests pass again --- railties/test/initializable_test.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index a1306adb60..f7237e69cc 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -85,29 +85,29 @@ module InitializableTests include ActiveSupport::Testing::Isolation test "initializers run" do - Foo.initialize! + Foo.run_initializers assert_equal 1, Foo.foo end test "initializers are inherited" do - Bar.initialize! + Bar.run_initializers assert_equal [1, 1], [Bar.foo, Bar.bar] end test "initializers only get run once" do - Foo.initialize! - Foo.initialize! + Foo.run_initializers + Foo.run_initializers assert_equal 1, Foo.foo end test "running initializers on children does not effect the parent" do - Bar.initialize! + Bar.run_initializers assert_nil Foo.foo assert_nil Foo.bar end test "initializing with modules" do - Word.initialize! + Word.run_initializers assert_equal "bird", $word end end @@ -115,13 +115,13 @@ module InitializableTests class BeforeAfter < ActiveSupport::TestCase test "running on parent" do $arr = [] - Parent.initialize! + Parent.run_initializers assert_equal [5, 1, 2], $arr end test "running on child" do $arr = [] - Child.initialize! + Child.run_initializers assert_equal [5, 3, 1, 4, 2], $arr end end @@ -130,13 +130,13 @@ module InitializableTests test "running locals" do $arr = [] instance = Instance.new - instance.initialize! + instance.run_initializers assert_equal [1, 2], $arr end test "running globals" do $arr = [] - Instance.initialize! + Instance.run_initializers assert_equal [3, 4], $arr end end -- cgit v1.2.3 From a288b74f1c75c6f100de7611a5093a421f1ad6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Oct 2009 18:32:53 -0200 Subject: Generators should use Rails.root instead of Dir.pwd [#3408 status:resolved] Signed-off-by: Yehuda Katz --- railties/test/generators/actions_test.rb | 2 +- railties/test/generators/app_generator_test.rb | 4 ++-- railties/test/generators/controller_generator_test.rb | 2 +- railties/test/generators/generator_generator_test.rb | 2 +- railties/test/generators/generators_test_helper.rb | 11 ++++++++--- railties/test/generators/helper_generator_test.rb | 2 +- railties/test/generators/integration_test_generator_test.rb | 2 +- railties/test/generators/mailer_generator_test.rb | 2 +- railties/test/generators/metal_generator_test.rb | 2 +- railties/test/generators/migration_generator_test.rb | 2 +- railties/test/generators/model_generator_test.rb | 2 +- railties/test/generators/observer_generator_test.rb | 2 +- railties/test/generators/performance_test_generator_test.rb | 2 +- railties/test/generators/plugin_generator_test.rb | 2 +- railties/test/generators/resource_generator_test.rb | 2 +- .../test/generators/scaffold_controller_generator_test.rb | 2 +- railties/test/generators/scaffold_generator_test.rb | 3 +-- railties/test/generators/session_migration_generator_test.rb | 2 +- railties/test/generators/stylesheets_generator_test.rb | 2 +- 19 files changed, 27 insertions(+), 23 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 199b5fa8b4..f5cb26cf52 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -182,7 +182,7 @@ class ActionsTest < GeneratorsTestCase end def generator(config={}) - @generator ||= Rails::Generators::Base.new([], {}, { :destination_root => destination_root }.merge!(config)) + @generator ||= Rails::Generators::Base.new([], {}, config) end def action(*args, &block) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 20f2a24e6d..c44d25b72c 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -126,7 +126,7 @@ 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(["-m", "../lib/template.rb"]) end def test_template_raises_an_error_with_invalid_path @@ -170,7 +170,7 @@ class AppGeneratorTest < GeneratorsTestCase end def generator(options={}) - @generator ||= Rails::Generators::AppGenerator.new([destination_root], options, :destination_root => destination_root) + @generator ||= Rails::Generators::AppGenerator.new([destination_root], options) end def action(*args, &block) diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 56bc688ad0..3020e928dc 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -74,7 +74,7 @@ class ControllerGeneratorTest < GeneratorsTestCase protected def run_generator(args=["Account", "foo", "bar"]) - silence(:stdout) { Rails::Generators::ControllerGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::ControllerGenerator.start args } end end diff --git a/railties/test/generators/generator_generator_test.rb b/railties/test/generators/generator_generator_test.rb index aea3f4da51..703aa20914 100644 --- a/railties/test/generators/generator_generator_test.rb +++ b/railties/test/generators/generator_generator_test.rb @@ -20,7 +20,7 @@ class GeneratorGeneratorTest < GeneratorsTestCase protected def run_generator(args=["awesome"], config={}) - silence(:stdout) { Rails::Generators::GeneratorGenerator.start args, config.merge(:destination_root => destination_root) } + silence(:stdout) { Rails::Generators::GeneratorGenerator.start args, config } end end diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index ccf08c347c..829a38c103 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -1,5 +1,5 @@ # TODO: Fix this RAILS_ENV stuff -RAILS_ENV = 'test' +RAILS_ENV = 'test' unless defined?(RAILS_ENV) require 'abstract_unit' Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) @@ -11,12 +11,17 @@ require 'action_dispatch' CURRENT_PATH = File.expand_path(Dir.pwd) Rails::Generators.no_color! +module Rails + def self.root + @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures', 'tmp')) + end +end + class GeneratorsTestCase < Test::Unit::TestCase include FileUtils def destination_root - @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__), - '..', 'fixtures', 'tmp')) + Rails.root end def setup diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb index f8bfc517a2..44f5a324af 100644 --- a/railties/test/generators/helper_generator_test.rb +++ b/railties/test/generators/helper_generator_test.rb @@ -54,7 +54,7 @@ class HelperGeneratorTest < GeneratorsTestCase protected def run_generator(args=["admin"]) - silence(:stdout) { Rails::Generators::HelperGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::HelperGenerator.start args } end end diff --git a/railties/test/generators/integration_test_generator_test.rb b/railties/test/generators/integration_test_generator_test.rb index 6a504ceea2..68b55a66f9 100644 --- a/railties/test/generators/integration_test_generator_test.rb +++ b/railties/test/generators/integration_test_generator_test.rb @@ -12,7 +12,7 @@ class IntegrationTestGeneratorTest < GeneratorsTestCase protected def run_generator(args=["integration"]) - silence(:stdout) { Rails::Generators::IntegrationTestGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::IntegrationTestGenerator.start args } end end diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 251474ad16..e33af25773 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -46,7 +46,7 @@ class MailerGeneratorTest < GeneratorsTestCase protected def run_generator(args=["notifier", "foo", "bar"]) - silence(:stdout) { Rails::Generators::MailerGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::MailerGenerator.start args } end end diff --git a/railties/test/generators/metal_generator_test.rb b/railties/test/generators/metal_generator_test.rb index 80bf342892..4f36e0f612 100644 --- a/railties/test/generators/metal_generator_test.rb +++ b/railties/test/generators/metal_generator_test.rb @@ -17,7 +17,7 @@ class MetalGeneratorTest < GeneratorsTestCase protected def run_generator(args=["foo"]) - silence(:stdout) { Rails::Generators::MetalGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::MetalGenerator.start args } end end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 35172a8be4..b1fdbef425 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -53,7 +53,7 @@ class MigrationGeneratorTest < GeneratorsTestCase protected def run_generator(args=[@migration]) - silence(:stdout) { Rails::Generators::MigrationGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::MigrationGenerator.start args } end end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index e073b11e1e..a0d4bed992 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -175,7 +175,7 @@ class ModelGeneratorTest < GeneratorsTestCase protected def run_generator(args=["Account", "name:string", "age:integer"], config={}) - silence(:stdout) { Rails::Generators::ModelGenerator.start args, config.merge(:destination_root => destination_root) } + silence(:stdout) { Rails::Generators::ModelGenerator.start args, config } end end diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb index 6fed2998dd..becc217ac0 100644 --- a/railties/test/generators/observer_generator_test.rb +++ b/railties/test/generators/observer_generator_test.rb @@ -27,7 +27,7 @@ class ObserverGeneratorTest < GeneratorsTestCase protected def run_generator(args=["account"]) - silence(:stdout) { Rails::Generators::ObserverGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::ObserverGenerator.start args } end end diff --git a/railties/test/generators/performance_test_generator_test.rb b/railties/test/generators/performance_test_generator_test.rb index d19128f79a..00906a61e0 100644 --- a/railties/test/generators/performance_test_generator_test.rb +++ b/railties/test/generators/performance_test_generator_test.rb @@ -12,7 +12,7 @@ class PerformanceTestGeneratorTest < GeneratorsTestCase protected def run_generator(args=["performance"]) - silence(:stdout) { Rails::Generators::PerformanceTestGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::PerformanceTestGenerator.start args } end end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index f5b8b6ffb6..c8bfaf3d97 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -50,7 +50,7 @@ class PluginGeneratorTest < GeneratorsTestCase protected def run_generator(args=["plugin_fu"], config={}) - silence(:stdout) { Rails::Generators::PluginGenerator.start args, config.merge(:destination_root => destination_root) } + silence(:stdout){ Rails::Generators::PluginGenerator.start args, config } end end diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index dcae81c204..99811bc07b 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -100,7 +100,7 @@ class ResourceGeneratorTest < GeneratorsTestCase protected def run_generator(args=["account"], config={}) - silence(:stdout) { Rails::Generators::ResourceGenerator.start args, config.merge(:destination_root => destination_root) } + silence(:stdout) { Rails::Generators::ResourceGenerator.start args, config } end end diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 02155c295c..43647360d6 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -139,7 +139,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase protected def run_generator(args=["User", "name:string", "age:integer"]) - silence(:stdout) { Rails::Generators::ScaffoldControllerGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::ScaffoldControllerGenerator.start args } end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index c0652c034f..09ab58e404 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -122,8 +122,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase def run_generator(config={}) silence(:stdout) do - Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"], - config.merge(:destination_root => destination_root) + Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"], config end end diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb index 34fb996b7f..342b9a900e 100644 --- a/railties/test/generators/session_migration_generator_test.rb +++ b/railties/test/generators/session_migration_generator_test.rb @@ -28,7 +28,7 @@ class SessionMigrationGeneratorTest < GeneratorsTestCase protected def run_generator(args=[]) - silence(:stdout) { Rails::Generators::SessionMigrationGenerator.start args, :destination_root => destination_root } + silence(:stdout) { Rails::Generators::SessionMigrationGenerator.start args } end end diff --git a/railties/test/generators/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb index 15263d4bb8..6a07898c51 100644 --- a/railties/test/generators/stylesheets_generator_test.rb +++ b/railties/test/generators/stylesheets_generator_test.rb @@ -18,7 +18,7 @@ class StylesheetsGeneratorTest < GeneratorsTestCase protected def run_generator(config={}) - silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config.merge(:destination_root => destination_root) } + silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config } end end -- cgit v1.2.3 From 14370e1aab6ddfb5b86cf50bd7e5abcebae0684c Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Mon, 2 Nov 2009 17:12:01 -0800 Subject: CI breakage This reverts commit a288b74f1c75c6f100de7611a5093a421f1ad6d1. --- railties/test/generators/actions_test.rb | 2 +- railties/test/generators/app_generator_test.rb | 4 ++-- railties/test/generators/controller_generator_test.rb | 2 +- railties/test/generators/generator_generator_test.rb | 2 +- railties/test/generators/generators_test_helper.rb | 11 +++-------- railties/test/generators/helper_generator_test.rb | 2 +- railties/test/generators/integration_test_generator_test.rb | 2 +- railties/test/generators/mailer_generator_test.rb | 2 +- railties/test/generators/metal_generator_test.rb | 2 +- railties/test/generators/migration_generator_test.rb | 2 +- railties/test/generators/model_generator_test.rb | 2 +- railties/test/generators/observer_generator_test.rb | 2 +- railties/test/generators/performance_test_generator_test.rb | 2 +- railties/test/generators/plugin_generator_test.rb | 2 +- railties/test/generators/resource_generator_test.rb | 2 +- .../test/generators/scaffold_controller_generator_test.rb | 2 +- railties/test/generators/scaffold_generator_test.rb | 3 ++- railties/test/generators/session_migration_generator_test.rb | 2 +- railties/test/generators/stylesheets_generator_test.rb | 2 +- 19 files changed, 23 insertions(+), 27 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index f5cb26cf52..199b5fa8b4 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -182,7 +182,7 @@ class ActionsTest < GeneratorsTestCase end def generator(config={}) - @generator ||= Rails::Generators::Base.new([], {}, config) + @generator ||= Rails::Generators::Base.new([], {}, { :destination_root => destination_root }.merge!(config)) end def action(*args, &block) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index c44d25b72c..20f2a24e6d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -126,7 +126,7 @@ 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(["-m", "lib/template.rb"]) end def test_template_raises_an_error_with_invalid_path @@ -170,7 +170,7 @@ class AppGeneratorTest < GeneratorsTestCase end def generator(options={}) - @generator ||= Rails::Generators::AppGenerator.new([destination_root], options) + @generator ||= Rails::Generators::AppGenerator.new([destination_root], options, :destination_root => destination_root) end def action(*args, &block) diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 3020e928dc..56bc688ad0 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -74,7 +74,7 @@ class ControllerGeneratorTest < GeneratorsTestCase protected def run_generator(args=["Account", "foo", "bar"]) - silence(:stdout) { Rails::Generators::ControllerGenerator.start args } + 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 703aa20914..aea3f4da51 100644 --- a/railties/test/generators/generator_generator_test.rb +++ b/railties/test/generators/generator_generator_test.rb @@ -20,7 +20,7 @@ class GeneratorGeneratorTest < GeneratorsTestCase protected def run_generator(args=["awesome"], config={}) - silence(:stdout) { Rails::Generators::GeneratorGenerator.start args, 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 829a38c103..ccf08c347c 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -1,5 +1,5 @@ # TODO: Fix this RAILS_ENV stuff -RAILS_ENV = 'test' unless defined?(RAILS_ENV) +RAILS_ENV = 'test' require 'abstract_unit' Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) @@ -11,17 +11,12 @@ require 'action_dispatch' CURRENT_PATH = File.expand_path(Dir.pwd) Rails::Generators.no_color! -module Rails - def self.root - @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures', 'tmp')) - end -end - class GeneratorsTestCase < Test::Unit::TestCase include FileUtils def destination_root - Rails.root + @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__), + '..', 'fixtures', 'tmp')) end def setup diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb index 44f5a324af..f8bfc517a2 100644 --- a/railties/test/generators/helper_generator_test.rb +++ b/railties/test/generators/helper_generator_test.rb @@ -54,7 +54,7 @@ class HelperGeneratorTest < GeneratorsTestCase protected def run_generator(args=["admin"]) - silence(:stdout) { Rails::Generators::HelperGenerator.start args } + 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 68b55a66f9..6a504ceea2 100644 --- a/railties/test/generators/integration_test_generator_test.rb +++ b/railties/test/generators/integration_test_generator_test.rb @@ -12,7 +12,7 @@ class IntegrationTestGeneratorTest < GeneratorsTestCase protected def run_generator(args=["integration"]) - silence(:stdout) { Rails::Generators::IntegrationTestGenerator.start args } + 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 e33af25773..251474ad16 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -46,7 +46,7 @@ class MailerGeneratorTest < GeneratorsTestCase protected def run_generator(args=["notifier", "foo", "bar"]) - silence(:stdout) { Rails::Generators::MailerGenerator.start args } + 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 4f36e0f612..80bf342892 100644 --- a/railties/test/generators/metal_generator_test.rb +++ b/railties/test/generators/metal_generator_test.rb @@ -17,7 +17,7 @@ class MetalGeneratorTest < GeneratorsTestCase protected def run_generator(args=["foo"]) - silence(:stdout) { Rails::Generators::MetalGenerator.start args } + 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 b1fdbef425..35172a8be4 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -53,7 +53,7 @@ class MigrationGeneratorTest < GeneratorsTestCase protected def run_generator(args=[@migration]) - silence(:stdout) { Rails::Generators::MigrationGenerator.start args } + 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 a0d4bed992..e073b11e1e 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -175,7 +175,7 @@ class ModelGeneratorTest < GeneratorsTestCase protected def run_generator(args=["Account", "name:string", "age:integer"], config={}) - silence(:stdout) { Rails::Generators::ModelGenerator.start args, config } + silence(:stdout) { Rails::Generators::ModelGenerator.start args, config.merge(:destination_root => destination_root) } end end diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb index becc217ac0..6fed2998dd 100644 --- a/railties/test/generators/observer_generator_test.rb +++ b/railties/test/generators/observer_generator_test.rb @@ -27,7 +27,7 @@ class ObserverGeneratorTest < GeneratorsTestCase protected def run_generator(args=["account"]) - silence(:stdout) { Rails::Generators::ObserverGenerator.start args } + 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 00906a61e0..d19128f79a 100644 --- a/railties/test/generators/performance_test_generator_test.rb +++ b/railties/test/generators/performance_test_generator_test.rb @@ -12,7 +12,7 @@ class PerformanceTestGeneratorTest < GeneratorsTestCase protected def run_generator(args=["performance"]) - silence(:stdout) { Rails::Generators::PerformanceTestGenerator.start args } + 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 c8bfaf3d97..f5b8b6ffb6 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -50,7 +50,7 @@ class PluginGeneratorTest < GeneratorsTestCase protected def run_generator(args=["plugin_fu"], config={}) - silence(:stdout){ Rails::Generators::PluginGenerator.start args, 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 99811bc07b..dcae81c204 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -100,7 +100,7 @@ class ResourceGeneratorTest < GeneratorsTestCase protected def run_generator(args=["account"], config={}) - silence(:stdout) { Rails::Generators::ResourceGenerator.start args, 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 43647360d6..02155c295c 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -139,7 +139,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase protected def run_generator(args=["User", "name:string", "age:integer"]) - silence(:stdout) { Rails::Generators::ScaffoldControllerGenerator.start args } + 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 09ab58e404..c0652c034f 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -122,7 +122,8 @@ class ScaffoldGeneratorTest < GeneratorsTestCase def run_generator(config={}) silence(:stdout) do - Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"], config + Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"], + config.merge(:destination_root => destination_root) end end diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb index 342b9a900e..34fb996b7f 100644 --- a/railties/test/generators/session_migration_generator_test.rb +++ b/railties/test/generators/session_migration_generator_test.rb @@ -28,7 +28,7 @@ class SessionMigrationGeneratorTest < GeneratorsTestCase protected def run_generator(args=[]) - silence(:stdout) { Rails::Generators::SessionMigrationGenerator.start 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 6a07898c51..15263d4bb8 100644 --- a/railties/test/generators/stylesheets_generator_test.rb +++ b/railties/test/generators/stylesheets_generator_test.rb @@ -18,7 +18,7 @@ class StylesheetsGeneratorTest < GeneratorsTestCase protected def run_generator(config={}) - silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config } + silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config.merge(:destination_root => destination_root) } end end -- cgit v1.2.3 From d226f17507805c145cc7a1727d46714b88910094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 3 Nov 2009 00:08:33 -0200 Subject: Ensure that generators can be invoked from any directory. Signed-off-by: Engine Yard --- railties/test/generators/generators_test_helper.rb | 15 ++++++++++----- railties/test/generators_test.rb | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index ccf08c347c..fdf6b4041f 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -1,8 +1,14 @@ # TODO: Fix this RAILS_ENV stuff -RAILS_ENV = 'test' - +RAILS_ENV = 'test' unless defined?(RAILS_ENV) require 'abstract_unit' -Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) + +module Rails + def self.root + @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) + end +end +Rails.application.config.root = Rails.root + require 'rails/generators' require 'rubygems' require 'active_record' @@ -15,8 +21,7 @@ class GeneratorsTestCase < Test::Unit::TestCase include FileUtils def destination_root - @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__), - '..', 'fixtures', 'tmp')) + File.join(Rails.root, "tmp") end def setup diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 178b5ef6de..8f1984c7d2 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -105,7 +105,7 @@ class GeneratorsTest < GeneratorsTestCase end def test_warning_is_shown_if_generator_cant_be_loaded - Rails::Generators.load_paths << File.expand_path("../fixtures/vendor/gems/gems/wrong", __FILE__) + Rails::Generators.load_paths << File.join(Rails.root, "vendor", "gems", "gems", "wrong") output = capture(:stderr){ Rails::Generators.find_by_namespace(:wrong) } assert_match /\[WARNING\] Could not load generator at/, output assert_match /Error: uninitialized constant Rails::Generator/, output -- cgit v1.2.3 From e15b5eda2b4888764cd0c63a297136babac026d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 3 Nov 2009 20:50:39 -0200 Subject: Avoid duplicated names on help description and show proper error message if trying to load a Rails 2.x generator. Signed-off-by: Jeremy Kemper --- .../test/fixtures/lib/generators/foobar/foobar_generator.rb | 4 ++++ railties/test/generators_test.rb | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 railties/test/fixtures/lib/generators/foobar/foobar_generator.rb (limited to 'railties/test') diff --git a/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb b/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb new file mode 100644 index 0000000000..d1de8c56fa --- /dev/null +++ b/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb @@ -0,0 +1,4 @@ +module Foobar + class FoobarGenerator < Rails::Generators::Base + end +end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 8f1984c7d2..07f51eca01 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -45,6 +45,12 @@ class GeneratorsTest < GeneratorsTestCase assert_equal "test_unit:generators:model", klass.namespace end + def test_find_by_namespace_with_duplicated_name + klass = Rails::Generators.find_by_namespace(:foobar) + assert klass + 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 @@ -101,14 +107,15 @@ 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, mspec, rails:javascripts.", output + assert_equal "Others: active_record:fixjour, fixjour, foobar, mspec, rails:javascripts.", output end def test_warning_is_shown_if_generator_cant_be_loaded Rails::Generators.load_paths << File.join(Rails.root, "vendor", "gems", "gems", "wrong") output = capture(:stderr){ Rails::Generators.find_by_namespace(:wrong) } + assert_match /\[WARNING\] Could not load generator at/, output - assert_match /Error: uninitialized constant Rails::Generator/, output + assert_match /Rails 2\.x generator/, output end def test_no_color_sets_proper_shell -- cgit v1.2.3 From 3b8e29fe5697d4aec99229abcbd04141d3e53b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 3 Nov 2009 22:02:24 -0200 Subject: Remove --freeze (since Rails will come bundled in all new apps) and update gem action to change Gemfile instead of config.environment. Signed-off-by: Jeremy Kemper --- railties/test/generators/actions_test.rb | 47 +++++++++++----------- railties/test/generators/app_generator_test.rb | 14 ------- railties/test/generators/generators_test_helper.rb | 2 +- 3 files changed, 25 insertions(+), 38 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 199b5fa8b4..7d03a37f2a 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -54,37 +54,37 @@ class ActionsTest < GeneratorsTestCase action :plugin, 'rest_auth', {} end - def test_gem_should_put_gem_dependency_in_enviroment + def test_add_source_adds_source_to_gemfile run_generator - action :gem, 'will-paginate' - assert_file 'config/application.rb', /config\.gem 'will\-paginate'/ + action :add_source, 'http://gems.github.com' + assert_file 'Gemfile', /source "http:\/\/gems\.github\.com"/ end - def test_gem_with_options_should_include_options_in_gem_dependency_in_environment + def test_gem_should_put_gem_dependency_in_gemfile run_generator - action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com' - - regexp = /#{Regexp.escape("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'")}/ - assert_file 'config/application.rb', regexp + action :gem, 'will-paginate' + assert_file 'Gemfile', /gem "will\-paginate"/ end - def test_gem_with_env_string_should_put_gem_dependency_in_specified_environment + def test_gem_with_options_should_include_all_options_in_gemfile run_generator - action :gem, 'rspec', :env => 'test' - assert_file 'config/environments/test.rb', /config\.gem 'rspec'/ - end - def test_gem_with_env_array_should_put_gem_dependency_in_specified_environments - run_generator - action :gem, 'quietbacktrace', :env => %w[ development test ] - assert_file 'config/environments/development.rb', /config\.gem 'quietbacktrace'/ - assert_file 'config/environments/test.rb', /config\.gem 'quietbacktrace'/ + assert_deprecated do + action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com' + end + + assert_file 'Gemfile', /gem "mislav\-will\-paginate", :require_as => "will\-paginate"/ + assert_file 'Gemfile', /source "http:\/\/gems\.github\.com"/ end - def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly + def test_gem_with_env_should_include_all_dependencies_in_gemfile run_generator - action :gem, 'mislav-will-paginate', :lib => false - assert_file 'config/application.rb', /config\.gem 'mislav\-will\-paginate'\, :lib => false/ + + assert_deprecated do + action :gem, 'rspec', :env => %w(development test) + end + + assert_file 'Gemfile', /gem "rspec", :only => \["development", "test"\]/ end def test_environment_should_include_data_in_environment_initializer_block @@ -163,9 +163,10 @@ class ActionsTest < GeneratorsTestCase action :capify! end - def test_freeze_should_freeze_rails_edge - generator.expects(:run).once.with('rake rails:freeze:edge', :verbose => false) - action :freeze! + def test_freeze_is_deprecated + assert_deprecated do + action :freeze! + end end def test_route_should_add_data_to_the_routes_block_in_config_routes diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 20f2a24e6d..10d0bc6bc2 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -110,20 +110,6 @@ class AppGeneratorTest < GeneratorsTestCase ).each { |path| assert_file "script/#{path}", /#!\/usr\/bin\/env/ } end - def test_rails_is_frozen - generator(:freeze => true, :database => "sqlite3").expects(:run). - with("rake rails:freeze:edge", :verbose => false) - silence(:stdout){ generator.invoke } - - assert_file 'Gemfile' do |content| - flag = %(gem "rails", "#{Rails::VERSION::STRING}", :git => "git://github.com/rails/rails.git") - assert_match /^#{Regexp.escape(flag)}$/, content - - flag = %(# gem "rails", "#{Rails::VERSION::STRING}") - assert_match /^#{Regexp.escape(flag)}$/, content - end - end - def test_template_from_dir_pwd FileUtils.cd(Rails.root) assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"]) diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index fdf6b4041f..4ce48a453b 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -17,7 +17,7 @@ require 'action_dispatch' CURRENT_PATH = File.expand_path(Dir.pwd) Rails::Generators.no_color! -class GeneratorsTestCase < Test::Unit::TestCase +class GeneratorsTestCase < ActiveSupport::TestCase include FileUtils def destination_root -- cgit v1.2.3 From d627c932bdc5c0e2911e39cfb38952c29dab7afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 4 Nov 2009 00:14:44 -0200 Subject: Pass config.generators options along when RAILS_GENERATORS is set and show --force-plural message just once. Signed-off-by: Jeremy Kemper --- railties/test/application/generators_test.rb | 6 ++++-- railties/test/generators/resource_generator_test.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 445a867c85..bfbf1ffd16 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -1,4 +1,5 @@ require "isolation/abstract_unit" +RAILS_GENERATORS = true module ApplicationTests class GeneratorsTest < Test::Unit::TestCase @@ -23,7 +24,8 @@ module ApplicationTests Rails::Initializer.run do |c| c.generators.orm = :datamapper c.generators.test_framework = :rspec - expected = { :rails => { :orm => :datamapper, :test_framework => :rspec } } + c.generators.helper = false + expected = { :rails => { :orm => :datamapper, :test_framework => :rspec, :helper => false } } assert_equal(expected, c.generators.options) end end @@ -93,4 +95,4 @@ module ApplicationTests assert Rails::Generators.options.size >= 1 end end -end \ No newline at end of file +end diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index dcae81c204..886af01b22 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -75,7 +75,7 @@ class ResourceGeneratorTest < GeneratorsTestCase end def test_plural_names_are_singularized - content = run_generator ["accounts"] + content = run_generator ["accounts".freeze] assert_file "app/models/account.rb", /class Account < ActiveRecord::Base/ assert_file "test/unit/account_test.rb", /class AccountTest/ assert_match /Plural version of the model detected, using singularized version. Override with --force-plural./, content -- cgit v1.2.3 From a3d5274e67c841a6fdc9f9acb9e1b6bbc351dd28 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 3 Nov 2009 18:58:40 -0800 Subject: Configure generator when needed rather than during initialization --- railties/test/application/generators_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index bfbf1ffd16..ccbcd84176 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -1,5 +1,4 @@ require "isolation/abstract_unit" -RAILS_GENERATORS = true module ApplicationTests class GeneratorsTest < Test::Unit::TestCase @@ -47,6 +46,7 @@ module ApplicationTests end # Initialize the application Rails.initialize! + Rails::Generators.configure! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] @@ -59,6 +59,7 @@ module ApplicationTests end # Initialize the application Rails.initialize! + Rails::Generators.configure! assert_equal Thor::Base.shell, Thor::Shell::Basic end -- cgit v1.2.3 From 897164ddb70ed6f51b026e5c91f2bf3f7aa46ba6 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Mon, 2 Nov 2009 17:19:03 -0800 Subject: Conceptually unify instance & global initializers --- railties/test/initializable_test.rb | 72 ++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 12 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index f7237e69cc..463fdc03c0 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -4,59 +4,59 @@ require 'rails/initializable' module InitializableTests class Foo - extend Rails::Initializable + include Rails::Initializable class << self attr_accessor :foo, :bar end - initializer :omg do + initializer :omg, :global => true do @foo ||= 0 @foo += 1 end end class Bar < Foo - initializer :bar do + initializer :bar, :global => true do @bar ||= 0 @bar += 1 end end module Word - extend Rails::Initializable + include Rails::Initializable - initializer :word do + initializer :word, :global => true do $word = "bird" end end class Parent - extend Rails::Initializable + include Rails::Initializable - initializer :one do + initializer :one, :global => true do $arr << 1 end - initializer :two do + initializer :two, :global => true do $arr << 2 end end class Child < Parent - extend Rails::Initializable + include Rails::Initializable - initializer :three, :before => :one do + initializer :three, :before => :one, :global => true do $arr << 3 end - initializer :four, :after => :one do + initializer :four, :after => :one, :global => true do $arr << 4 end end class Parent - initializer :five, :before => :one do + initializer :five, :before => :one, :global => true do $arr << 5 end end @@ -81,6 +81,38 @@ module InitializableTests end end + class WithArgs + include Rails::Initializable + + initializer :foo do |arg| + $with_arg = arg + end + end + + class OverriddenInitializer + class MoreInitializers + include Rails::Initializable + + initializer :startup, :before => :last do + $arr << 2 + end + end + + include Rails::Initializable + + initializer :first do + $arr << 1 + end + + initializer :last do + $arr << 3 + end + + def self.initializers + super + MoreInitializers.initializers + end + end + class Basic < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation @@ -140,4 +172,20 @@ module InitializableTests assert_equal [3, 4], $arr end end + + class WithArgsTest < ActiveSupport::TestCase + test "running initializers with args" do + $with_arg = nil + WithArgs.new.run_initializers('foo') + assert_equal 'foo', $with_arg + end + end + + class OverriddenInitializerTest < ActiveSupport::TestCase + test "merges in the initializers from the parent in the right order" do + $arr = [] + OverriddenInitializer.new.run_initializers + assert_equal [1, 2, 3], $arr + end + end end \ No newline at end of file -- cgit v1.2.3 From 43694269934540de2a73130d7ff47bd1a25ed3e4 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 5 Nov 2009 14:45:53 -0800 Subject: Add the ability to merge initializers from various objects in order. --- railties/test/initializable_test.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index 463fdc03c0..2920883132 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -94,7 +94,11 @@ module InitializableTests include Rails::Initializable initializer :startup, :before => :last do - $arr << 2 + $arr << two + end + + def two + 2 end end @@ -109,7 +113,7 @@ module InitializableTests end def self.initializers - super + MoreInitializers.initializers + super + MoreInitializers.new.initializers end end -- cgit v1.2.3 From b0dfd1d19b83f1812317345a68c6bc1ad590be53 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 5 Nov 2009 15:37:01 -0800 Subject: Update Ruby version check to 1.8.7 --- .../test/initializer/check_ruby_version_test.rb | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index cf956e68fb..97d884e1be 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -14,24 +14,32 @@ module InitializerTests assert_rails_does_not_boot "1.8.1" end - test "rails initializes with ruby version 1.8.2" do - assert_rails_boots "1.8.2" + 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 initializes with ruby version 1.8.4" do - assert_rails_boots "1.8.4" + test "rails does not initialize with ruby version 1.8.4" do + assert_rails_does_not_boot "1.8.4" end - test "rails initializes with ruby version 1.8.5" do - assert_rails_boots "1.8.5" + test "rails does not initializes with ruby version 1.8.5" do + assert_rails_does_not_boot "1.8.5" end - test "rails initializes with ruby version 1.8.6" do - assert_rails_boots "1.8.6" + 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) @@ -39,8 +47,8 @@ module InitializerTests Object.const_set(:RUBY_VERSION, version.freeze) end - def assert_rails_boots(version) - set_ruby_version(version) + def assert_rails_boots(version = nil) + set_ruby_version(version) if version assert_nothing_raised "It appears that rails does not boot" do Rails::Initializer.run { |c| c.frameworks = [] } Rails.initialize! -- cgit v1.2.3 From 60911c39336fea92536f78a4deb6b52535b613cd Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 5 Nov 2009 16:04:43 -0800 Subject: Ruby 1.9: Rack apps must *always* take an env arg on 1.9 --- railties/test/metal_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb index 6864254e4c..2256b191e2 100644 --- a/railties/test/metal_test.rb +++ b/railties/test/metal_test.rb @@ -85,7 +85,7 @@ class MetalTest < Test::Unit::TestCase private def app - lambda{[402,{},["End of the Line"]]} + lambda{|env|[402,{},["End of the Line"]]} end def use_appdir(root) -- cgit v1.2.3 From cb9a1759c0b8ad104b8e591b952bc440f9e06dc0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 5 Nov 2009 16:11:52 -0800 Subject: Fix generators tests that expect a class name --- railties/test/generators_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 07f51eca01..9c9a4e6016 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'generators', 'generators_test_helper') +require 'generators/generators_test_helper' require 'rails/generators/rails/model/model_generator' require 'rails/generators/test_unit/model/model_generator' require 'mocha' -- cgit v1.2.3 From a66449d85255fc3ec69aa842b8059f954d7b76e2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 9 Nov 2009 14:36:49 -0800 Subject: Ruby 1.9.2: work around inherited hook being called before yielding to block --- railties/test/generators_test.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 9c9a4e6016..5579e0f40d 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -165,15 +165,13 @@ class GeneratorsTest < GeneratorsTestCase def test_developer_options_are_overwriten_by_user_options Rails::Generators.options[:new_generator] = { :generate => false } - klass = Class.new(Rails::Generators::Base) do - def self.name - "NewGenerator" + self.class.class_eval <<-end_eval + class NewGenerator < Rails::Generators::Base + class_option :generate, :default => true end + end_eval - class_option :generate, :default => true - end - - assert_equal false, klass.class_options[:generate].default + assert_equal false, NewGenerator.class_options[:generate].default end def test_source_paths_for_not_namespaced_generators -- cgit v1.2.3 From 3ce6a10b67b8a683c2543b29ac71102ca452e8b8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 9 Nov 2009 20:09:55 -0800 Subject: Contortions to work around brittle naming dependency --- railties/test/generators_test.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 5579e0f40d..a8716d9992 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -165,13 +165,12 @@ class GeneratorsTest < GeneratorsTestCase def test_developer_options_are_overwriten_by_user_options Rails::Generators.options[:new_generator] = { :generate => false } - self.class.class_eval <<-end_eval - class NewGenerator < Rails::Generators::Base - class_option :generate, :default => true - end - end_eval + klass = Class.new(Rails::Generators::Base) do + def self.name() 'NewGenerator' end + class_option :generate, :default => true + end - assert_equal false, NewGenerator.class_options[:generate].default + assert_equal false, klass.class_options[:generate].default end def test_source_paths_for_not_namespaced_generators -- cgit v1.2.3 From 335c0e62cd1e809a79e209977a62dba2e583cb88 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Nov 2009 22:36:30 -0600 Subject: Fix railties isolated tests if bundler environment doesn't exist --- railties/test/isolation/abstract_unit.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 462a4d8dea..0b479e944c 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -157,9 +157,13 @@ Module.new do FileUtils.mkdir(tmp_path) environment = File.expand_path('../../../../vendor/gems/environment', __FILE__) + if File.exist?(environment) + require_environment = "-r #{environment}" + end - `#{Gem.ruby} -r #{environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` + `#{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}' ; require 'rails'" + f.puts "require '#{environment}'" if require_environment + f.puts "require 'rails'" end end -- cgit v1.2.3 From 322b6b29c272aa6c9b9d2556b736dbe32db3aa45 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 10 Nov 2009 21:04:00 -0800 Subject: test-unit 2: filter_backtrace is private --- railties/test/backtrace_cleaner_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 4e273852e0..6cff591b94 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -16,12 +16,12 @@ if defined? Test::Unit::Util::BacktraceFilter test "test with backtrace should use the rails backtrace cleaner to clean" do Rails.stubs(:backtrace_cleaner).returns(stub(:clean)) Rails.backtrace_cleaner.expects(:clean).with(@backtrace, nil) - @test.filter_backtrace(@backtrace) + @test.send(:filter_backtrace, @backtrace) end test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do assert_nothing_raised do - @test.filter_backtrace(@backtrace, '/opt/local/lib') + @test.send(:filter_backtrace, @backtrace, '/opt/local/lib') end end end -- cgit v1.2.3 From 82b9b151ffde44305d67744c0bfd9bb5505f6fbe Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 6 Nov 2009 17:21:39 -0800 Subject: Refactor plugins --- railties/test/application/plugins_test.rb | 117 ------------- railties/test/initializable_test.rb | 8 +- railties/test/initializer/initialize_i18n_test.rb | 42 ++--- railties/test/isolation/abstract_unit.rb | 28 ++++ railties/test/plugin_loader_test.rb | 176 -------------------- railties/test/plugin_locator_test.rb | 73 --------- railties/test/plugin_test.rb | 174 -------------------- railties/test/plugin_test_helper.rb | 29 ---- railties/test/plugins/vendored_test.rb | 190 +++++++++++++++++++++- 9 files changed, 238 insertions(+), 599 deletions(-) delete mode 100644 railties/test/application/plugins_test.rb delete mode 100644 railties/test/plugin_loader_test.rb delete mode 100644 railties/test/plugin_locator_test.rb delete mode 100644 railties/test/plugin_test.rb delete mode 100644 railties/test/plugin_test_helper.rb (limited to 'railties/test') diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb deleted file mode 100644 index 80a19856d7..0000000000 --- a/railties/test/application/plugins_test.rb +++ /dev/null @@ -1,117 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class PluginTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def assert_plugins(list_of_names, array_of_plugins, message=nil) - assert_equal list_of_names.map { |n| n.to_s }, array_of_plugins.map { |p| p.name }, message - end - - def setup - build_app - boot_rails - require "rails" - @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - # Tmp hax to get tests working - FileUtils.cp_r "#{File.dirname(__FILE__)}/../fixtures/plugins", "#{app_path}/vendor" - end - - test "all plugins are loaded when registered plugin list is untouched" do - Rails::Initializer.run { |c| c.root = app_path } - Rails.initialize! - assert_plugins [ - :a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby - ], Rails.application.config.loaded_plugins, @failure_tip - end - - test "no plugins are loaded if the configuration has an empty plugin list" do - Rails::Initializer.run { |c| c.root = app_path; c.plugins = [] } - assert_plugins [], Rails.application.config.loaded_plugins - end - - test "only the specified plugins are located in the order listed" do - plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon] - Rails::Initializer.run { |c| c.root = app_path; c.plugins = plugin_names } - Rails.initialize! - assert_plugins plugin_names, Rails.application.config.loaded_plugins - end - - test "all plugins loaded after all" do - Rails::Initializer.run do |config| - config.root = app_path - config.plugins = [:stubby, :all, :acts_as_chunky_bacon] - end - Rails.initialize! - assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], Rails.application.config.loaded_plugins, @failure_tip - end - - test "plugin names may be strings" do - plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] - Rails::Initializer.run do |config| - config.root = app_path - config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] - end - Rails.initialize! - - assert_plugins plugin_names, Rails.application.config.loaded_plugins, @failure_tip - end - - test "all plugins loaded when all is used" do - Rails::Initializer.run do |config| - config.root = app_path - config.plugins = [:stubby, :acts_as_chunky_bacon, :all] - end - Rails.initialize! - - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], Rails.application.config.loaded_plugins, @failure_tip - end - - test "all loaded plugins are added to the load paths" do - Rails::Initializer.run do |config| - config.root = app_path - config.plugins = [:stubby, :acts_as_chunky_bacon] - end - Rails.initialize! - - assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/stubby/lib") - assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/acts/acts_as_chunky_bacon/lib") - end - - test "registering a plugin name that does not exist raises a load error" do - Rails::Initializer.run do |config| - config.root = app_path - config.plugins = [:stubby, :acts_as_a_non_existant_plugin] - end - - assert_raise(LoadError) do - Rails.initialize! - end - end - - test "load error messages mention missing plugins and no others" do - valid_plugins = [:stubby, :acts_as_chunky_bacon] - invalid_plugins = [:non_existant_plugin1, :non_existant_plugin2] - - begin - Rails::Initializer.run do |config| - config.root = app_path - config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2] - end - Rails.initialize! - flunk "Expected a LoadError but did not get one" - rescue LoadError => e - assert_plugins valid_plugins, Rails.application.config.loaded_plugins, @failure_tip - - invalid_plugins.each do |plugin| - assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'") - end - - valid_plugins.each do |plugin| - assert_no_match(/#{plugin.to_s}/, e.message, "LoadError message should not mention '#{plugin}'") - end - end - end - - end -end \ No newline at end of file diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index 2920883132..a9e60680ac 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -94,6 +94,10 @@ module InitializableTests include Rails::Initializable initializer :startup, :before => :last do + $arr << 3 + end + + initializer :terminate, :after => :first do $arr << two end @@ -109,7 +113,7 @@ module InitializableTests end initializer :last do - $arr << 3 + $arr << 4 end def self.initializers @@ -189,7 +193,7 @@ module InitializableTests test "merges in the initializers from the parent in the right order" do $arr = [] OverriddenInitializer.new.run_initializers - assert_equal [1, 2, 3], $arr + assert_equal [1, 2, 3, 4], $arr end end end \ No newline at end of file diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index d664f96ad1..076816d73b 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -30,27 +30,27 @@ module InitializerTests 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) } + # 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/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 0b479e944c..145d16b6d9 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -92,6 +92,34 @@ module TestHelpers add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' end + class Bukkit + def initialize(path) + @path = path + end + + def write(file, string) + path = "#{@path}/#{file}" + FileUtils.mkdir_p(File.dirname(path)) + File.open(path, "w") {|f| f.puts string } + end + + def delete(file) + File.delete("#{@path}/#{file}") + end + end + + def plugin(name, string = "") + dir = "#{app_path}/vendor/plugins/#{name}" + FileUtils.mkdir_p(dir) + File.open("#{dir}/init.rb", 'w') do |f| + f.puts "::#{name.upcase} = 'loaded'" + f.puts string + end + Bukkit.new(dir).tap do |bukkit| + yield bukkit if block_given? + end + end + def script(script) Dir.chdir(app_path) do `#{Gem.ruby} #{app_path}/script/#{script}` diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb deleted file mode 100644 index 0b43c49bb2..0000000000 --- a/railties/test/plugin_loader_test.rb +++ /dev/null @@ -1,176 +0,0 @@ -require 'plugin_test_helper' - -$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" -$:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib" -require 'action_controller' -require 'action_mailer' - -# TODO: Rewrite all these tests -class FakeInitializerSlashApplication - attr_reader :config - alias configuration config - - def initialize - @config = Rails::Configuration.new - end -end - -class TestPluginLoader < Test::Unit::TestCase - ORIGINAL_LOAD_PATH = $LOAD_PATH.dup - - def setup - reset_load_path! - - @initializer = FakeInitializerSlashApplication.new - @configuration = @initializer.config - Rails.application = @initializer - @configuration.plugin_paths << plugin_fixture_root_path - @valid_plugin_path = plugin_fixture_path('default/stubby') - @empty_plugin_path = plugin_fixture_path('default/empty') - - @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - - @loader = Rails::Plugin::Loader.new(@initializer) - end - - def test_should_locate_plugins_by_asking_each_locator_specifed_in_configuration_for_its_plugins_result - locator_1 = stub(:plugins => [:a, :b, :c]) - locator_2 = stub(:plugins => [:d, :e, :f]) - locator_class_1 = stub(:new => locator_1) - locator_class_2 = stub(:new => locator_2) - @configuration.plugin_locators = [locator_class_1, locator_class_2] - assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins) - end - - def test_should_memoize_the_result_of_locate_plugins_as_all_plugins - plugin_list = [:a, :b, :c] - @loader.expects(:locate_plugins).once.returns(plugin_list) - assert_equal plugin_list, @loader.all_plugins - assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again - end - - def test_should_return_empty_array_if_configuration_plugins_is_empty - @configuration.plugins = [] - assert_equal [], @loader.plugins - end - - def test_should_find_all_availble_plugins_and_return_as_all_plugins - assert_plugins [ :engine, :stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip - end - - def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched - assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end - - def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil - @configuration.plugins = nil - assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end - - def test_should_return_specific_plugins_named_in_config_plugins_array_if_set - plugin_names = [:acts_as_chunky_bacon, :stubby] - only_load_the_following_plugins! plugin_names - assert_plugins plugin_names, @loader.plugins - end - - def test_should_respect_the_order_of_plugins_given_in_configuration - plugin_names = [:stubby, :acts_as_chunky_bacon] - only_load_the_following_plugins! plugin_names - assert_plugins plugin_names, @loader.plugins - end - - def test_should_load_all_plugins_in_natural_order_when_all_is_used - only_load_the_following_plugins! [:all] - assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end - - def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip - end - - def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all - only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] - assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip - end - - def test_should_accept_plugin_names_given_as_strings - only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip - end - - def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - stubbed_application_lib_index_in_LOAD_PATHS = 4 - @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS) - - @loader.add_plugin_load_paths - - assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS - assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS - end - - def test_should_add_plugin_load_paths_to_Dependencies_load_paths - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - - @loader.add_plugin_load_paths - - assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) - assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) - end - - def test_should_add_engine_load_paths_to_Dependencies_load_paths - only_load_the_following_plugins! [:engine] - - @loader.add_plugin_load_paths - - %w( models controllers metal helpers ).each do |app_part| - assert ActiveSupport::Dependencies.load_paths.include?( - File.join(plugin_fixture_path('engines/engine'), 'app', app_part) - ), "Couldn't find #{app_part} in load path" - end - end - - def test_engine_controllers_and_action_mailers_should_have_their_view_path_set_when_loaded - only_load_the_following_plugins!([ :engine ]) - - @loader.send :add_engine_view_paths - - assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths.map { |p| p.to_s } - assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionMailer::Base.view_paths.map { |p| p.to_s } - end - - def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - - @loader.add_plugin_load_paths - - assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) - assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) - end - - def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array - plugin_load_paths = ["a", "b"] - plugin = stub(:load_paths => plugin_load_paths) - @loader.stubs(:plugins).returns([plugin]) - - @loader.add_plugin_load_paths - - plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) } - end - - def test_should_add_locale_files_to_I18n_load_path - only_load_the_following_plugins! [:engine] - - @loader.send :add_engine_locales - - assert I18n.load_path.include?(File.join(plugin_fixture_path('engines/engine'), 'config', 'locales', 'en.yml')) - end - - - private - def reset_load_path! - $LOAD_PATH.clear - ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } - end -end diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb deleted file mode 100644 index ef57e7ed4c..0000000000 --- a/railties/test/plugin_locator_test.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'plugin_test_helper' - -# TODO: Rewrite all these tests -class FakeInitializerSlashApplication - attr_reader :config - alias configuration config - - def initialize - @config = Rails::Configuration.new - end -end - -class PluginLocatorTest < Test::Unit::TestCase - def test_should_require_subclasses_to_implement_the_plugins_method - assert_raise(RuntimeError) do - Rails::Plugin::Locator.new(nil).plugins - end - end - - def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each - locator = Rails::Plugin::Locator.new(nil) - locator.stubs(:plugins).returns([:a, :b, :c]) - plugin_consumer = mock - plugin_consumer.expects(:consume).with(:a) - plugin_consumer.expects(:consume).with(:b) - plugin_consumer.expects(:consume).with(:c) - - locator.each do |plugin| - plugin_consumer.consume(plugin) - end - end -end - -class PluginFileSystemLocatorTest < Test::Unit::TestCase - def setup - @initializer = FakeInitializerSlashApplication.new - @configuration = @initializer.config - Rails.application = @initializer - # We need to add our testing plugin directory to the plugin paths so - # the locator knows where to look for our plugins - @configuration.plugin_paths << plugin_fixture_root_path - @locator = Rails::Plugin::FileSystemLocator.new(@initializer) - @valid_plugin_path = plugin_fixture_path('default/stubby') - @empty_plugin_path = plugin_fixture_path('default/empty') - end - - def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory - assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path) - end - - def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory - assert_nil @locator.send(:create_plugin, @empty_plugin_path) - end - - def test_should_return_all_plugins_found_under_the_set_plugin_paths - assert_equal ["a", "acts_as_chunky_bacon", "engine", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map { |p| p.name }.sort - end - - def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration - @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")] - assert_equal ["acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map { |p| p.name }.sort - - @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")] - assert_equal ["a"], @locator.plugins.map { |p| p.name } - end - - def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist - @configuration.plugin_paths = ["some_missing_directory"] - assert_nothing_raised do - assert @locator.plugins.empty? - end - end -end diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb deleted file mode 100644 index 199adcfe39..0000000000 --- a/railties/test/plugin_test.rb +++ /dev/null @@ -1,174 +0,0 @@ -require 'plugin_test_helper' - -# TODO: Rewrite all these tests -class FakeInitializerSlashApplication - attr_reader :config - alias configuration config - - def initialize - @config = Rails::Configuration.new - end -end - -class PluginTest < Test::Unit::TestCase - def setup - @initializer = FakeInitializerSlashApplication.new - @configuration = @initializer.config - Rails.application = @initializer - @valid_plugin_path = plugin_fixture_path('default/stubby') - @empty_plugin_path = plugin_fixture_path('default/empty') - @gemlike_plugin_path = plugin_fixture_path('default/gemlike') - end - - def test_should_determine_plugin_name_from_the_directory_of_the_plugin - assert_equal 'stubby', plugin_for(@valid_plugin_path).name - assert_equal 'empty', plugin_for(@empty_plugin_path).name - end - - def test_should_not_be_loaded_when_created - assert !plugin_for(@valid_plugin_path).loaded? - end - - def test_should_be_marked_as_loaded_when_load_is_called - plugin = plugin_for(@valid_plugin_path) - assert !plugin.loaded? - plugin.stubs(:evaluate_init_rb) - assert_nothing_raised do - plugin.send(:load, anything) - end - assert plugin.loaded? - end - - def test_should_determine_validity_of_given_path - # This is a plugin path, with a lib dir - assert plugin_for(@valid_plugin_path).valid? - # This just has an init.rb and no lib dir - assert plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).valid? - # This would be a plugin path, but the directory is empty - assert !plugin_for(plugin_fixture_path('default/empty')).valid? - # This is a non sense path - assert !plugin_for(plugin_fixture_path('default/this_directory_does_not_exist')).valid? - end - - def test_should_return_empty_array_for_load_paths_when_plugin_has_no_lib_directory - assert_equal [], plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).load_paths - end - - def test_should_return_array_with_lib_path_for_load_paths_when_plugin_has_a_lib_directory - expected_lib_dir = File.join(plugin_fixture_path('default/stubby'), 'lib') - assert_equal [expected_lib_dir], plugin_for(plugin_fixture_path('default/stubby')).load_paths - end - - def test_should_raise_a_load_error_when_trying_to_determine_the_load_paths_from_an_invalid_plugin - assert_nothing_raised do - plugin_for(@valid_plugin_path).load_paths - end - - assert_raise(LoadError) do - plugin_for(@empty_plugin_path).load_paths - end - - assert_raise(LoadError) do - plugin_for('this_is_not_a_plugin_directory').load_paths - end - end - - def test_should_raise_a_load_error_when_trying_to_load_an_invalid_plugin - # This path is fine so nothing is raised - assert_nothing_raised do - plugin = plugin_for(@valid_plugin_path) - plugin.stubs(:evaluate_init_rb) - plugin.send(:load, @initializer) - end - - # This path is fine so nothing is raised - assert_nothing_raised do - plugin = plugin_for(@gemlike_plugin_path) - plugin.stubs(:evaluate_init_rb) - plugin.send(:load, @initializer) - end - - # This is an empty path so it raises - assert_raise(LoadError) do - plugin = plugin_for(@empty_plugin_path) - plugin.stubs(:evaluate_init_rb) - plugin.send(:load, @initializer) - end - - assert_raise(LoadError) do - plugin = plugin_for('this_is_not_a_plugin_directory') - plugin.stubs(:evaluate_init_rb) - plugin.send(:load, @initializer) - end - end - - def test_should_raise_a_load_error_when_trying_to_access_load_paths_of_an_invalid_plugin - # This path is fine so nothing is raised - assert_nothing_raised do - plugin_for(@valid_plugin_path).load_paths - end - - # This is an empty path so it raises - assert_raise(LoadError) do - plugin_for(@empty_plugin_path).load_paths - end - - assert_raise(LoadError) do - plugin_for('this_is_not_a_plugin_directory').load_paths - end - end - - def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs - failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already." - assert !defined?(StubbyMixin), failure_tip - plugin = plugin_for(@valid_plugin_path) - plugin.load_paths.each { |path| $LOAD_PATH.unshift(path) } - # The init.rb of this plugin raises if it doesn't have access to all the things it needs - assert_nothing_raised do - plugin.load(@initializer) - end - assert defined?(StubbyMixin) - end - - def test_should_sort_naturally_by_name - a = plugin_for("path/a") - b = plugin_for("path/b") - z = plugin_for("path/z") - assert_equal [a, b, z], [b, z, a].sort - end - - def test_should_only_be_loaded_once - plugin = plugin_for(@valid_plugin_path) - assert !plugin.loaded? - plugin.expects(:evaluate_init_rb) - assert_nothing_raised do - plugin.send(:load, @initializer) - plugin.send(:load, @initializer) - end - assert plugin.loaded? - end - - def test_should_make_about_yml_available_as_about_method_on_plugin - plugin = plugin_for(@valid_plugin_path) - assert_equal "Plugin Author", plugin.about['author'] - assert_equal "1.0.0", plugin.about['version'] - end - - def test_should_return_empty_hash_for_about_if_about_yml_is_missing - assert_equal({}, plugin_for(about_yml_plugin_path('plugin_without_about_yaml')).about) - end - - def test_should_return_empty_hash_for_about_if_about_yml_is_malformed - assert_equal({}, plugin_for(about_yml_plugin_path('bad_about_yml')).about) - end - - private - - def about_yml_plugin_path(name) - File.join(File.dirname(__FILE__), 'fixtures', 'about_yml_plugins', name) - end - - def plugin_for(path) - Rails::Plugin.new(path) - end -end diff --git a/railties/test/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb deleted file mode 100644 index 93004e0ddf..0000000000 --- a/railties/test/plugin_test_helper.rb +++ /dev/null @@ -1,29 +0,0 @@ -$:.unshift File.dirname(__FILE__) + "/../lib" -$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" - -require 'test/unit' -require 'active_support' -require 'rails/initializer' -require 'abstract_unit' - -# We need to set RAILS_ROOT if it isn't already set -RAILS_ROOT = '.' unless defined?(RAILS_ROOT) - -class Test::Unit::TestCase - private - def plugin_fixture_root_path - File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'plugins')) - end - - def only_load_the_following_plugins!(plugins) - @initializer.configuration.plugins = plugins - end - - def plugin_fixture_path(path) - File.join(plugin_fixture_root_path, path) - end - - def assert_plugins(list_of_names, array_of_plugins, message=nil) - assert_equal list_of_names.map { |n| n.to_s }, array_of_plugins.map { |p| p.name }, message - end -end diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 71de542ff7..9a2d40cad8 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -1,19 +1,195 @@ require "isolation/abstract_unit" -module ApplicationTests - class PluginTest < Test::Unit::TestCase +module PluginsTest + class VendoredTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation def setup build_app - end - test "generates the plugin" do - script "generate plugin my_plugin" - File.open("#{app_path}/vendor/plugins/my_plugin/init.rb", 'w') do |f| - f.puts "OMG = 'hello'" + @plugin = plugin "bukkits", "::LEVEL = config.log_level" do |plugin| + plugin.write "lib/bukkits.rb", "class Bukkits; end" end + end + + def boot_rails + super + require "#{app_path}/config/environment" + end + + test "it loads the plugin's init.rb file" do + boot_rails + assert_equal "loaded", BUKKITS + end + + test "the init.rb file has access to the config object" do + boot_rails + assert_equal :debug, LEVEL + end + + test "the plugin puts its lib directory on the load path" do + boot_rails + require "bukkits" + assert_equal "Bukkits", Bukkits.name + end + + test "plugin paths get added to the AS::Dependency list" do + boot_rails + assert_equal "Bukkits", Bukkits.name + end + + test "plugin constants do not get reloaded by default" do + boot_rails + assert_equal "Bukkits", Bukkits.name + ActiveSupport::Dependencies.clear + @plugin.delete("lib/bukkits.rb") + assert_nothing_raised { Bukkits } + end + + test "plugin constants get reloaded if config.reload_plugins is set" do + add_to_config <<-RUBY + config.reload_plugins = true + RUBY + + boot_rails + + assert_equal "Bukkits", Bukkits.name + ActiveSupport::Dependencies.clear + @plugin.delete("lib/bukkits.rb") + assert_raises(NameError) { Bukkits } + end + + test "plugin should work without init.rb" do + @plugin.delete("init.rb") + + boot_rails + + require "bukkits" + assert_nothing_raised { Bukkits } + end + + test "the plugin puts its models directory on the load path" do + @plugin.write "app/models/my_bukkit.rb", "class MyBukkit ; end" + + boot_rails + + assert_nothing_raised { MyBukkit } + end + + test "the plugin puts is controllers directory on the load path" do + @plugin.write "app/controllers/bukkit_controller.rb", "class BukkitController ; end" + + boot_rails + + assert_nothing_raised { BukkitController } + end + + test "the plugin adds its view to the load path" do + @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY + class BukkitController < ActionController::Base + def index + end + end + RUBY + + @plugin.write "app/views/bukkit/index.html.erb", "Hello bukkits" + + boot_rails + + require "action_controller" + require "rack/mock" + response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) + assert_equal "Hello bukkits\n", response[2].body + end + + test "the plugin adds helpers to the controller's views" do + @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY + class BukkitController < ActionController::Base + def index + end + end + RUBY + + @plugin.write "app/helpers/bukkit_helper.rb", <<-RUBY + module BukkitHelper + def bukkits + "bukkits" + end + end + RUBY + + @plugin.write "app/views/bukkit/index.html.erb", "Hello <%= bukkits %>" + + boot_rails + + require "rack/mock" + response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) + assert_equal "Hello bukkits\n", response[2].body + end + + test "routes.rb are added to the router" do + @plugin.write "config/routes.rb", <<-RUBY + class Sprokkit + def self.call(env) + [200, {'Content-Type' => 'text/html'}, ["I am a Sprokkit"]] + end + end + + ActionController::Routing::Routes.draw do + match "/sprokkit", :to => Sprokkit + end + RUBY + + boot_rails + require "rack/mock" + response = Rails.application.call(Rack::MockRequest.env_for("/sprokkit")) + assert_equal "I am a Sprokkit", response[2].join + end + end + + class VendoredOrderingTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + $arr = [] + plugin "a_plugin", "$arr << :a" + plugin "b_plugin", "$arr << :b" + plugin "c_plugin", "$arr << :c" + end + + def boot_rails + super require "#{app_path}/config/environment" end + + test "plugins are loaded alphabetically by default" do + boot_rails + assert_equal [:a, :b, :c], $arr + end + + test "if specified, only those plugins are loaded" do + add_to_config "config.plugins = [:b_plugin]" + boot_rails + assert_equal [:b], $arr + end + + test "the plugins are initialized in the order they are specified" do + add_to_config "config.plugins = [:b_plugin, :a_plugin]" + boot_rails + assert_equal [:b, :a], $arr + end + + test "if :all is specified, the remaining plugins are loaded in alphabetical order" do + add_to_config "config.plugins = [:c_plugin, :all]" + boot_rails + assert_equal [:c, :a, :b], $arr + end + + test "if :all is at the beginning, it represents the plugins not otherwise specified" do + add_to_config "config.plugins = [:all, :b_plugin]" + boot_rails + assert_equal [:a, :c, :b], $arr + end end end \ No newline at end of file -- cgit v1.2.3 From 313a7ea9d63f3df6e4ad0ef9941f83394f95fa0b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 14 Nov 2009 02:38:22 -0800 Subject: Fix bundler environment check --- railties/test/isolation/abstract_unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 145d16b6d9..ba8b35d5cc 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -185,7 +185,7 @@ Module.new do FileUtils.mkdir(tmp_path) environment = File.expand_path('../../../../vendor/gems/environment', __FILE__) - if File.exist?(environment) + if File.exist?("#{environment}.rb") require_environment = "-r #{environment}" end -- cgit v1.2.3 From 795213a5f44f750d431fccdfd00d8520264bba0e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 14 Nov 2009 02:38:35 -0800 Subject: Just use abstract_unit --- railties/test/rails_info_test.rb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index dcf9966c0d..fc28d7e912 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -1,15 +1,4 @@ -$:.unshift File.dirname(__FILE__) + "/../lib" -$:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" -$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" -$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" - -require 'rubygems' -gem 'rack', '~> 1.0.0' - -require 'test/unit' -require 'active_support' -require 'active_support/test_case' -require 'action_controller' +require 'abstract_unit' unless defined?(Rails) && defined?(Rails::Info) module Rails -- cgit v1.2.3