From 2eacdb0cbf558a46faeb42abc2df02adc4f677ae Mon Sep 17 00:00:00 2001 From: slainer68 Date: Wed, 20 Aug 2014 17:28:23 +0200 Subject: Require ActiveJob in case a skip_xxx option is given Change position of require active_job --- 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 70c439672f..d687a8f506 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -395,6 +395,7 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--skip-test-unit", "--skip-active-record"] assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/ assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ + assert_file "config/application.rb", /\s+require\s+["']active_job\/railtie["']/ end def test_new_hash_style -- cgit v1.2.3 From f9a84bb2361d7ec2147ca9e104f66ceb159a4039 Mon Sep 17 00:00:00 2001 From: Sam Aarons Date: Wed, 20 Aug 2014 15:42:32 -0700 Subject: Refactor ActionDispatch::RemoteIp Refactored IP address checking in ActionDispatch::RemoteIp to rely on the IPAddr class instead of the unwieldly regular expression to match IP addresses. This commit keeps the same api but allows users to pass IPAddr objects to config.action_dispatch.trusted_proxies in addition to passing strings and regular expressions. Example: # config/environments/production.rb config.action_dispatch.trusted_proxies = IPAddr.new('4.8.15.0/16') --- railties/test/application/middleware/remote_ip_test.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/middleware/remote_ip_test.rb b/railties/test/application/middleware/remote_ip_test.rb index 946b82eeb3..97d5b5c698 100644 --- a/railties/test/application/middleware/remote_ip_test.rb +++ b/railties/test/application/middleware/remote_ip_test.rb @@ -1,3 +1,4 @@ +require 'ipaddr' require 'isolation/abstract_unit' require 'active_support/key_generator' @@ -53,12 +54,25 @@ module ApplicationTests end end + test "remote_ip works with HTTP_X_FORWARDED_FOR" do + make_basic_app + assert_equal "4.2.42.42", remote_ip("REMOTE_ADDR" => "1.1.1.1", "HTTP_X_FORWARDED_FOR" => "4.2.42.42") + end + test "the user can set trusted proxies" do make_basic_app do |app| app.config.action_dispatch.trusted_proxies = /^4\.2\.42\.42$/ end - assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "4.2.42.42,1.1.1.1") + assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "1.1.1.1", "HTTP_X_FORWARDED_FOR" => "4.2.42.42") + end + + test "the user can set trusted proxies with an IPAddr argument" do + make_basic_app do |app| + app.config.action_dispatch.trusted_proxies = IPAddr.new('4.2.42.0/24') + end + + assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "1.1.1.1", "HTTP_X_FORWARDED_FOR" => "10.0.0.0,4.2.42.42") end end end -- cgit v1.2.3 From b9b521306c47d65bdbe18ec31a7b784adbfd1849 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 27 Aug 2014 12:30:35 +0200 Subject: fix broken `gem` method with non-String arguments. Closes #16709. This was caused by #15327. --- railties/test/generators/actions_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index a4337926d1..2206e389b5 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -79,6 +79,16 @@ class ActionsTest < Rails::Generators::TestCase assert_file 'Gemfile', /gem 'rspec', github: 'dchelimsky\/rspec', tag: '1\.2\.9\.rc1'/ end + def test_gem_with_non_string_options + run_generator + + action :gem, 'rspec', require: false + action :gem, 'rspec-rails', group: [:development, :test] + + assert_file 'Gemfile', /^gem 'rspec', require: false$/ + assert_file 'Gemfile', /^gem 'rspec-rails', group: \[:development, :test\]$/ + end + def test_gem_falls_back_to_inspect_if_string_contains_single_quote run_generator -- cgit v1.2.3 From 357edaaf8309e5ebfd1b5bae7b7210cacc501c7b Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Tue, 26 Aug 2014 19:08:54 +0900 Subject: Rails.root should be a Pathname --- railties/test/generators/generators_test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index e7990de754..6cc91f166b 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -7,7 +7,7 @@ module Rails class << self remove_possible_method :root def root - @root ||= File.expand_path('../../fixtures', __FILE__) + @root ||= Pathname.new(File.expand_path('../../fixtures', __FILE__)) end end end -- cgit v1.2.3 From 0c885d68189c4548dea3a833cb411c076799459c Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 27 Aug 2014 00:17:21 +0900 Subject: Reset RACK_ENV after modified in a test case --- railties/test/commands/dbconsole_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index ede08e7b86..214c7aa313 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -95,6 +95,7 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end ensure ENV['RAILS_ENV'] = "test" + ENV['RACK_ENV'] = nil end def test_rails_env_is_development_when_argument_is_dev -- cgit v1.2.3 From 4ded1311810312fe6614a28b93d7859fb854b23a Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 27 Aug 2014 00:53:19 +0900 Subject: Expectations first --- railties/test/application/configuration_test.rb | 2 +- railties/test/application/initializers/frameworks_test.rb | 4 ++-- railties/test/application/middleware_test.rb | 2 +- railties/test/commands/dbconsole_test.rb | 10 +++++----- 4 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 e661b6f4cc..db2106aed3 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -118,7 +118,7 @@ module ApplicationTests test "Rails::Application responds to paths" do require "#{app_path}/config/environment" assert_respond_to AppTemplate::Application, :paths - assert_equal AppTemplate::Application.paths["app/views"].expanded, ["#{app_path}/app/views"] + assert_equal ["#{app_path}/app/views"], AppTemplate::Application.paths["app/views"].expanded end test "the application root is set correctly" do diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index ae550331bd..2d45c9b53f 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -35,8 +35,8 @@ module ApplicationTests require "#{app_path}/config/environment" expanded_path = File.expand_path("app/views", app_path) - assert_equal ActionController::Base.view_paths[0].to_s, expanded_path - assert_equal ActionMailer::Base.view_paths[0].to_s, expanded_path + assert_equal expanded_path, ActionController::Base.view_paths[0].to_s + assert_equal expanded_path, ActionMailer::Base.view_paths[0].to_s end test "allows me to configure default url options for ActionMailer" do diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 33eb034b1c..a905598d80 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -83,7 +83,7 @@ module ApplicationTests add_to_config "config.ssl_options = { host: 'example.com' }" boot! - assert_equal Rails.application.middleware.first.args, [{host: 'example.com'}] + assert_equal [{host: 'example.com'}], Rails.application.middleware.first.args end test "removing Active Record omits its middleware" do diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 214c7aa313..a3cd1eb0ed 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -28,7 +28,7 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase } } app_db_config(config_sample) do - assert_equal Rails::DBConsole.new.config, config_sample["test"] + assert_equal config_sample["test"], Rails::DBConsole.new.config end end @@ -79,19 +79,19 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end def test_env - assert_equal Rails::DBConsole.new.environment, "test" + assert_equal "test", Rails::DBConsole.new.environment ENV['RAILS_ENV'] = nil ENV['RACK_ENV'] = nil Rails.stub(:respond_to?, false) do - assert_equal Rails::DBConsole.new.environment, "development" + assert_equal "development", Rails::DBConsole.new.environment ENV['RACK_ENV'] = "rack_env" - assert_equal Rails::DBConsole.new.environment, "rack_env" + assert_equal "rack_env", Rails::DBConsole.new.environment ENV['RAILS_ENV'] = "rails_env" - assert_equal Rails::DBConsole.new.environment, "rails_env" + assert_equal "rails_env", Rails::DBConsole.new.environment end ensure ENV['RAILS_ENV'] = "test" -- cgit v1.2.3