From eec2d301d4ce9df9c71c1a5aa63053eb970b6818 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 15 Feb 2010 10:20:11 -0600 Subject: Fix test load paths for those not using bundler --- railties/test/abstract_unit.rb | 7 ++++++- railties/test/application/configuration_test.rb | 2 +- railties/test/edge_rails.rb | 14 ++++++++++++++ railties/test/isolation/abstract_unit.rb | 14 ++++---------- 4 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 railties/test/edge_rails.rb (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index aa66dbb9be..2ac165fc49 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,8 +1,13 @@ ORIG_ARGV = ARGV.dup -require File.expand_path("../../../load_paths", __FILE__) +require File.expand_path("../../../bundler", __FILE__) $:.unshift File.expand_path("../../builtin/rails_info", __FILE__) +lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") +$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) + +require 'edge_rails' + require 'stringio' require 'test/unit' require 'fileutils' diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 56f45582c8..7ca605ec23 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -140,7 +140,7 @@ module ApplicationTests require "#{app_path}/config/environment" end end - + test "filter_parameters should be able to set via config.filter_parameters" do add_to_config <<-RUBY config.filter_parameters += [ :foo, 'bar', lambda { |key, value| diff --git a/railties/test/edge_rails.rb b/railties/test/edge_rails.rb new file mode 100644 index 0000000000..bd8a674738 --- /dev/null +++ b/railties/test/edge_rails.rb @@ -0,0 +1,14 @@ +require File.expand_path('../../../bundler', __FILE__) + +%w( + actionmailer + actionpack + activemodel + activerecord + activeresource + activesupport + railties +).each do |framework| + framework_path = File.expand_path("../../../#{framework}/lib", __FILE__) + $:.unshift(framework_path) if File.directory?(framework_path) && !$:.include?(framework_path) +end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 364dbd8e55..f3c1d64f7b 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -187,7 +187,7 @@ module TestHelpers end def boot_rails - require File.expand_path('../../../../load_paths', __FILE__) + require File.expand_path('../../edge_rails', __FILE__) end end end @@ -208,18 +208,12 @@ Module.new do end FileUtils.mkdir(tmp_path) - environment = File.expand_path('../../../../load_paths', __FILE__) - if File.exist?("#{environment}.rb") - require_environment = "-r #{environment}" - end + environment = File.expand_path('../../edge_rails', __FILE__) + require_environment = "-r #{environment}" `#{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| - if require_environment - f.puts "Dir.chdir('#{File.dirname(environment)}') do" - f.puts " require '#{environment}'" - f.puts "end" - end + f.puts "require '#{environment}'" f.puts "require 'rails/all'" end end -- cgit v1.2.3 From f0523f72b46db14e2f50c8347a8708734c650f84 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 15 Feb 2010 21:44:30 +0700 Subject: Rename Rails::Subscriber to Rails::LogSubscriber --- .../application/initializers/notifications_test.rb | 2 +- railties/test/log_subscriber_test.rb | 119 +++++++++++++++++++++ railties/test/railties/railtie_test.rb | 8 +- railties/test/subscriber_test.rb | 119 --------------------- 4 files changed, 124 insertions(+), 124 deletions(-) create mode 100644 railties/test/log_subscriber_test.rb delete mode 100644 railties/test/subscriber_test.rb (limited to 'railties/test') diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb index 061bb34c19..b99cf5bb4f 100644 --- a/railties/test/application/initializers/notifications_test.rb +++ b/railties/test/application/initializers/notifications_test.rb @@ -28,7 +28,7 @@ module ApplicationTests ActiveSupport::Notifications.notifier.wait end - test "rails subscribers are added" do + test "rails log_subscribers are added" do add_to_config <<-RUBY config.colorize_logging = false RUBY diff --git a/railties/test/log_subscriber_test.rb b/railties/test/log_subscriber_test.rb new file mode 100644 index 0000000000..be176df1bb --- /dev/null +++ b/railties/test/log_subscriber_test.rb @@ -0,0 +1,119 @@ +require 'abstract_unit' +require 'rails/log_subscriber/test_helper' + +class MyLogSubscriber < Rails::LogSubscriber + attr_reader :event + + def some_event(event) + @event = event + info event.name + end + + def foo(event) + debug "debug" + info "info" + warn "warn" + end + + def bar(event) + info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}" + end + + def puke(event) + raise "puke" + end +end + +class SyncLogSubscriberTest < ActiveSupport::TestCase + include Rails::LogSubscriber::TestHelper + + def setup + super + @log_subscriber = MyLogSubscriber.new + Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil) + end + + def teardown + super + Rails::LogSubscriber.log_subscribers.clear + Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil) + end + + def instrument(*args, &block) + ActiveSupport::Notifications.instrument(*args, &block) + end + + def test_proxies_method_to_rails_logger + @log_subscriber.foo(nil) + assert_equal %w(debug), @logger.logged(:debug) + assert_equal %w(info), @logger.logged(:info) + assert_equal %w(warn), @logger.logged(:warn) + end + + def test_set_color_for_messages + Rails::LogSubscriber.colorize_logging = true + @log_subscriber.bar(nil) + assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last + end + + def test_does_not_set_color_if_colorize_logging_is_set_to_false + @log_subscriber.bar(nil) + assert_equal "cool, isn't it?", @logger.logged(:info).last + end + + def test_event_is_sent_to_the_registered_class + Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber + instrument "my_log_subscriber.some_event" + wait + assert_equal %w(my_log_subscriber.some_event), @logger.logged(:info) + end + + def test_event_is_an_active_support_notifications_event + Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber + instrument "my_log_subscriber.some_event" + wait + assert_kind_of ActiveSupport::Notifications::Event, @log_subscriber.event + end + + def test_does_not_send_the_event_if_it_doesnt_match_the_class + Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber + instrument "my_log_subscriber.unknown_event" + wait + # If we get here, it means that NoMethodError was raised. + end + + def test_does_not_send_the_event_if_logger_is_nil + Rails.logger = nil + @log_subscriber.expects(:some_event).never + Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber + instrument "my_log_subscriber.some_event" + wait + end + + def test_flushes_loggers + Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber + Rails::LogSubscriber.flush_all! + assert_equal 1, @logger.flush_count + end + + def test_flushes_the_same_logger_just_once + Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber + Rails::LogSubscriber.add :another, @log_subscriber + Rails::LogSubscriber.flush_all! + wait + assert_equal 1, @logger.flush_count + end + + def test_logging_does_not_die_on_failures + Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber + instrument "my_log_subscriber.puke" + instrument "my_log_subscriber.some_event" + wait + + assert_equal 1, @logger.logged(:info).size + assert_equal 'my_log_subscriber.some_event', @logger.logged(:info).last + + assert_equal 1, @logger.logged(:error).size + assert_equal 'Could not log "my_log_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last + end +end \ No newline at end of file diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb index b723e08281..9eb4e9993a 100644 --- a/railties/test/railties/railtie_test.rb +++ b/railties/test/railties/railtie_test.rb @@ -51,12 +51,12 @@ module RailtiesTest assert_equal "bar", Bar.config.foo.bar end - test "railtie can add subscribers" do + test "railtie can add log subscribers" do begin - class Foo < Rails::Railtie ; subscriber(Rails::Subscriber.new) ; end - assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo] + class Foo < Rails::Railtie ; log_subscriber(Rails::LogSubscriber.new) ; end + assert_kind_of Rails::LogSubscriber, Rails::LogSubscriber.log_subscribers[:foo] ensure - Rails::Subscriber.subscribers.clear + Rails::LogSubscriber.log_subscribers.clear end end diff --git a/railties/test/subscriber_test.rb b/railties/test/subscriber_test.rb deleted file mode 100644 index f6c895093f..0000000000 --- a/railties/test/subscriber_test.rb +++ /dev/null @@ -1,119 +0,0 @@ -require 'abstract_unit' -require 'rails/subscriber/test_helper' - -class MySubscriber < Rails::Subscriber - attr_reader :event - - def some_event(event) - @event = event - info event.name - end - - def foo(event) - debug "debug" - info "info" - warn "warn" - end - - def bar(event) - info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}" - end - - def puke(event) - raise "puke" - end -end - -class SyncSubscriberTest < ActiveSupport::TestCase - include Rails::Subscriber::TestHelper - - def setup - super - @subscriber = MySubscriber.new - Rails::Subscriber.instance_variable_set(:@log_tailer, nil) - end - - def teardown - super - Rails::Subscriber.subscribers.clear - Rails::Subscriber.instance_variable_set(:@log_tailer, nil) - end - - def instrument(*args, &block) - ActiveSupport::Notifications.instrument(*args, &block) - end - - def test_proxies_method_to_rails_logger - @subscriber.foo(nil) - assert_equal %w(debug), @logger.logged(:debug) - assert_equal %w(info), @logger.logged(:info) - assert_equal %w(warn), @logger.logged(:warn) - end - - def test_set_color_for_messages - Rails::Subscriber.colorize_logging = true - @subscriber.bar(nil) - assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last - end - - def test_does_not_set_color_if_colorize_logging_is_set_to_false - @subscriber.bar(nil) - assert_equal "cool, isn't it?", @logger.logged(:info).last - end - - def test_event_is_sent_to_the_registered_class - Rails::Subscriber.add :my_subscriber, @subscriber - instrument "my_subscriber.some_event" - wait - assert_equal %w(my_subscriber.some_event), @logger.logged(:info) - end - - def test_event_is_an_active_support_notifications_event - Rails::Subscriber.add :my_subscriber, @subscriber - instrument "my_subscriber.some_event" - wait - assert_kind_of ActiveSupport::Notifications::Event, @subscriber.event - end - - def test_does_not_send_the_event_if_it_doesnt_match_the_class - Rails::Subscriber.add :my_subscriber, @subscriber - instrument "my_subscriber.unknown_event" - wait - # If we get here, it means that NoMethodError was raised. - end - - def test_does_not_send_the_event_if_logger_is_nil - Rails.logger = nil - @subscriber.expects(:some_event).never - Rails::Subscriber.add :my_subscriber, @subscriber - instrument "my_subscriber.some_event" - wait - end - - def test_flushes_loggers - Rails::Subscriber.add :my_subscriber, @subscriber - Rails::Subscriber.flush_all! - assert_equal 1, @logger.flush_count - end - - def test_flushes_the_same_logger_just_once - Rails::Subscriber.add :my_subscriber, @subscriber - Rails::Subscriber.add :another, @subscriber - Rails::Subscriber.flush_all! - wait - assert_equal 1, @logger.flush_count - end - - def test_logging_does_not_die_on_failures - Rails::Subscriber.add :my_subscriber, @subscriber - instrument "my_subscriber.puke" - instrument "my_subscriber.some_event" - wait - - assert_equal 1, @logger.logged(:info).size - assert_equal 'my_subscriber.some_event', @logger.logged(:info).last - - assert_equal 1, @logger.logged(:error).size - assert_equal 'Could not log "my_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last - end -end \ No newline at end of file -- cgit v1.2.3 From 01cd9d66ede0a528725728f2d73cf6e7796ccb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 16 Feb 2010 21:37:30 +0100 Subject: Subscriber should not explode if a non namespaced instrumentation is given. --- railties/test/log_subscriber_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/log_subscriber_test.rb b/railties/test/log_subscriber_test.rb index be176df1bb..a4de023e65 100644 --- a/railties/test/log_subscriber_test.rb +++ b/railties/test/log_subscriber_test.rb @@ -79,7 +79,7 @@ class SyncLogSubscriberTest < ActiveSupport::TestCase Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber instrument "my_log_subscriber.unknown_event" wait - # If we get here, it means that NoMethodError was raised. + # If we get here, it means that NoMethodError was not raised. end def test_does_not_send_the_event_if_logger_is_nil @@ -90,6 +90,12 @@ class SyncLogSubscriberTest < ActiveSupport::TestCase wait end + def test_does_not_fail_with_non_namespaced_events + Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber + instrument "whatever" + wait + end + def test_flushes_loggers Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber Rails::LogSubscriber.flush_all! -- cgit v1.2.3 From 23fd1f12801c8585ff3b114e74264b67ad6264e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 17 Feb 2010 00:15:21 +0100 Subject: Show deprecation message for rails/init.rb in plugins. --- railties/test/railties/plugin_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb index 09b859dcdd..0f5f29468c 100644 --- a/railties/test/railties/plugin_test.rb +++ b/railties/test/railties/plugin_test.rb @@ -94,6 +94,15 @@ module RailtiesTest assert rescued, "Expected boot rails to fail" end + test "loads deprecated rails/init.rb" do + @plugin.write "rails/init.rb", <<-RUBY + $loaded = true + RUBY + + boot_rails + assert $loaded + end + test "deprecated tasks are also loaded" do $executed = false @plugin.write "tasks/foo.rake", <<-RUBY -- cgit v1.2.3 From d4e008fd0f9ebac3383a0c3ac093de68db9e2e66 Mon Sep 17 00:00:00 2001 From: Kyle Maxwell Date: Thu, 11 Feb 2010 16:04:24 -0800 Subject: Invalid namespace on app generation raises an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/test/generators/app_generator_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 0a746b200f..01d643cd8c 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -50,6 +50,11 @@ class AppGeneratorTest < Rails::Generators::TestCase ).each{ |path| assert_file path } end + def test_name_collision_raises_an_error + content = capture(:stderr){ run_generator [File.join(destination_root, "generate")] } + assert_equal "Invalid application name generate. Please give a name which does not match one of the reserved rails words.\n", content + end + def test_invalid_database_option_raises_an_error content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) } assert_match /Invalid value for \-\-database option/, content -- cgit v1.2.3 From d0454e57661ceeaebd6f3fce4a608ec624257b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 17 Feb 2010 18:09:13 +0100 Subject: Add readme as method in Rails::Generators::Actions (as we had in 2.3) --- railties/test/generators/actions_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 5929db6318..3585e6e7c0 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -210,6 +210,12 @@ class ActionsTest < Rails::Generators::TestCase assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ end + def test_readme + run_generator + Rails::Generators::AppGenerator.expects(:source_root).returns(destination_root) + assert_match(/Welcome to Rails/, action(:readme, "README")) + end + protected def action(*args, &block) -- cgit v1.2.3 From a5684dfa3c16472bfa5d5d861ba78cb6dbadcb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 18 Feb 2010 18:39:39 +0100 Subject: Ensure config.after_initializer is executed before building the middleware stack. --- .../test/application/initializers/initializers_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/initializers/initializers_test.rb b/railties/test/application/initializers/initializers_test.rb index 0c3de7ce33..a6d37b15f1 100644 --- a/railties/test/application/initializers/initializers_test.rb +++ b/railties/test/application/initializers/initializers_test.rb @@ -51,5 +51,19 @@ module ApplicationTests assert $activerecord_configurations assert $activerecord_configurations['development'] end + + test "after_initialize happens before to_prepare (i.e. before the middleware stack is built) on production" do + $order = [] + add_to_config <<-RUBY + config.after_initialize { $order << :after_initialize } + config.to_prepare { $order << :to_prepare } + RUBY + + require "#{app_path}/config/application" + Rails.env.replace "production" + require "#{app_path}/config/environment" + assert [:after_initialize, :to_prepare], $order + end + end end -- cgit v1.2.3 From e49f94d71cdcdd3b891959e59203fd5e664c8add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 19 Feb 2010 08:02:28 +0100 Subject: Revert behavior from a5684dfa3c16472bfa5d5d861ba78cb6dbadcb59 and ensure after_initializer is executed after to_prepare callbacks. --- .../test/application/initializers/initializers_test.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/initializers/initializers_test.rb b/railties/test/application/initializers/initializers_test.rb index a6d37b15f1..2e6a707175 100644 --- a/railties/test/application/initializers/initializers_test.rb +++ b/railties/test/application/initializers/initializers_test.rb @@ -52,9 +52,22 @@ module ApplicationTests assert $activerecord_configurations['development'] end - test "after_initialize happens before to_prepare (i.e. before the middleware stack is built) on production" do + test "after_initialize happens after to_prepare in development" do $order = [] add_to_config <<-RUBY + config.cache_classes = false + config.after_initialize { $order << :after_initialize } + config.to_prepare { $order << :to_prepare } + RUBY + + require "#{app_path}/config/environment" + assert [:to_prepare, :after_initialize], $order + end + + test "after_initialize happens after to_prepare in production" do + $order = [] + add_to_config <<-RUBY + config.cache_classes = true config.after_initialize { $order << :after_initialize } config.to_prepare { $order << :to_prepare } RUBY @@ -62,8 +75,7 @@ module ApplicationTests require "#{app_path}/config/application" Rails.env.replace "production" require "#{app_path}/config/environment" - assert [:after_initialize, :to_prepare], $order + assert [:to_prepare, :after_initialize], $order end - end end -- cgit v1.2.3 From 7fe4ca3253e902c67d4765eeece285ffc49f3d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 21 Feb 2010 13:19:21 +0100 Subject: Add a test for default_url_options in AM. --- railties/test/application/initializers/frameworks_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 1e7b9c9997..94d3505518 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -32,6 +32,17 @@ module ApplicationTests ActionMailer::Base.view_paths.include?(File.expand_path("app/views", app_path)) end + test "allows me to configure default url options for ActionMailer" do + app_file "config/environments/development.rb", <<-RUBY + Rails::Application.configure do + config.action_mailer.default_url_options = { :host => "test.rails" } + end + RUBY + + require "#{app_path}/config/environment" + assert "test.rails", ActionMailer::Base.default_url_options[:host] + end + # AS test "if there's no config.active_support.bare, all of ActiveSupport is required" do use_frameworks [] -- cgit v1.2.3 From 6bc24d40d56332593bc22612d4618a2f80b1d91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sch=C3=BCrrer?= Date: Sun, 21 Feb 2010 17:21:25 +0100 Subject: Use ActionDispatch::Routing everywhere --- railties/test/rails_info_controller_test.rb | 2 +- railties/test/railties/shared_tests.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 4163fb2c6d..9cfa1d6aaa 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -14,7 +14,7 @@ class InfoControllerTest < ActionController::TestCase tests Rails::InfoController def setup - ActionController::Routing::Routes.draw do |map| + ActionDispatch::Routing::Routes.draw do |map| match ':controller/:action' end @controller.stubs(:consider_all_requests_local? => false, :local_request? => true) diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index d51a0d153c..c9e6e6081a 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -133,7 +133,7 @@ module RailtiesTest end end - ActionController::Routing::Routes.draw do + ActionDispatch::Routing::Routes.draw do match "/sprokkit", :to => Sprokkit end RUBY @@ -170,7 +170,7 @@ module RailtiesTest RUBY @plugin.write "config/routes.rb", <<-RUBY - ActionController::Routing::Routes.draw do |map| + ActionDispatch::Routing::Routes.draw do |map| match 'foo', :to => 'bar#index' match 'bar', :to => 'bar#index' end @@ -261,7 +261,7 @@ YAML def test_namespaced_controllers_with_namespaced_routes @plugin.write "config/routes.rb", <<-RUBY - ActionController::Routing::Routes.draw do + ActionDispatch::Routing::Routes.draw do namespace :admin do match "index", :to => "admin/foo#index" end @@ -312,4 +312,4 @@ YAML boot_rails end end -end \ No newline at end of file +end -- cgit v1.2.3 From 5e2bd08023344f3fd4675e80203a10967ffe9000 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 23 Feb 2010 17:03:06 -0800 Subject: Makes send_file work again by deferring to Rack::Sendfile. * Add the Rack::Sendfile middleware * Make the header to use configurable via config.action_dispatch.x_sendfile_header (default to "X-Sendfile"). * Add Railties tests to confirm that these work * Remove the :stream, :buffer_size, and :x_senfile default options to send_file * Change the log subscriber to always say "Sent file" * Add deprecation warnings for options that are now no-ops Note that servers can configure this by setting X-Sendfile-Type. Hosting companies and those creating packages of servers specially designed for Rails applications are encouraged to specify this header so that this can work transparently. --- railties/test/application/configuration_test.rb | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 7ca605ec23..3e03a01ff3 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -171,5 +171,60 @@ module ApplicationTests get "/" assert $prepared end + + test "config.action_dispatch.x_sendfile_header defaults to X-Sendfile" do + require "rails" + require "action_controller/railtie" + + class MyApp < Rails::Application + config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + end + + MyApp.initialize! + + class ::OmgController < ActionController::Base + def index + send_file __FILE__ + end + end + + MyApp.routes.draw do + match "/" => "omg#index" + end + + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert_equal File.expand_path(__FILE__), last_response.headers["X-Sendfile"] + end + + test "config.action_dispatch.x_sendfile_header is sent to Rack::Sendfile" do + require "rails" + require "action_controller/railtie" + + class MyApp < Rails::Application + config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + config.action_dispatch.x_sendfile_header = 'X-Lighttpd-Send-File' + end + + MyApp.initialize! + + class ::OmgController < ActionController::Base + def index + send_file __FILE__ + end + end + + MyApp.routes.draw do + match "/" => "omg#index" + end + + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert_equal File.expand_path(__FILE__), last_response.headers["X-Lighttpd-Send-File"] + end end end -- cgit v1.2.3 From 24ab5665b2f12a589e96a4b742cc49c08bf0e9df Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 23 Feb 2010 17:31:17 -0800 Subject: Revert "Fix test load paths for those not using bundler" This reverts commit eec2d301d4ce9df9c71c1a5aa63053eb970b6818. This commit broke tests. You cannot have a file called "bundler" on the load path. --- railties/test/abstract_unit.rb | 7 +------ railties/test/application/configuration_test.rb | 2 +- railties/test/edge_rails.rb | 14 -------------- railties/test/isolation/abstract_unit.rb | 14 ++++++++++---- 4 files changed, 12 insertions(+), 25 deletions(-) delete mode 100644 railties/test/edge_rails.rb (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 2ac165fc49..aa66dbb9be 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,13 +1,8 @@ ORIG_ARGV = ARGV.dup -require File.expand_path("../../../bundler", __FILE__) +require File.expand_path("../../../load_paths", __FILE__) $:.unshift File.expand_path("../../builtin/rails_info", __FILE__) -lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") -$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) - -require 'edge_rails' - require 'stringio' require 'test/unit' require 'fileutils' diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 3e03a01ff3..acf752a448 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -140,7 +140,7 @@ module ApplicationTests require "#{app_path}/config/environment" end end - + test "filter_parameters should be able to set via config.filter_parameters" do add_to_config <<-RUBY config.filter_parameters += [ :foo, 'bar', lambda { |key, value| diff --git a/railties/test/edge_rails.rb b/railties/test/edge_rails.rb deleted file mode 100644 index bd8a674738..0000000000 --- a/railties/test/edge_rails.rb +++ /dev/null @@ -1,14 +0,0 @@ -require File.expand_path('../../../bundler', __FILE__) - -%w( - actionmailer - actionpack - activemodel - activerecord - activeresource - activesupport - railties -).each do |framework| - framework_path = File.expand_path("../../../#{framework}/lib", __FILE__) - $:.unshift(framework_path) if File.directory?(framework_path) && !$:.include?(framework_path) -end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index f3c1d64f7b..364dbd8e55 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -187,7 +187,7 @@ module TestHelpers end def boot_rails - require File.expand_path('../../edge_rails', __FILE__) + require File.expand_path('../../../../load_paths', __FILE__) end end end @@ -208,12 +208,18 @@ Module.new do end FileUtils.mkdir(tmp_path) - environment = File.expand_path('../../edge_rails', __FILE__) - require_environment = "-r #{environment}" + environment = File.expand_path('../../../../load_paths', __FILE__) + if File.exist?("#{environment}.rb") + require_environment = "-r #{environment}" + end `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f| - f.puts "require '#{environment}'" + if require_environment + f.puts "Dir.chdir('#{File.dirname(environment)}') do" + f.puts " require '#{environment}'" + f.puts "end" + end f.puts "require 'rails/all'" end end -- cgit v1.2.3 From 47498a7f59d0196e9b8aa8e3569cbb4937477cef Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 23 Feb 2010 17:42:14 -0800 Subject: Woops, forgot to actually add active_support/core_ext/file/path.rb --- railties/test/application/middleware_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index ce9cd510a3..5e869bff1e 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -19,6 +19,7 @@ module ApplicationTests "Rack::Runtime", "Rails::Rack::Logger", "ActionDispatch::ShowExceptions", + "Rack::Sendfile", "ActionDispatch::Callbacks", "ActionDispatch::Cookies", "ActionDispatch::Session::CookieStore", -- cgit v1.2.3 From ba57575e03647df78f8f2d4b56f1395c10061366 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 23 Feb 2010 17:56:28 -0800 Subject: Remove references to ActionDispatch::Routing::Routes in favor of Rails.appication.routes. --- railties/test/rails_info_controller_test.rb | 2 +- railties/test/railties/shared_tests.rb | 6 +++--- 2 files changed, 4 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 9cfa1d6aaa..a6fc23d95b 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -14,7 +14,7 @@ class InfoControllerTest < ActionController::TestCase tests Rails::InfoController def setup - ActionDispatch::Routing::Routes.draw do |map| + Rails.application.routes.draw do |map| match ':controller/:action' end @controller.stubs(:consider_all_requests_local? => false, :local_request? => true) diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index c9e6e6081a..151abe21f8 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -133,7 +133,7 @@ module RailtiesTest end end - ActionDispatch::Routing::Routes.draw do + Rails.application.routes.draw do match "/sprokkit", :to => Sprokkit end RUBY @@ -170,7 +170,7 @@ module RailtiesTest RUBY @plugin.write "config/routes.rb", <<-RUBY - ActionDispatch::Routing::Routes.draw do |map| + Rails.application.routes.draw do |map| match 'foo', :to => 'bar#index' match 'bar', :to => 'bar#index' end @@ -261,7 +261,7 @@ YAML def test_namespaced_controllers_with_namespaced_routes @plugin.write "config/routes.rb", <<-RUBY - ActionDispatch::Routing::Routes.draw do + Rails.application.routes.draw do namespace :admin do match "index", :to => "admin/foo#index" end -- cgit v1.2.3 From c7f9e8c06cb60aef33cf0a03cb3c1b927eb8c1cf Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 25 Feb 2010 10:46:29 -0800 Subject: Fix test on 1.8.8. Broken by inherited hook now running before Class.new block. --- railties/test/generators_test.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 33cc27bd84..844497c8e3 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -147,12 +147,13 @@ class GeneratorsTest < Rails::Generators::TestCase 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' end - class_option :generate, :default => true - end + self.class.class_eval <<-end_eval + class NewGenerator < Rails::Generators::Base + class_option :generate, :default => true + end + end_eval - assert_equal false, klass.class_options[:generate].default + assert_equal false, NewGenerator.class_options[:generate].default ensure Rails::Generators.subclasses.delete(klass) end -- cgit v1.2.3 From ffc45f3e7128f0ef1efca0f39d4717447c15f5b8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 25 Feb 2010 11:01:15 -0800 Subject: Fix dangling klass reference --- 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 844497c8e3..07bc92c55c 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -155,7 +155,7 @@ class GeneratorsTest < Rails::Generators::TestCase assert_equal false, NewGenerator.class_options[:generate].default ensure - Rails::Generators.subclasses.delete(klass) + Rails::Generators.subclasses.delete(NewGenerator) end def test_load_generators_from_railties -- cgit v1.2.3 From 9a5be2e5a80ab9e74294f32cfef58fbbcd9b637c Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 24 Feb 2010 16:47:43 -0800 Subject: Get Railties tests passing --- railties/test/rails_info_controller_test.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index a6fc23d95b..017e51326c 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -18,6 +18,9 @@ class InfoControllerTest < ActionController::TestCase match ':controller/:action' end @controller.stubs(:consider_all_requests_local? => false, :local_request? => true) + @router = Rails.application.routes + + Rails::InfoController.send(:include, @router.named_url_helpers) end test "info controller does not allow remote requests" do -- cgit v1.2.3 From fc4582fb6684ce72f5628629ea7d061659b790f8 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 25 Feb 2010 16:48:36 -0800 Subject: Final pass at removing the router from a global constant --- railties/test/application/url_generation_test.rb | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 railties/test/application/url_generation_test.rb (limited to 'railties/test') diff --git a/railties/test/application/url_generation_test.rb b/railties/test/application/url_generation_test.rb new file mode 100644 index 0000000000..a0d9ff7a3a --- /dev/null +++ b/railties/test/application/url_generation_test.rb @@ -0,0 +1,42 @@ +require 'isolation/abstract_unit' + +module ApplicationTests + class UrlGenerationTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def app + Rails.application + end + + test "it works" do + boot_rails + require "rails" + require "action_controller/railtie" + + class MyApp < Rails::Application + config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + end + + MyApp.initialize! + + class ::ApplicationController < ActionController::Base + end + + class ::OmgController < ::ApplicationController + def index + render :text => omg_path + end + end + + MyApp.routes.draw do + match "/" => "omg#index", :as => :omg + end + + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert_equal "/", last_response.body + end + end +end -- cgit v1.2.3 From 5893baa683e9b3c85c07d2811656be03765ebad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 26 Feb 2010 10:44:53 +0100 Subject: Add autoload to generators modules and fix failing test. --- railties/test/generators_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 07bc92c55c..dd17f8f756 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -145,17 +145,17 @@ class GeneratorsTest < Rails::Generators::TestCase end def test_developer_options_are_overwriten_by_user_options - Rails::Generators.options[:new_generator] = { :generate => false } + Rails::Generators.options[:with_options] = { :generate => false } self.class.class_eval <<-end_eval - class NewGenerator < Rails::Generators::Base + class WithOptionsGenerator < Rails::Generators::Base class_option :generate, :default => true end end_eval - assert_equal false, NewGenerator.class_options[:generate].default + assert_equal false, WithOptionsGenerator.class_options[:generate].default ensure - Rails::Generators.subclasses.delete(NewGenerator) + Rails::Generators.subclasses.delete(WithOptionsGenerator) end def test_load_generators_from_railties -- cgit v1.2.3 From 79c47abe6ce0bdcc81c35aa30da8a05c3650d04d Mon Sep 17 00:00:00 2001 From: Ramon Soares Date: Sun, 21 Feb 2010 20:49:54 -0300 Subject: the folder public/javascripts should be created by default [#4027 status:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/test/generators/app_generator_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 01d643cd8c..412034029e 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -107,6 +107,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_prototype_and_test_unit_are_skipped_if_required run_generator [destination_root, "--skip-prototype", "--skip-testunit"] assert_no_file "public/javascripts/prototype.js" + assert_file "public/javascripts" assert_no_file "test" end -- cgit v1.2.3 From e6dffb70e6c1d524eeb5a40e1f8e01b067781143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 26 Feb 2010 12:09:39 +0100 Subject: reload! on console now works as expected. [#3822 status:resolved] --- railties/test/application/console_test.rb | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 22ab60f4a0..8ff69f0208 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -6,7 +6,9 @@ class ConsoleTest < Test::Unit::TestCase def setup build_app boot_rails + end + def load_environment # Load steps taken from rails/commands/console.rb require "#{rails_root}/config/environment" require 'rails/console/app' @@ -14,18 +16,21 @@ class ConsoleTest < Test::Unit::TestCase end def test_app_method_should_return_integration_session + load_environment console_session = app assert_not_nil console_session assert_instance_of ActionController::Integration::Session, console_session end def test_new_session_should_return_integration_session + load_environment session = new_session assert_not_nil session assert_instance_of ActionController::Integration::Session, session end def test_reload_should_fire_preparation_callbacks + load_environment a = b = c = nil # TODO: These should be defined on the initializer @@ -34,16 +39,37 @@ class ConsoleTest < Test::Unit::TestCase ActionDispatch::Callbacks.to_prepare { c = 3 } # Hide Reloading... output - silence_stream(STDOUT) do - reload! - end + silence_stream(STDOUT) { reload! } assert_equal 1, a assert_equal 2, b assert_equal 3, c end + def test_reload_should_reload_constants + app_file "app/models/user.rb", <<-MODEL + class User + attr_accessor :name + end + MODEL + + load_environment + assert User.new.respond_to?(:name) + assert !User.new.respond_to?(:age) + + app_file "app/models/user.rb", <<-MODEL + class User + attr_accessor :name, :age + end + MODEL + + assert !User.new.respond_to?(:age) + silence_stream(STDOUT) { reload! } + assert User.new.respond_to?(:age) + end + def test_access_to_helpers + load_environment assert_not_nil helper assert_instance_of ActionView::Base, helper assert_equal 'Once upon a time in a world...', -- cgit v1.2.3 From 98f77e08278658ec47c9eb2e8f819d781c1eaebf Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Fri, 26 Feb 2010 15:00:33 -0800 Subject: Rename named_url_helpers to url_helpers and url_helpers to url_for --- railties/test/rails_info_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 017e51326c..7275755130 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -20,7 +20,7 @@ class InfoControllerTest < ActionController::TestCase @controller.stubs(:consider_all_requests_local? => false, :local_request? => true) @router = Rails.application.routes - Rails::InfoController.send(:include, @router.named_url_helpers) + Rails::InfoController.send(:include, @router.url_helpers) end test "info controller does not allow remote requests" do -- cgit v1.2.3 From 82deaf5f052caf0a906ed0e83c6efd00c057b5ba Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 28 Feb 2010 18:43:20 -0600 Subject: nested controllers need to be explicitly declared with the new mapper --- railties/test/application/routing_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index b93e349a46..dcac1a87d9 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -120,7 +120,8 @@ module ApplicationTests app_file 'config/routes.rb', <<-RUBY AppTemplate::Application.routes.draw do |map| - match ':controller(/:action)' + match 'admin/foo', :to => 'admin/foo#index' + match 'foo', :to => 'foo#index' end RUBY -- cgit v1.2.3 From a64fcc1a8d84b274691b5e332257eabf0cb5c2a8 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 2 Mar 2010 12:06:40 -0800 Subject: :controller doesn't work for namespaced controllers anymore. --- railties/test/rails_info_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 7275755130..d904d7b461 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -15,7 +15,7 @@ class InfoControllerTest < ActionController::TestCase def setup Rails.application.routes.draw do |map| - match ':controller/:action' + match '/rails/info/properties' => "rails/info#properties" end @controller.stubs(:consider_all_requests_local? => false, :local_request? => true) @router = Rails.application.routes -- cgit v1.2.3 From 57bae9764e45ad19dff7a879eeb46d1dffc5ca22 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 2 Mar 2010 12:31:29 -0800 Subject: Fix a test that assumes that defined?(ActiveRecord) == defined?(ActiveRecord::Base) --- railties/test/application/initializers/frameworks_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 94d3505518..91f31df2e7 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -91,7 +91,7 @@ module ApplicationTests test "database middleware doesn't initialize when activerecord is not in frameworks" do use_frameworks [] require "#{app_path}/config/environment" - assert_nil defined?(ActiveRecord) + assert_nil defined?(ActiveRecord::Base) end end end -- cgit v1.2.3 From d434c5406846fb280b8a9d6ec40247b1f1b464c6 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 2 Mar 2010 12:34:26 -0800 Subject: Log Tailer doesn't exist anymore. Removing some traces left over in tests. --- railties/test/log_subscriber_test.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/log_subscriber_test.rb b/railties/test/log_subscriber_test.rb index a4de023e65..49288cfaa8 100644 --- a/railties/test/log_subscriber_test.rb +++ b/railties/test/log_subscriber_test.rb @@ -30,13 +30,11 @@ class SyncLogSubscriberTest < ActiveSupport::TestCase def setup super @log_subscriber = MyLogSubscriber.new - Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil) end def teardown super Rails::LogSubscriber.log_subscribers.clear - Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil) end def instrument(*args, &block) -- cgit v1.2.3 From aa749a74f63547a503772f4489fb60b5e4fbea1a Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 2 Mar 2010 14:00:17 -0800 Subject: Get the railties tests to pass again. --- railties/test/railties/railtie_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb index 9eb4e9993a..9fefb285b4 100644 --- a/railties/test/railties/railtie_test.rb +++ b/railties/test/railties/railtie_test.rb @@ -54,7 +54,7 @@ module RailtiesTest test "railtie can add log subscribers" do begin class Foo < Rails::Railtie ; log_subscriber(Rails::LogSubscriber.new) ; end - assert_kind_of Rails::LogSubscriber, Rails::LogSubscriber.log_subscribers[:foo] + assert_kind_of Rails::LogSubscriber, Rails::LogSubscriber.log_subscribers[0] ensure Rails::LogSubscriber.log_subscribers.clear end -- cgit v1.2.3 From 93422af5d5bc0285bd72cfb2fd9b59f6d64ba141 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 3 Mar 2010 16:22:30 -0800 Subject: Move remote_ip to a middleware: * ActionController::Base.ip_spoofing_check deprecated => config.action_dispatch.ip_spoofing_check * ActionController::Base.trusted_proxies deprecated => config.action_dispatch.trusted_proxies --- .../application/middleware_stack_defaults_test.rb | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 railties/test/application/middleware_stack_defaults_test.rb (limited to 'railties/test') diff --git a/railties/test/application/middleware_stack_defaults_test.rb b/railties/test/application/middleware_stack_defaults_test.rb new file mode 100644 index 0000000000..94151a90da --- /dev/null +++ b/railties/test/application/middleware_stack_defaults_test.rb @@ -0,0 +1,53 @@ +require 'isolation/abstract_unit' + +class MiddlewareStackDefaultsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + boot_rails + require "rails" + require "action_controller/railtie" + + Object.const_set(:MyApplication, Class.new(Rails::Application)) + MyApplication.class_eval do + config.action_controller.session = { :key => "_myapp_session", :secret => "OMG A SEKRET" * 10 } + end + end + + def remote_ip(env = {}) + remote_ip = nil + env = Rack::MockRequest.env_for("/").merge(env).merge('action_dispatch.show_exceptions' => false) + + endpoint = Proc.new do |e| + remote_ip = ActionDispatch::Request.new(e).remote_ip + [200, {}, ["Hello"]] + end + + out = MyApplication.middleware.build(endpoint).call(env) + remote_ip + end + + test "remote_ip works" do + assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "1.1.1.1") + end + + test "checks IP spoofing by default" do + assert_raises(ActionDispatch::RemoteIp::IpSpoofAttackError) do + remote_ip("HTTP_X_FORWARDED_FOR" => "1.1.1.1", "HTTP_CLIENT_IP" => "1.1.1.2") + end + end + + test "can disable IP spoofing check" do + MyApplication.config.action_dispatch.ip_spoofing_check = false + + assert_nothing_raised(ActionDispatch::RemoteIp::IpSpoofAttackError) do + assert_equal "1.1.1.2", remote_ip("HTTP_X_FORWARDED_FOR" => "1.1.1.1", "HTTP_CLIENT_IP" => "1.1.1.2") + end + end + + test "the user can set trusted proxies" do + MyApplication.config.action_dispatch.trusted_proxies = /^4\.2\.42\.42$/ + + assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "4.2.42.42,1.1.1.1") + end +end -- cgit v1.2.3 From 15b3b74624eb4c5ae383956950cab12ca9899131 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 3 Mar 2010 21:16:35 -0800 Subject: Fix all the broken tests due to the AC configuration refactor --- railties/test/application/metal_test.rb | 4 ++-- railties/test/application/middleware_test.rb | 1 + railties/test/railties/shared_tests.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/metal_test.rb b/railties/test/application/metal_test.rb index 225bede117..1ec62282c8 100644 --- a/railties/test/application/metal_test.rb +++ b/railties/test/application/metal_test.rb @@ -28,7 +28,7 @@ module ApplicationTests end RUBY - get "/" + get "/not/slash" assert_equal 200, last_response.status assert_equal "FooMetal", last_response.body end @@ -50,7 +50,7 @@ module ApplicationTests end RUBY - get "/" + get "/not/slash" assert_equal 200, last_response.status assert_equal "Metal B", last_response.body end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 5e869bff1e..9a359d20b1 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -19,6 +19,7 @@ module ApplicationTests "Rack::Runtime", "Rails::Rack::Logger", "ActionDispatch::ShowExceptions", + "ActionDispatch::RemoteIp", "Rack::Sendfile", "ActionDispatch::Callbacks", "ActionDispatch::Cookies", diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 151abe21f8..0ebc8a2d3f 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -254,7 +254,7 @@ YAML require 'rack/test' extend Rack::Test::Methods - get "/" + get "/not/slash" assert_equal 200, last_response.status assert_equal "FooMetal", last_response.body end -- cgit v1.2.3 From 9795bf0e74612aa542404460220720c14fac1038 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 4 Mar 2010 12:12:04 -0800 Subject: Fix Sam Ruby's tests and deprecation warnings --- railties/test/application/configuration_test.rb | 4 ++-- railties/test/application/initializers/frameworks_test.rb | 4 ++-- railties/test/application/middleware_stack_defaults_test.rb | 2 +- railties/test/application/paths_test.rb | 4 ++-- railties/test/application/url_generation_test.rb | 2 +- railties/test/isolation/abstract_unit.rb | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index acf752a448..25389c86f7 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -177,7 +177,7 @@ module ApplicationTests require "action_controller/railtie" class MyApp < Rails::Application - config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + config.action_dispatch.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } end MyApp.initialize! @@ -204,7 +204,7 @@ module ApplicationTests require "action_controller/railtie" class MyApp < Rails::Application - config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + config.action_dispatch.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } config.action_dispatch.x_sendfile_header = 'X-Lighttpd-Send-File' end diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 91f31df2e7..d74de3d666 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -65,7 +65,7 @@ module ApplicationTests test "database middleware doesn't initialize when session store is not active_record" do add_to_config <<-RUBY config.root = "#{app_path}" - config.action_controller.session_store = :cookie_store + config.action_dispatch.session_store = :cookie_store RUBY require "#{app_path}/config/environment" @@ -73,7 +73,7 @@ module ApplicationTests end test "database middleware initializes when session store is active record" do - add_to_config "config.action_controller.session_store = :active_record_store" + add_to_config "config.action_dispatch.session_store = :active_record_store" require "#{app_path}/config/environment" diff --git a/railties/test/application/middleware_stack_defaults_test.rb b/railties/test/application/middleware_stack_defaults_test.rb index 94151a90da..9086ddcfe7 100644 --- a/railties/test/application/middleware_stack_defaults_test.rb +++ b/railties/test/application/middleware_stack_defaults_test.rb @@ -10,7 +10,7 @@ class MiddlewareStackDefaultsTest < Test::Unit::TestCase Object.const_set(:MyApplication, Class.new(Rails::Application)) MyApplication.class_eval do - config.action_controller.session = { :key => "_myapp_session", :secret => "OMG A SEKRET" * 10 } + config.action_dispatch.session = { :key => "_myapp_session", :secret => "OMG A SEKRET" * 10 } end end diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb index ac0aa27c64..89f74eb60b 100644 --- a/railties/test/application/paths_test.rb +++ b/railties/test/application/paths_test.rb @@ -11,8 +11,8 @@ module ApplicationTests app_file "config/environments/development.rb", "" add_to_config <<-RUBY config.root = "#{app_path}" - config.after_initialize do - ActionController::Base.session_store = nil + config.after_initialize do |app| + app.config.action_dispatch.session_store = nil end RUBY use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] diff --git a/railties/test/application/url_generation_test.rb b/railties/test/application/url_generation_test.rb index a0d9ff7a3a..f8e9a39969 100644 --- a/railties/test/application/url_generation_test.rb +++ b/railties/test/application/url_generation_test.rb @@ -14,7 +14,7 @@ module ApplicationTests require "action_controller/railtie" class MyApp < Rails::Application - config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + config.action_dispatch.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } end MyApp.initialize! diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 364dbd8e55..2b0d5a8ba0 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -100,7 +100,7 @@ module TestHelpers end end - add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' + add_to_config 'config.action_dispatch.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' end class Bukkit -- cgit v1.2.3 From e311622e7b20b3fdeab6a93418c8a45c6e7137b6 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 4 Mar 2010 15:06:25 -0800 Subject: Deprecated ActionController::Base.session_options= and ActionController::Base.session_store= in favor of a config.session_store method (which takes params) and a config.cookie_secret variable, which is used in various secret scenarios. The old AC::Base options will continue to work with deprecation warnings. --- railties/test/application/configuration_test.rb | 6 ++++-- railties/test/application/initializers/frameworks_test.rb | 4 ++-- railties/test/application/middleware_stack_defaults_test.rb | 3 ++- railties/test/application/url_generation_test.rb | 3 ++- railties/test/isolation/abstract_unit.rb | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 25389c86f7..54cd751f4e 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -177,7 +177,8 @@ module ApplicationTests require "action_controller/railtie" class MyApp < Rails::Application - config.action_dispatch.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4" + config.session_store :cookie_store, :key => "_myapp_session" end MyApp.initialize! @@ -204,7 +205,8 @@ module ApplicationTests require "action_controller/railtie" class MyApp < Rails::Application - config.action_dispatch.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4" + config.session_store :cookie_store, :key => "_myapp_session" config.action_dispatch.x_sendfile_header = 'X-Lighttpd-Send-File' end diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index d74de3d666..8e57022e5b 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -65,7 +65,7 @@ module ApplicationTests test "database middleware doesn't initialize when session store is not active_record" do add_to_config <<-RUBY config.root = "#{app_path}" - config.action_dispatch.session_store = :cookie_store + config.session_store :cookie_store, { :key => "blahblahblah" } RUBY require "#{app_path}/config/environment" @@ -73,7 +73,7 @@ module ApplicationTests end test "database middleware initializes when session store is active record" do - add_to_config "config.action_dispatch.session_store = :active_record_store" + add_to_config "config.session_store :active_record_store" require "#{app_path}/config/environment" diff --git a/railties/test/application/middleware_stack_defaults_test.rb b/railties/test/application/middleware_stack_defaults_test.rb index 9086ddcfe7..284f7e2e5b 100644 --- a/railties/test/application/middleware_stack_defaults_test.rb +++ b/railties/test/application/middleware_stack_defaults_test.rb @@ -10,7 +10,8 @@ class MiddlewareStackDefaultsTest < Test::Unit::TestCase Object.const_set(:MyApplication, Class.new(Rails::Application)) MyApplication.class_eval do - config.action_dispatch.session = { :key => "_myapp_session", :secret => "OMG A SEKRET" * 10 } + config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4" + config.session_store :cookie_store, :key => "_myapp_session" end end diff --git a/railties/test/application/url_generation_test.rb b/railties/test/application/url_generation_test.rb index f8e9a39969..04f5454e09 100644 --- a/railties/test/application/url_generation_test.rb +++ b/railties/test/application/url_generation_test.rb @@ -14,7 +14,8 @@ module ApplicationTests require "action_controller/railtie" class MyApp < Rails::Application - config.action_dispatch.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4" + config.session_store :cookie_store, :key => "_myapp_session" end MyApp.initialize! diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 2b0d5a8ba0..8f2f15b49e 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -100,7 +100,7 @@ module TestHelpers end end - add_to_config 'config.action_dispatch.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' + add_to_config 'config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4"; config.session_store :cookie_store, :key => "_myapp_session"' end class Bukkit -- cgit v1.2.3 From ecf84b239f30e647b8bb12fb34f4569975bef4de Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 4 Mar 2010 16:12:34 -0800 Subject: Change generated code to replace faulty comment --- railties/test/application/paths_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb index 89f74eb60b..d1192206dd 100644 --- a/railties/test/application/paths_test.rb +++ b/railties/test/application/paths_test.rb @@ -12,7 +12,7 @@ module ApplicationTests add_to_config <<-RUBY config.root = "#{app_path}" config.after_initialize do |app| - app.config.action_dispatch.session_store = nil + app.config.session_store nil end RUBY use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] -- cgit v1.2.3 From 028e54c63df84ad1ded1fb9c438eed540564552c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 6 Mar 2010 19:19:26 +0100 Subject: Add mailers to paths in case someone wants to access it directly and ensures deep nesting works in controllers. --- railties/test/application/paths_test.rb | 7 ++++--- railties/test/railties/shared_tests.rb | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb index d1192206dd..511b8b629a 100644 --- a/railties/test/application/paths_test.rb +++ b/railties/test/application/paths_test.rb @@ -56,9 +56,10 @@ module ApplicationTests end test "booting up Rails yields a list of paths that are eager" do - assert @paths.app.eager_load? - assert @paths.app.controllers.eager_load? - assert @paths.app.helpers.eager_load? + eager_load = @paths.eager_load + assert eager_load.include?(root("app/controllers")) + assert eager_load.include?(root("app/helpers")) + assert eager_load.include?(root("app/models")) end test "environments has a glob equal to the current environment" do diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 0ebc8a2d3f..83d25be5db 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -263,13 +263,15 @@ YAML @plugin.write "config/routes.rb", <<-RUBY Rails.application.routes.draw do namespace :admin do - match "index", :to => "admin/foo#index" + namespace :foo do + match "bar", :to => "admin/foo/bar#index" + end end end RUBY - @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY - class Admin::FooController < ApplicationController + @plugin.write "app/controllers/admin/foo/bar_controller.rb", <<-RUBY + class Admin::Foo::BarController < ApplicationController def index render :text => "Rendered from namespace" end @@ -280,7 +282,7 @@ YAML require 'rack/test' extend Rack::Test::Methods - get "/admin/index" + get "/admin/foo/bar" assert_equal 200, last_response.status assert_equal "Rendered from namespace", last_response.body end -- cgit v1.2.3