diff options
Diffstat (limited to 'actionpack/test/dispatch')
41 files changed, 3445 insertions, 3350 deletions
diff --git a/actionpack/test/dispatch/callbacks_test.rb b/actionpack/test/dispatch/callbacks_test.rb index 7b707df7f6..57e21a22c6 100644 --- a/actionpack/test/dispatch/callbacks_test.rb +++ b/actionpack/test/dispatch/callbacks_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class DispatcherTest < ActiveSupport::TestCase class Foo @@ -7,7 +7,7 @@ class DispatcherTest < ActiveSupport::TestCase class DummyApp def call(env) - [200, {}, 'response'] + [200, {}, "response"] end end @@ -57,8 +57,7 @@ class DispatcherTest < ActiveSupport::TestCase def dispatch(&block) ActionDispatch::Callbacks.new(block || DummyApp.new).call( - {'rack.input' => StringIO.new('')} + "rack.input" => StringIO.new("") ) end - end diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index c7194cde4a..38cf0a2346 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'openssl' -require 'active_support/key_generator' -require 'active_support/message_verifier' +require "abstract_unit" +require "openssl" +require "active_support/key_generator" +require "active_support/message_verifier" class CookieJarTest < ActiveSupport::TestCase attr_reader :request @@ -12,26 +12,26 @@ class CookieJarTest < ActiveSupport::TestCase def test_fetch x = Object.new - assert_not request.cookie_jar.key?('zzzzzz') - assert_equal x, request.cookie_jar.fetch('zzzzzz', x) - assert_not request.cookie_jar.key?('zzzzzz') + assert_not request.cookie_jar.key?("zzzzzz") + assert_equal x, request.cookie_jar.fetch("zzzzzz", x) + assert_not request.cookie_jar.key?("zzzzzz") end def test_fetch_exists x = Object.new - request.cookie_jar['foo'] = 'bar' - assert_equal 'bar', request.cookie_jar.fetch('foo', x) + request.cookie_jar["foo"] = "bar" + assert_equal "bar", request.cookie_jar.fetch("foo", x) end def test_fetch_block x = Object.new - assert_not request.cookie_jar.key?('zzzzzz') - assert_equal x, request.cookie_jar.fetch('zzzzzz') { x } + assert_not request.cookie_jar.key?("zzzzzz") + assert_equal x, request.cookie_jar.fetch("zzzzzz") { x } end def test_key_is_to_s - request.cookie_jar['foo'] = 'bar' - assert_equal 'bar', request.cookie_jar.fetch(:foo) + request.cookie_jar["foo"] = "bar" + assert_equal "bar", request.cookie_jar.fetch(:foo) end def test_fetch_type_error @@ -41,19 +41,19 @@ class CookieJarTest < ActiveSupport::TestCase end def test_each - request.cookie_jar['foo'] = :bar + request.cookie_jar["foo"] = :bar list = [] request.cookie_jar.each do |k,v| list << [k, v] end - assert_equal [['foo', :bar]], list + assert_equal [["foo", :bar]], list end def test_enumerable - request.cookie_jar['foo'] = :bar + request.cookie_jar["foo"] = :bar actual = request.cookie_jar.map { |k,v| [k.to_s, v.to_s] } - assert_equal [['foo', 'bar']], actual + assert_equal [["foo", "bar"]], actual end def test_key_methods @@ -68,7 +68,7 @@ class CookieJarTest < ActiveSupport::TestCase def test_write_doesnt_set_a_nil_header headers = {} request.cookie_jar.write(headers) - assert !headers.include?('Set-Cookie') + assert !headers.include?("Set-Cookie") end end @@ -100,7 +100,7 @@ class CookiesTest < ActionController::TestCase end def authenticate_for_fourteen_days_with_symbols - cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) } + cookies[:user_name] = { value: "david", expires: Time.utc(2005, 10, 10,5) } head :ok end @@ -123,17 +123,17 @@ class CookiesTest < ActionController::TestCase alias delete_cookie logout def delete_cookie_with_path - cookies.delete("user_name", :path => '/beaten') + cookies.delete("user_name", path: "/beaten") head :ok end def authenticate_with_http_only - cookies["user_name"] = { :value => "david", :httponly => true } + cookies["user_name"] = { value: "david", httponly: true } head :ok end def authenticate_with_secure - cookies["user_name"] = { :value => "david", :secure => true } + cookies["user_name"] = { value: "david", secure: true } head :ok end @@ -153,7 +153,7 @@ class CookiesTest < ActionController::TestCase end def set_encrypted_cookie - cookies.encrypted[:foo] = 'bar' + cookies.encrypted[:foo] = "bar" head :ok end @@ -173,7 +173,7 @@ class CookiesTest < ActionController::TestCase end def set_wrapped_encrypted_cookie - cookies.encrypted[:foo] = JSONWrapper.new('bar') + cookies.encrypted[:foo] = JSONWrapper.new("bar") head :ok end @@ -183,12 +183,12 @@ class CookiesTest < ActionController::TestCase end def set_invalid_encrypted_cookie - cookies[:invalid_cookie] = 'invalid--9170e00a57cfc27083363b5c75b835e477bd90cf' + cookies[:invalid_cookie] = "invalid--9170e00a57cfc27083363b5c75b835e477bd90cf" head :ok end def raise_data_overflow - cookies.signed[:foo] = 'bye!' * 1024 + cookies.signed[:foo] = "bye!" * 1024 head :ok end @@ -205,47 +205,47 @@ class CookiesTest < ActionController::TestCase def delete_and_set_cookie cookies.delete :user_name - cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) } + cookies[:user_name] = { value: "david", expires: Time.utc(2005, 10, 10,5) } head :ok end def set_cookie_with_domain - cookies[:user_name] = {:value => "rizwanreza", :domain => :all} + cookies[:user_name] = { value: "rizwanreza", domain: :all } head :ok end def set_cookie_with_domain_all_as_string - cookies[:user_name] = {:value => "rizwanreza", :domain => 'all'} + cookies[:user_name] = { value: "rizwanreza", domain: "all" } head :ok end def delete_cookie_with_domain - cookies.delete(:user_name, :domain => :all) + cookies.delete(:user_name, domain: :all) head :ok end def delete_cookie_with_domain_all_as_string - cookies.delete(:user_name, :domain => 'all') + cookies.delete(:user_name, domain: "all") head :ok end def set_cookie_with_domain_and_tld - cookies[:user_name] = {:value => "rizwanreza", :domain => :all, :tld_length => 2} + cookies[:user_name] = { value: "rizwanreza", domain: :all, tld_length: 2 } head :ok end def delete_cookie_with_domain_and_tld - cookies.delete(:user_name, :domain => :all, :tld_length => 2) + cookies.delete(:user_name, domain: :all, tld_length: 2) head :ok end def set_cookie_with_domains - cookies[:user_name] = {:value => "rizwanreza", :domain => %w(example1.com example2.com .example3.com)} + cookies[:user_name] = { value: "rizwanreza", domain: %w(example1.com example2.com .example3.com) } head :ok end def delete_cookie_with_domains - cookies.delete(:user_name, :domain => %w(example1.com example2.com .example3.com)) + cookies.delete(:user_name, domain: %w(example1.com example2.com .example3.com)) head :ok end @@ -255,7 +255,7 @@ class CookiesTest < ActionController::TestCase end def string_key - cookies['user_name'] = "dhh" + cookies["user_name"] = "dhh" head :ok end @@ -265,7 +265,7 @@ class CookiesTest < ActionController::TestCase end def string_key_mock - cookies['user_name'] = "david" if cookies['user_name'] == "andrew" + cookies["user_name"] = "david" if cookies["user_name"] == "andrew" head :ok end @@ -276,7 +276,7 @@ class CookiesTest < ActionController::TestCase tests TestController - SALT = 'b3c631c314c0bbca50c1b2843150fe33' + SALT = "b3c631c314c0bbca50c1b2843150fe33" def setup super @@ -293,57 +293,57 @@ class CookiesTest < ActionController::TestCase def test_setting_cookie get :authenticate assert_cookie_header "user_name=david; path=/" - assert_equal({"user_name" => "david"}, @response.cookies) + assert_equal({ "user_name" => "david" }, @response.cookies) end def test_setting_the_same_value_to_cookie - request.cookies[:user_name] = 'david' + request.cookies[:user_name] = "david" get :authenticate assert_predicate response.cookies, :empty? end def test_setting_the_same_value_to_permanent_cookie - request.cookies[:user_name] = 'Jamie' + request.cookies[:user_name] = "Jamie" get :set_permanent_cookie - assert_equal({'user_name' => 'Jamie'}, response.cookies) + assert_equal({ "user_name" => "Jamie" }, response.cookies) end def test_setting_with_escapable_characters get :set_with_with_escapable_characters assert_cookie_header "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/" - assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies) + assert_equal({ "that & guy" => "foo & bar => baz" }, @response.cookies) end def test_setting_cookie_for_fourteen_days get :authenticate_for_fourteen_days assert_cookie_header "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000" - assert_equal({"user_name" => "david"}, @response.cookies) + assert_equal({ "user_name" => "david" }, @response.cookies) end def test_setting_cookie_for_fourteen_days_with_symbols get :authenticate_for_fourteen_days_with_symbols assert_cookie_header "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000" - assert_equal({"user_name" => "david"}, @response.cookies) + assert_equal({ "user_name" => "david" }, @response.cookies) end def test_setting_cookie_with_http_only get :authenticate_with_http_only assert_cookie_header "user_name=david; path=/; HttpOnly" - assert_equal({"user_name" => "david"}, @response.cookies) + assert_equal({ "user_name" => "david" }, @response.cookies) end def test_setting_cookie_with_secure @request.env["HTTPS"] = "on" get :authenticate_with_secure assert_cookie_header "user_name=david; path=/; secure" - assert_equal({"user_name" => "david"}, @response.cookies) + assert_equal({ "user_name" => "david" }, @response.cookies) end def test_setting_cookie_with_secure_when_always_write_cookie_is_true old_cookie, @request.cookie_jar.always_write_cookie = @request.cookie_jar.always_write_cookie, true get :authenticate_with_secure assert_cookie_header "user_name=david; path=/; secure" - assert_equal({"user_name" => "david"}, @response.cookies) + assert_equal({ "user_name" => "david" }, @response.cookies) ensure @request.cookie_jar.always_write_cookie = old_cookie end @@ -351,14 +351,14 @@ class CookiesTest < ActionController::TestCase def test_not_setting_cookie_with_secure get :authenticate_with_secure assert_not_cookie_header "user_name=david; path=/; secure" - assert_not_equal({"user_name" => "david"}, @response.cookies) + assert_not_equal({ "user_name" => "david" }, @response.cookies) end def test_multiple_cookies get :set_multiple_cookies assert_equal 2, @response.cookies.size assert_cookie_header "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000\nlogin=XJ-122; path=/" - assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies) + assert_equal({ "login" => "XJ-122", "user_name" => "david" }, @response.cookies) end def test_setting_test_cookie @@ -366,14 +366,14 @@ class CookiesTest < ActionController::TestCase end def test_expiring_cookie - request.cookies[:user_name] = 'Joe' + request.cookies[:user_name] = "Joe" get :logout assert_cookie_header "user_name=; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" - assert_equal({"user_name" => nil}, @response.cookies) + assert_equal({ "user_name" => nil }, @response.cookies) end def test_delete_cookie_with_path - request.cookies[:user_name] = 'Joe' + request.cookies[:user_name] = "Joe" get :delete_cookie_with_path assert_cookie_header "user_name=; path=/beaten; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" end @@ -385,16 +385,16 @@ class CookiesTest < ActionController::TestCase end def test_deleted_cookie_predicate - cookies[:user_name] = 'Joe' + cookies[:user_name] = "Joe" cookies.delete("user_name") assert cookies.deleted?("user_name") assert_equal false, cookies.deleted?("another") end def test_deleted_cookie_predicate_with_mismatching_options - cookies[:user_name] = 'Joe' - cookies.delete("user_name", :path => "/path") - assert_equal false, cookies.deleted?("user_name", :path => "/different") + cookies[:user_name] = "Joe" + cookies.delete("user_name", path: "/path") + assert_equal false, cookies.deleted?("user_name", path: "/different") end def test_cookies_persist_throughout_request @@ -410,7 +410,7 @@ class CookiesTest < ActionController::TestCase def test_read_permanent_cookie get :set_permanent_cookie - assert_equal 'Jamie', @controller.send(:cookies).permanent[:user_name] + assert_equal "Jamie", @controller.send(:cookies).permanent[:user_name] end def test_signed_cookie_using_default_digest @@ -423,12 +423,12 @@ class CookiesTest < ActionController::TestCase signed_cookie_salt = @request.env["action_dispatch.signed_cookie_salt"] secret = key_generator.generate_key(signed_cookie_salt) - verifier = ActiveSupport::MessageVerifier.new(secret, serializer: Marshal, digest: 'SHA1') + verifier = ActiveSupport::MessageVerifier.new(secret, serializer: Marshal, digest: "SHA1") assert_equal verifier.generate(45), cookies[:user_id] end def test_signed_cookie_using_custom_digest - @request.env["action_dispatch.cookies_digest"] = 'SHA256' + @request.env["action_dispatch.cookies_digest"] = "SHA256" get :set_signed_cookie cookies = @controller.send :cookies assert_not_equal 45, cookies[:user_id] @@ -438,7 +438,7 @@ class CookiesTest < ActionController::TestCase signed_cookie_salt = @request.env["action_dispatch.signed_cookie_salt"] secret = key_generator.generate_key(signed_cookie_salt) - verifier = ActiveSupport::MessageVerifier.new(secret, serializer: Marshal, digest: 'SHA256') + verifier = ActiveSupport::MessageVerifier.new(secret, serializer: Marshal, digest: "SHA256") assert_equal verifier.generate(45), cookies[:user_id] end @@ -469,15 +469,15 @@ class CookiesTest < ActionController::TestCase @request.env["action_dispatch.cookies_serializer"] = :json get :set_wrapped_signed_cookie cookies = @controller.send :cookies - assert_not_equal 'wrapped: 45', cookies[:user_id] - assert_equal 'wrapped: 45', cookies.signed[:user_id] + assert_not_equal "wrapped: 45", cookies[:user_id] + assert_equal "wrapped: 45", cookies.signed[:user_id] end def test_signed_cookie_using_custom_serializer @request.env["action_dispatch.cookies_serializer"] = CustomSerializer get :set_signed_cookie assert_not_equal 45, cookies[:user_id] - assert_equal '45 was dumped and loaded', cookies.signed[:user_id] + assert_equal "45 was dumped and loaded", cookies.signed[:user_id] end def test_signed_cookie_using_hybrid_serializer_can_migrate_marshal_dumped_value_to_json @@ -497,7 +497,7 @@ class CookiesTest < ActionController::TestCase assert_equal 45, cookies.signed[:user_id] verifier = ActiveSupport::MessageVerifier.new(secret, serializer: JSON) - assert_equal 45, verifier.verify(@response.cookies['user_id']) + assert_equal 45, verifier.verify(@response.cookies["user_id"]) end def test_signed_cookie_using_hybrid_serializer_can_read_from_json_dumped_value @@ -526,64 +526,64 @@ class CookiesTest < ActionController::TestCase def test_encrypted_cookie_using_default_serializer get :set_encrypted_cookie cookies = @controller.send :cookies - assert_not_equal 'bar', cookies[:foo] + assert_not_equal "bar", cookies[:foo] assert_raise TypeError do cookies.signed[:foo] end - assert_equal 'bar', cookies.encrypted[:foo] + assert_equal "bar", cookies.encrypted[:foo] end def test_encrypted_cookie_using_marshal_serializer @request.env["action_dispatch.cookies_serializer"] = :marshal get :set_encrypted_cookie cookies = @controller.send :cookies - assert_not_equal 'bar', cookies[:foo] + assert_not_equal "bar", cookies[:foo] assert_raises TypeError do cookies.signed[:foo] end - assert_equal 'bar', cookies.encrypted[:foo] + assert_equal "bar", cookies.encrypted[:foo] end def test_encrypted_cookie_using_json_serializer @request.env["action_dispatch.cookies_serializer"] = :json get :set_encrypted_cookie cookies = @controller.send :cookies - assert_not_equal 'bar', cookies[:foo] + assert_not_equal "bar", cookies[:foo] assert_raises ::JSON::ParserError do cookies.signed[:foo] end - assert_equal 'bar', cookies.encrypted[:foo] + assert_equal "bar", cookies.encrypted[:foo] end def test_wrapped_encrypted_cookie_using_json_serializer @request.env["action_dispatch.cookies_serializer"] = :json get :set_wrapped_encrypted_cookie cookies = @controller.send :cookies - assert_not_equal 'wrapped: bar', cookies[:foo] + assert_not_equal "wrapped: bar", cookies[:foo] assert_raises ::JSON::ParserError do cookies.signed[:foo] end - assert_equal 'wrapped: bar', cookies.encrypted[:foo] + assert_equal "wrapped: bar", cookies.encrypted[:foo] end def test_encrypted_cookie_using_custom_serializer @request.env["action_dispatch.cookies_serializer"] = CustomSerializer get :set_encrypted_cookie - assert_not_equal 'bar', cookies.encrypted[:foo] - assert_equal 'bar was dumped and loaded', cookies.encrypted[:foo] + assert_not_equal "bar", cookies.encrypted[:foo] + assert_equal "bar was dumped and loaded", cookies.encrypted[:foo] end def test_encrypted_cookie_using_custom_digest - @request.env["action_dispatch.cookies_digest"] = 'SHA256' + @request.env["action_dispatch.cookies_digest"] = "SHA256" get :set_encrypted_cookie cookies = @controller.send :cookies - assert_not_equal 'bar', cookies[:foo] - assert_equal 'bar', cookies.encrypted[:foo] + assert_not_equal "bar", cookies[:foo] + assert_equal "bar", cookies.encrypted[:foo] sign_secret = @request.env["action_dispatch.key_generator"].generate_key(@request.env["action_dispatch.encrypted_signed_cookie_salt"]) - sha1_verifier = ActiveSupport::MessageVerifier.new(sign_secret, serializer: ActiveSupport::MessageEncryptor::NullSerializer, digest: 'SHA1') - sha256_verifier = ActiveSupport::MessageVerifier.new(sign_secret, serializer: ActiveSupport::MessageEncryptor::NullSerializer, digest: 'SHA256') + sha1_verifier = ActiveSupport::MessageVerifier.new(sign_secret, serializer: ActiveSupport::MessageEncryptor::NullSerializer, digest: "SHA1") + sha256_verifier = ActiveSupport::MessageVerifier.new(sign_secret, serializer: ActiveSupport::MessageEncryptor::NullSerializer, digest: "SHA256") assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do sha1_verifier.verify(cookies[:foo]) @@ -603,7 +603,7 @@ class CookiesTest < ActionController::TestCase secret = key_generator.generate_key(encrypted_cookie_salt) sign_secret = key_generator.generate_key(encrypted_signed_cookie_salt) - marshal_value = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: Marshal).encrypt_and_sign("bar") + marshal_value = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret, serializer: Marshal).encrypt_and_sign("bar") @request.headers["Cookie"] = "foo=#{marshal_value}" get :get_encrypted_cookie @@ -612,7 +612,7 @@ class CookiesTest < ActionController::TestCase assert_not_equal "bar", cookies[:foo] assert_equal "bar", cookies.encrypted[:foo] - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret, serializer: JSON) assert_equal "bar", encryptor.decrypt_and_verify(@response.cookies["foo"]) end @@ -624,7 +624,7 @@ class CookiesTest < ActionController::TestCase encrypted_signed_cookie_salt = @request.env["action_dispatch.encrypted_signed_cookie_salt"] secret = key_generator.generate_key(encrypted_cookie_salt) sign_secret = key_generator.generate_key(encrypted_signed_cookie_salt) - json_value = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON).encrypt_and_sign("bar") + json_value = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret, serializer: JSON).encrypt_and_sign("bar") @request.headers["Cookie"] = "foo=#{json_value}" get :get_encrypted_cookie @@ -636,6 +636,19 @@ class CookiesTest < ActionController::TestCase assert_nil @response.cookies["foo"] end + def test_compat_encrypted_cookie_using_64_byte_key + # Cookie generated with 64 bytes secret + message = ["566d4e75536d686e633246564e6b493062557079626c566d51574d30515430394c53315665564a694e4563786555744f57537454576b396a5a31566a626e52525054303d2d2d34663234333330623130623261306163363562316266323335396164666364613564643134623131"].pack("H*") + @request.headers["Cookie"] = "foo=#{message}" + + get :get_encrypted_cookie + + cookies = @controller.send :cookies + assert_not_equal "bar", cookies[:foo] + assert_equal "bar", cookies.encrypted[:foo] + assert_nil @response.cookies["foo"] + end + def test_accessing_nonexistent_encrypted_cookie_should_not_raise_invalid_message get :set_encrypted_cookie assert_nil @controller.send(:cookies).encrypted[:non_existent_attribute] @@ -653,10 +666,10 @@ class CookiesTest < ActionController::TestCase end def test_delete_and_set_cookie - request.cookies[:user_name] = 'Joe' + request.cookies[:user_name] = "Joe" get :delete_and_set_cookie assert_cookie_header "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000" - assert_equal({"user_name" => "david"}, @response.cookies) + assert_equal({ "user_name" => "david" }, @response.cookies) end def test_raise_data_overflow @@ -687,7 +700,7 @@ class CookiesTest < ActionController::TestCase get :set_signed_cookie } - assert_raise(ArgumentError, ''.inspect) { + assert_raise(ArgumentError, "".inspect) { @request.env["action_dispatch.key_generator"] = ActiveSupport::LegacyKeyGenerator.new("") get :set_signed_cookie } @@ -789,18 +802,18 @@ class CookiesTest < ActionController::TestCase @request.env["action_dispatch.encrypted_cookie_salt"] = "4433796b79d99a7735553e316522acee" @request.env["action_dispatch.encrypted_signed_cookie_salt"] = "00646eb40062e1b1deff205a27cd30f9" - legacy_value = ActiveSupport::MessageVerifier.new("b3c631c314c0bbca50c1b2843150fe33").generate('bar') + legacy_value = ActiveSupport::MessageVerifier.new("b3c631c314c0bbca50c1b2843150fe33").generate("bar") @request.headers["Cookie"] = "foo=#{legacy_value}" get :get_encrypted_cookie - assert_equal 'bar', @controller.send(:cookies).encrypted[:foo] + assert_equal "bar", @controller.send(:cookies).encrypted[:foo] key_generator = @request.env["action_dispatch.key_generator"] secret = key_generator.generate_key(@request.env["action_dispatch.encrypted_cookie_salt"]) sign_secret = key_generator.generate_key(@request.env["action_dispatch.encrypted_signed_cookie_salt"]) - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret) - assert_equal 'bar', encryptor.decrypt_and_verify(@response.cookies["foo"]) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret) + assert_equal "bar", encryptor.decrypt_and_verify(@response.cookies["foo"]) end def test_legacy_json_signed_cookie_is_read_and_transparently_upgraded_by_signed_json_cookie_jar_if_both_secret_token_and_secret_key_base_are_set @@ -828,18 +841,18 @@ class CookiesTest < ActionController::TestCase @request.env["action_dispatch.encrypted_cookie_salt"] = "4433796b79d99a7735553e316522acee" @request.env["action_dispatch.encrypted_signed_cookie_salt"] = "00646eb40062e1b1deff205a27cd30f9" - legacy_value = ActiveSupport::MessageVerifier.new("b3c631c314c0bbca50c1b2843150fe33", serializer: JSON).generate('bar') + legacy_value = ActiveSupport::MessageVerifier.new("b3c631c314c0bbca50c1b2843150fe33", serializer: JSON).generate("bar") @request.headers["Cookie"] = "foo=#{legacy_value}" get :get_encrypted_cookie - assert_equal 'bar', @controller.send(:cookies).encrypted[:foo] + assert_equal "bar", @controller.send(:cookies).encrypted[:foo] key_generator = @request.env["action_dispatch.key_generator"] secret = key_generator.generate_key(@request.env["action_dispatch.encrypted_cookie_salt"]) sign_secret = key_generator.generate_key(@request.env["action_dispatch.encrypted_signed_cookie_salt"]) - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON) - assert_equal 'bar', encryptor.decrypt_and_verify(@response.cookies["foo"]) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret, serializer: JSON) + assert_equal "bar", encryptor.decrypt_and_verify(@response.cookies["foo"]) end def test_legacy_json_signed_cookie_is_read_and_transparently_upgraded_by_signed_json_hybrid_jar_if_both_secret_token_and_secret_key_base_are_set @@ -867,18 +880,18 @@ class CookiesTest < ActionController::TestCase @request.env["action_dispatch.encrypted_cookie_salt"] = "4433796b79d99a7735553e316522acee" @request.env["action_dispatch.encrypted_signed_cookie_salt"] = "00646eb40062e1b1deff205a27cd30f9" - legacy_value = ActiveSupport::MessageVerifier.new("b3c631c314c0bbca50c1b2843150fe33", serializer: JSON).generate('bar') + legacy_value = ActiveSupport::MessageVerifier.new("b3c631c314c0bbca50c1b2843150fe33", serializer: JSON).generate("bar") @request.headers["Cookie"] = "foo=#{legacy_value}" get :get_encrypted_cookie - assert_equal 'bar', @controller.send(:cookies).encrypted[:foo] + assert_equal "bar", @controller.send(:cookies).encrypted[:foo] key_generator = @request.env["action_dispatch.key_generator"] secret = key_generator.generate_key(@request.env["action_dispatch.encrypted_cookie_salt"]) sign_secret = key_generator.generate_key(@request.env["action_dispatch.encrypted_signed_cookie_salt"]) - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON) - assert_equal 'bar', encryptor.decrypt_and_verify(@response.cookies["foo"]) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret, serializer: JSON) + assert_equal "bar", encryptor.decrypt_and_verify(@response.cookies["foo"]) end def test_legacy_marshal_signed_cookie_is_read_and_transparently_upgraded_by_signed_json_hybrid_jar_if_both_secret_token_and_secret_key_base_are_set @@ -906,18 +919,18 @@ class CookiesTest < ActionController::TestCase @request.env["action_dispatch.encrypted_cookie_salt"] = "4433796b79d99a7735553e316522acee" @request.env["action_dispatch.encrypted_signed_cookie_salt"] = "00646eb40062e1b1deff205a27cd30f9" - legacy_value = ActiveSupport::MessageVerifier.new("b3c631c314c0bbca50c1b2843150fe33").generate('bar') + legacy_value = ActiveSupport::MessageVerifier.new("b3c631c314c0bbca50c1b2843150fe33").generate("bar") @request.headers["Cookie"] = "foo=#{legacy_value}" get :get_encrypted_cookie - assert_equal 'bar', @controller.send(:cookies).encrypted[:foo] + assert_equal "bar", @controller.send(:cookies).encrypted[:foo] key_generator = @request.env["action_dispatch.key_generator"] secret = key_generator.generate_key(@request.env["action_dispatch.encrypted_cookie_salt"]) sign_secret = key_generator.generate_key(@request.env["action_dispatch.encrypted_signed_cookie_salt"]) - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON) - assert_equal 'bar', encryptor.decrypt_and_verify(@response.cookies["foo"]) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret, serializer: JSON) + assert_equal "bar", encryptor.decrypt_and_verify(@response.cookies["foo"]) end def test_legacy_signed_cookie_is_treated_as_nil_by_signed_cookie_jar_if_tampered @@ -998,7 +1011,7 @@ class CookiesTest < ActionController::TestCase end def test_deleting_cookie_with_all_domain_option - request.cookies[:user_name] = 'Joe' + request.cookies[:user_name] = "Joe" get :delete_cookie_with_domain assert_response :success assert_cookie_header "user_name=; domain=.nextangle.com; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" @@ -1032,7 +1045,7 @@ class CookiesTest < ActionController::TestCase end def test_deleting_cookie_with_all_domain_option_and_tld_length - request.cookies[:user_name] = 'Joe' + request.cookies[:user_name] = "Joe" get :delete_cookie_with_domain_and_tld assert_response :success assert_cookie_header "user_name=; domain=.nextangle.com; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" @@ -1061,7 +1074,7 @@ class CookiesTest < ActionController::TestCase def test_deletings_cookie_with_several_preset_domains_using_one_of_these_domains @request.host = "example2.com" - request.cookies[:user_name] = 'Joe' + request.cookies[:user_name] = "Joe" get :delete_cookie_with_domains assert_response :success assert_cookie_header "user_name=; domain=example2.com; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" @@ -1069,7 +1082,7 @@ class CookiesTest < ActionController::TestCase def test_deletings_cookie_with_several_preset_domains_using_other_domain @request.host = "other-domain.com" - request.cookies[:user_name] = 'Joe' + request.cookies[:user_name] = "Joe" get :delete_cookie_with_domains assert_response :success assert_cookie_header "user_name=; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" @@ -1078,20 +1091,20 @@ class CookiesTest < ActionController::TestCase def test_cookies_hash_is_indifferent_access get :symbol_key assert_equal "david", cookies[:user_name] - assert_equal "david", cookies['user_name'] + assert_equal "david", cookies["user_name"] get :string_key assert_equal "dhh", cookies[:user_name] - assert_equal "dhh", cookies['user_name'] + assert_equal "dhh", cookies["user_name"] end def test_setting_request_cookies_is_indifferent_access cookies.clear cookies[:user_name] = "andrew" get :string_key_mock - assert_equal "david", cookies['user_name'] + assert_equal "david", cookies["user_name"] cookies.clear - cookies['user_name'] = "andrew" + cookies["user_name"] = "andrew" get :symbol_key_mock assert_equal "david", cookies[:user_name] end @@ -1123,57 +1136,57 @@ class CookiesTest < ActionController::TestCase end def test_can_set_http_cookie_header - @request.env['HTTP_COOKIE'] = 'user_name=david' + @request.env["HTTP_COOKIE"] = "user_name=david" get :noop - assert_equal 'david', cookies['user_name'] - assert_equal 'david', cookies[:user_name] + assert_equal "david", cookies["user_name"] + assert_equal "david", cookies[:user_name] get :noop - assert_equal 'david', cookies['user_name'] - assert_equal 'david', cookies[:user_name] + assert_equal "david", cookies["user_name"] + assert_equal "david", cookies[:user_name] - @request.env['HTTP_COOKIE'] = 'user_name=andrew' + @request.env["HTTP_COOKIE"] = "user_name=andrew" get :noop - assert_equal 'andrew', cookies['user_name'] - assert_equal 'andrew', cookies[:user_name] + assert_equal "andrew", cookies["user_name"] + assert_equal "andrew", cookies[:user_name] end def test_can_set_request_cookies - @request.cookies['user_name'] = 'david' + @request.cookies["user_name"] = "david" get :noop - assert_equal 'david', cookies['user_name'] - assert_equal 'david', cookies[:user_name] + assert_equal "david", cookies["user_name"] + assert_equal "david", cookies[:user_name] get :noop - assert_equal 'david', cookies['user_name'] - assert_equal 'david', cookies[:user_name] + assert_equal "david", cookies["user_name"] + assert_equal "david", cookies[:user_name] - @request.cookies[:user_name] = 'andrew' + @request.cookies[:user_name] = "andrew" get :noop - assert_equal 'andrew', cookies['user_name'] - assert_equal 'andrew', cookies[:user_name] + assert_equal "andrew", cookies["user_name"] + assert_equal "andrew", cookies[:user_name] end def test_cookies_precedence_over_http_cookie - @request.env['HTTP_COOKIE'] = 'user_name=andrew' + @request.env["HTTP_COOKIE"] = "user_name=andrew" get :authenticate - assert_equal 'david', cookies['user_name'] - assert_equal 'david', cookies[:user_name] + assert_equal "david", cookies["user_name"] + assert_equal "david", cookies[:user_name] get :noop - assert_equal 'david', cookies['user_name'] - assert_equal 'david', cookies[:user_name] + assert_equal "david", cookies["user_name"] + assert_equal "david", cookies[:user_name] end def test_cookies_precedence_over_request_cookies - @request.cookies['user_name'] = 'andrew' + @request.cookies["user_name"] = "andrew" get :authenticate - assert_equal 'david', cookies['user_name'] - assert_equal 'david', cookies[:user_name] + assert_equal "david", cookies["user_name"] + assert_equal "david", cookies[:user_name] get :noop - assert_equal 'david', cookies['user_name'] - assert_equal 'david', cookies[:user_name] + assert_equal "david", cookies["user_name"] + assert_equal "david", cookies[:user_name] end private diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 6f3d30ebf9..2c5e09e283 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -1,7 +1,6 @@ -require 'abstract_unit' +require "abstract_unit" class DebugExceptionsTest < ActionDispatch::IntegrationTest - class Boomer attr_accessor :closed @@ -20,11 +19,11 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end def method_that_raises - raise StandardError.new 'error in framework' + raise StandardError.new "error in framework" end def call(env) - env['action_dispatch.show_detailed_exceptions'] = @detailed + env["action_dispatch.show_detailed_exceptions"] = @detailed req = ActionDispatch::Request.new(env) case req.path when %r{/pass} @@ -45,10 +44,10 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest begin raise AbstractController::ActionNotFound.new rescue - raise ActionView::Template::Error.new('template') + raise ActionView::Template::Error.new("template") end when %r{/missing_template} - raise ActionView::MissingTemplate.new(%w(foo), 'foo/index', %w(foo), false, 'mailer') + raise ActionView::MissingTemplate.new(%w(foo), "foo/index", %w(foo), false, "mailer") when %r{/bad_request} raise ActionController::BadRequest when %r{/missing_keys} @@ -56,10 +55,10 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest when %r{/parameter_missing} raise ActionController::ParameterMissing, :missing_param_key when %r{/original_syntax_error} - eval 'broke_syntax =' # `eval` need for raise native SyntaxError at runtime + eval "broke_syntax =" # `eval` need for raise native SyntaxError at runtime when %r{/syntax_error_into_view} begin - eval 'broke_syntax =' + eval "broke_syntax =" rescue Exception template = ActionView::Template.new(File.read(__FILE__), __FILE__, @@ -79,85 +78,85 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest ProductionApp = ActionDispatch::DebugExceptions.new(Boomer.new(false), RoutesApp) DevelopmentApp = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp) - test 'skip diagnosis if not showing detailed exceptions' do + test "skip diagnosis if not showing detailed exceptions" do @app = ProductionApp assert_raise RuntimeError do - get "/", headers: { 'action_dispatch.show_exceptions' => true } + get "/", headers: { "action_dispatch.show_exceptions" => true } end end - test 'skip diagnosis if not showing exceptions' do + test "skip diagnosis if not showing exceptions" do @app = DevelopmentApp assert_raise RuntimeError do - get "/", headers: { 'action_dispatch.show_exceptions' => false } + get "/", headers: { "action_dispatch.show_exceptions" => false } end end - test 'raise an exception on cascade pass' do + test "raise an exception on cascade pass" do @app = ProductionApp assert_raise ActionController::RoutingError do - get "/pass", headers: { 'action_dispatch.show_exceptions' => true } + get "/pass", headers: { "action_dispatch.show_exceptions" => true } end end - test 'closes the response body on cascade pass' do + test "closes the response body on cascade pass" do boomer = Boomer.new(false) @app = ActionDispatch::DebugExceptions.new(boomer) assert_raise ActionController::RoutingError do - get "/pass", headers: { 'action_dispatch.show_exceptions' => true } + get "/pass", headers: { "action_dispatch.show_exceptions" => true } end assert boomer.closed, "Expected to close the response body" end - test 'displays routes in a table when a RoutingError occurs' do + test "displays routes in a table when a RoutingError occurs" do @app = DevelopmentApp - get "/pass", headers: { 'action_dispatch.show_exceptions' => true } + get "/pass", headers: { "action_dispatch.show_exceptions" => true } routing_table = body[/route_table.*<.table>/m] - assert_match '/:controller(/:action)(.:format)', routing_table - assert_match ':controller#:action', routing_table - assert_no_match '<|>', routing_table, "there should not be escaped html in the output" + assert_match "/:controller(/:action)(.:format)", routing_table + assert_match ":controller#:action", routing_table + assert_no_match "<|>", routing_table, "there should not be escaped html in the output" end - test 'displays request and response info when a RoutingError occurs' do + test "displays request and response info when a RoutingError occurs" do @app = DevelopmentApp - get "/pass", headers: { 'action_dispatch.show_exceptions' => true } + get "/pass", headers: { "action_dispatch.show_exceptions" => true } - assert_select 'h2', /Request/ - assert_select 'h2', /Response/ + assert_select "h2", /Request/ + assert_select "h2", /Response/ end test "rescue with diagnostics message" do @app = DevelopmentApp - get "/", headers: { 'action_dispatch.show_exceptions' => true } + get "/", headers: { "action_dispatch.show_exceptions" => true } assert_response 500 assert_match(/puke/, body) - get "/not_found", headers: { 'action_dispatch.show_exceptions' => true } + get "/not_found", headers: { "action_dispatch.show_exceptions" => true } assert_response 404 assert_match(/#{AbstractController::ActionNotFound.name}/, body) - get "/method_not_allowed", headers: { 'action_dispatch.show_exceptions' => true } + get "/method_not_allowed", headers: { "action_dispatch.show_exceptions" => true } assert_response 405 assert_match(/ActionController::MethodNotAllowed/, body) - get "/unknown_http_method", headers: { 'action_dispatch.show_exceptions' => true } + get "/unknown_http_method", headers: { "action_dispatch.show_exceptions" => true } assert_response 405 assert_match(/ActionController::UnknownHttpMethod/, body) - get "/bad_request", headers: { 'action_dispatch.show_exceptions' => true } + get "/bad_request", headers: { "action_dispatch.show_exceptions" => true } assert_response 400 assert_match(/ActionController::BadRequest/, body) - get "/parameter_missing", headers: { 'action_dispatch.show_exceptions' => true } + get "/parameter_missing", headers: { "action_dispatch.show_exceptions" => true } assert_response 400 assert_match(/ActionController::ParameterMissing/, body) end test "rescue with text error for xhr request" do @app = DevelopmentApp - xhr_request_env = {'action_dispatch.show_exceptions' => true, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'} + xhr_request_env = { "action_dispatch.show_exceptions" => true, "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" } get "/", headers: xhr_request_env assert_response 500 @@ -166,12 +165,12 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest assert_equal "text/plain", response.content_type assert_match(/RuntimeError\npuke/, body) - Rails.stub :root, Pathname.new('.') do + Rails.stub :root, Pathname.new(".") do get "/", headers: xhr_request_env assert_response 500 - assert_match 'Extracted source (around line #', body - assert_select 'pre', { count: 0 }, body + assert_match "Extracted source (around line #", body + assert_select "pre", { count: 0 }, body end get "/not_found", headers: xhr_request_env @@ -208,38 +207,38 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "rescue with JSON error for JSON API request" do @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api) - get "/", headers: { 'action_dispatch.show_exceptions' => true }, as: :json + get "/", headers: { "action_dispatch.show_exceptions" => true }, as: :json assert_response 500 assert_no_match(/<header>/, body) assert_no_match(/<body>/, body) assert_equal "application/json", response.content_type assert_match(/RuntimeError: puke/, body) - get "/not_found", headers: { 'action_dispatch.show_exceptions' => true }, as: :json + get "/not_found", headers: { "action_dispatch.show_exceptions" => true }, as: :json assert_response 404 assert_no_match(/<body>/, body) assert_equal "application/json", response.content_type assert_match(/#{AbstractController::ActionNotFound.name}/, body) - get "/method_not_allowed", headers: { 'action_dispatch.show_exceptions' => true }, as: :json + get "/method_not_allowed", headers: { "action_dispatch.show_exceptions" => true }, as: :json assert_response 405 assert_no_match(/<body>/, body) assert_equal "application/json", response.content_type assert_match(/ActionController::MethodNotAllowed/, body) - get "/unknown_http_method", headers: { 'action_dispatch.show_exceptions' => true }, as: :json + get "/unknown_http_method", headers: { "action_dispatch.show_exceptions" => true }, as: :json assert_response 405 assert_no_match(/<body>/, body) assert_equal "application/json", response.content_type assert_match(/ActionController::UnknownHttpMethod/, body) - get "/bad_request", headers: { 'action_dispatch.show_exceptions' => true }, as: :json + get "/bad_request", headers: { "action_dispatch.show_exceptions" => true }, as: :json assert_response 400 assert_no_match(/<body>/, body) assert_equal "application/json", response.content_type assert_match(/ActionController::BadRequest/, body) - get "/parameter_missing", headers: { 'action_dispatch.show_exceptions' => true }, as: :json + get "/parameter_missing", headers: { "action_dispatch.show_exceptions" => true }, as: :json assert_response 400 assert_no_match(/<body>/, body) assert_equal "application/json", response.content_type @@ -249,7 +248,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "rescue with HTML format for HTML API request" do @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api) - get "/index.html", headers: { 'action_dispatch.show_exceptions' => true } + get "/index.html", headers: { "action_dispatch.show_exceptions" => true } assert_response 500 assert_match(/<header>/, body) assert_match(/<body>/, body) @@ -260,7 +259,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "rescue with XML format for XML API requests" do @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api) - get "/index.xml", headers: { 'action_dispatch.show_exceptions' => true } + get "/index.xml", headers: { "action_dispatch.show_exceptions" => true } assert_response 500 assert_equal "application/xml", response.content_type assert_match(/RuntimeError: puke/, body) @@ -268,14 +267,14 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "rescue with JSON format as fallback if API request format is not supported" do begin - Mime::Type.register 'text/wibble', :wibble + Mime::Type.register "text/wibble", :wibble ActionDispatch::IntegrationTest.register_encoder(:wibble, param_encoder: -> params { params }) @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api) - get "/index", headers: { 'action_dispatch.show_exceptions' => true }, as: :wibble + get "/index", headers: { "action_dispatch.show_exceptions" => true }, as: :wibble assert_response 500 assert_equal "application/json", response.content_type assert_match(/RuntimeError: puke/, body) @@ -288,8 +287,8 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "does not show filtered parameters" do @app = DevelopmentApp - get "/", params: { "foo"=>"bar" }, headers: { 'action_dispatch.show_exceptions' => true, - 'action_dispatch.parameter_filter' => [:foo] } + get "/", params: { "foo"=>"bar" }, headers: { "action_dispatch.show_exceptions" => true, + "action_dispatch.parameter_filter" => [:foo] } assert_response 500 assert_match(""foo"=>"[FILTERED]"", body) end @@ -297,7 +296,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "show registered original exception for wrapped exceptions" do @app = DevelopmentApp - get "/not_found_original_exception", headers: { 'action_dispatch.show_exceptions' => true } + get "/not_found_original_exception", headers: { "action_dispatch.show_exceptions" => true } assert_response 404 assert_match(/AbstractController::ActionNotFound/, body) end @@ -305,7 +304,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "named urls missing keys raise 500 level error" do @app = DevelopmentApp - get "/missing_keys", headers: { 'action_dispatch.show_exceptions' => true } + get "/missing_keys", headers: { "action_dispatch.show_exceptions" => true } assert_response 500 assert_match(/ActionController::UrlGenerationError/, body) @@ -314,11 +313,11 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "show the controller name in the diagnostics template when controller name is present" do @app = DevelopmentApp get("/runtime_error", headers: { - 'action_dispatch.show_exceptions' => true, - 'action_dispatch.request.parameters' => { - 'action' => 'show', - 'id' => 'unknown', - 'controller' => 'featured_tile' + "action_dispatch.show_exceptions" => true, + "action_dispatch.request.parameters" => { + "action" => "show", + "id" => "unknown", + "controller" => "featured_tile" } }) assert_response 500 @@ -329,18 +328,18 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest @app = DevelopmentApp params = { - 'id' => 'unknown', - 'someparam' => { - 'foo' => 'bar', - 'abc' => 'goo' + "id" => "unknown", + "someparam" => { + "foo" => "bar", + "abc" => "goo" } } get("/runtime_error", headers: { - 'action_dispatch.show_exceptions' => true, - 'action_dispatch.request.parameters' => { - 'action' => 'show', - 'controller' => 'featured_tile' + "action_dispatch.show_exceptions" => true, + "action_dispatch.request.parameters" => { + "action" => "show", + "controller" => "featured_tile" }.merge(params) }) assert_response 500 @@ -351,25 +350,25 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "sets the HTTP charset parameter" do @app = DevelopmentApp - get "/", headers: { 'action_dispatch.show_exceptions' => true } + get "/", headers: { "action_dispatch.show_exceptions" => true } assert_equal "text/html; charset=utf-8", response.headers["Content-Type"] end - test 'uses logger from env' do + test "uses logger from env" do @app = DevelopmentApp output = StringIO.new - get "/", headers: { 'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => Logger.new(output) } + get "/", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => Logger.new(output) } assert_match(/puke/, output.rewind && output.read) end - test 'logs only what is necessary' do + test "logs only what is necessary" do @app = DevelopmentApp io = StringIO.new logger = ActiveSupport::Logger.new(io) _old, ActionView::Base.logger = ActionView::Base.logger, logger begin - get "/", headers: { 'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => logger } + get "/", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => logger } ensure ActionView::Base.logger = _old end @@ -385,41 +384,41 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end end - test 'uses backtrace cleaner from env' do + test "uses backtrace cleaner from env" do @app = DevelopmentApp backtrace_cleaner = ActiveSupport::BacktraceCleaner.new - backtrace_cleaner.stub :clean, ['passed backtrace cleaner'] do - get "/", headers: { 'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => backtrace_cleaner } + backtrace_cleaner.stub :clean, ["passed backtrace cleaner"] do + get "/", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.backtrace_cleaner" => backtrace_cleaner } assert_match(/passed backtrace cleaner/, body) end end - test 'logs exception backtrace when all lines silenced' do + test "logs exception backtrace when all lines silenced" do output = StringIO.new backtrace_cleaner = ActiveSupport::BacktraceCleaner.new backtrace_cleaner.add_silencer { true } - env = {'action_dispatch.show_exceptions' => true, - 'action_dispatch.logger' => Logger.new(output), - 'action_dispatch.backtrace_cleaner' => backtrace_cleaner} + env = { "action_dispatch.show_exceptions" => true, + "action_dispatch.logger" => Logger.new(output), + "action_dispatch.backtrace_cleaner" => backtrace_cleaner } get "/", headers: env assert_operator((output.rewind && output.read).lines.count, :>, 10) end - test 'display backtrace when error type is SyntaxError' do + test "display backtrace when error type is SyntaxError" do @app = DevelopmentApp - get '/original_syntax_error', headers: { 'action_dispatch.backtrace_cleaner' => ActiveSupport::BacktraceCleaner.new } + get "/original_syntax_error", headers: { "action_dispatch.backtrace_cleaner" => ActiveSupport::BacktraceCleaner.new } assert_response 500 - assert_select '#Application-Trace' do - assert_select 'pre code', /syntax error, unexpected/ + assert_select "#Application-Trace" do + assert_select "pre code", /syntax error, unexpected/ end end - test 'display backtrace on template missing errors' do + test "display backtrace on template missing errors" do @app = DevelopmentApp get "/missing_template" @@ -428,56 +427,56 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest assert_select "#container h2", /^Missing template/ - assert_select '#Application-Trace' - assert_select '#Framework-Trace' - assert_select '#Full-Trace' + assert_select "#Application-Trace" + assert_select "#Framework-Trace" + assert_select "#Full-Trace" - assert_select 'h2', /Request/ + assert_select "h2", /Request/ end - test 'display backtrace when error type is SyntaxError wrapped by ActionView::Template::Error' do + test "display backtrace when error type is SyntaxError wrapped by ActionView::Template::Error" do @app = DevelopmentApp - get '/syntax_error_into_view', headers: { 'action_dispatch.backtrace_cleaner' => ActiveSupport::BacktraceCleaner.new } + get "/syntax_error_into_view", headers: { "action_dispatch.backtrace_cleaner" => ActiveSupport::BacktraceCleaner.new } assert_response 500 - assert_select '#Application-Trace' do - assert_select 'pre code', /syntax error, unexpected/ + assert_select "#Application-Trace" do + assert_select "pre code", /syntax error, unexpected/ end end - test 'debug exceptions app shows user code that caused the error in source view' do + test "debug exceptions app shows user code that caused the error in source view" do @app = DevelopmentApp - Rails.stub :root, Pathname.new('.') do + Rails.stub :root, Pathname.new(".") do cleaner = ActiveSupport::BacktraceCleaner.new.tap do |bc| bc.add_silencer { |line| line =~ /method_that_raises/ } bc.add_silencer { |line| line !~ %r{test/dispatch/debug_exceptions_test.rb} } end - get '/framework_raises', headers: { 'action_dispatch.backtrace_cleaner' => cleaner } + get "/framework_raises", headers: { "action_dispatch.backtrace_cleaner" => cleaner } # Assert correct error assert_response 500 - assert_select 'h2', /error in framework/ + assert_select "h2", /error in framework/ # assert source view line is the call to method_that_raises - assert_select 'div.source:not(.hidden)' do - assert_select 'pre .line.active', /method_that_raises/ + assert_select "div.source:not(.hidden)" do + assert_select "pre .line.active", /method_that_raises/ end # assert first source view (hidden) that throws the error - assert_select 'div.source:first' do - assert_select 'pre .line.active', /raise StandardError\.new/ + assert_select "div.source:first" do + assert_select "pre .line.active", /raise StandardError\.new/ end # assert application trace refers to line that calls method_that_raises is first - assert_select '#Application-Trace' do - assert_select 'pre code a:first', %r{test/dispatch/debug_exceptions_test\.rb:\d+:in `call} + assert_select "#Application-Trace" do + assert_select "pre code a:first", %r{test/dispatch/debug_exceptions_test\.rb:\d+:in `call} end # assert framework trace that threw the error is first - assert_select '#Framework-Trace' do - assert_select 'pre code a:first', /method_that_raises/ + assert_select "#Framework-Trace" do + assert_select "pre code a:first", /method_that_raises/ end end end diff --git a/actionpack/test/dispatch/exception_wrapper_test.rb b/actionpack/test/dispatch/exception_wrapper_test.rb index 0959cf2805..316661a116 100644 --- a/actionpack/test/dispatch/exception_wrapper_test.rb +++ b/actionpack/test/dispatch/exception_wrapper_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module ActionDispatch class ExceptionWrapperTest < ActionDispatch::IntegrationTest @@ -21,49 +21,49 @@ module ActionDispatch @cleaner.add_silencer { |line| line !~ /^lib/ } end - test '#source_extracts fetches source fragments for every backtrace entry' do + test "#source_extracts fetches source fragments for every backtrace entry" do exception = TestError.new("lib/file.rb:42:in `index'") wrapper = ExceptionWrapper.new(nil, exception) - assert_called_with(wrapper, :source_fragment, ['lib/file.rb', 42], returns: 'foo') do - assert_equal [ code: 'foo', line_number: 42 ], wrapper.source_extracts + assert_called_with(wrapper, :source_fragment, ["lib/file.rb", 42], returns: "foo") do + assert_equal [ code: "foo", line_number: 42 ], wrapper.source_extracts end end - test '#source_extracts works with Windows paths' do + test "#source_extracts works with Windows paths" do exc = TestError.new("c:/path/to/rails/app/controller.rb:27:in 'index':") wrapper = ExceptionWrapper.new(nil, exc) - assert_called_with(wrapper, :source_fragment, ['c:/path/to/rails/app/controller.rb', 27], returns: 'nothing') do - assert_equal [ code: 'nothing', line_number: 27 ], wrapper.source_extracts + assert_called_with(wrapper, :source_fragment, ["c:/path/to/rails/app/controller.rb", 27], returns: "nothing") do + assert_equal [ code: "nothing", line_number: 27 ], wrapper.source_extracts end end - test '#source_extracts works with non standard backtrace' do - exc = TestError.new('invalid') + test "#source_extracts works with non standard backtrace" do + exc = TestError.new("invalid") wrapper = ExceptionWrapper.new(nil, exc) - assert_called_with(wrapper, :source_fragment, ['invalid', 0], returns: 'nothing') do - assert_equal [ code: 'nothing', line_number: 0 ], wrapper.source_extracts + assert_called_with(wrapper, :source_fragment, ["invalid", 0], returns: "nothing") do + assert_equal [ code: "nothing", line_number: 0 ], wrapper.source_extracts end end - test '#application_trace returns traces only from the application' do + test "#application_trace returns traces only from the application" do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal [ "lib/file.rb:42:in `index'" ], wrapper.application_trace end - test '#status_code returns 400 for Rack::Utils::ParameterTypeError' do + test "#status_code returns 400 for Rack::Utils::ParameterTypeError" do exception = Rack::Utils::ParameterTypeError.new wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal 400, wrapper.status_code end - test '#application_trace cannot be nil' do + test "#application_trace cannot be nil" do nil_backtrace_wrapper = ExceptionWrapper.new(@cleaner, BadlyDefinedError.new) nil_cleaner_wrapper = ExceptionWrapper.new(nil, BadlyDefinedError.new) @@ -71,14 +71,14 @@ module ActionDispatch assert_equal [], nil_cleaner_wrapper.application_trace end - test '#framework_trace returns traces outside the application' do + test "#framework_trace returns traces outside the application" do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal caller, wrapper.framework_trace end - test '#framework_trace cannot be nil' do + test "#framework_trace cannot be nil" do nil_backtrace_wrapper = ExceptionWrapper.new(@cleaner, BadlyDefinedError.new) nil_cleaner_wrapper = ExceptionWrapper.new(nil, BadlyDefinedError.new) @@ -86,14 +86,14 @@ module ActionDispatch assert_equal [], nil_cleaner_wrapper.framework_trace end - test '#full_trace returns application and framework traces' do + test "#full_trace returns application and framework traces" do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal exception.backtrace, wrapper.full_trace end - test '#full_trace cannot be nil' do + test "#full_trace cannot be nil" do nil_backtrace_wrapper = ExceptionWrapper.new(@cleaner, BadlyDefinedError.new) nil_cleaner_wrapper = ExceptionWrapper.new(nil, BadlyDefinedError.new) @@ -101,14 +101,14 @@ module ActionDispatch assert_equal [], nil_cleaner_wrapper.full_trace end - test '#traces returns every trace by category enumerated with an index' do + test "#traces returns every trace by category enumerated with an index" do exception = TestError.new("lib/file.rb:42:in `index'", "/gems/rack.rb:43:in `index'") wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal({ - 'Application Trace' => [ id: 0, trace: "lib/file.rb:42:in `index'" ], - 'Framework Trace' => [ id: 1, trace: "/gems/rack.rb:43:in `index'" ], - 'Full Trace' => [ + "Application Trace" => [ id: 0, trace: "lib/file.rb:42:in `index'" ], + "Framework Trace" => [ id: 1, trace: "/gems/rack.rb:43:in `index'" ], + "Full Trace" => [ { id: 0, trace: "lib/file.rb:42:in `index'" }, { id: 1, trace: "/gems/rack.rb:43:in `index'" } ] diff --git a/actionpack/test/dispatch/executor_test.rb b/actionpack/test/dispatch/executor_test.rb index 28bb232ecd..0b4e0849c3 100644 --- a/actionpack/test/dispatch/executor_test.rb +++ b/actionpack/test/dispatch/executor_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class ExecutorTest < ActiveSupport::TestCase class MyBody < Array @@ -119,8 +119,8 @@ class ExecutorTest < ActiveSupport::TestCase private def call_and_return_body(&block) - app = middleware(block || proc { [200, {}, 'response'] }) - _, _, body = app.call({'rack.input' => StringIO.new('')}) + app = middleware(block || proc { [200, {}, "response"] }) + _, _, body = app.call("rack.input" => StringIO.new("")) body end diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index 7f1ef121b7..374e618b42 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -18,14 +18,14 @@ class HeaderTest < ActiveSupport::TestCase "HTTP_REFERER" => "/some/page", "Host" => "http://test.com") - assert_equal({"Content-Type" => "application/json", + assert_equal({ "Content-Type" => "application/json", "HTTP_REFERER" => "/some/page", - "Host" => "http://test.com"}, headers.env) + "Host" => "http://test.com" }, headers.env) end test "#env returns the headers as env variables" do - assert_equal({"CONTENT_TYPE" => "text/plain", - "HTTP_REFERER" => "/some/page"}, @headers.env) + assert_equal({ "CONTENT_TYPE" => "text/plain", + "HTTP_REFERER" => "/some/page" }, @headers.env) end test "#each iterates through the env variables" do @@ -44,20 +44,20 @@ class HeaderTest < ActiveSupport::TestCase test "add to multivalued headers" do # Sets header when not present - @headers.add 'Foo', '1' - assert_equal '1', @headers['Foo'] + @headers.add "Foo", "1" + assert_equal "1", @headers["Foo"] # Ignores nil values - @headers.add 'Foo', nil - assert_equal '1', @headers['Foo'] + @headers.add "Foo", nil + assert_equal "1", @headers["Foo"] # Converts value to string - @headers.add 'Foo', 1 - assert_equal '1,1', @headers['Foo'] + @headers.add "Foo", 1 + assert_equal "1,1", @headers["Foo"] # Case-insensitive - @headers.add 'fOo', 2 - assert_equal '1,1,2', @headers['foO'] + @headers.add "fOo", 2 + assert_equal "1,1,2", @headers["foO"] end test "headers can contain numbers" do @@ -105,28 +105,28 @@ class HeaderTest < ActiveSupport::TestCase test "#merge! headers with mutation" do @headers.merge!("Host" => "http://example.test", "Content-Type" => "text/html") - assert_equal({"HTTP_HOST" => "http://example.test", + assert_equal({ "HTTP_HOST" => "http://example.test", "CONTENT_TYPE" => "text/html", - "HTTP_REFERER" => "/some/page"}, @headers.env) + "HTTP_REFERER" => "/some/page" }, @headers.env) end test "#merge! env with mutation" do @headers.merge!("HTTP_HOST" => "http://first.com", "CONTENT_TYPE" => "text/html") - assert_equal({"HTTP_HOST" => "http://first.com", + assert_equal({ "HTTP_HOST" => "http://first.com", "CONTENT_TYPE" => "text/html", - "HTTP_REFERER" => "/some/page"}, @headers.env) + "HTTP_REFERER" => "/some/page" }, @headers.env) end test "merge without mutation" do combined = @headers.merge("HTTP_HOST" => "http://example.com", "CONTENT_TYPE" => "text/html") - assert_equal({"HTTP_HOST" => "http://example.com", + assert_equal({ "HTTP_HOST" => "http://example.com", "CONTENT_TYPE" => "text/html", - "HTTP_REFERER" => "/some/page"}, combined.env) + "HTTP_REFERER" => "/some/page" }, combined.env) - assert_equal({"CONTENT_TYPE" => "text/plain", - "HTTP_REFERER" => "/some/page"}, @headers.env) + assert_equal({ "CONTENT_TYPE" => "text/plain", + "HTTP_REFERER" => "/some/page" }, @headers.env) end test "env variables with . are not modified" do @@ -151,11 +151,17 @@ class HeaderTest < ActiveSupport::TestCase end test "headers directly modifies the passed environment" do - env = {"HTTP_REFERER" => "/"} + env = { "HTTP_REFERER" => "/" } headers = make_headers(env) - headers['Referer'] = "http://example.com/" + headers["Referer"] = "http://example.com/" headers.merge! "CONTENT_TYPE" => "text/plain" - assert_equal({"HTTP_REFERER"=>"http://example.com/", - "CONTENT_TYPE"=>"text/plain"}, env) + assert_equal({ "HTTP_REFERER"=>"http://example.com/", + "CONTENT_TYPE"=>"text/plain" }, env) + end + + test "fetch exception" do + assert_raises KeyError do + @headers.fetch(:some_key_that_doesnt_exist) + end end end diff --git a/actionpack/test/dispatch/live_response_test.rb b/actionpack/test/dispatch/live_response_test.rb index de57c4be1d..d10fc7d575 100644 --- a/actionpack/test/dispatch/live_response_test.rb +++ b/actionpack/test/dispatch/live_response_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'concurrent/atomic/count_down_latch' +require "abstract_unit" +require "concurrent/atomic/count_down_latch" module ActionController module Live @@ -10,7 +10,7 @@ module ActionController end def test_header_merge - header = @response.header.merge('Foo' => 'Bar') + header = @response.header.merge("Foo" => "Bar") assert_kind_of(ActionController::Live::Response::Header, header) assert_not_equal header, @response.header end @@ -18,7 +18,7 @@ module ActionController def test_initialize_with_default_headers r = Class.new(Live::Response) do def self.default_headers - { 'omg' => 'g' } + { "omg" => "g" } end end @@ -30,38 +30,38 @@ module ActionController latch = Concurrent::CountDownLatch.new t = Thread.new { - @response.stream.write 'foo' + @response.stream.write "foo" latch.wait @response.stream.close } @response.await_commit @response.each do |part| - assert_equal 'foo', part + assert_equal "foo", part latch.count_down end assert t.join end def test_setting_body_populates_buffer - @response.body = 'omg' + @response.body = "omg" @response.close - assert_equal ['omg'], @response.body_parts + assert_equal ["omg"], @response.body_parts end def test_cache_control_is_set - @response.stream.write 'omg' - assert_equal 'no-cache', @response.headers['Cache-Control'] + @response.stream.write "omg" + assert_equal "no-cache", @response.headers["Cache-Control"] end def test_content_length_is_removed - @response.headers['Content-Length'] = "1234" - @response.stream.write 'omg' - assert_nil @response.headers['Content-Length'] + @response.headers["Content-Length"] = "1234" + @response.stream.write "omg" + assert_nil @response.headers["Content-Length"] end def test_headers_cannot_be_written_after_webserver_reads - @response.stream.write 'omg' + @response.stream.write "omg" latch = Concurrent::CountDownLatch.new t = Thread.new { @@ -73,10 +73,10 @@ module ActionController latch.wait assert @response.headers.frozen? e = assert_raises(ActionDispatch::IllegalStateError) do - @response.headers['Content-Length'] = "zomg" + @response.headers["Content-Length"] = "zomg" end - assert_equal 'header already sent', e.message + assert_equal "header already sent", e.message @response.stream.close t.join end @@ -87,9 +87,9 @@ module ActionController @response.each { |x| } e = assert_raises(ActionDispatch::IllegalStateError) do - @response.headers['Content-Length'] = "zomg" + @response.headers["Content-Length"] = "zomg" end - assert_equal 'header already sent', e.message + assert_equal "header already sent", e.message end end end diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index f6dd9272a6..1596d23b1e 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module ActionDispatch module Routing @@ -50,15 +50,15 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset assert_raises(ArgumentError) do - mapper.match '/', :to => 'posts#index', :as => :main + mapper.match "/", to: "posts#index", as: :main end end def test_unscoped_formatted fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/foo', :to => 'posts#index', :as => :main, :format => true - assert_equal({:controller=>"posts", :action=>"index"}, + mapper.get "/foo", to: "posts#index", as: :main, format: true + assert_equal({ controller: "posts", action: "index" }, fakeset.defaults.first) assert_equal "/foo.:format", fakeset.asts.first.to_s end @@ -67,9 +67,9 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(format: true) do - mapper.get '/foo', :to => 'posts#index', :as => :main + mapper.get "/foo", to: "posts#index", as: :main end - assert_equal({:controller=>"posts", :action=>"index"}, + assert_equal({ controller: "posts", action: "index" }, fakeset.defaults.first) assert_equal "/foo.:format", fakeset.asts.first.to_s end @@ -78,18 +78,18 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(omg: :awesome) do - mapper.get '/', :to => 'posts#index', :as => :main + mapper.get "/", to: "posts#index", as: :main end - assert_equal({:omg=>:awesome, :controller=>"posts", :action=>"index"}, + assert_equal({ omg: :awesome, controller: "posts", action: "index" }, fakeset.defaults.first) assert_equal("GET", fakeset.routes.first.verb) end def test_mapping_requirements - options = { } + options = {} scope = Mapper::Scope.new({}) - ast = Journey::Parser.parse '/store/:name(*rest)' - m = Mapper::Mapping.build(scope, FakeSet.new, ast, 'foo', 'bar', nil, [:get], nil, {}, true, options) + ast = Journey::Parser.parse "/store/:name(*rest)" + m = Mapper::Mapping.build(scope, FakeSet.new, ast, "foo", "bar", nil, [:get], nil, {}, true, options) assert_equal(/.+?/, m.requirements[:rest]) end @@ -97,7 +97,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(via: :put) do - mapper.match '/', :to => 'posts#index', :as => :main + mapper.match "/", to: "posts#index", as: :main end assert_equal("PUT", fakeset.routes.first.verb) end @@ -117,8 +117,8 @@ module ActionDispatch def test_map_slash fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/', :to => 'posts#index', :as => :main - assert_equal '/', fakeset.asts.first.to_s + mapper.get "/", to: "posts#index", as: :main + assert_equal "/", fakeset.asts.first.to_s end def test_map_more_slashes @@ -126,31 +126,31 @@ module ActionDispatch mapper = Mapper.new fakeset # FIXME: is this a desired behavior? - mapper.get '/one/two/', :to => 'posts#index', :as => :main - assert_equal '/one/two(.:format)', fakeset.asts.first.to_s + mapper.get "/one/two/", to: "posts#index", as: :main + assert_equal "/one/two(.:format)", fakeset.asts.first.to_s end def test_map_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*path', :to => 'pages#show' - assert_equal '/*path(.:format)', fakeset.asts.first.to_s + mapper.get "/*path", to: "pages#show" + assert_equal "/*path(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end def test_map_wildcard_with_other_element fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*path/foo/:bar', :to => 'pages#show' - assert_equal '/*path/foo/:bar(.:format)', fakeset.asts.first.to_s + mapper.get "/*path/foo/:bar", to: "pages#show" + assert_equal "/*path/foo/:bar(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end def test_map_wildcard_with_multiple_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*foo/*bar', :to => 'pages#show' - assert_equal '/*foo/*bar(.:format)', fakeset.asts.first.to_s + mapper.get "/*foo/*bar", to: "pages#show" + assert_equal "/*foo/*bar(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:foo]) assert_equal(/.+?/, fakeset.requirements.first[:bar]) end @@ -158,16 +158,16 @@ module ActionDispatch def test_map_wildcard_with_format_false fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*path', :to => 'pages#show', :format => false - assert_equal '/*path', fakeset.asts.first.to_s + mapper.get "/*path", to: "pages#show", format: false + assert_equal "/*path", fakeset.asts.first.to_s assert_nil fakeset.requirements.first[:path] end def test_map_wildcard_with_format_true fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*path', :to => 'pages#show', :format => true - assert_equal '/*path.:format', fakeset.asts.first.to_s + mapper.get "/*path", to: "pages#show", format: true + assert_equal "/*path.:format", fakeset.asts.first.to_s end def test_raising_error_when_path_is_not_passed diff --git a/actionpack/test/dispatch/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb index a8c8e0784f..27da5935b5 100644 --- a/actionpack/test/dispatch/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class MiddlewareStackTest < ActiveSupport::TestCase class FooMiddleware; end @@ -59,10 +59,10 @@ class MiddlewareStackTest < ActiveSupport::TestCase test "use should push middleware class with arguments onto the stack" do assert_difference "@stack.size" do - @stack.use BazMiddleware, true, :foo => "bar" + @stack.use BazMiddleware, true, foo: "bar" end assert_equal BazMiddleware, @stack.last.klass - assert_equal([true, {:foo => "bar"}], @stack.last.args) + assert_equal([true, { foo: "bar" }], @stack.last.args) end test "use should push middleware class with block arguments onto the stack" do @@ -102,7 +102,7 @@ class MiddlewareStackTest < ActiveSupport::TestCase test "swaps one middleware out for same middleware class" do assert_equal FooMiddleware, @stack[0].klass - @stack.swap(FooMiddleware, FooMiddleware, Proc.new { |env| [500, {}, ['error!']] }) + @stack.swap(FooMiddleware, FooMiddleware, Proc.new { |env| [500, {}, ["error!"]] }) assert_equal FooMiddleware, @stack[0].klass end diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index e1d19c3520..421ae6e133 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' +require "abstract_unit" class MimeTypeTest < ActiveSupport::TestCase test "parse single" do Mime::LOOKUP.each_key do |mime_type| - unless mime_type == 'image/*' + unless mime_type == "image/*" assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type) end end @@ -15,7 +15,7 @@ class MimeTypeTest < ActiveSupport::TestCase begin mime = Mime::Type.register("text/x-mobile", :mobile) assert_equal mime, Mime[:mobile] - assert_equal mime, Mime::Type.lookup('text/x-mobile') + assert_equal mime, Mime::Type.lookup("text/x-mobile") assert_equal mime, Mime::Type.lookup_by_extension(:mobile) Mime::Type.unregister(:mobile) @@ -56,13 +56,13 @@ class MimeTypeTest < ActiveSupport::TestCase test "parse without q" do accept = "text/xml,application/xhtml+xml,text/yaml,application/xml,text/html,image/png,text/plain,application/pdf,*/*" - expect = [Mime[:html], Mime[:xml], Mime[:yaml], Mime[:png], Mime[:text], Mime[:pdf], '*/*'] + expect = [Mime[:html], Mime[:xml], Mime[:yaml], Mime[:png], Mime[:text], Mime[:pdf], "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end test "parse with q" do accept = "text/xml,application/xhtml+xml,text/yaml; q=0.3,application/xml,text/html; q=0.8,image/png,text/plain; q=0.5,application/pdf,*/*; q=0.2" - expect = [Mime[:html], Mime[:xml], Mime[:png], Mime[:pdf], Mime[:text], Mime[:yaml], '*/*'] + expect = [Mime[:html], Mime[:xml], Mime[:png], Mime[:pdf], Mime[:text], Mime[:yaml], "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end @@ -81,7 +81,7 @@ class MimeTypeTest < ActiveSupport::TestCase # Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP) test "parse broken acceptlines" do accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5" - expect = [Mime[:html], Mime[:xml], "image/*", Mime[:text], '*/*'] + expect = [Mime[:html], Mime[:xml], "image/*", Mime[:text], "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end @@ -89,7 +89,7 @@ class MimeTypeTest < ActiveSupport::TestCase # (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1) test "parse other broken acceptlines" do accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*" - expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', '*/*'] + expect = ["image/gif", "image/x-xbitmap", "image/jpeg","image/pjpeg", "application/x-shockwave-flash", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/msword", "pronto/1.00.00", "sslvpn/1.00.00.00", "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end @@ -141,14 +141,14 @@ class MimeTypeTest < ActiveSupport::TestCase test "register alias" do begin Mime::Type.register_alias "application/xhtml+xml", :foobar - assert_equal Mime[:html], Mime::EXTENSION_LOOKUP['foobar'] + assert_equal Mime[:html], Mime::EXTENSION_LOOKUP["foobar"] ensure Mime::Type.unregister(:foobar) end end test "type should be equal to symbol" do - assert_equal Mime[:html], 'application/xhtml+xml' + assert_equal Mime[:html], "application/xhtml+xml" assert_equal Mime[:html], :html end @@ -192,6 +192,6 @@ class MimeTypeTest < ActiveSupport::TestCase assert Mime[:js] !~ "text/html" assert !(Mime[:js] !~ "text/javascript") assert !(Mime[:js] !~ "application/javascript") - assert Mime[:html] =~ 'application/xhtml+xml' + assert Mime[:html] =~ "application/xhtml+xml" end end diff --git a/actionpack/test/dispatch/mount_test.rb b/actionpack/test/dispatch/mount_test.rb index d027f09762..a7d5ba2345 100644 --- a/actionpack/test/dispatch/mount_test.rb +++ b/actionpack/test/dispatch/mount_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'rails/engine' +require "abstract_unit" +require "rails/engine" class TestRoutingMount < ActionDispatch::IntegrationTest Router = ActionDispatch::Routing::RouteSet.new @@ -15,30 +15,30 @@ class TestRoutingMount < ActionDispatch::IntegrationTest def self.routes; Object.new; end def self.call(env) - [200, {"Content-Type" => "text/html"}, ["OK"]] + [200, { "Content-Type" => "text/html" }, ["OK"]] end end Router.draw do SprocketsApp = lambda { |env| - [200, {"Content-Type" => "text/html"}, ["#{env["SCRIPT_NAME"]} -- #{env["PATH_INFO"]}"]] + [200, { "Content-Type" => "text/html" }, ["#{env["SCRIPT_NAME"]} -- #{env["PATH_INFO"]}"]] } - mount SprocketsApp, :at => "/sprockets" + mount SprocketsApp, at: "/sprockets" mount SprocketsApp => "/shorthand" - mount SinatraLikeApp, :at => "/fakeengine", :as => :fake - mount SinatraLikeApp, :at => "/getfake", :via => :get + mount SinatraLikeApp, at: "/fakeengine", as: :fake + mount SinatraLikeApp, at: "/getfake", via: :get scope "/its_a" do - mount SprocketsApp, :at => "/sprocket" + mount SprocketsApp, at: "/sprocket" end resources :users do - mount AppWithRoutes, :at => "/fakeengine", :as => :fake_mounted_at_resource + mount AppWithRoutes, at: "/fakeengine", as: :fake_mounted_at_resource end - mount SprocketsApp, :at => "/", :via => :get + mount SprocketsApp, at: "/", via: :get end APP = RoutedRackApp.new Router @@ -64,7 +64,7 @@ class TestRoutingMount < ActionDispatch::IntegrationTest end def test_mounting_works_with_nested_script_name - get "/foo/sprockets/omg", headers: { 'SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/sprockets/omg' } + get "/foo/sprockets/omg", headers: { "SCRIPT_NAME" => "/foo", "PATH_INFO" => "/sprockets/omg" } assert_equal "/foo/sprockets -- /omg", response.body end diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb index b8f0ffb64a..bb2fc53add 100644 --- a/actionpack/test/dispatch/prefix_generation_test.rb +++ b/actionpack/test/dispatch/prefix_generation_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'rack/test' -require 'rails/engine' +require "abstract_unit" +require "rack/test" +require "rails/engine" module TestGenerationPrefix class Post @@ -26,42 +26,42 @@ module TestGenerationPrefix class BlogEngine < Rails::Engine routes.draw do - get "/posts/:id", :to => "inside_engine_generating#show", :as => :post - get "/posts", :to => "inside_engine_generating#index", :as => :posts - get "/url_to_application", :to => "inside_engine_generating#url_to_application" - get "/polymorphic_path_for_engine", :to => "inside_engine_generating#polymorphic_path_for_engine" - get "/conflicting_url", :to => "inside_engine_generating#conflicting" - get "/foo", :to => "never#invoked", :as => :named_helper_that_should_be_invoked_only_in_respond_to_test - - get "/relative_path_root", :to => redirect("") - get "/relative_path_redirect", :to => redirect("foo") - get "/relative_option_root", :to => redirect(:path => "") - get "/relative_option_redirect", :to => redirect(:path => "foo") - get "/relative_custom_root", :to => redirect { |params, request| "" } - get "/relative_custom_redirect", :to => redirect { |params, request| "foo" } - - get "/absolute_path_root", :to => redirect("/") - get "/absolute_path_redirect", :to => redirect("/foo") - get "/absolute_option_root", :to => redirect(:path => "/") - get "/absolute_option_redirect", :to => redirect(:path => "/foo") - get "/absolute_custom_root", :to => redirect { |params, request| "/" } - get "/absolute_custom_redirect", :to => redirect { |params, request| "/foo" } + get "/posts/:id", to: "inside_engine_generating#show", as: :post + get "/posts", to: "inside_engine_generating#index", as: :posts + get "/url_to_application", to: "inside_engine_generating#url_to_application" + get "/polymorphic_path_for_engine", to: "inside_engine_generating#polymorphic_path_for_engine" + get "/conflicting_url", to: "inside_engine_generating#conflicting" + get "/foo", to: "never#invoked", as: :named_helper_that_should_be_invoked_only_in_respond_to_test + + get "/relative_path_root", to: redirect("") + get "/relative_path_redirect", to: redirect("foo") + get "/relative_option_root", to: redirect(path: "") + get "/relative_option_redirect", to: redirect(path: "foo") + get "/relative_custom_root", to: redirect { |params, request| "" } + get "/relative_custom_redirect", to: redirect { |params, request| "foo" } + + get "/absolute_path_root", to: redirect("/") + get "/absolute_path_redirect", to: redirect("/foo") + get "/absolute_option_root", to: redirect(path: "/") + get "/absolute_option_redirect", to: redirect(path: "/foo") + get "/absolute_custom_root", to: redirect { |params, request| "/" } + get "/absolute_custom_redirect", to: redirect { |params, request| "/foo" } end end class RailsApplication < Rails::Engine routes.draw do - scope "/:omg", :omg => "awesome" do + scope "/:omg", omg: "awesome" do mount BlogEngine => "/blog", :as => "blog_engine" end - get "/posts/:id", :to => "outside_engine_generating#post", :as => :post - get "/generate", :to => "outside_engine_generating#index" - get "/polymorphic_path_for_app", :to => "outside_engine_generating#polymorphic_path_for_app" - get "/polymorphic_path_for_engine", :to => "outside_engine_generating#polymorphic_path_for_engine" - get "/polymorphic_with_url_for", :to => "outside_engine_generating#polymorphic_with_url_for" - get "/conflicting_url", :to => "outside_engine_generating#conflicting" - get "/ivar_usage", :to => "outside_engine_generating#ivar_usage" - root :to => "outside_engine_generating#index" + get "/posts/:id", to: "outside_engine_generating#post", as: :post + get "/generate", to: "outside_engine_generating#index" + get "/polymorphic_path_for_app", to: "outside_engine_generating#polymorphic_path_for_app" + get "/polymorphic_path_for_engine", to: "outside_engine_generating#polymorphic_path_for_engine" + get "/polymorphic_with_url_for", to: "outside_engine_generating#polymorphic_with_url_for" + get "/conflicting_url", to: "outside_engine_generating#conflicting" + get "/ivar_usage", to: "outside_engine_generating#ivar_usage" + root to: "outside_engine_generating#index" end end @@ -81,9 +81,9 @@ module TestGenerationPrefix end def url_to_application - path = main_app.url_for(:controller => "outside_engine_generating", - :action => "index", - :only_path => true) + path = main_app.url_for(controller: "outside_engine_generating", + action: "index", + only_path: true) render plain: path end @@ -238,7 +238,7 @@ module TestGenerationPrefix end test "[APP] generating engine's route includes default_url_options[:script_name]" do - RailsApplication.routes.default_url_options = {:script_name => "/something"} + RailsApplication.routes.default_url_options = { script_name: "/something" } get "/generate" assert_equal "/something/awesome/blog/posts/1", last_response.body end @@ -269,16 +269,16 @@ module TestGenerationPrefix end test "[OBJECT] generating engine's route includes prefix" do - assert_equal "/awesome/blog/posts/1", engine_object.post_path(:id => 1) + assert_equal "/awesome/blog/posts/1", engine_object.post_path(id: 1) end test "[OBJECT] generating engine's route includes dynamic prefix" do - assert_equal "/pure-awesomeness/blog/posts/3", engine_object.post_path(:id => 3, :omg => "pure-awesomeness") + assert_equal "/pure-awesomeness/blog/posts/3", engine_object.post_path(id: 3, omg: "pure-awesomeness") end test "[OBJECT] generating engine's route includes default_url_options[:script_name]" do - RailsApplication.routes.default_url_options = {:script_name => "/something"} - assert_equal "/something/pure-awesomeness/blog/posts/3", engine_object.post_path(:id => 3, :omg => "pure-awesomeness") + RailsApplication.routes.default_url_options = { script_name: "/something" } + assert_equal "/something/pure-awesomeness/blog/posts/3", engine_object.post_path(id: 3, omg: "pure-awesomeness") end test "[OBJECT] generating application's route" do @@ -286,7 +286,7 @@ module TestGenerationPrefix end test "[OBJECT] generating application's route includes default_url_options[:script_name]" do - RailsApplication.routes.default_url_options = {:script_name => "/something"} + RailsApplication.routes.default_url_options = { script_name: "/something" } assert_equal "/something/", app_object.root_path end @@ -296,11 +296,11 @@ module TestGenerationPrefix end test "[OBJECT] generating engine's route with url_for" do - path = engine_object.url_for(:controller => "inside_engine_generating", - :action => "show", - :only_path => true, - :omg => "omg", - :id => 1) + path = engine_object.url_for(controller: "inside_engine_generating", + action: "show", + only_path: true, + omg: "omg", + id: 1) assert_equal "/omg/blog/posts/1", path end @@ -308,7 +308,7 @@ module TestGenerationPrefix path = engine_object.posts_path assert_equal "/awesome/blog/posts", path - path = engine_object.posts_url(:host => "example.com") + path = engine_object.posts_url(host: "example.com") assert_equal "http://example.com/awesome/blog/posts", path end @@ -316,7 +316,7 @@ module TestGenerationPrefix path = engine_object.polymorphic_path(Post.new) assert_equal "/awesome/blog/posts/1", path - path = engine_object.polymorphic_url(Post.new, :host => "www.example.com") + path = engine_object.polymorphic_url(Post.new, host: "www.example.com") assert_equal "http://www.example.com/awesome/blog/posts/1", path end @@ -340,21 +340,21 @@ module TestGenerationPrefix @routes ||= begin routes = ActionDispatch::Routing::RouteSet.new routes.draw do - get "/posts/:id", :to => "posts#show", :as => :post - - get "/relative_path_root", :to => redirect("") - get "/relative_path_redirect", :to => redirect("foo") - get "/relative_option_root", :to => redirect(:path => "") - get "/relative_option_redirect", :to => redirect(:path => "foo") - get "/relative_custom_root", :to => redirect { |params, request| "" } - get "/relative_custom_redirect", :to => redirect { |params, request| "foo" } - - get "/absolute_path_root", :to => redirect("/") - get "/absolute_path_redirect", :to => redirect("/foo") - get "/absolute_option_root", :to => redirect(:path => "/") - get "/absolute_option_redirect", :to => redirect(:path => "/foo") - get "/absolute_custom_root", :to => redirect { |params, request| "/" } - get "/absolute_custom_redirect", :to => redirect { |params, request| "/foo" } + get "/posts/:id", to: "posts#show", as: :post + + get "/relative_path_root", to: redirect("") + get "/relative_path_redirect", to: redirect("foo") + get "/relative_option_root", to: redirect(path: "") + get "/relative_option_redirect", to: redirect(path: "foo") + get "/relative_custom_root", to: redirect { |params, request| "" } + get "/relative_custom_redirect", to: redirect { |params, request| "foo" } + + get "/absolute_path_root", to: redirect("/") + get "/absolute_path_redirect", to: redirect("/foo") + get "/absolute_option_root", to: redirect(path: "/") + get "/absolute_option_redirect", to: redirect(path: "/foo") + get "/absolute_custom_root", to: redirect { |params, request| "/" } + get "/absolute_custom_redirect", to: redirect { |params, request| "/foo" } end routes @@ -362,7 +362,7 @@ module TestGenerationPrefix end def self.call(env) - env['action_dispatch.routes'] = routes + env["action_dispatch.routes"] = routes routes.call(env) end end diff --git a/actionpack/test/dispatch/rack_cache_test.rb b/actionpack/test/dispatch/rack_cache_test.rb index 79d8a64d29..d7bb90abbf 100644 --- a/actionpack/test/dispatch/rack_cache_test.rb +++ b/actionpack/test/dispatch/rack_cache_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'action_dispatch/http/rack_cache' +require "abstract_unit" +require "action_dispatch/http/rack_cache" class RackCacheMetaStoreTest < ActiveSupport::TestCase class ReadWriteHash < ::Hash @@ -12,7 +12,7 @@ class RackCacheMetaStoreTest < ActiveSupport::TestCase end test "stuff is deep duped" do - @store.write(:foo, { :bar => :original }) + @store.write(:foo, bar: :original) hash = @store.read(:foo) hash[:bar] = :changed hash = @store.read(:foo) diff --git a/actionpack/test/dispatch/reloader_test.rb b/actionpack/test/dispatch/reloader_test.rb index fe8a4a3a17..e74b8e40fd 100644 --- a/actionpack/test/dispatch/reloader_test.rb +++ b/actionpack/test/dispatch/reloader_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class ReloaderTest < ActiveSupport::TestCase Reloader = ActionDispatch::Reloader @@ -166,7 +166,7 @@ class ReloaderTest < ActiveSupport::TestCase i = 10 assert_deprecated do Reloader.to_prepare { i += 1 } - Reloader.to_prepare(:prepend => true) { i = 0 } + Reloader.to_prepare(prepend: true) { i = 0 } end assert_deprecated do @@ -196,8 +196,8 @@ class ReloaderTest < ActiveSupport::TestCase x = Class.new(ActiveSupport::Reloader) x.check = lambda { true } - @response ||= 'response' - @reloader ||= Reloader.new(block || proc {[200, {}, @response]}, x) - @reloader.call({'rack.input' => StringIO.new('')})[2] + @response ||= "response" + @reloader ||= Reloader.new(block || proc { [200, {}, @response] }, x) + @reloader.call("rack.input" => StringIO.new(""))[2] end end diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index 6ab71ebc81..d0cd32a242 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class JsonParamsParsingTest < ActionDispatch::IntegrationTest class TestController < ActionController::Base @@ -18,44 +18,44 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest test "parses json params for application json" do assert_parses( - {"person" => {"name" => "David"}}, - "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/json' } + { "person" => { "name" => "David" } }, + "{\"person\": {\"name\": \"David\"}}", "CONTENT_TYPE" => "application/json" ) end test "parses boolean and number json params for application json" do assert_parses( - {"item" => {"enabled" => false, "count" => 10}}, - "{\"item\": {\"enabled\": false, \"count\": 10}}", { 'CONTENT_TYPE' => 'application/json' } + { "item" => { "enabled" => false, "count" => 10 } }, + "{\"item\": {\"enabled\": false, \"count\": 10}}", "CONTENT_TYPE" => "application/json" ) end test "parses json params for application jsonrequest" do assert_parses( - {"person" => {"name" => "David"}}, - "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/jsonrequest' } + { "person" => { "name" => "David" } }, + "{\"person\": {\"name\": \"David\"}}", "CONTENT_TYPE" => "application/jsonrequest" ) end test "does not parse unregistered media types such as application/vnd.api+json" do assert_parses( {}, - "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/vnd.api+json' } + "{\"person\": {\"name\": \"David\"}}", "CONTENT_TYPE" => "application/vnd.api+json" ) end test "nils are stripped from collections" do assert_parses( - {"person" => []}, - "{\"person\":[null]}", { 'CONTENT_TYPE' => 'application/json' } + { "person" => [] }, + "{\"person\":[null]}", "CONTENT_TYPE" => "application/json" ) assert_parses( - {"person" => ['foo']}, - "{\"person\":[\"foo\",null]}", { 'CONTENT_TYPE' => 'application/json' } + { "person" => ["foo"] }, + "{\"person\":[\"foo\",null]}", "CONTENT_TYPE" => "application/json" ) assert_parses( - {"person" => []}, - "{\"person\":[null, null]}", { 'CONTENT_TYPE' => 'application/json' } + { "person" => [] }, + "{\"person\":[null, null]}", "CONTENT_TYPE" => "application/json" ) end @@ -63,7 +63,7 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest with_test_routing do output = StringIO.new json = "[\"person]\": {\"name\": \"David\"}}" - post "/parse", params: json, headers: { 'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => true, 'action_dispatch.logger' => ActiveSupport::Logger.new(output) } + post "/parse", params: json, headers: { "CONTENT_TYPE" => "application/json", "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => ActiveSupport::Logger.new(output) } assert_response :bad_request output.rewind && err = output.read assert err =~ /Error occurred while parsing request parameters/ @@ -75,7 +75,7 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest begin $stderr = StringIO.new # suppress the log json = "[\"person]\": {\"name\": \"David\"}}" - exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} } + exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", json, "CONTENT_TYPE" => "application/json", "action_dispatch.show_exceptions" => false } assert_equal JSON::ParserError, exception.cause.class assert_equal exception.cause.message, exception.message ensure @@ -84,9 +84,9 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest end end - test 'raw_post is not empty for JSON request' do + test "raw_post is not empty for JSON request" do with_test_routing do - post '/parse', params: '{"posts": [{"title": "Post Title"}]}', headers: { 'CONTENT_TYPE' => 'application/json' } + post "/parse", params: '{"posts": [{"title": "Post Title"}]}', headers: { "CONTENT_TYPE" => "application/json" } assert_equal '{"posts": [{"title": "Post Title"}]}', request.raw_post end end @@ -104,7 +104,7 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - post ':action', :to => ::JsonParamsParsingTest::TestController + post ":action", to: ::JsonParamsParsingTest::TestController end end yield @@ -114,7 +114,7 @@ end class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest class UsersController < ActionController::Base - wrap_parameters :format => :json + wrap_parameters format: :json class << self attr_accessor :last_request_parameters, :last_parameters @@ -133,22 +133,22 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest test "parses json params for application json" do assert_parses( - {"user" => {"username" => "sikachu"}, "username" => "sikachu"}, - "{\"username\": \"sikachu\"}", { 'CONTENT_TYPE' => 'application/json' } + { "user" => { "username" => "sikachu" }, "username" => "sikachu" }, + "{\"username\": \"sikachu\"}", "CONTENT_TYPE" => "application/json" ) end test "parses json params for application jsonrequest" do assert_parses( - {"user" => {"username" => "sikachu"}, "username" => "sikachu"}, - "{\"username\": \"sikachu\"}", { 'CONTENT_TYPE' => 'application/jsonrequest' } + { "user" => { "username" => "sikachu" }, "username" => "sikachu" }, + "{\"username\": \"sikachu\"}", "CONTENT_TYPE" => "application/jsonrequest" ) end test "parses json with non-object JSON content" do assert_parses( - {"user" => {"_json" => "string content" }, "_json" => "string content" }, - "\"string content\"", { 'CONTENT_TYPE' => 'application/json' } + { "user" => { "_json" => "string content" }, "_json" => "string content" }, + "\"string content\"", "CONTENT_TYPE" => "application/json" ) end @@ -157,8 +157,8 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest Mime::Type.unregister :json Mime::Type.register "application/json", :json, %w(application/vnd.rails+json) assert_parses( - {"user" => {"username" => "meinac"}, "username" => "meinac"}, - "{\"username\": \"meinac\"}", { 'CONTENT_TYPE' => 'application/json' } + { "user" => { "username" => "meinac" }, "username" => "meinac" }, + "{\"username\": \"meinac\"}", "CONTENT_TYPE" => "application/json" ) ensure Mime::Type.unregister :json @@ -171,8 +171,8 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest Mime::Type.unregister :json Mime::Type.register "application/json", :json, %w(application/vnd.rails+json) assert_parses( - {"user" => {"username" => "meinac"}, "username" => "meinac"}, - "{\"username\": \"meinac\"}", { 'CONTENT_TYPE' => 'application/vnd.rails+json' } + { "user" => { "username" => "meinac" }, "username" => "meinac" }, + "{\"username\": \"meinac\"}", "CONTENT_TYPE" => "application/vnd.rails+json" ) ensure Mime::Type.unregister :json @@ -186,7 +186,7 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest post "/parse", params: actual, headers: headers assert_response :ok assert_equal(expected, UsersController.last_request_parameters) - assert_equal(expected.merge({"action" => "parse"}), UsersController.last_parameters) + assert_equal(expected.merge("action" => "parse"), UsersController.last_parameters) end end @@ -194,7 +194,7 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - post ':action', :to => controller + post ":action", to: controller end end yield diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index bab4413b2a..e572c722a0 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class MultipartParamsParsingTest < ActionDispatch::IntegrationTest class TestController < ActionController::Base @@ -21,136 +21,136 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest end end - FIXTURE_PATH = File.dirname(__FILE__) + '/../../fixtures/multipart' + FIXTURE_PATH = File.dirname(__FILE__) + "/../../fixtures/multipart" def teardown TestController.last_request_parameters = nil end test "parses single parameter" do - assert_equal({ 'foo' => 'bar' }, parse_multipart('single_parameter')) + assert_equal({ "foo" => "bar" }, parse_multipart("single_parameter")) end test "parses bracketed parameters" do - assert_equal({ 'foo' => { 'baz' => 'bar'}}, parse_multipart('bracketed_param')) + assert_equal({ "foo" => { "baz" => "bar" } }, parse_multipart("bracketed_param")) end test "parse single utf8 parameter" do - assert_equal({ 'Iñtërnâtiônàlizætiøn_name' => 'Iñtërnâtiônàlizætiøn_value'}, - parse_multipart('single_utf8_param'), "request.request_parameters") + assert_equal({ "Iñtërnâtiônàlizætiøn_name" => "Iñtërnâtiônàlizætiøn_value" }, + parse_multipart("single_utf8_param"), "request.request_parameters") assert_equal( - 'Iñtërnâtiônàlizætiøn_value', - TestController.last_parameters['Iñtërnâtiônàlizætiøn_name'], "request.parameters") + "Iñtërnâtiônàlizætiøn_value", + TestController.last_parameters["Iñtërnâtiônàlizætiøn_name"], "request.parameters") end test "parse bracketed utf8 parameter" do - assert_equal({ 'Iñtërnâtiônàlizætiøn_name' => { - 'Iñtërnâtiônàlizætiøn_nested_name' => 'Iñtërnâtiônàlizætiøn_value'} }, - parse_multipart('bracketed_utf8_param'), "request.request_parameters") + assert_equal({ "Iñtërnâtiônàlizætiøn_name" => { + "Iñtërnâtiônàlizætiøn_nested_name" => "Iñtërnâtiônàlizætiøn_value" } }, + parse_multipart("bracketed_utf8_param"), "request.request_parameters") assert_equal( - {'Iñtërnâtiônàlizætiøn_nested_name' => 'Iñtërnâtiônàlizætiøn_value'}, - TestController.last_parameters['Iñtërnâtiônàlizætiøn_name'], "request.parameters") + { "Iñtërnâtiônàlizætiøn_nested_name" => "Iñtërnâtiônàlizætiøn_value" }, + TestController.last_parameters["Iñtërnâtiônàlizætiøn_name"], "request.parameters") end test "parses text file" do - params = parse_multipart('text_file') + params = parse_multipart("text_file") assert_equal %w(file foo), params.keys.sort - assert_equal 'bar', params['foo'] + assert_equal "bar", params["foo"] - file = params['file'] - assert_equal 'file.txt', file.original_filename + file = params["file"] + assert_equal "file.txt", file.original_filename assert_equal "text/plain", file.content_type - assert_equal 'contents', file.read + assert_equal "contents", file.read end test "parses utf8 filename with percent character" do - params = parse_multipart('utf8_filename') + params = parse_multipart("utf8_filename") assert_equal %w(file foo), params.keys.sort - assert_equal 'bar', params['foo'] + assert_equal "bar", params["foo"] - file = params['file'] - assert_equal 'ファイル%名.txt', file.original_filename + file = params["file"] + assert_equal "ファイル%名.txt", file.original_filename assert_equal "text/plain", file.content_type - assert_equal 'contents', file.read + assert_equal "contents", file.read end test "parses boundary problem file" do - params = parse_multipart('boundary_problem_file') + params = parse_multipart("boundary_problem_file") assert_equal %w(file foo), params.keys.sort - file = params['file'] - foo = params['foo'] + file = params["file"] + foo = params["foo"] - assert_equal 'file.txt', file.original_filename + assert_equal "file.txt", file.original_filename assert_equal "text/plain", file.content_type - assert_equal 'bar', foo + assert_equal "bar", foo end test "parses large text file" do - params = parse_multipart('large_text_file') + params = parse_multipart("large_text_file") assert_equal %w(file foo), params.keys.sort - assert_equal 'bar', params['foo'] + assert_equal "bar", params["foo"] - file = params['file'] + file = params["file"] - assert_equal 'file.txt', file.original_filename + assert_equal "file.txt", file.original_filename assert_equal "text/plain", file.content_type - assert_equal(('a' * 20480), file.read) + assert_equal(("a" * 20480), file.read) end test "parses binary file" do - params = parse_multipart('binary_file') + params = parse_multipart("binary_file") assert_equal %w(file flowers foo), params.keys.sort - assert_equal 'bar', params['foo'] + assert_equal "bar", params["foo"] - file = params['file'] - assert_equal 'file.csv', file.original_filename + file = params["file"] + assert_equal "file.csv", file.original_filename assert_nil file.content_type - assert_equal 'contents', file.read + assert_equal "contents", file.read - file = params['flowers'] - assert_equal 'flowers.jpg', file.original_filename + file = params["flowers"] + assert_equal "flowers.jpg", file.original_filename assert_equal "image/jpeg", file.content_type assert_equal 19512, file.size end test "parses mixed files" do - params = parse_multipart('mixed_files') + params = parse_multipart("mixed_files") assert_equal %w(files foo), params.keys.sort - assert_equal 'bar', params['foo'] + assert_equal "bar", params["foo"] # Rack doesn't handle multipart/mixed for us. - files = params['files'] + files = params["files"] assert_equal 19756, files.bytesize end test "does not create tempfile if no file has been selected" do - params = parse_multipart('none') + params = parse_multipart("none") assert_equal %w(submit-name), params.keys.sort - assert_equal 'Larry', params['submit-name'] - assert_equal nil, params['files'] + assert_equal "Larry", params["submit-name"] + assert_equal nil, params["files"] end test "parses empty upload file" do - params = parse_multipart('empty') + params = parse_multipart("empty") assert_equal %w(files submit-name), params.keys.sort - assert_equal 'Larry', params['submit-name'] - assert params['files'] - assert_equal "", params['files'].read + assert_equal "Larry", params["submit-name"] + assert params["files"] + assert_equal "", params["files"].read end test "uploads and reads binary file" do with_test_routing do fixture = FIXTURE_PATH + "/mona_lisa.jpg" - params = { :uploaded_data => fixture_file_upload(fixture, "image/jpg") } - post '/read', params: params + params = { uploaded_data: fixture_file_upload(fixture, "image/jpg") } + post "/read", params: params end end test "uploads and reads file" do with_test_routing do - post '/read', params: { uploaded_data: fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain") } + post "/read", params: { uploaded_data: fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain") } assert_equal "File: Hello", response.body end end @@ -160,7 +160,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ':action', controller: 'multipart_params_parsing_test/test' + get ":action", controller: "multipart_params_parsing_test/test" end end headers = { "CONTENT_TYPE" => "multipart/form-data; boundary=AaB03x" } @@ -171,7 +171,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest private def fixture(name) - File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| + File.open(File.join(FIXTURE_PATH, name), "rb") do |file| { "rack.input" => file.read, "CONTENT_TYPE" => "multipart/form-data; boundary=AaB03x", "CONTENT_LENGTH" => file.stat.size.to_s } @@ -191,7 +191,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - post ':action', :controller => 'multipart_params_parsing_test/test' + post ":action", controller: "multipart_params_parsing_test/test" end end yield diff --git a/actionpack/test/dispatch/request/query_string_parsing_test.rb b/actionpack/test/dispatch/request/query_string_parsing_test.rb index f04022a544..5c992be216 100644 --- a/actionpack/test/dispatch/request/query_string_parsing_test.rb +++ b/actionpack/test/dispatch/request/query_string_parsing_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class QueryStringParsingTest < ActionDispatch::IntegrationTest class TestController < ActionController::Base @@ -29,92 +29,92 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest test "query string" do assert_parses( - {"action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"}, + { "action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1" }, "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1" ) end test "deep query string" do assert_parses( - {'x' => {'y' => {'z' => '10'}}}, + { "x" => { "y" => { "z" => "10" } } }, "x[y][z]=10" ) end test "deep query string with array" do - assert_parses({'x' => {'y' => {'z' => ['10']}}}, 'x[y][z][]=10') - assert_parses({'x' => {'y' => {'z' => ['10', '5']}}}, 'x[y][z][]=10&x[y][z][]=5') + assert_parses({ "x" => { "y" => { "z" => ["10"] } } }, "x[y][z][]=10") + assert_parses({ "x" => { "y" => { "z" => ["10", "5"] } } }, "x[y][z][]=10&x[y][z][]=5") end test "deep query string with array of hash" do - assert_parses({'x' => {'y' => [{'z' => '10'}]}}, 'x[y][][z]=10') - assert_parses({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, 'x[y][][z]=10&x[y][][w]=10') - assert_parses({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, 'x[y][][z]=10&x[y][][v][w]=10') + assert_parses({ "x" => { "y" => [{ "z" => "10" }] } }, "x[y][][z]=10") + assert_parses({ "x" => { "y" => [{ "z" => "10", "w" => "10" }] } }, "x[y][][z]=10&x[y][][w]=10") + assert_parses({ "x" => { "y" => [{ "z" => "10", "v" => { "w" => "10" } }] } }, "x[y][][z]=10&x[y][][v][w]=10") end test "deep query string with array of hashes with one pair" do - assert_parses({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, 'x[y][][z]=10&x[y][][z]=20') + assert_parses({ "x" => { "y" => [{ "z" => "10" }, { "z" => "20" }] } }, "x[y][][z]=10&x[y][][z]=20") end test "deep query string with array of hashes with multiple pairs" do assert_parses( - {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}, - 'x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b' + { "x" => { "y" => [{ "z" => "10", "w" => "a" }, { "z" => "20", "w" => "b" }] } }, + "x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b" ) end test "query string with nil" do assert_parses( - { "action" => "create_customer", "full_name" => ''}, + { "action" => "create_customer", "full_name" => "" }, "action=create_customer&full_name=" ) end test "query string with array" do assert_parses( - { "action" => "create_customer", "selected" => ["1", "2", "3"]}, + { "action" => "create_customer", "selected" => ["1", "2", "3"] }, "action=create_customer&selected[]=1&selected[]=2&selected[]=3" ) end test "query string with amps" do assert_parses( - { "action" => "create_customer", "name" => "Don't & Does"}, + { "action" => "create_customer", "name" => "Don't & Does" }, "action=create_customer&name=Don%27t+%26+Does" ) end test "query string with many equal" do assert_parses( - { "action" => "create_customer", "full_name" => "abc=def=ghi"}, + { "action" => "create_customer", "full_name" => "abc=def=ghi" }, "action=create_customer&full_name=abc=def=ghi" ) end test "query string without equal" do - assert_parses({"action" => nil}, "action") - assert_parses({"action" => {"foo" => nil}}, "action[foo]") - assert_parses({"action" => {"foo" => { "bar" => nil }}}, "action[foo][bar]") - assert_parses({"action" => {"foo" => { "bar" => [] }}}, "action[foo][bar][]") - assert_parses({"action" => {"foo" => [] }}, "action[foo][]") - assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]") + assert_parses({ "action" => nil }, "action") + assert_parses({ "action" => { "foo" => nil } }, "action[foo]") + assert_parses({ "action" => { "foo" => { "bar" => nil } } }, "action[foo][bar]") + assert_parses({ "action" => { "foo" => { "bar" => [] } } }, "action[foo][bar][]") + assert_parses({ "action" => { "foo" => [] } }, "action[foo][]") + assert_parses({ "action"=>{ "foo"=>[{ "bar"=>nil }] } }, "action[foo][][bar]") end def test_array_parses_without_nil - assert_parses({"action" => ['1']}, "action[]=1&action[]") + assert_parses({ "action" => ["1"] }, "action[]=1&action[]") end test "perform_deep_munge" do old_perform_deep_munge = ActionDispatch::Request::Utils.perform_deep_munge ActionDispatch::Request::Utils.perform_deep_munge = false begin - assert_parses({"action" => nil}, "action") - assert_parses({"action" => {"foo" => nil}}, "action[foo]") - assert_parses({"action" => {"foo" => {"bar" => nil}}}, "action[foo][bar]") - assert_parses({"action" => {"foo" => {"bar" => [nil]}}}, "action[foo][bar][]") - assert_parses({"action" => {"foo" => [nil]}}, "action[foo][]") - assert_parses({"action" => {"foo" => [{"bar" => nil}]}}, "action[foo][][bar]") - assert_parses({"action" => ['1',nil]}, "action[]=1&action[]") + assert_parses({ "action" => nil }, "action") + assert_parses({ "action" => { "foo" => nil } }, "action[foo]") + assert_parses({ "action" => { "foo" => { "bar" => nil } } }, "action[foo][bar]") + assert_parses({ "action" => { "foo" => { "bar" => [nil] } } }, "action[foo][bar][]") + assert_parses({ "action" => { "foo" => [nil] } }, "action[foo][]") + assert_parses({ "action" => { "foo" => [{ "bar" => nil }] } }, "action[foo][][bar]") + assert_parses({ "action" => ["1",nil] }, "action[]=1&action[]") ensure ActionDispatch::Request::Utils.perform_deep_munge = old_perform_deep_munge end @@ -129,14 +129,14 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest test "query string with many ampersands" do assert_parses( - { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"}, + { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" }, "&action=create_customer&&&full_name=David%20Heinemeier%20Hansson" ) end test "unbalanced query string with array" do assert_parses( - {'location' => ["1", "2"], 'age_group' => ["2"]}, + { "location" => ["1", "2"], "age_group" => ["2"] }, "location[]=1&location[]=2&age_group[]=2" ) end @@ -145,7 +145,7 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ':action', :to => ::QueryStringParsingTest::TestController + get ":action", to: ::QueryStringParsingTest::TestController end end @@ -159,7 +159,7 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ':action', :to => ::QueryStringParsingTest::TestController + get ":action", to: ::QueryStringParsingTest::TestController end end @app = self.class.build_app(set) do |middleware| diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb index e022e7e21e..311b80ea0a 100644 --- a/actionpack/test/dispatch/request/session_test.rb +++ b/actionpack/test/dispatch/request/session_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'action_dispatch/middleware/session/abstract_store' +require "abstract_unit" +require "action_dispatch/middleware/session/abstract_store" module ActionDispatch class Request @@ -17,18 +17,18 @@ module ActionDispatch def test_to_hash s = Session.create(store, req, {}) - s['foo'] = 'bar' - assert_equal 'bar', s['foo'] - assert_equal({'foo' => 'bar'}, s.to_hash) + s["foo"] = "bar" + assert_equal "bar", s["foo"] + assert_equal({ "foo" => "bar" }, s.to_hash) end def test_create_merges_old s = Session.create(store, req, {}) - s['foo'] = 'bar' + s["foo"] = "bar" s1 = Session.create(store, req, {}) assert_not_equal s, s1 - assert_equal 'bar', s1['foo'] + assert_equal "bar", s1["foo"] end def test_find @@ -40,7 +40,7 @@ module ActionDispatch def test_destroy s = Session.create(store, req, {}) - s['rails'] = 'ftw' + s["rails"] = "ftw" s.destroy @@ -49,22 +49,22 @@ module ActionDispatch def test_keys s = Session.create(store, req, {}) - s['rails'] = 'ftw' - s['adequate'] = 'awesome' + s["rails"] = "ftw" + s["adequate"] = "awesome" assert_equal %w[rails adequate], s.keys end def test_values s = Session.create(store, req, {}) - s['rails'] = 'ftw' - s['adequate'] = 'awesome' + s["rails"] = "ftw" + s["adequate"] = "awesome" assert_equal %w[ftw awesome], s.values end def test_clear s = Session.create(store, req, {}) - s['rails'] = 'ftw' - s['adequate'] = 'awesome' + s["rails"] = "ftw" + s["adequate"] = "awesome" s.clear assert_empty(s.values) @@ -72,19 +72,19 @@ module ActionDispatch def test_update s = Session.create(store, req, {}) - s['rails'] = 'ftw' + s["rails"] = "ftw" - s.update(:rails => 'awesome') + s.update(rails: "awesome") - assert_equal(['rails'], s.keys) - assert_equal('awesome', s['rails']) + assert_equal(["rails"], s.keys) + assert_equal("awesome", s["rails"]) end def test_delete s = Session.create(store, req, {}) - s['rails'] = 'ftw' + s["rails"] = "ftw" - s.delete('rails') + s.delete("rails") assert_empty(s.keys) end @@ -92,13 +92,13 @@ module ActionDispatch def test_fetch session = Session.create(store, req, {}) - session['one'] = '1' - assert_equal '1', session.fetch(:one) + session["one"] = "1" + assert_equal "1", session.fetch(:one) - assert_equal '2', session.fetch(:two, '2') + assert_equal "2", session.fetch(:two, "2") assert_nil session.fetch(:two, nil) - assert_equal 'three', session.fetch(:three) {|el| el.to_s } + assert_equal "three", session.fetch(:three) { |el| el.to_s } assert_raise KeyError do session.fetch(:three) @@ -106,27 +106,27 @@ module ActionDispatch end private - def store - Class.new { - def load_session(env); [1, {}]; end - def session_exists?(env); true; end - def delete_session(env, id, options); 123; end - }.new - end + def store + Class.new { + def load_session(env); [1, {}]; end + def session_exists?(env); true; end + def delete_session(env, id, options); 123; end + }.new + end end class SessionIntegrationTest < ActionDispatch::IntegrationTest class MySessionApp def call(env) request = Rack::Request.new(env) - request.session['hello'] = 'Hello from MySessionApp!' - [ 200, {}, ['Hello from MySessionApp!'] ] + request.session["hello"] = "Hello from MySessionApp!" + [ 200, {}, ["Hello from MySessionApp!"] ] end end Router = ActionDispatch::Routing::RouteSet.new Router.draw do - get '/mysessionapp' => MySessionApp.new + get "/mysessionapp" => MySessionApp.new end def app @@ -134,10 +134,10 @@ module ActionDispatch end def test_session_follows_rack_api_contract_1 - get '/mysessionapp' + get "/mysessionapp" assert_response :ok - assert_equal 'Hello from MySessionApp!', @response.body - assert_equal 'Hello from MySessionApp!', session['hello'] + assert_equal "Hello from MySessionApp!", @response.body + assert_equal "Hello from MySessionApp!", session["hello"] end end end diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index b9f8c52378..5c7558e48d 100644 --- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class UrlEncodedParamsParsingTest < ActionDispatch::IntegrationTest class TestController < ActionController::Base @@ -18,7 +18,7 @@ class UrlEncodedParamsParsingTest < ActionDispatch::IntegrationTest test "parses unbalanced query string with array" do query = "location[]=1&location[]=2&age_group[]=2" - expected = { 'location' => ["1", "2"], 'age_group' => ["2"] } + expected = { "location" => ["1", "2"], "age_group" => ["2"] } assert_parses expected, query end @@ -141,7 +141,7 @@ class UrlEncodedParamsParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - post ':action', to: ::UrlEncodedParamsParsingTest::TestController + post ":action", to: ::UrlEncodedParamsParsingTest::TestController end end yield diff --git a/actionpack/test/dispatch/request_id_test.rb b/actionpack/test/dispatch/request_id_test.rb index 00d8caf8f4..4fcd45acf5 100644 --- a/actionpack/test/dispatch/request_id_test.rb +++ b/actionpack/test/dispatch/request_id_test.rb @@ -1,16 +1,16 @@ -require 'abstract_unit' +require "abstract_unit" class RequestIdTest < ActiveSupport::TestCase test "passing on the request id from the outside" do - assert_equal "external-uu-rid", stub_request('HTTP_X_REQUEST_ID' => 'external-uu-rid').request_id + assert_equal "external-uu-rid", stub_request("HTTP_X_REQUEST_ID" => "external-uu-rid").request_id end test "ensure that only alphanumeric uurids are accepted" do - assert_equal "X-Hacked-HeaderStuff", stub_request('HTTP_X_REQUEST_ID' => '; X-Hacked-Header: Stuff').request_id + assert_equal "X-Hacked-HeaderStuff", stub_request("HTTP_X_REQUEST_ID" => "; X-Hacked-Header: Stuff").request_id end test "ensure that 255 char limit on the request id is being enforced" do - assert_equal "X" * 255, stub_request('HTTP_X_REQUEST_ID' => 'X' * 500).request_id + assert_equal "X" * 255, stub_request("HTTP_X_REQUEST_ID" => "X" * 500).request_id end test "generating a request id when none is supplied" do @@ -18,15 +18,15 @@ class RequestIdTest < ActiveSupport::TestCase end test "uuid alias" do - assert_equal "external-uu-rid", stub_request('HTTP_X_REQUEST_ID' => 'external-uu-rid').uuid + assert_equal "external-uu-rid", stub_request("HTTP_X_REQUEST_ID" => "external-uu-rid").uuid end private - def stub_request(env = {}) - ActionDispatch::RequestId.new(lambda { |environment| [ 200, environment, [] ] }).call(env) - ActionDispatch::Request.new(env) - end + def stub_request(env = {}) + ActionDispatch::RequestId.new(lambda { |environment| [ 200, environment, [] ] }).call(env) + ActionDispatch::Request.new(env) + end end class RequestIdResponseTest < ActionDispatch::IntegrationTest @@ -38,32 +38,31 @@ class RequestIdResponseTest < ActionDispatch::IntegrationTest test "request id is passed all the way to the response" do with_test_route_set do - get '/' + get "/" assert_match(/\w+/, @response.headers["X-Request-Id"]) end end test "request id given on request is passed all the way to the response" do with_test_route_set do - get '/', headers: { 'HTTP_X_REQUEST_ID' => 'X' * 500 } + get "/", headers: { "HTTP_X_REQUEST_ID" => "X" * 500 } assert_equal "X" * 255, @response.headers["X-Request-Id"] end end - private - def with_test_route_set - with_routing do |set| - set.draw do - get '/', :to => ::RequestIdResponseTest::TestController.action(:index) - end + def with_test_route_set + with_routing do |set| + set.draw do + get "/", to: ::RequestIdResponseTest::TestController.action(:index) + end - @app = self.class.build_app(set) do |middleware| - middleware.use ActionDispatch::RequestId - end + @app = self.class.build_app(set) do |middleware| + middleware.use ActionDispatch::RequestId + end - yield + yield + end end - end end diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 634f6d80c4..13a87b8976 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class BaseRequestTest < ActiveSupport::TestCase def setup @@ -14,7 +14,7 @@ class BaseRequestTest < ActiveSupport::TestCase end def url_for(options = {}) - options = { host: 'www.example.com' }.merge!(options) + options = { host: "www.example.com" }.merge!(options) ActionDispatch::Http::URL.url_for(options) end @@ -22,7 +22,7 @@ class BaseRequestTest < ActiveSupport::TestCase def stub_request(env = {}) ip_spoofing_check = env.key?(:ip_spoofing_check) ? env.delete(:ip_spoofing_check) : true @trusted_proxies ||= nil - ip_app = ActionDispatch::RemoteIp.new(Proc.new { }, ip_spoofing_check, @trusted_proxies) + ip_app = ActionDispatch::RemoteIp.new(Proc.new {}, ip_spoofing_check, @trusted_proxies) ActionDispatch::Http::URL.tld_length = env.delete(:tld_length) if env.key?(:tld_length) ip_app.call(env) @@ -34,78 +34,78 @@ end class RequestUrlFor < BaseRequestTest test "url_for class method" do - e = assert_raise(ArgumentError) { url_for(:host => nil) } + e = assert_raise(ArgumentError) { url_for(host: nil) } assert_match(/Please provide the :host parameter/, e.message) - assert_equal '/books', url_for(:only_path => true, :path => '/books') - - assert_equal 'http://www.example.com/books/?q=code', url_for(trailing_slash: true, path: '/books?q=code') - assert_equal 'http://www.example.com/books/?spareslashes=////', url_for(trailing_slash: true, path: '/books?spareslashes=////') - - assert_equal 'http://www.example.com', url_for - assert_equal 'http://api.example.com', url_for(:subdomain => 'api') - assert_equal 'http://example.com', url_for(:subdomain => false) - assert_equal 'http://www.ror.com', url_for(:domain => 'ror.com') - assert_equal 'http://api.ror.co.uk', url_for(:host => 'www.ror.co.uk', :subdomain => 'api', :tld_length => 2) - assert_equal 'http://www.example.com:8080', url_for(:port => 8080) - assert_equal 'https://www.example.com', url_for(:protocol => 'https') - assert_equal 'http://www.example.com/docs', url_for(:path => '/docs') - assert_equal 'http://www.example.com#signup', url_for(:anchor => 'signup') - assert_equal 'http://www.example.com/', url_for(:trailing_slash => true) - assert_equal 'http://dhh:supersecret@www.example.com', url_for(:user => 'dhh', :password => 'supersecret') - assert_equal 'http://www.example.com?search=books', url_for(:params => { :search => 'books' }) - assert_equal 'http://www.example.com?params=', url_for(:params => '') - assert_equal 'http://www.example.com?params=1', url_for(:params => 1) + assert_equal "/books", url_for(only_path: true, path: "/books") + + assert_equal "http://www.example.com/books/?q=code", url_for(trailing_slash: true, path: "/books?q=code") + assert_equal "http://www.example.com/books/?spareslashes=////", url_for(trailing_slash: true, path: "/books?spareslashes=////") + + assert_equal "http://www.example.com", url_for + assert_equal "http://api.example.com", url_for(subdomain: "api") + assert_equal "http://example.com", url_for(subdomain: false) + assert_equal "http://www.ror.com", url_for(domain: "ror.com") + assert_equal "http://api.ror.co.uk", url_for(host: "www.ror.co.uk", subdomain: "api", tld_length: 2) + assert_equal "http://www.example.com:8080", url_for(port: 8080) + assert_equal "https://www.example.com", url_for(protocol: "https") + assert_equal "http://www.example.com/docs", url_for(path: "/docs") + assert_equal "http://www.example.com#signup", url_for(anchor: "signup") + assert_equal "http://www.example.com/", url_for(trailing_slash: true) + assert_equal "http://dhh:supersecret@www.example.com", url_for(user: "dhh", password: "supersecret") + assert_equal "http://www.example.com?search=books", url_for(params: { search: "books" }) + assert_equal "http://www.example.com?params=", url_for(params: "") + assert_equal "http://www.example.com?params=1", url_for(params: 1) end end class RequestIP < BaseRequestTest test "remote ip" do - request = stub_request 'REMOTE_ADDR' => '1.2.3.4' - assert_equal '1.2.3.4', request.remote_ip + request = stub_request "REMOTE_ADDR" => "1.2.3.4" + assert_equal "1.2.3.4", request.remote_ip - request = stub_request 'REMOTE_ADDR' => '1.2.3.4,3.4.5.6' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "REMOTE_ADDR" => "1.2.3.4,3.4.5.6" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'REMOTE_ADDR' => '1.2.3.4', - 'HTTP_X_FORWARDED_FOR' => '3.4.5.6' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "REMOTE_ADDR" => "1.2.3.4", + "HTTP_X_FORWARDED_FOR" => "3.4.5.6" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'REMOTE_ADDR' => '127.0.0.1', - 'HTTP_X_FORWARDED_FOR' => '3.4.5.6' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "REMOTE_ADDR" => "127.0.0.1", + "HTTP_X_FORWARDED_FOR" => "3.4.5.6" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '3.4.5.6,unknown' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "3.4.5.6,unknown" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '3.4.5.6,172.16.0.1' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "3.4.5.6,172.16.0.1" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '3.4.5.6,192.168.0.1' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "3.4.5.6,192.168.0.1" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '3.4.5.6,10.0.0.1' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "3.4.5.6,10.0.0.1" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '3.4.5.6, 10.0.0.1, 10.0.0.1' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "3.4.5.6, 10.0.0.1, 10.0.0.1" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '3.4.5.6,127.0.0.1' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "3.4.5.6,127.0.0.1" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,192.168.0.1' + request = stub_request "HTTP_X_FORWARDED_FOR" => "unknown,192.168.0.1" assert_equal nil, request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '9.9.9.9, 3.4.5.6, 172.31.4.4, 10.0.0.1' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "9.9.9.9, 3.4.5.6, 172.31.4.4, 10.0.0.1" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'not_ip_address' + request = stub_request "HTTP_X_FORWARDED_FOR" => "not_ip_address" assert_equal nil, request.remote_ip end test "remote ip spoof detection" do - request = stub_request 'HTTP_X_FORWARDED_FOR' => '1.1.1.1', - 'HTTP_CLIENT_IP' => '2.2.2.2' + request = stub_request "HTTP_X_FORWARDED_FOR" => "1.1.1.1", + "HTTP_CLIENT_IP" => "2.2.2.2" e = assert_raise(ActionDispatch::RemoteIp::IpSpoofAttackError) { request.remote_ip } @@ -115,60 +115,60 @@ class RequestIP < BaseRequestTest end test "remote ip with spoof detection disabled" do - request = stub_request 'HTTP_X_FORWARDED_FOR' => '1.1.1.1', - 'HTTP_CLIENT_IP' => '2.2.2.2', + request = stub_request "HTTP_X_FORWARDED_FOR" => "1.1.1.1", + "HTTP_CLIENT_IP" => "2.2.2.2", :ip_spoofing_check => false - assert_equal '1.1.1.1', request.remote_ip + assert_equal "1.1.1.1", request.remote_ip end test "remote ip spoof protection ignores private addresses" do - request = stub_request 'HTTP_X_FORWARDED_FOR' => '172.17.19.51', - 'HTTP_CLIENT_IP' => '172.17.19.51', - 'REMOTE_ADDR' => '1.1.1.1', - 'HTTP_X_BLUECOAT_VIA' => 'de462e07a2db325e' - assert_equal '1.1.1.1', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "172.17.19.51", + "HTTP_CLIENT_IP" => "172.17.19.51", + "REMOTE_ADDR" => "1.1.1.1", + "HTTP_X_BLUECOAT_VIA" => "de462e07a2db325e" + assert_equal "1.1.1.1", request.remote_ip end test "remote ip v6" do - request = stub_request 'REMOTE_ADDR' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334' - assert_equal '2001:0db8:85a3:0000:0000:8a2e:0370:7334', request.remote_ip + request = stub_request "REMOTE_ADDR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334" + assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip - request = stub_request 'REMOTE_ADDR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329,2001:0db8:85a3:0000:0000:8a2e:0370:7334' - assert_equal '2001:0db8:85a3:0000:0000:8a2e:0370:7334', request.remote_ip + request = stub_request "REMOTE_ADDR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,2001:0db8:85a3:0000:0000:8a2e:0370:7334" + assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip - request = stub_request 'REMOTE_ADDR' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334', - 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329' - assert_equal 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', request.remote_ip + request = stub_request "REMOTE_ADDR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329" + assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip - request = stub_request 'REMOTE_ADDR' => '::1', - 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329' - assert_equal 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', request.remote_ip + request = stub_request "REMOTE_ADDR" => "::1", + "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329" + assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329,unknown' - assert_equal 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,unknown" + assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329,::1' - assert_equal 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,::1" + assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329, ::1, ::1' - assert_equal 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329, ::1, ::1" + assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,::1' + request = stub_request "HTTP_X_FORWARDED_FOR" => "unknown,::1" assert_equal nil, request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334, fe80:0000:0000:0000:0202:b3ff:fe1e:8329, ::1, fc00::, fc01::, fdff' - assert_equal 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334, fe80:0000:0000:0000:0202:b3ff:fe1e:8329, ::1, fc00::, fc01::, fdff" + assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'FE00::, FDFF::' - assert_equal 'FE00::', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "FE00::, FDFF::" + assert_equal "FE00::", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'not_ip_address' + request = stub_request "HTTP_X_FORWARDED_FOR" => "not_ip_address" assert_equal nil, request.remote_ip end test "remote ip v6 spoof detection" do - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', - 'HTTP_CLIENT_IP' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334' + request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", + "HTTP_CLIENT_IP" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334" e = assert_raise(ActionDispatch::RemoteIp::IpSpoofAttackError) { request.remote_ip } @@ -178,139 +178,139 @@ class RequestIP < BaseRequestTest end test "remote ip v6 spoof detection disabled" do - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', - 'HTTP_CLIENT_IP' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334', + request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", + "HTTP_CLIENT_IP" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334", :ip_spoofing_check => false - assert_equal 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329', request.remote_ip + assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip end test "remote ip with user specified trusted proxies String" do @trusted_proxies = "67.205.106.73" - request = stub_request 'REMOTE_ADDR' => '3.4.5.6', - 'HTTP_X_FORWARDED_FOR' => '67.205.106.73' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "REMOTE_ADDR" => "3.4.5.6", + "HTTP_X_FORWARDED_FOR" => "67.205.106.73" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'REMOTE_ADDR' => '172.16.0.1,67.205.106.73', - 'HTTP_X_FORWARDED_FOR' => '67.205.106.73' - assert_equal '67.205.106.73', request.remote_ip + request = stub_request "REMOTE_ADDR" => "172.16.0.1,67.205.106.73", + "HTTP_X_FORWARDED_FOR" => "67.205.106.73" + assert_equal "67.205.106.73", request.remote_ip - request = stub_request 'REMOTE_ADDR' => '67.205.106.73,3.4.5.6', - 'HTTP_X_FORWARDED_FOR' => '67.205.106.73' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "REMOTE_ADDR" => "67.205.106.73,3.4.5.6", + "HTTP_X_FORWARDED_FOR" => "67.205.106.73" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '67.205.106.73,unknown' + request = stub_request "HTTP_X_FORWARDED_FOR" => "67.205.106.73,unknown" assert_equal nil, request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '9.9.9.9, 3.4.5.6, 10.0.0.1, 67.205.106.73' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "9.9.9.9, 3.4.5.6, 10.0.0.1, 67.205.106.73" + assert_equal "3.4.5.6", request.remote_ip end test "remote ip v6 with user specified trusted proxies String" do - @trusted_proxies = 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329' + @trusted_proxies = "fe80:0000:0000:0000:0202:b3ff:fe1e:8329" - request = stub_request 'REMOTE_ADDR' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334', - 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329' - assert_equal '2001:0db8:85a3:0000:0000:8a2e:0370:7334', request.remote_ip + request = stub_request "REMOTE_ADDR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329" + assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip - request = stub_request 'REMOTE_ADDR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329,2001:0db8:85a3:0000:0000:8a2e:0370:7334', - 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329' - assert_equal '2001:0db8:85a3:0000:0000:8a2e:0370:7334', request.remote_ip + request = stub_request "REMOTE_ADDR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329" + assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip - request = stub_request 'REMOTE_ADDR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329,::1', - 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329' - assert_equal '::1', request.remote_ip + request = stub_request "REMOTE_ADDR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,::1", + "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329" + assert_equal "::1", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,fe80:0000:0000:0000:0202:b3ff:fe1e:8329' + request = stub_request "HTTP_X_FORWARDED_FOR" => "unknown,fe80:0000:0000:0000:0202:b3ff:fe1e:8329" assert_equal nil, request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329,2001:0db8:85a3:0000:0000:8a2e:0370:7334' + request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,2001:0db8:85a3:0000:0000:8a2e:0370:7334" assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip end test "remote ip with user specified trusted proxies Regexp" do @trusted_proxies = /^67\.205\.106\.73$/i - request = stub_request 'REMOTE_ADDR' => '67.205.106.73', - 'HTTP_X_FORWARDED_FOR' => '3.4.5.6' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "REMOTE_ADDR" => "67.205.106.73", + "HTTP_X_FORWARDED_FOR" => "3.4.5.6" + assert_equal "3.4.5.6", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '10.0.0.1, 9.9.9.9, 3.4.5.6, 67.205.106.73' - assert_equal '3.4.5.6', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "10.0.0.1, 9.9.9.9, 3.4.5.6, 67.205.106.73" + assert_equal "3.4.5.6", request.remote_ip end test "remote ip v6 with user specified trusted proxies Regexp" do @trusted_proxies = /^fe80:0000:0000:0000:0202:b3ff:fe1e:8329$/i - request = stub_request 'REMOTE_ADDR' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334', - 'HTTP_X_FORWARDED_FOR' => 'fe80:0000:0000:0000:0202:b3ff:fe1e:8329' - assert_equal '2001:0db8:85a3:0000:0000:8a2e:0370:7334', request.remote_ip + request = stub_request "REMOTE_ADDR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329" + assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip - request = stub_request 'HTTP_X_FORWARDED_FOR' => '2001:0db8:85a3:0000:0000:8a2e:0370:7334, fe80:0000:0000:0000:0202:b3ff:fe1e:8329' - assert_equal '2001:0db8:85a3:0000:0000:8a2e:0370:7334', request.remote_ip + request = stub_request "HTTP_X_FORWARDED_FOR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334, fe80:0000:0000:0000:0202:b3ff:fe1e:8329" + assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip end test "remote ip middleware not present still returns an IP" do - request = stub_request('REMOTE_ADDR' => '127.0.0.1') - assert_equal '127.0.0.1', request.remote_ip + request = stub_request("REMOTE_ADDR" => "127.0.0.1") + assert_equal "127.0.0.1", request.remote_ip end end class RequestDomain < BaseRequestTest test "domains" do - request = stub_request 'HTTP_HOST' => "192.168.1.200" + request = stub_request "HTTP_HOST" => "192.168.1.200" assert_nil request.domain - request = stub_request 'HTTP_HOST' => "foo.192.168.1.200" + request = stub_request "HTTP_HOST" => "foo.192.168.1.200" assert_nil request.domain - request = stub_request 'HTTP_HOST' => "192.168.1.200.com" + request = stub_request "HTTP_HOST" => "192.168.1.200.com" assert_equal "200.com", request.domain - request = stub_request 'HTTP_HOST' => 'www.rubyonrails.org' + request = stub_request "HTTP_HOST" => "www.rubyonrails.org" assert_equal "rubyonrails.org", request.domain - request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk" + request = stub_request "HTTP_HOST" => "www.rubyonrails.co.uk" assert_equal "rubyonrails.co.uk", request.domain(2) - request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk", :tld_length => 2 + request = stub_request "HTTP_HOST" => "www.rubyonrails.co.uk", :tld_length => 2 assert_equal "rubyonrails.co.uk", request.domain end test "subdomains" do - request = stub_request 'HTTP_HOST' => "foobar.foobar.com" + request = stub_request "HTTP_HOST" => "foobar.foobar.com" assert_equal %w( foobar ), request.subdomains assert_equal "foobar", request.subdomain - request = stub_request 'HTTP_HOST' => "192.168.1.200" + request = stub_request "HTTP_HOST" => "192.168.1.200" assert_equal [], request.subdomains assert_equal "", request.subdomain - request = stub_request 'HTTP_HOST' => "foo.192.168.1.200" + request = stub_request "HTTP_HOST" => "foo.192.168.1.200" assert_equal [], request.subdomains assert_equal "", request.subdomain - request = stub_request 'HTTP_HOST' => "192.168.1.200.com" + request = stub_request "HTTP_HOST" => "192.168.1.200.com" assert_equal %w( 192 168 1 ), request.subdomains assert_equal "192.168.1", request.subdomain - request = stub_request 'HTTP_HOST' => nil + request = stub_request "HTTP_HOST" => nil assert_equal [], request.subdomains assert_equal "", request.subdomain - request = stub_request 'HTTP_HOST' => "www.rubyonrails.org" + request = stub_request "HTTP_HOST" => "www.rubyonrails.org" assert_equal %w( www ), request.subdomains assert_equal "www", request.subdomain - request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk" + request = stub_request "HTTP_HOST" => "www.rubyonrails.co.uk" assert_equal %w( www ), request.subdomains(2) assert_equal "www", request.subdomain(2) - request = stub_request 'HTTP_HOST' => "dev.www.rubyonrails.co.uk" + request = stub_request "HTTP_HOST" => "dev.www.rubyonrails.co.uk" assert_equal %w( dev www ), request.subdomains(2) assert_equal "dev.www", request.subdomain(2) - request = stub_request 'HTTP_HOST' => "dev.www.rubyonrails.co.uk", :tld_length => 2 + request = stub_request "HTTP_HOST" => "dev.www.rubyonrails.co.uk", :tld_length => 2 assert_equal %w( dev www ), request.subdomains assert_equal "dev.www", request.subdomain end @@ -321,7 +321,7 @@ class RequestPort < BaseRequestTest request = stub_request assert_equal 80, request.standard_port - request = stub_request 'HTTPS' => 'on' + request = stub_request "HTTPS" => "on" assert_equal 443, request.standard_port end @@ -330,97 +330,97 @@ class RequestPort < BaseRequestTest assert !request.ssl? assert request.standard_port? - request = stub_request 'HTTPS' => 'on' + request = stub_request "HTTPS" => "on" assert request.ssl? assert request.standard_port? - request = stub_request 'HTTP_HOST' => 'www.example.org:8080' + request = stub_request "HTTP_HOST" => "www.example.org:8080" assert !request.ssl? assert !request.standard_port? - request = stub_request 'HTTP_HOST' => 'www.example.org:8443', 'HTTPS' => 'on' + request = stub_request "HTTP_HOST" => "www.example.org:8443", "HTTPS" => "on" assert request.ssl? assert !request.standard_port? end test "optional port" do - request = stub_request 'HTTP_HOST' => 'www.example.org:80' + request = stub_request "HTTP_HOST" => "www.example.org:80" assert_equal nil, request.optional_port - request = stub_request 'HTTP_HOST' => 'www.example.org:8080' + request = stub_request "HTTP_HOST" => "www.example.org:8080" assert_equal 8080, request.optional_port end test "port string" do - request = stub_request 'HTTP_HOST' => 'www.example.org:80' - assert_equal '', request.port_string + request = stub_request "HTTP_HOST" => "www.example.org:80" + assert_equal "", request.port_string - request = stub_request 'HTTP_HOST' => 'www.example.org:8080' - assert_equal ':8080', request.port_string + request = stub_request "HTTP_HOST" => "www.example.org:8080" + assert_equal ":8080", request.port_string end test "server port" do - request = stub_request 'SERVER_PORT' => '8080' + request = stub_request "SERVER_PORT" => "8080" assert_equal 8080, request.server_port - request = stub_request 'SERVER_PORT' => '80' + request = stub_request "SERVER_PORT" => "80" assert_equal 80, request.server_port - request = stub_request 'SERVER_PORT' => '' + request = stub_request "SERVER_PORT" => "" assert_equal 0, request.server_port end end class RequestPath < BaseRequestTest test "full path" do - request = stub_request 'SCRIPT_NAME' => '', 'PATH_INFO' => '/path/of/some/uri', 'QUERY_STRING' => 'mapped=1' + request = stub_request "SCRIPT_NAME" => "", "PATH_INFO" => "/path/of/some/uri", "QUERY_STRING" => "mapped=1" assert_equal "/path/of/some/uri?mapped=1", request.fullpath assert_equal "/path/of/some/uri", request.path_info - request = stub_request 'SCRIPT_NAME' => '', 'PATH_INFO' => '/path/of/some/uri' + request = stub_request "SCRIPT_NAME" => "", "PATH_INFO" => "/path/of/some/uri" assert_equal "/path/of/some/uri", request.fullpath assert_equal "/path/of/some/uri", request.path_info - request = stub_request 'SCRIPT_NAME' => '', 'PATH_INFO' => '/' + request = stub_request "SCRIPT_NAME" => "", "PATH_INFO" => "/" assert_equal "/", request.fullpath assert_equal "/", request.path_info - request = stub_request 'SCRIPT_NAME' => '', 'PATH_INFO' => '/', 'QUERY_STRING' => 'm=b' + request = stub_request "SCRIPT_NAME" => "", "PATH_INFO" => "/", "QUERY_STRING" => "m=b" assert_equal "/?m=b", request.fullpath assert_equal "/", request.path_info - request = stub_request 'SCRIPT_NAME' => '/hieraki', 'PATH_INFO' => '/' + request = stub_request "SCRIPT_NAME" => "/hieraki", "PATH_INFO" => "/" assert_equal "/hieraki/", request.fullpath assert_equal "/", request.path_info - request = stub_request 'SCRIPT_NAME' => '/collaboration/hieraki', 'PATH_INFO' => '/books/edit/2' + request = stub_request "SCRIPT_NAME" => "/collaboration/hieraki", "PATH_INFO" => "/books/edit/2" assert_equal "/collaboration/hieraki/books/edit/2", request.fullpath assert_equal "/books/edit/2", request.path_info - request = stub_request 'SCRIPT_NAME' => '/path', 'PATH_INFO' => '/of/some/uri', 'QUERY_STRING' => 'mapped=1' + request = stub_request "SCRIPT_NAME" => "/path", "PATH_INFO" => "/of/some/uri", "QUERY_STRING" => "mapped=1" assert_equal "/path/of/some/uri?mapped=1", request.fullpath assert_equal "/of/some/uri", request.path_info end test "original_fullpath returns ORIGINAL_FULLPATH" do - request = stub_request('ORIGINAL_FULLPATH' => "/foo?bar") + request = stub_request("ORIGINAL_FULLPATH" => "/foo?bar") path = request.original_fullpath assert_equal "/foo?bar", path end test "original_url returns url built using ORIGINAL_FULLPATH" do - request = stub_request('ORIGINAL_FULLPATH' => "/foo?bar", - 'HTTP_HOST' => "example.org", - 'rack.url_scheme' => "http") + request = stub_request("ORIGINAL_FULLPATH" => "/foo?bar", + "HTTP_HOST" => "example.org", + "rack.url_scheme" => "http") url = request.original_url assert_equal "http://example.org/foo?bar", url end test "original_fullpath returns fullpath if ORIGINAL_FULLPATH is not present" do - request = stub_request('PATH_INFO' => "/foo", - 'QUERY_STRING' => "bar") + request = stub_request("PATH_INFO" => "/foo", + "QUERY_STRING" => "bar") path = request.original_fullpath assert_equal "/foo?bar", path @@ -429,77 +429,77 @@ end class RequestHost < BaseRequestTest test "host without specifying port" do - request = stub_request 'HTTP_HOST' => 'rubyonrails.org' + request = stub_request "HTTP_HOST" => "rubyonrails.org" assert_equal "rubyonrails.org", request.host_with_port end test "host with default port" do - request = stub_request 'HTTP_HOST' => 'rubyonrails.org:80' + request = stub_request "HTTP_HOST" => "rubyonrails.org:80" assert_equal "rubyonrails.org", request.host_with_port end test "host with non default port" do - request = stub_request 'HTTP_HOST' => 'rubyonrails.org:81' + request = stub_request "HTTP_HOST" => "rubyonrails.org:81" assert_equal "rubyonrails.org:81", request.host_with_port end test "raw without specifying port" do - request = stub_request 'HTTP_HOST' => 'rubyonrails.org' + request = stub_request "HTTP_HOST" => "rubyonrails.org" assert_equal "rubyonrails.org", request.raw_host_with_port end test "raw host with default port" do - request = stub_request 'HTTP_HOST' => 'rubyonrails.org:80' + request = stub_request "HTTP_HOST" => "rubyonrails.org:80" assert_equal "rubyonrails.org:80", request.raw_host_with_port end test "raw host with non default port" do - request = stub_request 'HTTP_HOST' => 'rubyonrails.org:81' + request = stub_request "HTTP_HOST" => "rubyonrails.org:81" assert_equal "rubyonrails.org:81", request.raw_host_with_port end test "proxy request" do - request = stub_request 'HTTP_HOST' => 'glu.ttono.us:80' + request = stub_request "HTTP_HOST" => "glu.ttono.us:80" assert_equal "glu.ttono.us", request.host_with_port end test "http host" do - request = stub_request 'HTTP_HOST' => "rubyonrails.org:8080" + request = stub_request "HTTP_HOST" => "rubyonrails.org:8080" assert_equal "rubyonrails.org", request.host assert_equal "rubyonrails.org:8080", request.host_with_port - request = stub_request 'HTTP_X_FORWARDED_HOST' => "www.firsthost.org, www.secondhost.org" + request = stub_request "HTTP_X_FORWARDED_HOST" => "www.firsthost.org, www.secondhost.org" assert_equal "www.secondhost.org", request.host - request = stub_request 'HTTP_X_FORWARDED_HOST' => "", 'HTTP_HOST' => "rubyonrails.org" + request = stub_request "HTTP_X_FORWARDED_HOST" => "", "HTTP_HOST" => "rubyonrails.org" assert_equal "rubyonrails.org", request.host end test "http host with default port overrides server port" do - request = stub_request 'HTTP_HOST' => "rubyonrails.org" + request = stub_request "HTTP_HOST" => "rubyonrails.org" assert_equal "rubyonrails.org", request.host_with_port end test "host with port if http standard port is specified" do - request = stub_request 'HTTP_X_FORWARDED_HOST' => "glu.ttono.us:80" + request = stub_request "HTTP_X_FORWARDED_HOST" => "glu.ttono.us:80" assert_equal "glu.ttono.us", request.host_with_port end test "host with port if https standard port is specified" do request = stub_request( - 'HTTP_X_FORWARDED_PROTO' => "https", - 'HTTP_X_FORWARDED_HOST' => "glu.ttono.us:443" + "HTTP_X_FORWARDED_PROTO" => "https", + "HTTP_X_FORWARDED_HOST" => "glu.ttono.us:443" ) assert_equal "glu.ttono.us", request.host_with_port end test "host if ipv6 reference" do - request = stub_request 'HTTP_HOST' => "[2001:1234:5678:9abc:def0::dead:beef]" + request = stub_request "HTTP_HOST" => "[2001:1234:5678:9abc:def0::dead:beef]" assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", request.host end test "host if ipv6 reference with port" do - request = stub_request 'HTTP_HOST' => "[2001:1234:5678:9abc:def0::dead:beef]:8008" + request = stub_request "HTTP_HOST" => "[2001:1234:5678:9abc:def0::dead:beef]:8008" assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", request.host end end @@ -590,28 +590,28 @@ end class RequestParamsParsing < BaseRequestTest test "doesnt break when content type has charset" do request = stub_request( - 'REQUEST_METHOD' => 'POST', - 'CONTENT_LENGTH' => "flamenco=love".length, - 'CONTENT_TYPE' => 'application/x-www-form-urlencoded; charset=utf-8', - 'rack.input' => StringIO.new("flamenco=love") + "REQUEST_METHOD" => "POST", + "CONTENT_LENGTH" => "flamenco=love".length, + "CONTENT_TYPE" => "application/x-www-form-urlencoded; charset=utf-8", + "rack.input" => StringIO.new("flamenco=love") ) - assert_equal({"flamenco"=> "love"}, request.request_parameters) + assert_equal({ "flamenco"=> "love" }, request.request_parameters) end test "doesnt interpret request uri as query string when missing" do - request = stub_request('REQUEST_URI' => 'foo') + request = stub_request("REQUEST_URI" => "foo") assert_equal({}, request.query_parameters) end end class RequestRewind < BaseRequestTest test "body should be rewound" do - data = 'rewind' + data = "rewind" env = { - 'rack.input' => StringIO.new(data), - 'CONTENT_LENGTH' => data.length, - 'CONTENT_TYPE' => 'application/x-www-form-urlencoded; charset=utf-8' + "rack.input" => StringIO.new(data), + "CONTENT_LENGTH" => data.length, + "CONTENT_TYPE" => "application/x-www-form-urlencoded; charset=utf-8" } # Read the request body by parsing params. @@ -624,18 +624,18 @@ class RequestRewind < BaseRequestTest test "raw_post rewinds rack.input if RAW_POST_DATA is nil" do request = stub_request( - 'rack.input' => StringIO.new("raw"), - 'CONTENT_LENGTH' => 3 + "rack.input" => StringIO.new("raw"), + "CONTENT_LENGTH" => 3 ) assert_equal "raw", request.raw_post - assert_equal "raw", request.env['rack.input'].read + assert_equal "raw", request.env["rack.input"].read end end class RequestProtocol < BaseRequestTest test "server software" do - assert_equal 'lighttpd', stub_request('SERVER_SOFTWARE' => 'lighttpd/1.4.5').server_software - assert_equal 'apache', stub_request('SERVER_SOFTWARE' => 'Apache3.422').server_software + assert_equal "lighttpd", stub_request("SERVER_SOFTWARE" => "lighttpd/1.4.5").server_software + assert_equal "apache", stub_request("SERVER_SOFTWARE" => "Apache3.422").server_software end test "xml http request" do @@ -644,35 +644,35 @@ class RequestProtocol < BaseRequestTest assert !request.xml_http_request? assert !request.xhr? - request = stub_request 'HTTP_X_REQUESTED_WITH' => 'DefinitelyNotAjax1.0' + request = stub_request "HTTP_X_REQUESTED_WITH" => "DefinitelyNotAjax1.0" assert !request.xml_http_request? assert !request.xhr? - request = stub_request 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest' + request = stub_request "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" assert request.xml_http_request? assert request.xhr? end test "reports ssl" do assert !stub_request.ssl? - assert stub_request('HTTPS' => 'on').ssl? + assert stub_request("HTTPS" => "on").ssl? end test "reports ssl when proxied via lighttpd" do - assert stub_request('HTTP_X_FORWARDED_PROTO' => 'https').ssl? + assert stub_request("HTTP_X_FORWARDED_PROTO" => "https").ssl? end test "scheme returns https when proxied" do - request = stub_request 'rack.url_scheme' => 'http' + request = stub_request "rack.url_scheme" => "http" assert !request.ssl? - assert_equal 'http', request.scheme + assert_equal "http", request.scheme request = stub_request( - 'rack.url_scheme' => 'http', - 'HTTP_X_FORWARDED_PROTO' => 'https' + "rack.url_scheme" => "http", + "HTTP_X_FORWARDED_PROTO" => "https" ) assert request.ssl? - assert_equal 'https', request.scheme + assert_equal "https", request.scheme end end @@ -681,7 +681,7 @@ class RequestMethod < BaseRequestTest overridden by middleware".squish do ActionDispatch::Request::HTTP_METHODS.each do |method| - request = stub_request('REQUEST_METHOD' => method) + request = stub_request("REQUEST_METHOD" => method) assert_equal method, request.method assert_equal method.underscore.to_sym, request.method_symbol @@ -689,36 +689,36 @@ class RequestMethod < BaseRequestTest end test "allow request method hacking" do - request = stub_request('REQUEST_METHOD' => 'POST') + request = stub_request("REQUEST_METHOD" => "POST") - assert_equal 'POST', request.request_method - assert_equal 'POST', request.env["REQUEST_METHOD"] + assert_equal "POST", request.request_method + assert_equal "POST", request.env["REQUEST_METHOD"] - request.request_method = 'GET' + request.request_method = "GET" - assert_equal 'GET', request.request_method - assert_equal 'GET', request.env["REQUEST_METHOD"] + assert_equal "GET", request.request_method + assert_equal "GET", request.env["REQUEST_METHOD"] assert request.get? end test "invalid http method raises exception" do assert_raise(ActionController::UnknownHttpMethod) do - stub_request('REQUEST_METHOD' => 'RANDOM_METHOD').request_method + stub_request("REQUEST_METHOD" => "RANDOM_METHOD").request_method end end test "method returns original value of environment request method on POST" do - request = stub_request('rack.methodoverride.original_method' => 'POST') - assert_equal 'POST', request.method + request = stub_request("rack.methodoverride.original_method" => "POST") + assert_equal "POST", request.method end test "method raises exception on invalid HTTP method" do assert_raise(ActionController::UnknownHttpMethod) do - stub_request('rack.methodoverride.original_method' => '_RANDOM_METHOD').method + stub_request("rack.methodoverride.original_method" => "_RANDOM_METHOD").method end assert_raise(ActionController::UnknownHttpMethod) do - stub_request('REQUEST_METHOD' => '_RANDOM_METHOD').method + stub_request("REQUEST_METHOD" => "_RANDOM_METHOD").method end end @@ -730,7 +730,7 @@ class RequestMethod < BaseRequestTest I18n.available_locales = [:nl] I18n.config.enforce_available_locales = true assert_raise(ActionController::UnknownHttpMethod) do - stub_request('REQUEST_METHOD' => '_RANDOM_METHOD').method + stub_request("REQUEST_METHOD" => "_RANDOM_METHOD").method end ensure I18n.available_locales = old_locales @@ -740,7 +740,7 @@ class RequestMethod < BaseRequestTest test "post masquerading as patch" do request = stub_request( - 'REQUEST_METHOD' => 'PATCH', + "REQUEST_METHOD" => "PATCH", "rack.methodoverride.original_method" => "POST" ) @@ -751,7 +751,7 @@ class RequestMethod < BaseRequestTest test "post masquerading as put" do request = stub_request( - 'REQUEST_METHOD' => 'PUT', + "REQUEST_METHOD" => "PUT", "rack.methodoverride.original_method" => "POST" ) assert_equal "POST", request.method @@ -784,29 +784,29 @@ end class RequestFormat < BaseRequestTest test "xml format" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :xml}) do + assert_called(request, :parameters, times: 2, returns: { format: :xml }) do assert_equal Mime[:xml], request.format end end test "xhtml format" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :xhtml}) do + assert_called(request, :parameters, times: 2, returns: { format: :xhtml }) do assert_equal Mime[:html], request.format end end test "txt format" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :txt}) do + assert_called(request, :parameters, times: 2, returns: { format: :txt }) do assert_equal Mime[:text], request.format end end test "XMLHttpRequest" do request = stub_request( - 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest', - 'HTTP_ACCEPT' => [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(",") + "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest", + "HTTP_ACCEPT" => [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(",") ) assert_called(request, :parameters, times: 1, returns: {}) do @@ -817,56 +817,56 @@ class RequestFormat < BaseRequestTest test "can override format with parameter negative" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :txt}) do + assert_called(request, :parameters, times: 2, returns: { format: :txt }) do assert !request.format.xml? end end test "can override format with parameter positive" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :xml}) do + assert_called(request, :parameters, times: 2, returns: { format: :xml }) do assert request.format.xml? end end test "formats text/html with accept header" do - request = stub_request 'HTTP_ACCEPT' => 'text/html' + request = stub_request "HTTP_ACCEPT" => "text/html" assert_equal [Mime[:html]], request.formats end test "formats blank with accept header" do - request = stub_request 'HTTP_ACCEPT' => '' + request = stub_request "HTTP_ACCEPT" => "" assert_equal [Mime[:html]], request.formats end test "formats XMLHttpRequest with accept header" do - request = stub_request 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest" + request = stub_request "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" assert_equal [Mime[:js]], request.formats end test "formats application/xml with accept header" do - request = stub_request('CONTENT_TYPE' => 'application/xml; charset=UTF-8', - 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest") + request = stub_request("CONTENT_TYPE" => "application/xml; charset=UTF-8", + "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest") assert_equal [Mime[:xml]], request.formats end test "formats format:text with accept header" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :txt}) do + assert_called(request, :parameters, times: 2, returns: { format: :txt }) do assert_equal [Mime[:text]], request.formats end end test "formats format:unknown with accept header" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :unknown}) do + assert_called(request, :parameters, times: 2, returns: { format: :unknown }) do assert_instance_of Mime::NullType, request.format end end test "format is not nil with unknown format" do request = stub_request - assert_called(request, :parameters, times: 2, returns: {format: :hello}) do + assert_called(request, :parameters, times: 2, returns: { format: :hello }) do assert request.format.nil? assert_not request.format.html? assert_not request.format.xml? @@ -881,7 +881,7 @@ class RequestFormat < BaseRequestTest end test "formats with xhr request" do - request = stub_request 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest" + request = stub_request "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [Mime[:js]], request.formats end @@ -892,36 +892,36 @@ class RequestFormat < BaseRequestTest ActionDispatch::Request.ignore_accept_header = true begin - request = stub_request 'HTTP_ACCEPT' => 'application/xml' + request = stub_request "HTTP_ACCEPT" => "application/xml" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [ Mime[:html] ], request.formats end - request = stub_request 'HTTP_ACCEPT' => 'koz-asked/something-crazy' + request = stub_request "HTTP_ACCEPT" => "koz-asked/something-crazy" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [ Mime[:html] ], request.formats end - request = stub_request 'HTTP_ACCEPT' => '*/*;q=0.1' + request = stub_request "HTTP_ACCEPT" => "*/*;q=0.1" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [ Mime[:html] ], request.formats end - request = stub_request 'HTTP_ACCEPT' => 'application/jxw' + request = stub_request "HTTP_ACCEPT" => "application/jxw" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [ Mime[:html] ], request.formats end - request = stub_request 'HTTP_ACCEPT' => 'application/xml', - 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest" + request = stub_request "HTTP_ACCEPT" => "application/xml", + "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [ Mime[:js] ], request.formats end - request = stub_request 'HTTP_ACCEPT' => 'application/xml', - 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest" - assert_called(request, :parameters, times: 2, returns: {format: :json}) do + request = stub_request "HTTP_ACCEPT" => "application/xml", + "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" + assert_called(request, :parameters, times: 2, returns: { format: :json }) do assert_equal [ Mime[:json] ], request.formats end ensure @@ -930,20 +930,20 @@ class RequestFormat < BaseRequestTest end test "format taken from the path extension" do - request = stub_request 'PATH_INFO' => '/foo.xml' + request = stub_request "PATH_INFO" => "/foo.xml" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [Mime[:xml]], request.formats end - request = stub_request 'PATH_INFO' => '/foo.123' + request = stub_request "PATH_INFO" => "/foo.123" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [Mime[:html]], request.formats end end test "formats from accept headers have higher precedence than path extension" do - request = stub_request 'HTTP_ACCEPT' => 'application/json', - 'PATH_INFO' => '/foo.xml' + request = stub_request "HTTP_ACCEPT" => "application/json", + "PATH_INFO" => "/foo.xml" assert_called(request, :parameters, times: 1, returns: {}) do assert_equal [Mime[:json]], request.formats @@ -953,7 +953,7 @@ end class RequestMimeType < BaseRequestTest test "content type" do - assert_equal Mime[:html], stub_request('CONTENT_TYPE' => 'text/html').content_mime_type + assert_equal Mime[:html], stub_request("CONTENT_TYPE" => "text/html").content_mime_type end test "no content type" do @@ -961,21 +961,21 @@ class RequestMimeType < BaseRequestTest end test "content type is XML" do - assert_equal Mime[:xml], stub_request('CONTENT_TYPE' => 'application/xml').content_mime_type + assert_equal Mime[:xml], stub_request("CONTENT_TYPE" => "application/xml").content_mime_type end test "content type with charset" do - assert_equal Mime[:xml], stub_request('CONTENT_TYPE' => 'application/xml; charset=UTF-8').content_mime_type + assert_equal Mime[:xml], stub_request("CONTENT_TYPE" => "application/xml; charset=UTF-8").content_mime_type end test "user agent" do - assert_equal 'TestAgent', stub_request('HTTP_USER_AGENT' => 'TestAgent').user_agent + assert_equal "TestAgent", stub_request("HTTP_USER_AGENT" => "TestAgent").user_agent end test "negotiate_mime" do request = stub_request( - 'HTTP_ACCEPT' => 'text/html', - 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest" + "HTTP_ACCEPT" => "text/html", + "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" ) assert_equal nil, request.negotiate_mime([Mime[:xml], Mime[:json]]) @@ -985,8 +985,8 @@ class RequestMimeType < BaseRequestTest test "negotiate_mime with content_type" do request = stub_request( - 'CONTENT_TYPE' => 'application/xml; charset=UTF-8', - 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest" + "CONTENT_TYPE" => "application/xml; charset=UTF-8", + "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" ) assert_equal Mime[:xml], request.negotiate_mime([Mime[:xml], Mime[:csv]]) @@ -997,11 +997,11 @@ class RequestParameters < BaseRequestTest test "parameters" do request = stub_request - assert_called(request, :request_parameters, times: 2, returns: {"foo" => 1}) do - assert_called(request, :query_parameters, times: 2, returns: {"bar" => 2}) do - assert_equal({"foo" => 1, "bar" => 2}, request.parameters) - assert_equal({"foo" => 1}, request.request_parameters) - assert_equal({"bar" => 2}, request.query_parameters) + assert_called(request, :request_parameters, times: 2, returns: { "foo" => 1 }) do + assert_called(request, :query_parameters, times: 2, returns: { "bar" => 2 }) do + assert_equal({ "foo" => 1, "bar" => 2 }, request.parameters) + assert_equal({ "foo" => 1 }, request.request_parameters) + assert_equal({ "bar" => 2 }, request.query_parameters) end end end @@ -1044,10 +1044,10 @@ class RequestParameters < BaseRequestTest test "parameters not accessible after rack parse error 1" do request = stub_request( - 'REQUEST_METHOD' => 'POST', - 'CONTENT_LENGTH' => "a%=".length, - 'CONTENT_TYPE' => 'application/x-www-form-urlencoded; charset=utf-8', - 'rack.input' => StringIO.new("a%=") + "REQUEST_METHOD" => "POST", + "CONTENT_LENGTH" => "a%=".length, + "CONTENT_TYPE" => "application/x-www-form-urlencoded; charset=utf-8", + "rack.input" => StringIO.new("a%=") ) assert_raises(ActionController::BadRequest) do @@ -1069,31 +1069,30 @@ class RequestParameters < BaseRequestTest end end - class RequestParameterFilter < BaseRequestTest test "process parameter filter" do test_hashes = [ - [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'], - [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'], - [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'], - [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'], - [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'], - [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'], - [{'deep'=>{'cc'=>{'code'=>'bar','bar'=>'foo'},'ss'=>{'code'=>'bar'}}},{'deep'=>{'cc'=>{'code'=>'[FILTERED]','bar'=>'foo'},'ss'=>{'code'=>'bar'}}},%w'deep.cc.code'], - [{'baz'=>[{'foo'=>'baz'}, "1"]}, {'baz'=>[{'foo'=>'[FILTERED]'}, "1"]}, [/foo/]]] + [{ "foo"=>"bar" },{ "foo"=>"bar" },%w'food'], + [{ "foo"=>"bar" },{ "foo"=>"[FILTERED]" },%w'foo'], + [{ "foo"=>"bar", "bar"=>"foo" },{ "foo"=>"[FILTERED]", "bar"=>"foo" },%w'foo baz'], + [{ "foo"=>"bar", "baz"=>"foo" },{ "foo"=>"[FILTERED]", "baz"=>"[FILTERED]" },%w'foo baz'], + [{ "bar"=>{ "foo"=>"bar","bar"=>"foo" } },{ "bar"=>{ "foo"=>"[FILTERED]","bar"=>"foo" } },%w'fo'], + [{ "foo"=>{ "foo"=>"bar","bar"=>"foo" } },{ "foo"=>"[FILTERED]" },%w'f banana'], + [{ "deep"=>{ "cc"=>{ "code"=>"bar","bar"=>"foo" },"ss"=>{ "code"=>"bar" } } },{ "deep"=>{ "cc"=>{ "code"=>"[FILTERED]","bar"=>"foo" },"ss"=>{ "code"=>"bar" } } },%w'deep.cc.code'], + [{ "baz"=>[{ "foo"=>"baz" }, "1"] }, { "baz"=>[{ "foo"=>"[FILTERED]" }, "1"] }, [/foo/]]] test_hashes.each do |before_filter, after_filter, filter_words| parameter_filter = ActionDispatch::Http::ParameterFilter.new(filter_words) assert_equal after_filter, parameter_filter.filter(before_filter) - filter_words << 'blah' + filter_words << "blah" filter_words << lambda { |key, value| value.reverse! if key =~ /bargain/ } parameter_filter = ActionDispatch::Http::ParameterFilter.new(filter_words) - before_filter['barg'] = {:bargain=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}} - after_filter['barg'] = {:bargain=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}} + before_filter["barg"] = { :bargain=>"gain", "blah"=>"bar", "bar"=>{ "bargain"=>{ "blah"=>"foo" } } } + after_filter["barg"] = { :bargain=>"niag", "blah"=>"[FILTERED]", "bar"=>{ "bargain"=>{ "blah"=>"[FILTERED]" } } } assert_equal after_filter, parameter_filter.filter(before_filter) end @@ -1101,12 +1100,12 @@ class RequestParameterFilter < BaseRequestTest test "filtered_parameters returns params filtered" do request = stub_request( - 'action_dispatch.request.parameters' => { - 'lifo' => 'Pratik', - 'amount' => '420', - 'step' => '1' + "action_dispatch.request.parameters" => { + "lifo" => "Pratik", + "amount" => "420", + "step" => "1" }, - 'action_dispatch.parameter_filter' => [:lifo, :amount] + "action_dispatch.parameter_filter" => [:lifo, :amount] ) params = request.filtered_parameters @@ -1117,12 +1116,12 @@ class RequestParameterFilter < BaseRequestTest test "filtered_env filters env as a whole" do request = stub_request( - 'action_dispatch.request.parameters' => { - 'amount' => '420', - 'step' => '1' + "action_dispatch.request.parameters" => { + "amount" => "420", + "step" => "1" }, "RAW_POST_DATA" => "yada yada", - 'action_dispatch.parameter_filter' => [:lifo, :amount] + "action_dispatch.parameter_filter" => [:lifo, :amount] ) request = stub_request(request.filtered_env) @@ -1134,9 +1133,9 @@ class RequestParameterFilter < BaseRequestTest test "filtered_path returns path with filtered query string" do %w(; &).each do |sep| request = stub_request( - 'QUERY_STRING' => %w(username=sikachu secret=bd4f21f api_key=b1bc3b3cd352f68d79d7).join(sep), - 'PATH_INFO' => '/authenticate', - 'action_dispatch.parameter_filter' => [:secret, :api_key] + "QUERY_STRING" => %w(username=sikachu secret=bd4f21f api_key=b1bc3b3cd352f68d79d7).join(sep), + "PATH_INFO" => "/authenticate", + "action_dispatch.parameter_filter" => [:secret, :api_key] ) path = request.filtered_path @@ -1146,9 +1145,9 @@ class RequestParameterFilter < BaseRequestTest test "filtered_path should not unescape a genuine '[FILTERED]' value" do request = stub_request( - 'QUERY_STRING' => "secret=bd4f21f&genuine=%5BFILTERED%5D", - 'PATH_INFO' => '/authenticate', - 'action_dispatch.parameter_filter' => [:secret] + "QUERY_STRING" => "secret=bd4f21f&genuine=%5BFILTERED%5D", + "PATH_INFO" => "/authenticate", + "action_dispatch.parameter_filter" => [:secret] ) path = request.filtered_path @@ -1157,9 +1156,9 @@ class RequestParameterFilter < BaseRequestTest test "filtered_path should preserve duplication of keys in query string" do request = stub_request( - 'QUERY_STRING' => "username=sikachu&secret=bd4f21f&username=fxn", - 'PATH_INFO' => '/authenticate', - 'action_dispatch.parameter_filter' => [:secret] + "QUERY_STRING" => "username=sikachu&secret=bd4f21f&username=fxn", + "PATH_INFO" => "/authenticate", + "action_dispatch.parameter_filter" => [:secret] ) path = request.filtered_path @@ -1168,9 +1167,9 @@ class RequestParameterFilter < BaseRequestTest test "filtered_path should ignore searchparts" do request = stub_request( - 'QUERY_STRING' => "secret", - 'PATH_INFO' => '/authenticate', - 'action_dispatch.parameter_filter' => [:secret] + "QUERY_STRING" => "secret", + "PATH_INFO" => "/authenticate", + "action_dispatch.parameter_filter" => [:secret] ) path = request.filtered_path @@ -1180,10 +1179,10 @@ end class RequestEtag < BaseRequestTest test "always matches *" do - request = stub_request('HTTP_IF_NONE_MATCH' => '*') + request = stub_request("HTTP_IF_NONE_MATCH" => "*") - assert_equal '*', request.if_none_match - assert_equal ['*'], request.if_none_match_etags + assert_equal "*", request.if_none_match + assert_equal ["*"], request.if_none_match_etags assert request.etag_matches?('"strong"') assert request.etag_matches?('W/"weak"') @@ -1202,7 +1201,7 @@ class RequestEtag < BaseRequestTest test "matches opaque ETag validators without unquoting" do header = '"the-etag"' - request = stub_request('HTTP_IF_NONE_MATCH' => header) + request = stub_request("HTTP_IF_NONE_MATCH" => header) assert_equal header, request.if_none_match assert_equal ['"the-etag"'], request.if_none_match_etags @@ -1213,8 +1212,8 @@ class RequestEtag < BaseRequestTest test "if_none_match_etags multiple" do header = 'etag1, etag2, "third etag", "etag4"' - expected = ['etag1', 'etag2', '"third etag"', '"etag4"'] - request = stub_request('HTTP_IF_NONE_MATCH' => header) + expected = ["etag1", "etag2", '"third etag"', '"etag4"'] + request = stub_request("HTTP_IF_NONE_MATCH" => header) assert_equal header, request.if_none_match assert_equal expected, request.if_none_match_etags @@ -1230,7 +1229,7 @@ class RequestVariant < BaseRequestTest @request = stub_request end - test 'setting variant to a symbol' do + test "setting variant to a symbol" do @request.variant = :phone assert @request.variant.phone? @@ -1239,7 +1238,7 @@ class RequestVariant < BaseRequestTest assert_not @request.variant.any?(:tablet, :desktop) end - test 'setting variant to an array of symbols' do + test "setting variant to an array of symbols" do @request.variant = [:phone, :tablet] assert @request.variant.phone? @@ -1249,7 +1248,7 @@ class RequestVariant < BaseRequestTest assert_not @request.variant.any?(:desktop, :watch) end - test 'clearing variant' do + test "clearing variant" do @request.variant = nil assert @request.variant.empty? @@ -1257,35 +1256,35 @@ class RequestVariant < BaseRequestTest assert_not @request.variant.any?(:phone, :tablet) end - test 'setting variant to a non-symbol value' do + test "setting variant to a non-symbol value" do assert_raise ArgumentError do - @request.variant = 'phone' + @request.variant = "phone" end end - test 'setting variant to an array containing a non-symbol value' do + test "setting variant to an array containing a non-symbol value" do assert_raise ArgumentError do - @request.variant = [:phone, 'tablet'] + @request.variant = [:phone, "tablet"] end end end class RequestFormData < BaseRequestTest - test 'media_type is from the FORM_DATA_MEDIA_TYPES array' do - assert stub_request('CONTENT_TYPE' => 'application/x-www-form-urlencoded').form_data? - assert stub_request('CONTENT_TYPE' => 'multipart/form-data').form_data? + test "media_type is from the FORM_DATA_MEDIA_TYPES array" do + assert stub_request("CONTENT_TYPE" => "application/x-www-form-urlencoded").form_data? + assert stub_request("CONTENT_TYPE" => "multipart/form-data").form_data? end - test 'media_type is not from the FORM_DATA_MEDIA_TYPES array' do - assert !stub_request('CONTENT_TYPE' => 'application/xml').form_data? - assert !stub_request('CONTENT_TYPE' => 'multipart/related').form_data? + test "media_type is not from the FORM_DATA_MEDIA_TYPES array" do + assert !stub_request("CONTENT_TYPE" => "application/xml").form_data? + assert !stub_request("CONTENT_TYPE" => "multipart/related").form_data? end - test 'no Content-Type header is provided and the request_method is POST' do - request = stub_request('REQUEST_METHOD' => 'POST') + test "no Content-Type header is provided and the request_method is POST" do + request = stub_request("REQUEST_METHOD" => "POST") - assert_equal '', request.media_type - assert_equal 'POST', request.request_method + assert_equal "", request.media_type + assert_equal "POST", request.request_method assert !request.form_data? end end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 9eed796d3c..4e547ab7d5 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'timeout' -require 'rack/content_length' +require "abstract_unit" +require "timeout" +require "rack/content_length" class ResponseTest < ActiveSupport::TestCase def setup @@ -40,8 +40,8 @@ class ResponseTest < ActiveSupport::TestCase def test_each_isnt_called_if_str_body_is_written # Controller writes and reads response body each_counter = 0 - @response.body = Object.new.tap {|o| o.singleton_class.send(:define_method, :each) { |&block| each_counter += 1; block.call 'foo' } } - @response['X-Foo'] = @response.body + @response.body = Object.new.tap { |o| o.singleton_class.send(:define_method, :each) { |&block| each_counter += 1; block.call "foo" } } + @response["X-Foo"] = @response.body assert_equal 1, each_counter, "#each was not called once" @@ -49,7 +49,7 @@ class ResponseTest < ActiveSupport::TestCase status, headers, body = @response.to_a assert_equal 200, status - assert_equal "foo", headers['X-Foo'] + assert_equal "foo", headers["X-Foo"] assert_equal "foo", body.each.to_a.join # Show that #each was not called twice @@ -60,14 +60,14 @@ class ResponseTest < ActiveSupport::TestCase @response.body # set header after the action reads back @response.body - @response['x-header'] = "Best of all possible worlds." + @response["x-header"] = "Best of all possible worlds." # the response can be built. status, headers, body = @response.to_a assert_equal 200, status assert_equal "", body.body - assert_equal "Best of all possible worlds.", headers['x-header'] + assert_equal "Best of all possible worlds.", headers["x-header"] end def test_read_body_during_action @@ -99,15 +99,15 @@ class ResponseTest < ActiveSupport::TestCase end def test_response_charset_writer - @response.charset = 'utf-16' - assert_equal 'utf-16', @response.charset + @response.charset = "utf-16" + assert_equal "utf-16", @response.charset @response.charset = nil - assert_equal 'utf-8', @response.charset + assert_equal "utf-8", @response.charset end def test_setting_content_type_header_impacts_content_type_method - @response.headers['Content-Type'] = "application/aaron" - assert_equal 'application/aaron', @response.content_type + @response.headers["Content-Type"] = "application/aaron" + assert_equal "application/aaron", @response.content_type end test "simple output" do @@ -125,14 +125,14 @@ class ResponseTest < ActiveSupport::TestCase end test "status handled properly in initialize" do - assert_equal 200, ActionDispatch::Response.new('200 OK').status + assert_equal 200, ActionDispatch::Response.new("200 OK").status end def test_only_set_charset_still_defaults_to_text_html response = ActionDispatch::Response.new response.charset = "utf-16" _,headers,_ = response.to_a - assert_equal "text/html; charset=utf-16", headers['Content-Type'] + assert_equal "text/html; charset=utf-16", headers["Content-Type"] end test "utf8 output" do @@ -184,7 +184,7 @@ class ResponseTest < ActiveSupport::TestCase test "does not include Status header" do @response.status = "200 OK" _, headers, _ = @response.to_a - assert !headers.has_key?('Status') + assert !headers.has_key?("Status") end test "response code" do @@ -221,32 +221,32 @@ class ResponseTest < ActiveSupport::TestCase end test "cookies" do - @response.set_cookie("user_name", :value => "david", :path => "/") + @response.set_cookie("user_name", value: "david", path: "/") _status, headers, _body = @response.to_a assert_equal "user_name=david; path=/", headers["Set-Cookie"] - assert_equal({"user_name" => "david"}, @response.cookies) + assert_equal({ "user_name" => "david" }, @response.cookies) end test "multiple cookies" do - @response.set_cookie("user_name", :value => "david", :path => "/") - @response.set_cookie("login", :value => "foo&bar", :path => "/", :expires => Time.utc(2005, 10, 10,5)) + @response.set_cookie("user_name", value: "david", path: "/") + @response.set_cookie("login", value: "foo&bar", path: "/", expires: Time.utc(2005, 10, 10,5)) _status, headers, _body = @response.to_a assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000", headers["Set-Cookie"] - assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies) + assert_equal({ "login" => "foo&bar", "user_name" => "david" }, @response.cookies) end test "delete cookies" do - @response.set_cookie("user_name", :value => "david", :path => "/") - @response.set_cookie("login", :value => "foo&bar", :path => "/", :expires => Time.utc(2005, 10, 10,5)) + @response.set_cookie("user_name", value: "david", path: "/") + @response.set_cookie("login", value: "foo&bar", path: "/", expires: Time.utc(2005, 10, 10,5)) @response.delete_cookie("login") - assert_equal({"user_name" => "david", "login" => nil}, @response.cookies) + assert_equal({ "user_name" => "david", "login" => nil }, @response.cookies) end test "read ETag and Cache-Control" do resp = ActionDispatch::Response.new.tap { |response| response.cache_control[:public] = true - response.etag = '123' - response.body = 'Hello' + response.etag = "123" + response.body = "Hello" } resp.to_a @@ -254,17 +254,17 @@ class ResponseTest < ActiveSupport::TestCase assert resp.weak_etag? assert_not resp.strong_etag? assert_equal('W/"202cb962ac59075b964b07152d234b70"', resp.etag) - assert_equal({:public => true}, resp.cache_control) + assert_equal({ public: true }, resp.cache_control) - assert_equal('public', resp.headers['Cache-Control']) - assert_equal('W/"202cb962ac59075b964b07152d234b70"', resp.headers['ETag']) + assert_equal("public", resp.headers["Cache-Control"]) + assert_equal('W/"202cb962ac59075b964b07152d234b70"', resp.headers["ETag"]) end test "read strong ETag" do resp = ActionDispatch::Response.new.tap { |response| response.cache_control[:public] = true - response.strong_etag = '123' - response.body = 'Hello' + response.strong_etag = "123" + response.body = "Hello" } resp.to_a @@ -276,23 +276,23 @@ class ResponseTest < ActiveSupport::TestCase test "read charset and content type" do resp = ActionDispatch::Response.new.tap { |response| - response.charset = 'utf-16' + response.charset = "utf-16" response.content_type = Mime[:xml] - response.body = 'Hello' + response.body = "Hello" } resp.to_a - assert_equal('utf-16', resp.charset) + assert_equal("utf-16", resp.charset) assert_equal(Mime[:xml], resp.content_type) - assert_equal('application/xml; charset=utf-16', resp.headers['Content-Type']) + assert_equal("application/xml; charset=utf-16", resp.headers["Content-Type"]) end test "read content type with default charset utf-8" do original = ActionDispatch::Response.default_charset begin - resp = ActionDispatch::Response.new(200, { "Content-Type" => "text/xml" }) - assert_equal('utf-8', resp.charset) + resp = ActionDispatch::Response.new(200, "Content-Type" => "text/xml") + assert_equal("utf-8", resp.charset) ensure ActionDispatch::Response.default_charset = original end @@ -301,9 +301,9 @@ class ResponseTest < ActiveSupport::TestCase test "read content type with charset utf-16" do original = ActionDispatch::Response.default_charset begin - ActionDispatch::Response.default_charset = 'utf-16' - resp = ActionDispatch::Response.new(200, { "Content-Type" => "text/xml" }) - assert_equal('utf-16', resp.charset) + ActionDispatch::Response.default_charset = "utf-16" + resp = ActionDispatch::Response.new(200, "Content-Type" => "text/xml") + assert_equal("utf-16", resp.charset) ensure ActionDispatch::Response.default_charset = original end @@ -313,18 +313,18 @@ class ResponseTest < ActiveSupport::TestCase original_default_headers = ActionDispatch::Response.default_headers begin ActionDispatch::Response.default_headers = { - 'X-Frame-Options' => 'DENY', - 'X-Content-Type-Options' => 'nosniff', - 'X-XSS-Protection' => '1;' + "X-Frame-Options" => "DENY", + "X-Content-Type-Options" => "nosniff", + "X-XSS-Protection" => "1;" } resp = ActionDispatch::Response.create.tap { |response| - response.body = 'Hello' + response.body = "Hello" } resp.to_a - assert_equal('DENY', resp.headers['X-Frame-Options']) - assert_equal('nosniff', resp.headers['X-Content-Type-Options']) - assert_equal('1;', resp.headers['X-XSS-Protection']) + assert_equal("DENY", resp.headers["X-Frame-Options"]) + assert_equal("nosniff", resp.headers["X-Content-Type-Options"]) + assert_equal("1;", resp.headers["X-XSS-Protection"]) ensure ActionDispatch::Response.default_headers = original_default_headers end @@ -334,14 +334,14 @@ class ResponseTest < ActiveSupport::TestCase original_default_headers = ActionDispatch::Response.default_headers begin ActionDispatch::Response.default_headers = { - 'X-XX-XXXX' => 'Here is my phone number' + "X-XX-XXXX" => "Here is my phone number" } resp = ActionDispatch::Response.create.tap { |response| - response.body = 'Hello' + response.body = "Hello" } resp.to_a - assert_equal('Here is my phone number', resp.headers['X-XX-XXXX']) + assert_equal("Here is my phone number", resp.headers["X-XX-XXXX"]) ensure ActionDispatch::Response.default_headers = original_default_headers end @@ -353,13 +353,13 @@ class ResponseTest < ActiveSupport::TestCase end test "can be explicitly destructured into status, headers and an enumerable body" do - response = ActionDispatch::Response.new(404, { 'Content-Type' => 'text/plain' }, ['Not Found']) + response = ActionDispatch::Response.new(404, { "Content-Type" => "text/plain" }, ["Not Found"]) response.request = ActionDispatch::Request.empty status, headers, body = *response assert_equal 404, status - assert_equal({ 'Content-Type' => 'text/plain' }, headers) - assert_equal ['Not Found'], body.each.to_a + assert_equal({ "Content-Type" => "text/plain" }, headers) + assert_equal ["Not Found"], body.each.to_a end test "[response.to_a].flatten does not recurse infinitely" do @@ -372,74 +372,74 @@ class ResponseTest < ActiveSupport::TestCase end test "compatibility with Rack::ContentLength" do - @response.body = 'Hello' + @response.body = "Hello" app = lambda { |env| @response.to_a } env = Rack::MockRequest.env_for("/") status, headers, body = app.call(env) - assert_nil headers['Content-Length'] + assert_nil headers["Content-Length"] status, headers, body = Rack::ContentLength.new(app).call(env) - assert_equal '5', headers['Content-Length'] + assert_equal "5", headers["Content-Length"] end end class ResponseHeadersTest < ActiveSupport::TestCase def setup @response = ActionDispatch::Response.create - @response.set_header 'Foo', '1' + @response.set_header "Foo", "1" end - test 'has_header?' do - assert @response.has_header? 'Foo' - assert_not @response.has_header? 'foo' + test "has_header?" do + assert @response.has_header? "Foo" + assert_not @response.has_header? "foo" assert_not @response.has_header? nil end - test 'get_header' do - assert_equal '1', @response.get_header('Foo') - assert_nil @response.get_header('foo') + test "get_header" do + assert_equal "1", @response.get_header("Foo") + assert_nil @response.get_header("foo") assert_nil @response.get_header(nil) end - test 'set_header' do - assert_equal '2', @response.set_header('Foo', '2') - assert @response.has_header?('Foo') - assert_equal '2', @response.get_header('Foo') + test "set_header" do + assert_equal "2", @response.set_header("Foo", "2") + assert @response.has_header?("Foo") + assert_equal "2", @response.get_header("Foo") - assert_nil @response.set_header('Foo', nil) - assert @response.has_header?('Foo') - assert_nil @response.get_header('Foo') + assert_nil @response.set_header("Foo", nil) + assert @response.has_header?("Foo") + assert_nil @response.get_header("Foo") end - test 'delete_header' do + test "delete_header" do assert_nil @response.delete_header(nil) - assert_nil @response.delete_header('foo') - assert @response.has_header?('Foo') + assert_nil @response.delete_header("foo") + assert @response.has_header?("Foo") - assert_equal '1', @response.delete_header('Foo') - assert_not @response.has_header?('Foo') + assert_equal "1", @response.delete_header("Foo") + assert_not @response.has_header?("Foo") end - test 'add_header' do + test "add_header" do # Add a value to an existing header - assert_equal '1,2', @response.add_header('Foo', '2') - assert_equal '1,2', @response.get_header('Foo') + assert_equal "1,2", @response.add_header("Foo", "2") + assert_equal "1,2", @response.get_header("Foo") # Add nil to an existing header - assert_equal '1,2', @response.add_header('Foo', nil) - assert_equal '1,2', @response.get_header('Foo') + assert_equal "1,2", @response.add_header("Foo", nil) + assert_equal "1,2", @response.get_header("Foo") # Add nil to a nonexistent header - assert_nil @response.add_header('Bar', nil) - assert_not @response.has_header?('Bar') - assert_nil @response.get_header('Bar') + assert_nil @response.add_header("Bar", nil) + assert_not @response.has_header?("Bar") + assert_nil @response.get_header("Bar") # Add a value to a nonexistent header - assert_equal '1', @response.add_header('Bar', '1') - assert @response.has_header?('Bar') - assert_equal '1', @response.get_header('Bar') + assert_equal "1", @response.add_header("Bar", "1") + assert @response.has_header?("Bar") + assert_equal "1", @response.get_header("Bar") end end @@ -448,87 +448,87 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest @app = lambda { |env| ActionDispatch::Response.new.tap { |resp| resp.cache_control[:public] = true - resp.etag = '123' - resp.body = 'Hello' + resp.etag = "123" + resp.body = "Hello" resp.request = ActionDispatch::Request.empty }.to_a } - get '/' + get "/" assert_response :success - assert_equal('public', @response.headers['Cache-Control']) - assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.headers['ETag']) + assert_equal("public", @response.headers["Cache-Control"]) + assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.headers["ETag"]) assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.etag) - assert_equal({:public => true}, @response.cache_control) + assert_equal({ public: true }, @response.cache_control) end test "response cache control from rackish app" do @app = lambda { |env| [200, - {'ETag' => 'W/"202cb962ac59075b964b07152d234b70"', - 'Cache-Control' => 'public'}, ['Hello']] + { "ETag" => 'W/"202cb962ac59075b964b07152d234b70"', + "Cache-Control" => "public" }, ["Hello"]] } - get '/' + get "/" assert_response :success - assert_equal('public', @response.headers['Cache-Control']) - assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.headers['ETag']) + assert_equal("public", @response.headers["Cache-Control"]) + assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.headers["ETag"]) assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.etag) - assert_equal({:public => true}, @response.cache_control) + assert_equal({ public: true }, @response.cache_control) end test "response charset and content type from railsish app" do @app = lambda { |env| ActionDispatch::Response.new.tap { |resp| - resp.charset = 'utf-16' + resp.charset = "utf-16" resp.content_type = Mime[:xml] - resp.body = 'Hello' + resp.body = "Hello" resp.request = ActionDispatch::Request.empty }.to_a } - get '/' + get "/" assert_response :success - assert_equal('utf-16', @response.charset) + assert_equal("utf-16", @response.charset) assert_equal(Mime[:xml], @response.content_type) - assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type']) + assert_equal("application/xml; charset=utf-16", @response.headers["Content-Type"]) end test "response charset and content type from rackish app" do @app = lambda { |env| [200, - {'Content-Type' => 'application/xml; charset=utf-16'}, - ['Hello']] + { "Content-Type" => "application/xml; charset=utf-16" }, + ["Hello"]] } - get '/' + get "/" assert_response :success - assert_equal('utf-16', @response.charset) + assert_equal("utf-16", @response.charset) assert_equal(Mime[:xml], @response.content_type) - assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type']) + assert_equal("application/xml; charset=utf-16", @response.headers["Content-Type"]) end test "strong ETag validator" do @app = lambda { |env| ActionDispatch::Response.new.tap { |resp| - resp.strong_etag = '123' - resp.body = 'Hello' + resp.strong_etag = "123" + resp.body = "Hello" resp.request = ActionDispatch::Request.empty }.to_a } - get '/' + get "/" assert_response :ok - assert_equal('"202cb962ac59075b964b07152d234b70"', @response.headers['ETag']) + assert_equal('"202cb962ac59075b964b07152d234b70"', @response.headers["ETag"]) assert_equal('"202cb962ac59075b964b07152d234b70"', @response.etag) end end diff --git a/actionpack/test/dispatch/routing/concerns_test.rb b/actionpack/test/dispatch/routing/concerns_test.rb index 6934271846..2d71c37562 100644 --- a/actionpack/test/dispatch/routing/concerns_test.rb +++ b/actionpack/test/dispatch/routing/concerns_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class ReviewsController < ResourcesController; end diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb index 5aafcb23c2..a4babf8554 100644 --- a/actionpack/test/dispatch/routing/inspector_test.rb +++ b/actionpack/test/dispatch/routing/inspector_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'rails/engine' -require 'action_dispatch/routing/inspector' +require "abstract_unit" +require "rails/engine" +require "action_dispatch/routing/inspector" class MountedRackApp def self.call(env) @@ -30,11 +30,11 @@ module ActionDispatch end end engine.routes.draw do - get '/cart', :to => 'cart#show' + get "/cart", to: "cart#show" end output = draw do - get '/custom/assets', :to => 'custom_assets#show' + get "/custom/assets", to: "custom_assets#show" mount engine => "/blog", :as => "blog" end @@ -71,7 +71,7 @@ module ActionDispatch def test_cart_inspect output = draw do - get '/cart', :to => 'cart#show' + get "/cart", to: "cart#show" end assert_equal [ @@ -82,7 +82,7 @@ module ActionDispatch def test_articles_inspect_with_multiple_verbs output = draw do - match 'articles/:id', to: 'articles#update', via: [:put, :patch] + match "articles/:id", to: "articles#update", via: [:put, :patch] end assert_equal [ @@ -93,7 +93,7 @@ module ActionDispatch def test_inspect_shows_custom_assets output = draw do - get '/custom/assets', :to => 'custom_assets#show' + get "/custom/assets", to: "custom_assets#show" end assert_equal [ @@ -122,7 +122,7 @@ module ActionDispatch def test_inspect_routes_shows_root_route output = draw do - root :to => 'pages#main' + root to: "pages#main" end assert_equal [ @@ -134,7 +134,7 @@ module ActionDispatch def test_inspect_routes_shows_dynamic_action_route output = draw do ActiveSupport::Deprecation.silence do - get 'api/:action' => 'api' + get "api/:action" => "api" end end @@ -147,7 +147,7 @@ module ActionDispatch def test_inspect_routes_shows_controller_and_action_only_route output = draw do ActiveSupport::Deprecation.silence do - get ':controller/:action' + get ":controller/:action" end end @@ -160,7 +160,7 @@ module ActionDispatch def test_inspect_routes_shows_controller_and_action_route_with_constraints output = draw do ActiveSupport::Deprecation.silence do - get ':controller(/:action(/:id))', :id => /\d+/ + get ":controller(/:action(/:id))", id: /\d+/ end end @@ -172,18 +172,18 @@ module ActionDispatch def test_rails_routes_shows_route_with_defaults output = draw do - get 'photos/:id' => 'photos#show', :defaults => {:format => 'jpg'} + get "photos/:id" => "photos#show", :defaults => { format: "jpg" } end assert_equal [ "Prefix Verb URI Pattern Controller#Action", - %Q[ GET /photos/:id(.:format) photos#show {:format=>"jpg"}] + ' GET /photos/:id(.:format) photos#show {:format=>"jpg"}' ], output end def test_rails_routes_shows_route_with_constraints output = draw do - get 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/ + get "photos/:id" => "photos#show", :id => /[A-Z]\d{5}/ end assert_equal [ @@ -194,13 +194,13 @@ module ActionDispatch def test_rails_routes_shows_routes_with_dashes output = draw do - get 'about-us' => 'pages#about_us' - get 'our-work/latest' + get "about-us" => "pages#about_us" + get "our-work/latest" resources :photos, only: [:show] do - get 'user-favorites', on: :collection - get 'preview-photo', on: :member - get 'summary-text' + get "user-favorites", on: :collection + get "preview-photo", on: :member + get "summary-text" end end @@ -217,7 +217,7 @@ module ActionDispatch def test_rails_routes_shows_route_with_rack_app output = draw do - get 'foo/:id' => MountedRackApp, :id => /[A-Z]\d{5}/ + get "foo/:id" => MountedRackApp, :id => /[A-Z]\d{5}/ end assert_equal [ @@ -228,7 +228,7 @@ module ActionDispatch def test_rails_routes_shows_named_route_with_mounted_rack_app output = draw do - mount MountedRackApp => '/foo' + mount MountedRackApp => "/foo" end assert_equal [ @@ -239,7 +239,7 @@ module ActionDispatch def test_rails_routes_shows_overridden_named_route_with_mounted_rack_app_with_name output = draw do - mount MountedRackApp => '/foo', as: 'blog' + mount MountedRackApp => "/foo", as: "blog" end assert_equal [ @@ -256,8 +256,8 @@ module ActionDispatch end output = draw do - scope :constraint => constraint.new do - mount MountedRackApp => '/foo' + scope constraint: constraint.new do + mount MountedRackApp => "/foo" end end @@ -269,7 +269,7 @@ module ActionDispatch def test_rails_routes_dont_show_app_mounted_in_assets_prefix output = draw do - get '/sprockets' => MountedRackApp + get "/sprockets" => MountedRackApp end assert_no_match(/MountedRackApp/, output.first) assert_no_match(/\/sprockets/, output.first) @@ -277,8 +277,8 @@ module ActionDispatch def test_rails_routes_shows_route_defined_in_under_assets_prefix output = draw do - scope '/sprockets' do - get '/foo' => 'foo#bar' + scope "/sprockets" do + get "/foo" => "foo#bar" end end assert_equal [ @@ -289,9 +289,9 @@ module ActionDispatch def test_redirect output = draw do - get "/foo" => redirect("/foo/bar"), :constraints => { :subdomain => "admin" } + get "/foo" => redirect("/foo/bar"), :constraints => { subdomain: "admin" } get "/bar" => redirect(path: "/foo/bar", status: 307) - get "/foobar" => redirect{ "/foo/bar" } + get "/foobar" => redirect { "/foo/bar" } end assert_equal [ @@ -303,7 +303,7 @@ module ActionDispatch end def test_routes_can_be_filtered - output = draw('posts') do + output = draw("posts") do resources :articles resources :posts end @@ -320,7 +320,7 @@ module ActionDispatch end def test_routes_can_be_filtered_with_namespaced_controllers - output = draw('admin/posts') do + output = draw("admin/posts") do resources :articles namespace :admin do resources :posts @@ -338,11 +338,10 @@ module ActionDispatch " DELETE /admin/posts/:id(.:format) admin/posts#destroy"], output end - def test_regression_route_with_controller_regexp output = draw do ActiveSupport::Deprecation.silence do - get ':controller(/:action)', controller: /api\/[^\/]+/, format: false + get ":controller(/:action)", controller: /api\/[^\/]+/, format: false end end @@ -354,7 +353,7 @@ module ActionDispatch @set = ActionDispatch::Routing::RouteSet.new output = draw do - get '/cart', to: 'cart#show' + get "/cart", to: "cart#show" end assert_equal [ @@ -364,8 +363,8 @@ module ActionDispatch end def test_routes_with_undefined_filter - output = draw(controller: 'Rails::MissingController') do - get 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/ + output = draw(controller: "Rails::MissingController") do + get "photos/:id" => "photos#show", :id => /[A-Z]\d{5}/ end assert_equal [ @@ -375,8 +374,8 @@ module ActionDispatch end def test_no_routes_matched_filter - output = draw('rails/dummy') do - get 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/ + output = draw("rails/dummy") do + get "photos/:id" => "photos#show", :id => /[A-Z]\d{5}/ end assert_equal [ @@ -386,7 +385,7 @@ module ActionDispatch end def test_no_routes_were_defined - output = draw('Rails::DummyController') {} + output = draw("Rails::DummyController") {} assert_equal [ "You don't have any routes defined!", @@ -404,13 +403,13 @@ module ActionDispatch end end engine.routes.draw do - get '/cart', to: 'cart#show' - post '/cart', to: 'cart#create' - patch '/cart', to: 'cart#update' + get "/cart", to: "cart#show" + post "/cart", to: "cart#create" + patch "/cart", to: "cart#update" end output = draw do - get '/custom/assets', to: 'custom_assets#show' + get "/custom/assets", to: "custom_assets#show" mount engine => "/blog", as: "blog", internal: true end @@ -419,7 +418,6 @@ module ActionDispatch "custom_assets GET /custom/assets(.:format) custom_assets#show", ], output end - end end end diff --git a/actionpack/test/dispatch/routing/ipv6_redirect_test.rb b/actionpack/test/dispatch/routing/ipv6_redirect_test.rb index f1b2e8cfc7..4987ed84e4 100644 --- a/actionpack/test/dispatch/routing/ipv6_redirect_test.rb +++ b/actionpack/test/dispatch/routing/ipv6_redirect_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class IPv6IntegrationTest < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new @@ -7,17 +7,17 @@ class IPv6IntegrationTest < ActionDispatch::IntegrationTest class ::BadRouteRequestController < ActionController::Base include Routes.url_helpers def index - render :text => foo_path + render text: foo_path end def foo - redirect_to :action => :index + redirect_to action: :index end end Routes.draw do - get "/", :to => 'bad_route_request#index', :as => :index - get "/foo", :to => "bad_route_request#foo", :as => :foo + get "/", to: "bad_route_request#index", as: :index + get "/foo", to: "bad_route_request#foo", as: :foo end def _routes @@ -32,14 +32,13 @@ class IPv6IntegrationTest < ActionDispatch::IntegrationTest test "bad IPv6 redirection" do # def test_simple_redirect request_env = { - 'REMOTE_ADDR' => 'fd07:2fa:6cff:2112:225:90ff:fec7:22aa', - 'HTTP_HOST' => '[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000', - 'SERVER_NAME' => '[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]', - 'SERVER_PORT' => 3000 } + "REMOTE_ADDR" => "fd07:2fa:6cff:2112:225:90ff:fec7:22aa", + "HTTP_HOST" => "[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000", + "SERVER_NAME" => "[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]", + "SERVER_PORT" => 3000 } - get '/foo', env: request_env + get "/foo", env: request_env assert_response :redirect - assert_equal 'http://[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000/', redirect_to_url + assert_equal "http://[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000/", redirect_to_url end - end diff --git a/actionpack/test/dispatch/routing/route_set_test.rb b/actionpack/test/dispatch/routing/route_set_test.rb index 9327fe12c6..ace35dda53 100644 --- a/actionpack/test/dispatch/routing/route_set_test.rb +++ b/actionpack/test/dispatch/routing/route_set_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module ActionDispatch module Routing @@ -9,7 +9,7 @@ module ActionDispatch end def call(env) - [ 200, { 'Content-Type' => 'text/plain' }, [response] ] + [ 200, { "Content-Type" => "text/plain" }, [response] ] end end @@ -21,7 +21,7 @@ module ActionDispatch assert empty? draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end assert_not empty? @@ -29,101 +29,101 @@ module ActionDispatch test "url helpers are added when route is added" do draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal '/foo', url_helpers.foo_path + assert_equal "/foo", url_helpers.foo_path assert_raises NoMethodError do - assert_equal '/bar', url_helpers.bar_path + assert_equal "/bar", url_helpers.bar_path end draw do - get 'foo', to: SimpleApp.new('foo#index') - get 'bar', to: SimpleApp.new('bar#index') + get "foo", to: SimpleApp.new("foo#index") + get "bar", to: SimpleApp.new("bar#index") end - assert_equal '/foo', url_helpers.foo_path - assert_equal '/bar', url_helpers.bar_path + assert_equal "/foo", url_helpers.foo_path + assert_equal "/bar", url_helpers.bar_path end test "url helpers are updated when route is updated" do draw do - get 'bar', to: SimpleApp.new('bar#index'), as: :bar + get "bar", to: SimpleApp.new("bar#index"), as: :bar end - assert_equal '/bar', url_helpers.bar_path + assert_equal "/bar", url_helpers.bar_path draw do - get 'baz', to: SimpleApp.new('baz#index'), as: :bar + get "baz", to: SimpleApp.new("baz#index"), as: :bar end - assert_equal '/baz', url_helpers.bar_path + assert_equal "/baz", url_helpers.bar_path end test "url helpers are removed when route is removed" do draw do - get 'foo', to: SimpleApp.new('foo#index') - get 'bar', to: SimpleApp.new('bar#index') + get "foo", to: SimpleApp.new("foo#index") + get "bar", to: SimpleApp.new("bar#index") end - assert_equal '/foo', url_helpers.foo_path - assert_equal '/bar', url_helpers.bar_path + assert_equal "/foo", url_helpers.foo_path + assert_equal "/bar", url_helpers.bar_path draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal '/foo', url_helpers.foo_path + assert_equal "/foo", url_helpers.foo_path assert_raises NoMethodError do - assert_equal '/bar', url_helpers.bar_path + assert_equal "/bar", url_helpers.bar_path end end test "only_path: true with *_url and no :host option" do draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal '/foo', url_helpers.foo_url(only_path: true) + assert_equal "/foo", url_helpers.foo_url(only_path: true) end test "only_path: false with *_url and no :host option" do draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end assert_raises ArgumentError do - assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false) + assert_equal "http://example.com/foo", url_helpers.foo_url(only_path: false) end end test "only_path: false with *_url and local :host option" do draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false, host: 'example.com') + assert_equal "http://example.com/foo", url_helpers.foo_url(only_path: false, host: "example.com") end test "only_path: false with *_url and global :host option" do - @set.default_url_options = { host: 'example.com' } + @set.default_url_options = { host: "example.com" } draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false) + assert_equal "http://example.com/foo", url_helpers.foo_url(only_path: false) end test "explicit keys win over implicit keys" do draw do resources :foo do - resources :bar, to: SimpleApp.new('foo#show') + resources :bar, to: SimpleApp.new("foo#show") end end - assert_equal '/foo/1/bar/2', url_helpers.foo_bar_path(1, 2) - assert_equal '/foo/1/bar/2', url_helpers.foo_bar_path(2, foo_id: 1) + assert_equal "/foo/1/bar/2", url_helpers.foo_bar_path(1, 2) + assert_equal "/foo/1/bar/2", url_helpers.foo_bar_path(2, foo_id: 1) end test "having an optional scope with resources" do @@ -133,9 +133,9 @@ module ActionDispatch end end - assert_equal '/users/1', url_helpers.user_path(1) - assert_equal '/users/1', url_helpers.user_path(1, foo: nil) - assert_equal '/a/users/1', url_helpers.user_path(1, foo: 'a') + assert_equal "/users/1", url_helpers.user_path(1) + assert_equal "/users/1", url_helpers.user_path(1, foo: nil) + assert_equal "/a/users/1", url_helpers.user_path(1, foo: "a") end private diff --git a/actionpack/test/dispatch/routing_assertions_test.rb b/actionpack/test/dispatch/routing_assertions_test.rb index 56ea644f22..917ce7e668 100644 --- a/actionpack/test/dispatch/routing_assertions_test.rb +++ b/actionpack/test/dispatch/routing_assertions_test.rb @@ -1,130 +1,129 @@ -require 'abstract_unit' -require 'controller/fake_controllers' +require "abstract_unit" +require "controller/fake_controllers" class SecureArticlesController < ArticlesController; end class BlockArticlesController < ArticlesController; end class QueryArticlesController < ArticlesController; end class RoutingAssertionsTest < ActionController::TestCase - def setup @routes = ActionDispatch::Routing::RouteSet.new @routes.draw do resources :articles - scope 'secure', :constraints => { :protocol => 'https://' } do - resources :articles, :controller => 'secure_articles' + scope "secure", constraints: { protocol: "https://" } do + resources :articles, controller: "secure_articles" end - scope 'block', :constraints => lambda { |r| r.ssl? } do - resources :articles, :controller => 'block_articles' + scope "block", constraints: lambda { |r| r.ssl? } do + resources :articles, controller: "block_articles" end - scope 'query', :constraints => lambda { |r| r.params[:use_query] == 'true' } do - resources :articles, :controller => 'query_articles' + scope "query", constraints: lambda { |r| r.params[:use_query] == "true" } do + resources :articles, controller: "query_articles" end end end def test_assert_generates - assert_generates('/articles', { :controller => 'articles', :action => 'index' }) - assert_generates('/articles/1', { :controller => 'articles', :action => 'show', :id => '1' }) + assert_generates("/articles", controller: "articles", action: "index") + assert_generates("/articles/1", controller: "articles", action: "show", id: "1") end def test_assert_generates_with_defaults - assert_generates('/articles/1/edit', { :controller => 'articles', :action => 'edit' }, { :id => '1' }) + assert_generates("/articles/1/edit", { controller: "articles", action: "edit" }, id: "1") end def test_assert_generates_with_extras - assert_generates('/articles', { :controller => 'articles', :action => 'index', :page => '1' }, {}, { :page => '1' }) + assert_generates("/articles", { controller: "articles", action: "index", page: "1" }, {}, page: "1") end def test_assert_recognizes - assert_recognizes({ :controller => 'articles', :action => 'index' }, '/articles') - assert_recognizes({ :controller => 'articles', :action => 'show', :id => '1' }, '/articles/1') + assert_recognizes({ controller: "articles", action: "index" }, "/articles") + assert_recognizes({ controller: "articles", action: "show", id: "1" }, "/articles/1") end def test_assert_recognizes_with_extras - assert_recognizes({ :controller => 'articles', :action => 'index', :page => '1' }, '/articles', { :page => '1' }) + assert_recognizes({ controller: "articles", action: "index", page: "1" }, "/articles", page: "1") end def test_assert_recognizes_with_method - assert_recognizes({ :controller => 'articles', :action => 'create' }, { :path => '/articles', :method => :post }) - assert_recognizes({ :controller => 'articles', :action => 'update', :id => '1' }, { :path => '/articles/1', :method => :put }) + assert_recognizes({ controller: "articles", action: "create" }, path: "/articles", method: :post) + assert_recognizes({ controller: "articles", action: "update", id: "1" }, path: "/articles/1", method: :put) end def test_assert_recognizes_with_hash_constraint assert_raise(Assertion) do - assert_recognizes({ :controller => 'secure_articles', :action => 'index' }, 'http://test.host/secure/articles') + assert_recognizes({ controller: "secure_articles", action: "index" }, "http://test.host/secure/articles") end - assert_recognizes({ :controller => 'secure_articles', :action => 'index', :protocol => 'https://' }, 'https://test.host/secure/articles') + assert_recognizes({ controller: "secure_articles", action: "index", protocol: "https://" }, "https://test.host/secure/articles") end def test_assert_recognizes_with_block_constraint assert_raise(Assertion) do - assert_recognizes({ :controller => 'block_articles', :action => 'index' }, 'http://test.host/block/articles') + assert_recognizes({ controller: "block_articles", action: "index" }, "http://test.host/block/articles") end - assert_recognizes({ :controller => 'block_articles', :action => 'index' }, 'https://test.host/block/articles') + assert_recognizes({ controller: "block_articles", action: "index" }, "https://test.host/block/articles") end def test_assert_recognizes_with_query_constraint assert_raise(Assertion) do - assert_recognizes({ :controller => 'query_articles', :action => 'index', :use_query => 'false' }, '/query/articles', { :use_query => 'false' }) + assert_recognizes({ controller: "query_articles", action: "index", use_query: "false" }, "/query/articles", use_query: "false") end - assert_recognizes({ :controller => 'query_articles', :action => 'index', :use_query => 'true' }, '/query/articles', { :use_query => 'true' }) + assert_recognizes({ controller: "query_articles", action: "index", use_query: "true" }, "/query/articles", use_query: "true") end def test_assert_recognizes_raises_message err = assert_raise(Assertion) do - assert_recognizes({ :controller => 'secure_articles', :action => 'index' }, 'http://test.host/secure/articles', {}, "This is a really bad msg") + assert_recognizes({ controller: "secure_articles", action: "index" }, "http://test.host/secure/articles", {}, "This is a really bad msg") end assert_match err.message, "This is a really bad msg" end def test_assert_routing - assert_routing('/articles', :controller => 'articles', :action => 'index') + assert_routing("/articles", controller: "articles", action: "index") end def test_assert_routing_raises_message err = assert_raise(Assertion) do - assert_routing('/thisIsNotARoute', { :controller => 'articles', :action => 'edit', :id => '1' }, { :id => '1' }, {}, "This is a really bad msg") + assert_routing("/thisIsNotARoute", { controller: "articles", action: "edit", id: "1" }, { id: "1" }, {}, "This is a really bad msg") end assert_match err.message, "This is a really bad msg" end def test_assert_routing_with_defaults - assert_routing('/articles/1/edit', { :controller => 'articles', :action => 'edit', :id => '1' }, { :id => '1' }) + assert_routing("/articles/1/edit", { controller: "articles", action: "edit", id: "1" }, id: "1") end def test_assert_routing_with_extras - assert_routing('/articles', { :controller => 'articles', :action => 'index', :page => '1' }, { }, { :page => '1' }) + assert_routing("/articles", { controller: "articles", action: "index", page: "1" }, {}, page: "1") end def test_assert_routing_with_hash_constraint assert_raise(Assertion) do - assert_routing('http://test.host/secure/articles', { :controller => 'secure_articles', :action => 'index' }) + assert_routing("http://test.host/secure/articles", controller: "secure_articles", action: "index") end - assert_routing('https://test.host/secure/articles', { :controller => 'secure_articles', :action => 'index', :protocol => 'https://' }) + assert_routing("https://test.host/secure/articles", controller: "secure_articles", action: "index", protocol: "https://") end def test_assert_routing_with_block_constraint assert_raise(Assertion) do - assert_routing('http://test.host/block/articles', { :controller => 'block_articles', :action => 'index' }) + assert_routing("http://test.host/block/articles", controller: "block_articles", action: "index") end - assert_routing('https://test.host/block/articles', { :controller => 'block_articles', :action => 'index' }) + assert_routing("https://test.host/block/articles", controller: "block_articles", action: "index") end def test_with_routing with_routing do |routes| routes.draw do - resources :articles, :path => 'artikel' + resources :articles, path: "artikel" end - assert_routing('/artikel', :controller => 'articles', :action => 'index') + assert_routing("/artikel", controller: "articles", action: "index") assert_raise(Assertion) do - assert_routing('/articles', { :controller => 'articles', :action => 'index' }) + assert_routing("/articles", controller: "articles", action: "index") end end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index cac89417a5..6ba52e37b6 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -1,10 +1,10 @@ -require 'erb' -require 'abstract_unit' -require 'controller/fake_controllers' +require "erb" +require "abstract_unit" +require "controller/fake_controllers" class TestRoutingMapper < ActionDispatch::IntegrationTest SprocketsApp = lambda { |env| - [200, {"Content-Type" => "text/html"}, ["javascripts"]] + [200, { "Content-Type" => "text/html" }, ["javascripts"]] } class IpRestrictor @@ -28,87 +28,87 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_logout draw do controller :sessions do - delete 'logout' => :destroy + delete "logout" => :destroy end end - delete '/logout' - assert_equal 'sessions#destroy', @response.body + delete "/logout" + assert_equal "sessions#destroy", @response.body - assert_equal '/logout', logout_path - assert_equal '/logout', url_for(:controller => 'sessions', :action => 'destroy', :only_path => true) + assert_equal "/logout", logout_path + assert_equal "/logout", url_for(controller: "sessions", action: "destroy", only_path: true) end def test_login draw do - default_url_options :host => "rubyonrails.org" + default_url_options host: "rubyonrails.org" controller :sessions do - get 'login' => :new - post 'login' => :create + get "login" => :new + post "login" => :create end end - get '/login' - assert_equal 'sessions#new', @response.body - assert_equal '/login', login_path + get "/login" + assert_equal "sessions#new", @response.body + assert_equal "/login", login_path - post '/login' - assert_equal 'sessions#create', @response.body + post "/login" + assert_equal "sessions#create", @response.body - assert_equal '/login', url_for(:controller => 'sessions', :action => 'create', :only_path => true) - assert_equal '/login', url_for(:controller => 'sessions', :action => 'new', :only_path => true) + assert_equal "/login", url_for(controller: "sessions", action: "create", only_path: true) + assert_equal "/login", url_for(controller: "sessions", action: "new", only_path: true) - assert_equal 'http://rubyonrails.org/login', url_for(:controller => 'sessions', :action => 'create') - assert_equal 'http://rubyonrails.org/login', login_url + assert_equal "http://rubyonrails.org/login", url_for(controller: "sessions", action: "create") + assert_equal "http://rubyonrails.org/login", login_url end def test_login_redirect draw do - get 'account/login', :to => redirect("/login") + get "account/login", to: redirect("/login") end - get '/account/login' - verify_redirect 'http://www.example.com/login' + get "/account/login" + verify_redirect "http://www.example.com/login" end def test_logout_redirect_without_to draw do - get 'account/logout' => redirect("/logout"), :as => :logout_redirect + get "account/logout" => redirect("/logout"), :as => :logout_redirect end - assert_equal '/account/logout', logout_redirect_path - get '/account/logout' - verify_redirect 'http://www.example.com/logout' + assert_equal "/account/logout", logout_redirect_path + get "/account/logout" + verify_redirect "http://www.example.com/logout" end def test_namespace_redirect draw do namespace :private do - root :to => redirect('/private/index') - get "index", :to => 'private#index' + root to: redirect("/private/index") + get "index", to: "private#index" end end - get '/private' - verify_redirect 'http://www.example.com/private/index' + get "/private" + verify_redirect "http://www.example.com/private/index" end def test_redirect_with_failing_constraint draw do - get 'hi', to: redirect("/foo"), constraints: ::TestRoutingMapper::GrumpyRestrictor + get "hi", to: redirect("/foo"), constraints: ::TestRoutingMapper::GrumpyRestrictor end - get '/hi' + get "/hi" assert_equal 404, status end def test_redirect_with_passing_constraint draw do - get 'hi', to: redirect("/foo"), constraints: ->(req) { true } + get "hi", to: redirect("/foo"), constraints: ->(req) { true } end - get '/hi' + get "/hi" assert_equal 301, status end @@ -117,7 +117,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest draw do namespace :admin do ActiveSupport::Deprecation.silence do - get '/:controller(/:action(/:id(.:format)))' + get "/:controller(/:action(/:id(.:format)))" end end end @@ -128,12 +128,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest draw do namespace :admin do ActiveSupport::Deprecation.silence do - get 'hello/:controllers/:action' + get "hello/:controllers/:action" end end end - get '/admin/hello/foo/new' - assert_equal 'foo', @request.params["controllers"] + get "/admin/hello/foo/new" + assert_equal "foo", @request.params["controllers"] end def test_session_singleton_resource @@ -144,30 +144,30 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/session' - assert_equal 'sessions#create', @response.body - assert_equal '/session', session_path + get "/session" + assert_equal "sessions#create", @response.body + assert_equal "/session", session_path - post '/session' - assert_equal 'sessions#create', @response.body + post "/session" + assert_equal "sessions#create", @response.body - put '/session' - assert_equal 'sessions#update', @response.body + put "/session" + assert_equal "sessions#update", @response.body - delete '/session' - assert_equal 'sessions#destroy', @response.body + delete "/session" + assert_equal "sessions#destroy", @response.body - get '/session/new' - assert_equal 'sessions#new', @response.body - assert_equal '/session/new', new_session_path + get "/session/new" + assert_equal "sessions#new", @response.body + assert_equal "/session/new", new_session_path - get '/session/edit' - assert_equal 'sessions#edit', @response.body - assert_equal '/session/edit', edit_session_path + get "/session/edit" + assert_equal "sessions#edit", @response.body + assert_equal "/session/edit", edit_session_path - post '/session/reset' - assert_equal 'sessions#reset', @response.body - assert_equal '/session/reset', reset_session_path + post "/session/reset" + assert_equal "sessions#reset", @response.body + assert_equal "/session/reset", reset_session_path end def test_session_singleton_resource_for_api_app @@ -184,28 +184,28 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest @app = RoutedRackApp.new routes end - get '/session' - assert_equal 'sessions#create', @response.body - assert_equal '/session', session_path + get "/session" + assert_equal "sessions#create", @response.body + assert_equal "/session", session_path - post '/session' - assert_equal 'sessions#create', @response.body + post "/session" + assert_equal "sessions#create", @response.body - put '/session' - assert_equal 'sessions#update', @response.body + put "/session" + assert_equal "sessions#update", @response.body - delete '/session' - assert_equal 'sessions#destroy', @response.body + delete "/session" + assert_equal "sessions#destroy", @response.body - post '/session/reset' - assert_equal 'sessions#reset', @response.body - assert_equal '/session/reset', reset_session_path + post "/session/reset" + assert_equal "sessions#reset", @response.body + assert_equal "/session/reset", reset_session_path - get '/session/new' - assert_equal 'Not Found', @response.body + get "/session/new" + assert_equal "Not Found", @response.body - get '/session/edit' - assert_equal 'Not Found', @response.body + get "/session/edit" + assert_equal "Not Found", @response.body end def test_session_info_nested_singleton_resource @@ -215,9 +215,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/session/info' - assert_equal 'infos#show', @response.body - assert_equal '/session/info', session_info_path + get "/session/info" + assert_equal "infos#show", @response.body + assert_equal "/session/info", session_info_path end def test_member_on_resource @@ -229,248 +229,248 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/session/crush' - assert_equal 'sessions#crush', @response.body - assert_equal '/session/crush', crush_session_path + get "/session/crush" + assert_equal "sessions#crush", @response.body + assert_equal "/session/crush", crush_session_path end def test_redirect_modulo draw do - get 'account/modulo/:name', :to => redirect("/%{name}s") + get "account/modulo/:name", to: redirect("/%{name}s") end - get '/account/modulo/name' - verify_redirect 'http://www.example.com/names' + get "/account/modulo/name" + verify_redirect "http://www.example.com/names" end def test_redirect_proc draw do - get 'account/proc/:name', :to => redirect {|params, req| "/#{params[:name].pluralize}" } + get "account/proc/:name", to: redirect { |params, req| "/#{params[:name].pluralize}" } end - get '/account/proc/person' - verify_redirect 'http://www.example.com/people' + get "/account/proc/person" + verify_redirect "http://www.example.com/people" end def test_redirect_proc_with_request draw do - get 'account/proc_req' => redirect {|params, req| "/#{req.method}" } + get "account/proc_req" => redirect { |params, req| "/#{req.method}" } end - get '/account/proc_req' - verify_redirect 'http://www.example.com/GET' + get "/account/proc_req" + verify_redirect "http://www.example.com/GET" end def test_redirect_hash_with_subdomain draw do - get 'mobile', :to => redirect(:subdomain => 'mobile') + get "mobile", to: redirect(subdomain: "mobile") end - get '/mobile' - verify_redirect 'http://mobile.example.com/mobile' + get "/mobile" + verify_redirect "http://mobile.example.com/mobile" end def test_redirect_hash_with_domain_and_path draw do - get 'documentation', :to => redirect(:domain => 'example-documentation.com', :path => '') + get "documentation", to: redirect(domain: "example-documentation.com", path: "") end - get '/documentation' - verify_redirect 'http://www.example-documentation.com' + get "/documentation" + verify_redirect "http://www.example-documentation.com" end def test_redirect_hash_with_path draw do - get 'new_documentation', :to => redirect(:path => '/documentation/new') + get "new_documentation", to: redirect(path: "/documentation/new") end - get '/new_documentation' - verify_redirect 'http://www.example.com/documentation/new' + get "/new_documentation" + verify_redirect "http://www.example.com/documentation/new" end def test_redirect_hash_with_host draw do - get 'super_new_documentation', :to => redirect(:host => 'super-docs.com') + get "super_new_documentation", to: redirect(host: "super-docs.com") end - get '/super_new_documentation?section=top' - verify_redirect 'http://super-docs.com/super_new_documentation?section=top' + get "/super_new_documentation?section=top" + verify_redirect "http://super-docs.com/super_new_documentation?section=top" end def test_redirect_hash_path_substitution draw do - get 'stores/:name', :to => redirect(:subdomain => 'stores', :path => '/%{name}') + get "stores/:name", to: redirect(subdomain: "stores", path: "/%{name}") end - get '/stores/iernest' - verify_redirect 'http://stores.example.com/iernest' + get "/stores/iernest" + verify_redirect "http://stores.example.com/iernest" end def test_redirect_hash_path_substitution_with_catch_all draw do - get 'stores/:name(*rest)', :to => redirect(:subdomain => 'stores', :path => '/%{name}%{rest}') + get "stores/:name(*rest)", to: redirect(subdomain: "stores", path: "/%{name}%{rest}") end - get '/stores/iernest/products' - verify_redirect 'http://stores.example.com/iernest/products' + get "/stores/iernest/products" + verify_redirect "http://stores.example.com/iernest/products" end def test_redirect_class draw do - get 'youtube_favorites/:youtube_id/:name', :to => redirect(YoutubeFavoritesRedirector) + get "youtube_favorites/:youtube_id/:name", to: redirect(YoutubeFavoritesRedirector) end - get '/youtube_favorites/oHg5SJYRHA0/rick-rolld' - verify_redirect 'http://www.youtube.com/watch?v=oHg5SJYRHA0' + get "/youtube_favorites/oHg5SJYRHA0/rick-rolld" + verify_redirect "http://www.youtube.com/watch?v=oHg5SJYRHA0" end def test_openid draw do - match 'openid/login', :via => [:get, :post], :to => "openid#login" + match "openid/login", via: [:get, :post], to: "openid#login" end - get '/openid/login' - assert_equal 'openid#login', @response.body + get "/openid/login" + assert_equal "openid#login", @response.body - post '/openid/login' - assert_equal 'openid#login', @response.body + post "/openid/login" + assert_equal "openid#login", @response.body end def test_bookmarks draw do - scope "bookmark", :controller => "bookmarks", :as => :bookmark do - get :new, :path => "build" - post :create, :path => "create", :as => "" + scope "bookmark", controller: "bookmarks", as: :bookmark do + get :new, path: "build" + post :create, path: "create", as: "" put :update - get :remove, :action => :destroy, :as => :remove + get :remove, action: :destroy, as: :remove end end - get '/bookmark/build' - assert_equal 'bookmarks#new', @response.body - assert_equal '/bookmark/build', bookmark_new_path + get "/bookmark/build" + assert_equal "bookmarks#new", @response.body + assert_equal "/bookmark/build", bookmark_new_path - post '/bookmark/create' - assert_equal 'bookmarks#create', @response.body - assert_equal '/bookmark/create', bookmark_path + post "/bookmark/create" + assert_equal "bookmarks#create", @response.body + assert_equal "/bookmark/create", bookmark_path - put '/bookmark/update' - assert_equal 'bookmarks#update', @response.body - assert_equal '/bookmark/update', bookmark_update_path + put "/bookmark/update" + assert_equal "bookmarks#update", @response.body + assert_equal "/bookmark/update", bookmark_update_path - get '/bookmark/remove' - assert_equal 'bookmarks#destroy', @response.body - assert_equal '/bookmark/remove', bookmark_remove_path + get "/bookmark/remove" + assert_equal "bookmarks#destroy", @response.body + assert_equal "/bookmark/remove", bookmark_remove_path end def test_pagemarks tc = self draw do - scope "pagemark", :controller => "pagemarks", :as => :pagemark do + scope "pagemark", controller: "pagemarks", as: :pagemark do tc.assert_deprecated do - get "new", :path => "build" + get "new", path: "build" end - post "create", :as => "" + post "create", as: "" put "update" - get "remove", :action => :destroy, :as => :remove + get "remove", action: :destroy, as: :remove tc.assert_deprecated do get action: :show, as: :show end end end - get '/pagemark/build' - assert_equal 'pagemarks#new', @response.body - assert_equal '/pagemark/build', pagemark_new_path + get "/pagemark/build" + assert_equal "pagemarks#new", @response.body + assert_equal "/pagemark/build", pagemark_new_path - post '/pagemark/create' - assert_equal 'pagemarks#create', @response.body - assert_equal '/pagemark/create', pagemark_path + post "/pagemark/create" + assert_equal "pagemarks#create", @response.body + assert_equal "/pagemark/create", pagemark_path - put '/pagemark/update' - assert_equal 'pagemarks#update', @response.body - assert_equal '/pagemark/update', pagemark_update_path + put "/pagemark/update" + assert_equal "pagemarks#update", @response.body + assert_equal "/pagemark/update", pagemark_update_path - get '/pagemark/remove' - assert_equal 'pagemarks#destroy', @response.body - assert_equal '/pagemark/remove', pagemark_remove_path + get "/pagemark/remove" + assert_equal "pagemarks#destroy", @response.body + assert_equal "/pagemark/remove", pagemark_remove_path - get '/pagemark' - assert_equal 'pagemarks#show', @response.body - assert_equal '/pagemark', pagemark_show_path + get "/pagemark" + assert_equal "pagemarks#show", @response.body + assert_equal "/pagemark", pagemark_show_path end def test_admin draw do - constraints(:ip => /192\.168\.1\.\d\d\d/) do - get 'admin' => "queenbee#index" + constraints(ip: /192\.168\.1\.\d\d\d/) do + get "admin" => "queenbee#index" end constraints ::TestRoutingMapper::IpRestrictor do - get 'admin/accounts' => "queenbee#accounts" + get "admin/accounts" => "queenbee#accounts" end - get 'admin/passwords' => "queenbee#passwords", :constraints => ::TestRoutingMapper::IpRestrictor + get "admin/passwords" => "queenbee#passwords", :constraints => ::TestRoutingMapper::IpRestrictor end - get '/admin', headers: { 'REMOTE_ADDR' => '192.168.1.100' } - assert_equal 'queenbee#index', @response.body + get "/admin", headers: { "REMOTE_ADDR" => "192.168.1.100" } + assert_equal "queenbee#index", @response.body - get '/admin', headers: { 'REMOTE_ADDR' => '10.0.0.100' } - assert_equal 'pass', @response.headers['X-Cascade'] + get "/admin", headers: { "REMOTE_ADDR" => "10.0.0.100" } + assert_equal "pass", @response.headers["X-Cascade"] - get '/admin/accounts', headers: { 'REMOTE_ADDR' => '192.168.1.100' } - assert_equal 'queenbee#accounts', @response.body + get "/admin/accounts", headers: { "REMOTE_ADDR" => "192.168.1.100" } + assert_equal "queenbee#accounts", @response.body - get '/admin/accounts', headers: { 'REMOTE_ADDR' => '10.0.0.100' } - assert_equal 'pass', @response.headers['X-Cascade'] + get "/admin/accounts", headers: { "REMOTE_ADDR" => "10.0.0.100" } + assert_equal "pass", @response.headers["X-Cascade"] - get '/admin/passwords', headers: { 'REMOTE_ADDR' => '192.168.1.100' } - assert_equal 'queenbee#passwords', @response.body + get "/admin/passwords", headers: { "REMOTE_ADDR" => "192.168.1.100" } + assert_equal "queenbee#passwords", @response.body - get '/admin/passwords', headers: { 'REMOTE_ADDR' => '10.0.0.100' } - assert_equal 'pass', @response.headers['X-Cascade'] + get "/admin/passwords", headers: { "REMOTE_ADDR" => "10.0.0.100" } + assert_equal "pass", @response.headers["X-Cascade"] end def test_global draw do controller(:global) do - get 'global/hide_notice' - get 'global/export', :action => :export, :as => :export_request - get '/export/:id/:file', :action => :export, :as => :export_download, :constraints => { :file => /.*/ } + get "global/hide_notice" + get "global/export", action: :export, as: :export_request + get "/export/:id/:file", action: :export, as: :export_download, constraints: { file: /.*/ } ActiveSupport::Deprecation.silence do - get 'global/:action' + get "global/:action" end end end - get '/global/dashboard' - assert_equal 'global#dashboard', @response.body + get "/global/dashboard" + assert_equal "global#dashboard", @response.body - get '/global/export' - assert_equal 'global#export', @response.body + get "/global/export" + assert_equal "global#export", @response.body - get '/global/hide_notice' - assert_equal 'global#hide_notice', @response.body + get "/global/hide_notice" + assert_equal "global#hide_notice", @response.body - get '/export/123/foo.txt' - assert_equal 'global#export', @response.body + get "/export/123/foo.txt" + assert_equal "global#export", @response.body - assert_equal '/global/export', export_request_path - assert_equal '/global/hide_notice', global_hide_notice_path - assert_equal '/export/123/foo.txt', export_download_path(:id => 123, :file => 'foo.txt') + assert_equal "/global/export", export_request_path + assert_equal "/global/hide_notice", global_hide_notice_path + assert_equal "/export/123/foo.txt", export_download_path(id: 123, file: "foo.txt") end def test_local draw do ActiveSupport::Deprecation.silence do - get "/local/:action", :controller => "local" + get "/local/:action", controller: "local" end end - get '/local/dashboard' - assert_equal 'local#dashboard', @response.body + get "/local/dashboard" + assert_equal "local#dashboard", @response.body end # tests the use of dup in url_for @@ -480,7 +480,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end # without dup, additional (and possibly unwanted) values will be present in the options (eg. :host) - original_options = {:controller => 'projects', :action => 'status'} + original_options = { controller: "projects", action: "status" } options = original_options.dup url_for options @@ -494,23 +494,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects/status(.:format)" end - controller = '/projects' - options = {:controller => controller, :action => 'status', :only_path => true} + controller = "/projects" + options = { controller: controller, action: "status", only_path: true } url = url_for(options) - assert_equal '/projects/status', url - assert_equal '/projects', controller + assert_equal "/projects/status", url + assert_equal "/projects", controller end # tests the arguments modification free version of define_hash_access def test_named_route_with_no_side_effects draw do resources :customers do - get "profile", :on => :member + get "profile", on: :member end end - original_options = { :host => 'test.host' } + original_options = { host: "test.host" } options = original_options.dup profile_customer_url("customer_model", options) @@ -524,45 +524,45 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects/status(.:format)" end - assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true) - assert_equal '/projects/status.json', url_for(:controller => 'projects', :action => 'status', :format => 'json', :only_path => true) + assert_equal "/projects/status", url_for(controller: "projects", action: "status", only_path: true) + assert_equal "/projects/status.json", url_for(controller: "projects", action: "status", format: "json", only_path: true) end def test_projects draw do - resources :projects, :controller => :project + resources :projects, controller: :project end - get '/projects' - assert_equal 'project#index', @response.body - assert_equal '/projects', projects_path + get "/projects" + assert_equal "project#index", @response.body + assert_equal "/projects", projects_path - post '/projects' - assert_equal 'project#create', @response.body + post "/projects" + assert_equal "project#create", @response.body - get '/projects.xml' - assert_equal 'project#index', @response.body - assert_equal '/projects.xml', projects_path(:format => 'xml') + get "/projects.xml" + assert_equal "project#index", @response.body + assert_equal "/projects.xml", projects_path(format: "xml") - get '/projects/new' - assert_equal 'project#new', @response.body - assert_equal '/projects/new', new_project_path + get "/projects/new" + assert_equal "project#new", @response.body + assert_equal "/projects/new", new_project_path - get '/projects/new.xml' - assert_equal 'project#new', @response.body - assert_equal '/projects/new.xml', new_project_path(:format => 'xml') + get "/projects/new.xml" + assert_equal "project#new", @response.body + assert_equal "/projects/new.xml", new_project_path(format: "xml") - get '/projects/1' - assert_equal 'project#show', @response.body - assert_equal '/projects/1', project_path(:id => '1') + get "/projects/1" + assert_equal "project#show", @response.body + assert_equal "/projects/1", project_path(id: "1") - get '/projects/1.xml' - assert_equal 'project#show', @response.body - assert_equal '/projects/1.xml', project_path(:id => '1', :format => 'xml') + get "/projects/1.xml" + assert_equal "project#show", @response.body + assert_equal "/projects/1.xml", project_path(id: "1", format: "xml") - get '/projects/1/edit' - assert_equal 'project#edit', @response.body - assert_equal '/projects/1/edit', edit_project_path(:id => '1') + get "/projects/1/edit" + assert_equal "project#edit", @response.body + assert_equal "/projects/1/edit", edit_project_path(id: "1") end def test_projects_for_api_app @@ -576,166 +576,166 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest @app = RoutedRackApp.new routes end - get '/projects' - assert_equal 'project#index', @response.body - assert_equal '/projects', projects_path + get "/projects" + assert_equal "project#index", @response.body + assert_equal "/projects", projects_path - post '/projects' - assert_equal 'project#create', @response.body + post "/projects" + assert_equal "project#create", @response.body - get '/projects.xml' - assert_equal 'project#index', @response.body - assert_equal '/projects.xml', projects_path(format: 'xml') + get "/projects.xml" + assert_equal "project#index", @response.body + assert_equal "/projects.xml", projects_path(format: "xml") - get '/projects/1' - assert_equal 'project#show', @response.body - assert_equal '/projects/1', project_path(id: '1') + get "/projects/1" + assert_equal "project#show", @response.body + assert_equal "/projects/1", project_path(id: "1") - get '/projects/1.xml' - assert_equal 'project#show', @response.body - assert_equal '/projects/1.xml', project_path(id: '1', format: 'xml') + get "/projects/1.xml" + assert_equal "project#show", @response.body + assert_equal "/projects/1.xml", project_path(id: "1", format: "xml") - get '/projects/1/edit' - assert_equal 'Not Found', @response.body + get "/projects/1/edit" + assert_equal "Not Found", @response.body end def test_projects_with_post_action_and_new_path_on_collection draw do - resources :projects, :controller => :project do - post 'new', :action => 'new', :on => :collection, :as => :new + resources :projects, controller: :project do + post "new", action: "new", on: :collection, as: :new end end - post '/projects/new' + post "/projects/new" assert_equal "project#new", @response.body assert_equal "/projects/new", new_projects_path end def test_projects_involvements draw do - resources :projects, :controller => :project do + resources :projects, controller: :project do resources :involvements, :attachments end end - get '/projects/1/involvements' - assert_equal 'involvements#index', @response.body - assert_equal '/projects/1/involvements', project_involvements_path(:project_id => '1') + get "/projects/1/involvements" + assert_equal "involvements#index", @response.body + assert_equal "/projects/1/involvements", project_involvements_path(project_id: "1") - get '/projects/1/involvements/new' - assert_equal 'involvements#new', @response.body - assert_equal '/projects/1/involvements/new', new_project_involvement_path(:project_id => '1') + get "/projects/1/involvements/new" + assert_equal "involvements#new", @response.body + assert_equal "/projects/1/involvements/new", new_project_involvement_path(project_id: "1") - get '/projects/1/involvements/1' - assert_equal 'involvements#show', @response.body - assert_equal '/projects/1/involvements/1', project_involvement_path(:project_id => '1', :id => '1') + get "/projects/1/involvements/1" + assert_equal "involvements#show", @response.body + assert_equal "/projects/1/involvements/1", project_involvement_path(project_id: "1", id: "1") - put '/projects/1/involvements/1' - assert_equal 'involvements#update', @response.body + put "/projects/1/involvements/1" + assert_equal "involvements#update", @response.body - delete '/projects/1/involvements/1' - assert_equal 'involvements#destroy', @response.body + delete "/projects/1/involvements/1" + assert_equal "involvements#destroy", @response.body - get '/projects/1/involvements/1/edit' - assert_equal 'involvements#edit', @response.body - assert_equal '/projects/1/involvements/1/edit', edit_project_involvement_path(:project_id => '1', :id => '1') + get "/projects/1/involvements/1/edit" + assert_equal "involvements#edit", @response.body + assert_equal "/projects/1/involvements/1/edit", edit_project_involvement_path(project_id: "1", id: "1") end def test_projects_attachments draw do - resources :projects, :controller => :project do + resources :projects, controller: :project do resources :involvements, :attachments end end - get '/projects/1/attachments' - assert_equal 'attachments#index', @response.body - assert_equal '/projects/1/attachments', project_attachments_path(:project_id => '1') + get "/projects/1/attachments" + assert_equal "attachments#index", @response.body + assert_equal "/projects/1/attachments", project_attachments_path(project_id: "1") end def test_projects_participants draw do - resources :projects, :controller => :project do + resources :projects, controller: :project do resources :participants do - put :update_all, :on => :collection + put :update_all, on: :collection end end end - get '/projects/1/participants' - assert_equal 'participants#index', @response.body - assert_equal '/projects/1/participants', project_participants_path(:project_id => '1') + get "/projects/1/participants" + assert_equal "participants#index", @response.body + assert_equal "/projects/1/participants", project_participants_path(project_id: "1") - put '/projects/1/participants/update_all' - assert_equal 'participants#update_all', @response.body - assert_equal '/projects/1/participants/update_all', update_all_project_participants_path(:project_id => '1') + put "/projects/1/participants/update_all" + assert_equal "participants#update_all", @response.body + assert_equal "/projects/1/participants/update_all", update_all_project_participants_path(project_id: "1") end def test_projects_companies draw do - resources :projects, :controller => :project do + resources :projects, controller: :project do resources :companies do resources :people - resource :avatar, :controller => :avatar + resource :avatar, controller: :avatar end end end - get '/projects/1/companies' - assert_equal 'companies#index', @response.body - assert_equal '/projects/1/companies', project_companies_path(:project_id => '1') + get "/projects/1/companies" + assert_equal "companies#index", @response.body + assert_equal "/projects/1/companies", project_companies_path(project_id: "1") - get '/projects/1/companies/1/people' - assert_equal 'people#index', @response.body - assert_equal '/projects/1/companies/1/people', project_company_people_path(:project_id => '1', :company_id => '1') + get "/projects/1/companies/1/people" + assert_equal "people#index", @response.body + assert_equal "/projects/1/companies/1/people", project_company_people_path(project_id: "1", company_id: "1") - get '/projects/1/companies/1/avatar' - assert_equal 'avatar#show', @response.body - assert_equal '/projects/1/companies/1/avatar', project_company_avatar_path(:project_id => '1', :company_id => '1') + get "/projects/1/companies/1/avatar" + assert_equal "avatar#show", @response.body + assert_equal "/projects/1/companies/1/avatar", project_company_avatar_path(project_id: "1", company_id: "1") end def test_project_manager draw do resources :projects do - resource :manager, :as => :super_manager do + resource :manager, as: :super_manager do post :fire end end end - get '/projects/1/manager' - assert_equal 'managers#show', @response.body - assert_equal '/projects/1/manager', project_super_manager_path(:project_id => '1') + get "/projects/1/manager" + assert_equal "managers#show", @response.body + assert_equal "/projects/1/manager", project_super_manager_path(project_id: "1") - get '/projects/1/manager/new' - assert_equal 'managers#new', @response.body - assert_equal '/projects/1/manager/new', new_project_super_manager_path(:project_id => '1') + get "/projects/1/manager/new" + assert_equal "managers#new", @response.body + assert_equal "/projects/1/manager/new", new_project_super_manager_path(project_id: "1") - post '/projects/1/manager/fire' - assert_equal 'managers#fire', @response.body - assert_equal '/projects/1/manager/fire', fire_project_super_manager_path(:project_id => '1') + post "/projects/1/manager/fire" + assert_equal "managers#fire", @response.body + assert_equal "/projects/1/manager/fire", fire_project_super_manager_path(project_id: "1") end def test_project_images draw do resources :projects do - resources :images, :as => :funny_images do - post :revise, :on => :member + resources :images, as: :funny_images do + post :revise, on: :member end end end - get '/projects/1/images' - assert_equal 'images#index', @response.body - assert_equal '/projects/1/images', project_funny_images_path(:project_id => '1') + get "/projects/1/images" + assert_equal "images#index", @response.body + assert_equal "/projects/1/images", project_funny_images_path(project_id: "1") - get '/projects/1/images/new' - assert_equal 'images#new', @response.body - assert_equal '/projects/1/images/new', new_project_funny_image_path(:project_id => '1') + get "/projects/1/images/new" + assert_equal "images#new", @response.body + assert_equal "/projects/1/images/new", new_project_funny_image_path(project_id: "1") - post '/projects/1/images/1/revise' - assert_equal 'images#revise', @response.body - assert_equal '/projects/1/images/1/revise', revise_project_funny_image_path(:project_id => '1', :id => '1') + post "/projects/1/images/1/revise" + assert_equal "images#revise", @response.body + assert_equal "/projects/1/images/1/revise", revise_project_funny_image_path(project_id: "1", id: "1") end def test_projects_people @@ -756,181 +756,181 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/projects/1/people' - assert_equal 'people#index', @response.body - assert_equal '/projects/1/people', project_people_path(:project_id => '1') + get "/projects/1/people" + assert_equal "people#index", @response.body + assert_equal "/projects/1/people", project_people_path(project_id: "1") - get '/projects/1/people/1' - assert_equal 'people#show', @response.body - assert_equal '/projects/1/people/1', project_person_path(:project_id => '1', :id => '1') + get "/projects/1/people/1" + assert_equal "people#show", @response.body + assert_equal "/projects/1/people/1", project_person_path(project_id: "1", id: "1") - get '/projects/1/people/1/7a2dec8/avatar' - assert_equal 'avatars#show', @response.body - assert_equal '/projects/1/people/1/7a2dec8/avatar', project_person_avatar_path(:project_id => '1', :person_id => '1', :access_token => '7a2dec8') + get "/projects/1/people/1/7a2dec8/avatar" + assert_equal "avatars#show", @response.body + assert_equal "/projects/1/people/1/7a2dec8/avatar", project_person_avatar_path(project_id: "1", person_id: "1", access_token: "7a2dec8") - put '/projects/1/people/1/accessible_projects' - assert_equal 'people#accessible_projects', @response.body - assert_equal '/projects/1/people/1/accessible_projects', accessible_projects_project_person_path(:project_id => '1', :id => '1') + put "/projects/1/people/1/accessible_projects" + assert_equal "people#accessible_projects", @response.body + assert_equal "/projects/1/people/1/accessible_projects", accessible_projects_project_person_path(project_id: "1", id: "1") - post '/projects/1/people/1/resend' - assert_equal 'people#resend', @response.body - assert_equal '/projects/1/people/1/resend', resend_project_person_path(:project_id => '1', :id => '1') + post "/projects/1/people/1/resend" + assert_equal "people#resend", @response.body + assert_equal "/projects/1/people/1/resend", resend_project_person_path(project_id: "1", id: "1") - post '/projects/1/people/1/generate_new_password' - assert_equal 'people#generate_new_password', @response.body - assert_equal '/projects/1/people/1/generate_new_password', generate_new_password_project_person_path(:project_id => '1', :id => '1') + post "/projects/1/people/1/generate_new_password" + assert_equal "people#generate_new_password", @response.body + assert_equal "/projects/1/people/1/generate_new_password", generate_new_password_project_person_path(project_id: "1", id: "1") end def test_projects_with_resources_path_names draw do - resources_path_names :correlation_indexes => "info_about_correlation_indexes" + resources_path_names correlation_indexes: "info_about_correlation_indexes" resources :projects do - get :correlation_indexes, :on => :collection + get :correlation_indexes, on: :collection end end - get '/projects/info_about_correlation_indexes' - assert_equal 'projects#correlation_indexes', @response.body - assert_equal '/projects/info_about_correlation_indexes', correlation_indexes_projects_path + get "/projects/info_about_correlation_indexes" + assert_equal "projects#correlation_indexes", @response.body + assert_equal "/projects/info_about_correlation_indexes", correlation_indexes_projects_path end def test_projects_posts draw do resources :projects do resources :posts do - get :archive, :toggle_view, :on => :collection - post :preview, :on => :member + get :archive, :toggle_view, on: :collection + post :preview, on: :member resource :subscription resources :comments do - post :preview, :on => :collection + post :preview, on: :collection end end end end - get '/projects/1/posts' - assert_equal 'posts#index', @response.body - assert_equal '/projects/1/posts', project_posts_path(:project_id => '1') + get "/projects/1/posts" + assert_equal "posts#index", @response.body + assert_equal "/projects/1/posts", project_posts_path(project_id: "1") - get '/projects/1/posts/archive' - assert_equal 'posts#archive', @response.body - assert_equal '/projects/1/posts/archive', archive_project_posts_path(:project_id => '1') + get "/projects/1/posts/archive" + assert_equal "posts#archive", @response.body + assert_equal "/projects/1/posts/archive", archive_project_posts_path(project_id: "1") - get '/projects/1/posts/toggle_view' - assert_equal 'posts#toggle_view', @response.body - assert_equal '/projects/1/posts/toggle_view', toggle_view_project_posts_path(:project_id => '1') + get "/projects/1/posts/toggle_view" + assert_equal "posts#toggle_view", @response.body + assert_equal "/projects/1/posts/toggle_view", toggle_view_project_posts_path(project_id: "1") - post '/projects/1/posts/1/preview' - assert_equal 'posts#preview', @response.body - assert_equal '/projects/1/posts/1/preview', preview_project_post_path(:project_id => '1', :id => '1') + post "/projects/1/posts/1/preview" + assert_equal "posts#preview", @response.body + assert_equal "/projects/1/posts/1/preview", preview_project_post_path(project_id: "1", id: "1") - get '/projects/1/posts/1/subscription' - assert_equal 'subscriptions#show', @response.body - assert_equal '/projects/1/posts/1/subscription', project_post_subscription_path(:project_id => '1', :post_id => '1') + get "/projects/1/posts/1/subscription" + assert_equal "subscriptions#show", @response.body + assert_equal "/projects/1/posts/1/subscription", project_post_subscription_path(project_id: "1", post_id: "1") - get '/projects/1/posts/1/comments' - assert_equal 'comments#index', @response.body - assert_equal '/projects/1/posts/1/comments', project_post_comments_path(:project_id => '1', :post_id => '1') + get "/projects/1/posts/1/comments" + assert_equal "comments#index", @response.body + assert_equal "/projects/1/posts/1/comments", project_post_comments_path(project_id: "1", post_id: "1") - post '/projects/1/posts/1/comments/preview' - assert_equal 'comments#preview', @response.body - assert_equal '/projects/1/posts/1/comments/preview', preview_project_post_comments_path(:project_id => '1', :post_id => '1') + post "/projects/1/posts/1/comments/preview" + assert_equal "comments#preview", @response.body + assert_equal "/projects/1/posts/1/comments/preview", preview_project_post_comments_path(project_id: "1", post_id: "1") end def test_replies draw do resources :replies do member do - put :answer, :action => :mark_as_answer - delete :answer, :action => :unmark_as_answer + put :answer, action: :mark_as_answer + delete :answer, action: :unmark_as_answer end end end - put '/replies/1/answer' - assert_equal 'replies#mark_as_answer', @response.body + put "/replies/1/answer" + assert_equal "replies#mark_as_answer", @response.body - delete '/replies/1/answer' - assert_equal 'replies#unmark_as_answer', @response.body + delete "/replies/1/answer" + assert_equal "replies#unmark_as_answer", @response.body end def test_resource_routes_with_only_and_except draw do - resources :posts, :only => [:index, :show] do - resources :comments, :except => :destroy + resources :posts, only: [:index, :show] do + resources :comments, except: :destroy end end - get '/posts' - assert_equal 'posts#index', @response.body - assert_equal '/posts', posts_path + get "/posts" + assert_equal "posts#index", @response.body + assert_equal "/posts", posts_path - get '/posts/1' - assert_equal 'posts#show', @response.body - assert_equal '/posts/1', post_path(:id => 1) + get "/posts/1" + assert_equal "posts#show", @response.body + assert_equal "/posts/1", post_path(id: 1) - get '/posts/1/comments' - assert_equal 'comments#index', @response.body - assert_equal '/posts/1/comments', post_comments_path(:post_id => 1) + get "/posts/1/comments" + assert_equal "comments#index", @response.body + assert_equal "/posts/1/comments", post_comments_path(post_id: 1) - post '/posts' - assert_equal 'pass', @response.headers['X-Cascade'] - put '/posts/1' - assert_equal 'pass', @response.headers['X-Cascade'] - delete '/posts/1' - assert_equal 'pass', @response.headers['X-Cascade'] - delete '/posts/1/comments' - assert_equal 'pass', @response.headers['X-Cascade'] + post "/posts" + assert_equal "pass", @response.headers["X-Cascade"] + put "/posts/1" + assert_equal "pass", @response.headers["X-Cascade"] + delete "/posts/1" + assert_equal "pass", @response.headers["X-Cascade"] + delete "/posts/1/comments" + assert_equal "pass", @response.headers["X-Cascade"] end def test_resource_routes_only_create_update_destroy draw do - resource :past, :only => :destroy - resource :present, :only => :update - resource :future, :only => :create + resource :past, only: :destroy + resource :present, only: :update + resource :future, only: :create end - delete '/past' - assert_equal 'pasts#destroy', @response.body - assert_equal '/past', past_path + delete "/past" + assert_equal "pasts#destroy", @response.body + assert_equal "/past", past_path - patch '/present' - assert_equal 'presents#update', @response.body - assert_equal '/present', present_path + patch "/present" + assert_equal "presents#update", @response.body + assert_equal "/present", present_path - put '/present' - assert_equal 'presents#update', @response.body - assert_equal '/present', present_path + put "/present" + assert_equal "presents#update", @response.body + assert_equal "/present", present_path - post '/future' - assert_equal 'futures#create', @response.body - assert_equal '/future', future_path + post "/future" + assert_equal "futures#create", @response.body + assert_equal "/future", future_path end def test_resources_routes_only_create_update_destroy draw do - resources :relationships, :only => [:create, :destroy] - resources :friendships, :only => [:update] + resources :relationships, only: [:create, :destroy] + resources :friendships, only: [:update] end - post '/relationships' - assert_equal 'relationships#create', @response.body - assert_equal '/relationships', relationships_path + post "/relationships" + assert_equal "relationships#create", @response.body + assert_equal "/relationships", relationships_path - delete '/relationships/1' - assert_equal 'relationships#destroy', @response.body - assert_equal '/relationships/1', relationship_path(1) + delete "/relationships/1" + assert_equal "relationships#destroy", @response.body + assert_equal "/relationships/1", relationship_path(1) - patch '/friendships/1' - assert_equal 'friendships#update', @response.body - assert_equal '/friendships/1', friendship_path(1) + patch "/friendships/1" + assert_equal "friendships#update", @response.body + assert_equal "/friendships/1", friendship_path(1) - put '/friendships/1' - assert_equal 'friendships#update', @response.body - assert_equal '/friendships/1', friendship_path(1) + put "/friendships/1" + assert_equal "friendships#update", @response.body + assert_equal "/friendships/1", friendship_path(1) end def test_resource_with_slugs_in_ids @@ -938,153 +938,153 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :posts end - get '/posts/rails-rocks' - assert_equal 'posts#show', @response.body - assert_equal '/posts/rails-rocks', post_path(:id => 'rails-rocks') + get "/posts/rails-rocks" + assert_equal "posts#show", @response.body + assert_equal "/posts/rails-rocks", post_path(id: "rails-rocks") end def test_resources_for_uncountable_names draw do resources :sheep do - get "_it", :on => :member + get "_it", on: :member end end - assert_equal '/sheep', sheep_index_path - assert_equal '/sheep/1', sheep_path(1) - assert_equal '/sheep/new', new_sheep_path - assert_equal '/sheep/1/edit', edit_sheep_path(1) - assert_equal '/sheep/1/_it', _it_sheep_path(1) + assert_equal "/sheep", sheep_index_path + assert_equal "/sheep/1", sheep_path(1) + assert_equal "/sheep/new", new_sheep_path + assert_equal "/sheep/1/edit", edit_sheep_path(1) + assert_equal "/sheep/1/_it", _it_sheep_path(1) end def test_resource_does_not_modify_passed_options - options = {:id => /.+?/, :format => /json|xml/} + options = { id: /.+?/, format: /json|xml/ } draw { resource :user, options } - assert_equal({:id => /.+?/, :format => /json|xml/}, options) + assert_equal({ id: /.+?/, format: /json|xml/ }, options) end def test_resources_does_not_modify_passed_options - options = {:id => /.+?/, :format => /json|xml/} + options = { id: /.+?/, format: /json|xml/ } draw { resources :users, options } - assert_equal({:id => /.+?/, :format => /json|xml/}, options) + assert_equal({ id: /.+?/, format: /json|xml/ }, options) end def test_path_names draw do - scope 'pt', :as => 'pt' do - resources :projects, :path_names => { :edit => 'editar', :new => 'novo' }, :path => 'projetos' - resource :admin, :path_names => { :new => 'novo', :activate => 'ativar' }, :path => 'administrador' do - put :activate, :on => :member + scope "pt", as: "pt" do + resources :projects, path_names: { edit: "editar", new: "novo" }, path: "projetos" + resource :admin, path_names: { new: "novo", activate: "ativar" }, path: "administrador" do + put :activate, on: :member end end end - get '/pt/projetos' - assert_equal 'projects#index', @response.body - assert_equal '/pt/projetos', pt_projects_path + get "/pt/projetos" + assert_equal "projects#index", @response.body + assert_equal "/pt/projetos", pt_projects_path - get '/pt/projetos/1/editar' - assert_equal 'projects#edit', @response.body - assert_equal '/pt/projetos/1/editar', edit_pt_project_path(1) + get "/pt/projetos/1/editar" + assert_equal "projects#edit", @response.body + assert_equal "/pt/projetos/1/editar", edit_pt_project_path(1) - get '/pt/administrador' - assert_equal 'admins#show', @response.body - assert_equal '/pt/administrador', pt_admin_path + get "/pt/administrador" + assert_equal "admins#show", @response.body + assert_equal "/pt/administrador", pt_admin_path - get '/pt/administrador/novo' - assert_equal 'admins#new', @response.body - assert_equal '/pt/administrador/novo', new_pt_admin_path + get "/pt/administrador/novo" + assert_equal "admins#new", @response.body + assert_equal "/pt/administrador/novo", new_pt_admin_path - put '/pt/administrador/ativar' - assert_equal 'admins#activate', @response.body - assert_equal '/pt/administrador/ativar', activate_pt_admin_path + put "/pt/administrador/ativar" + assert_equal "admins#activate", @response.body + assert_equal "/pt/administrador/ativar", activate_pt_admin_path end def test_path_option_override draw do - scope 'pt', :as => 'pt' do - resources :projects, :path_names => { :new => 'novo' }, :path => 'projetos' do - put :close, :on => :member, :path => 'fechar' - get :open, :on => :new, :path => 'abrir' + scope "pt", as: "pt" do + resources :projects, path_names: { new: "novo" }, path: "projetos" do + put :close, on: :member, path: "fechar" + get :open, on: :new, path: "abrir" end end end - get '/pt/projetos/novo/abrir' - assert_equal 'projects#open', @response.body - assert_equal '/pt/projetos/novo/abrir', open_new_pt_project_path + get "/pt/projetos/novo/abrir" + assert_equal "projects#open", @response.body + assert_equal "/pt/projetos/novo/abrir", open_new_pt_project_path - put '/pt/projetos/1/fechar' - assert_equal 'projects#close', @response.body - assert_equal '/pt/projetos/1/fechar', close_pt_project_path(1) + put "/pt/projetos/1/fechar" + assert_equal "projects#close", @response.body + assert_equal "/pt/projetos/1/fechar", close_pt_project_path(1) end def test_sprockets draw do - get 'sprockets.js' => ::TestRoutingMapper::SprocketsApp + get "sprockets.js" => ::TestRoutingMapper::SprocketsApp end - get '/sprockets.js' - assert_equal 'javascripts', @response.body + get "/sprockets.js" + assert_equal "javascripts", @response.body end def test_update_person_route draw do - get 'people/:id/update', :to => 'people#update', :as => :update_person + get "people/:id/update", to: "people#update", as: :update_person end - get '/people/1/update' - assert_equal 'people#update', @response.body + get "/people/1/update" + assert_equal "people#update", @response.body - assert_equal '/people/1/update', update_person_path(:id => 1) + assert_equal "/people/1/update", update_person_path(id: 1) end def test_update_project_person draw do - get '/projects/:project_id/people/:id/update', :to => 'people#update', :as => :update_project_person + get "/projects/:project_id/people/:id/update", to: "people#update", as: :update_project_person end - get '/projects/1/people/2/update' - assert_equal 'people#update', @response.body + get "/projects/1/people/2/update" + assert_equal "people#update", @response.body - assert_equal '/projects/1/people/2/update', update_project_person_path(:project_id => 1, :id => 2) + assert_equal "/projects/1/people/2/update", update_project_person_path(project_id: 1, id: 2) end def test_forum_products draw do namespace :forum do - resources :products, :path => '' do + resources :products, path: "" do resources :questions end end end - get '/forum' - assert_equal 'forum/products#index', @response.body - assert_equal '/forum', forum_products_path + get "/forum" + assert_equal "forum/products#index", @response.body + assert_equal "/forum", forum_products_path - get '/forum/basecamp' - assert_equal 'forum/products#show', @response.body - assert_equal '/forum/basecamp', forum_product_path(:id => 'basecamp') + get "/forum/basecamp" + assert_equal "forum/products#show", @response.body + assert_equal "/forum/basecamp", forum_product_path(id: "basecamp") - get '/forum/basecamp/questions' - assert_equal 'forum/questions#index', @response.body - assert_equal '/forum/basecamp/questions', forum_product_questions_path(:product_id => 'basecamp') + get "/forum/basecamp/questions" + assert_equal "forum/questions#index", @response.body + assert_equal "/forum/basecamp/questions", forum_product_questions_path(product_id: "basecamp") - get '/forum/basecamp/questions/1' - assert_equal 'forum/questions#show', @response.body - assert_equal '/forum/basecamp/questions/1', forum_product_question_path(:product_id => 'basecamp', :id => 1) + get "/forum/basecamp/questions/1" + assert_equal "forum/questions#show", @response.body + assert_equal "/forum/basecamp/questions/1", forum_product_question_path(product_id: "basecamp", id: 1) end def test_articles_perma draw do - get 'articles/:year/:month/:day/:title', :to => "articles#show", :as => :article + get "articles/:year/:month/:day/:title", to: "articles#show", as: :article end - get '/articles/2009/08/18/rails-3' - assert_equal 'articles#show', @response.body + get "/articles/2009/08/18/rails-3" + assert_equal "articles#show", @response.body - assert_equal '/articles/2009/8/18/rails-3', article_path(:year => 2009, :month => 8, :day => 18, :title => 'rails-3') + assert_equal "/articles/2009/8/18/rails-3", article_path(year: 2009, month: 8, day: 18, title: "rails-3") end def test_account_namespace @@ -1094,17 +1094,17 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/account/subscription' - assert_equal 'account/subscriptions#show', @response.body - assert_equal '/account/subscription', account_subscription_path + get "/account/subscription" + assert_equal "account/subscriptions#show", @response.body + assert_equal "/account/subscription", account_subscription_path - get '/account/credit' - assert_equal 'account/credits#show', @response.body - assert_equal '/account/credit', account_credit_path + get "/account/credit" + assert_equal "account/credits#show", @response.body + assert_equal "/account/credit", account_credit_path - get '/account/credit_card' - assert_equal 'account/credit_cards#show', @response.body - assert_equal '/account/credit_card', account_credit_card_path + get "/account/credit_card" + assert_equal "account/credit_cards#show", @response.body + assert_equal "/account/credit_card", account_credit_card_path end def test_nested_namespace @@ -1116,9 +1116,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/account/admin/subscription' - assert_equal 'account/admin/subscriptions#show', @response.body - assert_equal '/account/admin/subscription', account_admin_subscription_path + get "/account/admin/subscription" + assert_equal "account/admin/subscriptions#show", @response.body + assert_equal "/account/admin/subscription", account_admin_subscription_path end def test_namespace_nested_in_resources @@ -1134,155 +1134,155 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/clients/1/google/account' - assert_equal '/clients/1/google/account', client_google_account_path(1) - assert_equal 'google/accounts#show', @response.body + get "/clients/1/google/account" + assert_equal "/clients/1/google/account", client_google_account_path(1) + assert_equal "google/accounts#show", @response.body - get '/clients/1/google/account/secret/info' - assert_equal '/clients/1/google/account/secret/info', client_google_account_secret_info_path(1) - assert_equal 'google/secret/infos#show', @response.body + get "/clients/1/google/account/secret/info" + assert_equal "/clients/1/google/account/secret/info", client_google_account_secret_info_path(1) + assert_equal "google/secret/infos#show", @response.body end def test_namespace_with_options draw do - namespace :users, :path => 'usuarios' do - root :to => 'home#index' + namespace :users, path: "usuarios" do + root to: "home#index" end end - get '/usuarios' - assert_equal '/usuarios', users_root_path - assert_equal 'users/home#index', @response.body + get "/usuarios" + assert_equal "/usuarios", users_root_path + assert_equal "users/home#index", @response.body end def test_namespaced_shallow_routes_with_module_option draw do - namespace :foo, module: 'bar' do + namespace :foo, module: "bar" do resources :posts, only: [:index, :show] do resources :comments, only: [:index, :show], shallow: true end end end - get '/foo/posts' - assert_equal '/foo/posts', foo_posts_path - assert_equal 'bar/posts#index', @response.body + get "/foo/posts" + assert_equal "/foo/posts", foo_posts_path + assert_equal "bar/posts#index", @response.body - get '/foo/posts/1' - assert_equal '/foo/posts/1', foo_post_path('1') - assert_equal 'bar/posts#show', @response.body + get "/foo/posts/1" + assert_equal "/foo/posts/1", foo_post_path("1") + assert_equal "bar/posts#show", @response.body - get '/foo/posts/1/comments' - assert_equal '/foo/posts/1/comments', foo_post_comments_path('1') - assert_equal 'bar/comments#index', @response.body + get "/foo/posts/1/comments" + assert_equal "/foo/posts/1/comments", foo_post_comments_path("1") + assert_equal "bar/comments#index", @response.body - get '/foo/comments/2' - assert_equal '/foo/comments/2', foo_comment_path('2') - assert_equal 'bar/comments#show', @response.body + get "/foo/comments/2" + assert_equal "/foo/comments/2", foo_comment_path("2") + assert_equal "bar/comments#show", @response.body end def test_namespaced_shallow_routes_with_path_option draw do - namespace :foo, path: 'bar' do + namespace :foo, path: "bar" do resources :posts, only: [:index, :show] do resources :comments, only: [:index, :show], shallow: true end end end - get '/bar/posts' - assert_equal '/bar/posts', foo_posts_path - assert_equal 'foo/posts#index', @response.body + get "/bar/posts" + assert_equal "/bar/posts", foo_posts_path + assert_equal "foo/posts#index", @response.body - get '/bar/posts/1' - assert_equal '/bar/posts/1', foo_post_path('1') - assert_equal 'foo/posts#show', @response.body + get "/bar/posts/1" + assert_equal "/bar/posts/1", foo_post_path("1") + assert_equal "foo/posts#show", @response.body - get '/bar/posts/1/comments' - assert_equal '/bar/posts/1/comments', foo_post_comments_path('1') - assert_equal 'foo/comments#index', @response.body + get "/bar/posts/1/comments" + assert_equal "/bar/posts/1/comments", foo_post_comments_path("1") + assert_equal "foo/comments#index", @response.body - get '/bar/comments/2' - assert_equal '/bar/comments/2', foo_comment_path('2') - assert_equal 'foo/comments#show', @response.body + get "/bar/comments/2" + assert_equal "/bar/comments/2", foo_comment_path("2") + assert_equal "foo/comments#show", @response.body end def test_namespaced_shallow_routes_with_as_option draw do - namespace :foo, as: 'bar' do + namespace :foo, as: "bar" do resources :posts, only: [:index, :show] do resources :comments, only: [:index, :show], shallow: true end end end - get '/foo/posts' - assert_equal '/foo/posts', bar_posts_path - assert_equal 'foo/posts#index', @response.body + get "/foo/posts" + assert_equal "/foo/posts", bar_posts_path + assert_equal "foo/posts#index", @response.body - get '/foo/posts/1' - assert_equal '/foo/posts/1', bar_post_path('1') - assert_equal 'foo/posts#show', @response.body + get "/foo/posts/1" + assert_equal "/foo/posts/1", bar_post_path("1") + assert_equal "foo/posts#show", @response.body - get '/foo/posts/1/comments' - assert_equal '/foo/posts/1/comments', bar_post_comments_path('1') - assert_equal 'foo/comments#index', @response.body + get "/foo/posts/1/comments" + assert_equal "/foo/posts/1/comments", bar_post_comments_path("1") + assert_equal "foo/comments#index", @response.body - get '/foo/comments/2' - assert_equal '/foo/comments/2', bar_comment_path('2') - assert_equal 'foo/comments#show', @response.body + get "/foo/comments/2" + assert_equal "/foo/comments/2", bar_comment_path("2") + assert_equal "foo/comments#show", @response.body end def test_namespaced_shallow_routes_with_shallow_path_option draw do - namespace :foo, shallow_path: 'bar' do + namespace :foo, shallow_path: "bar" do resources :posts, only: [:index, :show] do resources :comments, only: [:index, :show], shallow: true end end end - get '/foo/posts' - assert_equal '/foo/posts', foo_posts_path - assert_equal 'foo/posts#index', @response.body + get "/foo/posts" + assert_equal "/foo/posts", foo_posts_path + assert_equal "foo/posts#index", @response.body - get '/foo/posts/1' - assert_equal '/foo/posts/1', foo_post_path('1') - assert_equal 'foo/posts#show', @response.body + get "/foo/posts/1" + assert_equal "/foo/posts/1", foo_post_path("1") + assert_equal "foo/posts#show", @response.body - get '/foo/posts/1/comments' - assert_equal '/foo/posts/1/comments', foo_post_comments_path('1') - assert_equal 'foo/comments#index', @response.body + get "/foo/posts/1/comments" + assert_equal "/foo/posts/1/comments", foo_post_comments_path("1") + assert_equal "foo/comments#index", @response.body - get '/bar/comments/2' - assert_equal '/bar/comments/2', foo_comment_path('2') - assert_equal 'foo/comments#show', @response.body + get "/bar/comments/2" + assert_equal "/bar/comments/2", foo_comment_path("2") + assert_equal "foo/comments#show", @response.body end def test_namespaced_shallow_routes_with_shallow_prefix_option draw do - namespace :foo, shallow_prefix: 'bar' do + namespace :foo, shallow_prefix: "bar" do resources :posts, only: [:index, :show] do resources :comments, only: [:index, :show], shallow: true end end end - get '/foo/posts' - assert_equal '/foo/posts', foo_posts_path - assert_equal 'foo/posts#index', @response.body + get "/foo/posts" + assert_equal "/foo/posts", foo_posts_path + assert_equal "foo/posts#index", @response.body - get '/foo/posts/1' - assert_equal '/foo/posts/1', foo_post_path('1') - assert_equal 'foo/posts#show', @response.body + get "/foo/posts/1" + assert_equal "/foo/posts/1", foo_post_path("1") + assert_equal "foo/posts#show", @response.body - get '/foo/posts/1/comments' - assert_equal '/foo/posts/1/comments', foo_post_comments_path('1') - assert_equal 'foo/comments#index', @response.body + get "/foo/posts/1/comments" + assert_equal "/foo/posts/1/comments", foo_post_comments_path("1") + assert_equal "foo/comments#index", @response.body - get '/foo/comments/2' - assert_equal '/foo/comments/2', bar_comment_path('2') - assert_equal 'foo/comments#show', @response.body + get "/foo/comments/2" + assert_equal "/foo/comments/2", bar_comment_path("2") + assert_equal "foo/comments#show", @response.body end def test_namespace_containing_numbers @@ -1292,81 +1292,81 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/v2/subscriptions' - assert_equal 'v2/subscriptions#index', @response.body - assert_equal '/v2/subscriptions', v2_subscriptions_path + get "/v2/subscriptions" + assert_equal "v2/subscriptions#index", @response.body + assert_equal "/v2/subscriptions", v2_subscriptions_path end def test_articles_with_id draw do controller :articles do - scope '/articles', :as => 'article' do - scope :path => '/:title', :title => /[a-z]+/, :as => :with_title do - get '/:id', :action => :with_id, :as => "" + scope "/articles", as: "article" do + scope path: "/:title", title: /[a-z]+/, as: :with_title do + get "/:id", action: :with_id, as: "" end end end end - get '/articles/rails/1' - assert_equal 'articles#with_id', @response.body + get "/articles/rails/1" + assert_equal "articles#with_id", @response.body - get '/articles/123/1' - assert_equal 'pass', @response.headers['X-Cascade'] + get "/articles/123/1" + assert_equal "pass", @response.headers["X-Cascade"] - assert_equal '/articles/rails/1', article_with_title_path(:title => 'rails', :id => 1) + assert_equal "/articles/rails/1", article_with_title_path(title: "rails", id: 1) end def test_access_token_rooms draw do - scope ':access_token', :constraints => { :access_token => /\w{5,5}/ } do + scope ":access_token", constraints: { access_token: /\w{5,5}/ } do resources :rooms end end - get '/12345/rooms' - assert_equal 'rooms#index', @response.body + get "/12345/rooms" + assert_equal "rooms#index", @response.body - get '/12345/rooms/1' - assert_equal 'rooms#show', @response.body + get "/12345/rooms/1" + assert_equal "rooms#show", @response.body - get '/12345/rooms/1/edit' - assert_equal 'rooms#edit', @response.body + get "/12345/rooms/1/edit" + assert_equal "rooms#edit", @response.body end def test_root draw do - root :to => 'projects#index' + root to: "projects#index" end - assert_equal '/', root_path - get '/' - assert_equal 'projects#index', @response.body + assert_equal "/", root_path + get "/" + assert_equal "projects#index", @response.body end def test_scoped_root draw do - scope '(:locale)', :locale => /en|pl/ do - root :to => 'projects#index' + scope "(:locale)", locale: /en|pl/ do + root to: "projects#index" end end - assert_equal '/en', root_path(:locale => 'en') - get '/en' - assert_equal 'projects#index', @response.body + assert_equal "/en", root_path(locale: "en") + get "/en" + assert_equal "projects#index", @response.body end def test_scoped_root_as_name draw do - scope '(:locale)', :locale => /en|pl/ do - root :to => 'projects#index', :as => 'projects' + scope "(:locale)", locale: /en|pl/ do + root to: "projects#index", as: "projects" end end - assert_equal '/en', projects_path(:locale => 'en') - assert_equal '/', projects_path - get '/en' - assert_equal 'projects#index', @response.body + assert_equal "/en", projects_path(locale: "en") + assert_equal "/", projects_path + get "/en" + assert_equal "projects#index", @response.body end def test_scope_with_format_option @@ -1384,10 +1384,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal "/scoped/index", no_format_scoped_path assert_equal "/scoped/index?format=html", no_format_scoped_path(format: "html") - get '/scoped/index' + get "/scoped/index" assert_equal "scoped#index", @response.body - get '/scoped/index.html' + get "/scoped/index.html" assert_equal "Not Found", @response.body end @@ -1422,63 +1422,63 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_index draw do - get '/info' => 'projects#info', :as => 'info' + get "/info" => "projects#info", :as => "info" end - assert_equal '/info', info_path - get '/info' - assert_equal 'projects#info', @response.body + assert_equal "/info", info_path + get "/info" + assert_equal "projects#info", @response.body end def test_match_with_many_paths_containing_a_slash draw do - get 'get/first', 'get/second', 'get/third', :to => 'get#show' + get "get/first", "get/second", "get/third", to: "get#show" end - get '/get/first' - assert_equal 'get#show', @response.body + get "/get/first" + assert_equal "get#show", @response.body - get '/get/second' - assert_equal 'get#show', @response.body + get "/get/second" + assert_equal "get#show", @response.body - get '/get/third' - assert_equal 'get#show', @response.body + get "/get/third" + assert_equal "get#show", @response.body end def test_match_shorthand_with_no_scope draw do - get 'account/overview' + get "account/overview" end - assert_equal '/account/overview', account_overview_path - get '/account/overview' - assert_equal 'account#overview', @response.body + assert_equal "/account/overview", account_overview_path + get "/account/overview" + assert_equal "account#overview", @response.body end def test_match_shorthand_inside_namespace draw do namespace :account do - get 'shorthand' + get "shorthand" end end - assert_equal '/account/shorthand', account_shorthand_path - get '/account/shorthand' - assert_equal 'account#shorthand', @response.body + assert_equal "/account/shorthand", account_shorthand_path + get "/account/shorthand" + assert_equal "account#shorthand", @response.body end def test_match_shorthand_with_multiple_paths_inside_namespace draw do namespace :proposals do - put 'activate', 'inactivate' + put "activate", "inactivate" end end - put '/proposals/activate' - assert_equal 'proposals#activate', @response.body + put "/proposals/activate" + assert_equal "proposals#activate", @response.body - put '/proposals/inactivate' - assert_equal 'proposals#inactivate', @response.body + put "/proposals/inactivate" + assert_equal "proposals#inactivate", @response.body end def test_match_shorthand_inside_namespace_with_controller @@ -1488,130 +1488,130 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - assert_equal '/api/products/list', api_products_list_path - get '/api/products/list' - assert_equal 'api/products#list', @response.body + assert_equal "/api/products/list", api_products_list_path + get "/api/products/list" + assert_equal "api/products#list", @response.body end def test_match_shorthand_inside_scope_with_variables_with_controller draw do - scope ':locale' do - match 'questions/new', via: [:get] + scope ":locale" do + match "questions/new", via: [:get] end end - get '/de/questions/new' - assert_equal 'questions#new', @response.body - assert_equal 'de', @request.params[:locale] + get "/de/questions/new" + assert_equal "questions#new", @response.body + assert_equal "de", @request.params[:locale] end def test_match_shorthand_inside_nested_namespaces_and_scopes_with_controller draw do namespace :api do namespace :v3 do - scope ':locale' do + scope ":locale" do get "products/list" end end end end - get '/api/v3/en/products/list' - assert_equal 'api/v3/products#list', @response.body + get "/api/v3/en/products/list" + assert_equal "api/v3/products#list", @response.body end def test_not_matching_shorthand_with_dynamic_parameters draw do ActiveSupport::Deprecation.silence do - get ':controller/:action/admin' + get ":controller/:action/admin" end end - get '/finances/overview/admin' - assert_equal 'finances#overview', @response.body + get "/finances/overview/admin" + assert_equal "finances#overview", @response.body end def test_controller_option_with_nesting_and_leading_slash draw do - scope '/job', controller: 'job' do - scope ':id', action: 'manage_applicant' do + scope "/job", controller: "job" do + scope ":id", action: "manage_applicant" do get "/active" end end end - get '/job/5/active' - assert_equal 'job#manage_applicant', @response.body + get "/job/5/active" + assert_equal "job#manage_applicant", @response.body end def test_dynamically_generated_helpers_on_collection_do_not_clobber_resources_url_helper draw do resources :replies do collection do - get 'page/:page' => 'replies#index', :page => %r{\d+} - get ':page' => 'replies#index', :page => %r{\d+} + get "page/:page" => "replies#index", :page => %r{\d+} + get ":page" => "replies#index", :page => %r{\d+} end end end - assert_equal '/replies', replies_path + assert_equal "/replies", replies_path end def test_scoped_controller_with_namespace_and_action draw do namespace :account do ActiveSupport::Deprecation.silence do - get ':action/callback', :action => /twitter|github/, :controller => "callbacks", :as => :callback + get ":action/callback", action: /twitter|github/, controller: "callbacks", as: :callback end end end - assert_equal '/account/twitter/callback', account_callback_path("twitter") - get '/account/twitter/callback' - assert_equal 'account/callbacks#twitter', @response.body + assert_equal "/account/twitter/callback", account_callback_path("twitter") + get "/account/twitter/callback" + assert_equal "account/callbacks#twitter", @response.body - get '/account/whatever/callback' - assert_equal 'Not Found', @response.body + get "/account/whatever/callback" + assert_equal "Not Found", @response.body end def test_convention_match_nested_and_with_leading_slash draw do - get '/account/nested/overview' + get "/account/nested/overview" end - assert_equal '/account/nested/overview', account_nested_overview_path - get '/account/nested/overview' - assert_equal 'account/nested#overview', @response.body + assert_equal "/account/nested/overview", account_nested_overview_path + get "/account/nested/overview" + assert_equal "account/nested#overview", @response.body end def test_convention_with_explicit_end draw do - get 'sign_in' => "sessions#new" + get "sign_in" => "sessions#new" end - get '/sign_in' - assert_equal 'sessions#new', @response.body - assert_equal '/sign_in', sign_in_path + get "/sign_in" + assert_equal "sessions#new", @response.body + assert_equal "/sign_in", sign_in_path end def test_redirect_with_complete_url_and_status draw do - get 'account/google' => redirect('http://www.google.com/', :status => 302) + get "account/google" => redirect("http://www.google.com/", status: 302) end - get '/account/google' - verify_redirect 'http://www.google.com/', 302 + get "/account/google" + verify_redirect "http://www.google.com/", 302 end def test_redirect_with_port draw do - get 'account/login', :to => redirect("/login") + get "account/login", to: redirect("/login") end - previous_host, self.host = self.host, 'www.example.com:3000' + previous_host, self.host = self.host, "www.example.com:3000" - get '/account/login' - verify_redirect 'http://www.example.com:3000/login' + get "/account/login" + verify_redirect "http://www.example.com:3000/login" ensure self.host = previous_host end @@ -1619,258 +1619,276 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_normalize_namespaced_matches draw do namespace :account do - get 'description', :action => :description, :as => "description" + get "description", action: :description, as: "description" end end - assert_equal '/account/description', account_description_path + assert_equal "/account/description", account_description_path - get '/account/description' - assert_equal 'account#description', @response.body + get "/account/description" + assert_equal "account#description", @response.body end def test_namespaced_roots draw do namespace :account do - root :to => "account#index" + root to: "account#index" end end - assert_equal '/account', account_root_path - get '/account' - assert_equal 'account/account#index', @response.body + assert_equal "/account", account_root_path + get "/account" + assert_equal "account/account#index", @response.body end def test_optional_scoped_root draw do - scope '(:locale)', :locale => /en|pl/ do - root :to => 'projects#index' + scope "(:locale)", locale: /en|pl/ do + root to: "projects#index" end end - assert_equal '/en', root_path("en") - get '/en' - assert_equal 'projects#index', @response.body + assert_equal "/en", root_path("en") + get "/en" + assert_equal "projects#index", @response.body end def test_optional_scoped_path draw do - scope '(:locale)', :locale => /en|pl/ do + scope "(:locale)", locale: /en|pl/ do resources :descriptions end end - assert_equal '/en/descriptions', descriptions_path("en") - assert_equal '/descriptions', descriptions_path(nil) - assert_equal '/en/descriptions/1', description_path("en", 1) - assert_equal '/descriptions/1', description_path(nil, 1) + assert_equal "/en/descriptions", descriptions_path("en") + assert_equal "/descriptions", descriptions_path(nil) + assert_equal "/en/descriptions/1", description_path("en", 1) + assert_equal "/descriptions/1", description_path(nil, 1) - get '/en/descriptions' - assert_equal 'descriptions#index', @response.body + get "/en/descriptions" + assert_equal "descriptions#index", @response.body - get '/descriptions' - assert_equal 'descriptions#index', @response.body + get "/descriptions" + assert_equal "descriptions#index", @response.body - get '/en/descriptions/1' - assert_equal 'descriptions#show', @response.body + get "/en/descriptions/1" + assert_equal "descriptions#show", @response.body - get '/descriptions/1' - assert_equal 'descriptions#show', @response.body + get "/descriptions/1" + assert_equal "descriptions#show", @response.body end def test_nested_optional_scoped_path draw do namespace :admin do - scope '(:locale)', :locale => /en|pl/ do + scope "(:locale)", locale: /en|pl/ do resources :descriptions end end end - assert_equal '/admin/en/descriptions', admin_descriptions_path("en") - assert_equal '/admin/descriptions', admin_descriptions_path(nil) - assert_equal '/admin/en/descriptions/1', admin_description_path("en", 1) - assert_equal '/admin/descriptions/1', admin_description_path(nil, 1) + assert_equal "/admin/en/descriptions", admin_descriptions_path("en") + assert_equal "/admin/descriptions", admin_descriptions_path(nil) + assert_equal "/admin/en/descriptions/1", admin_description_path("en", 1) + assert_equal "/admin/descriptions/1", admin_description_path(nil, 1) - get '/admin/en/descriptions' - assert_equal 'admin/descriptions#index', @response.body + get "/admin/en/descriptions" + assert_equal "admin/descriptions#index", @response.body - get '/admin/descriptions' - assert_equal 'admin/descriptions#index', @response.body + get "/admin/descriptions" + assert_equal "admin/descriptions#index", @response.body - get '/admin/en/descriptions/1' - assert_equal 'admin/descriptions#show', @response.body + get "/admin/en/descriptions/1" + assert_equal "admin/descriptions#show", @response.body - get '/admin/descriptions/1' - assert_equal 'admin/descriptions#show', @response.body + get "/admin/descriptions/1" + assert_equal "admin/descriptions#show", @response.body end def test_nested_optional_path_shorthand draw do - scope '(:locale)', :locale => /en|pl/ do + scope "(:locale)", locale: /en|pl/ do get "registrations/new" end end - get '/registrations/new' + get "/registrations/new" assert_nil @request.params[:locale] - get '/en/registrations/new' - assert_equal 'en', @request.params[:locale] + get "/en/registrations/new" + assert_equal "en", @request.params[:locale] end def test_default_string_params draw do - get 'inline_pages/(:id)', :to => 'pages#show', :id => 'home' - get 'default_pages/(:id)', :to => 'pages#show', :defaults => { :id => 'home' } + get "inline_pages/(:id)", to: "pages#show", id: "home" + get "default_pages/(:id)", to: "pages#show", defaults: { id: "home" } - defaults :id => 'home' do - get 'scoped_pages/(:id)', :to => 'pages#show' + defaults id: "home" do + get "scoped_pages/(:id)", to: "pages#show" end end - get '/inline_pages' - assert_equal 'home', @request.params[:id] + get "/inline_pages" + assert_equal "home", @request.params[:id] - get '/default_pages' - assert_equal 'home', @request.params[:id] + get "/default_pages" + assert_equal "home", @request.params[:id] - get '/scoped_pages' - assert_equal 'home', @request.params[:id] + get "/scoped_pages" + assert_equal "home", @request.params[:id] end def test_default_integer_params draw do - get 'inline_pages/(:page)', to: 'pages#show', page: 1 - get 'default_pages/(:page)', to: 'pages#show', defaults: { page: 1 } + get "inline_pages/(:page)", to: "pages#show", page: 1 + get "default_pages/(:page)", to: "pages#show", defaults: { page: 1 } defaults page: 1 do - get 'scoped_pages/(:page)', to: 'pages#show' + get "scoped_pages/(:page)", to: "pages#show" end end - get '/inline_pages' + get "/inline_pages" assert_equal 1, @request.params[:page] - get '/default_pages' + get "/default_pages" assert_equal 1, @request.params[:page] - get '/scoped_pages' + get "/scoped_pages" assert_equal 1, @request.params[:page] end + def test_keyed_default_string_params_with_match + draw do + match "/", to: "pages#show", via: :get, defaults: { id: "home" } + end + + get "/" + assert_equal "home", @request.params[:id] + end + + def test_default_string_params_with_match + draw do + match "/", to: "pages#show", via: :get, id: "home" + end + + get "/" + assert_equal "home", @request.params[:id] + end + def test_keyed_default_string_params_with_root draw do - root to: 'pages#show', defaults: { id: 'home' } + root to: "pages#show", defaults: { id: "home" } end - get '/' - assert_equal 'home', @request.params[:id] + get "/" + assert_equal "home", @request.params[:id] end def test_default_string_params_with_root draw do - root to: 'pages#show', id: 'home' + root to: "pages#show", id: "home" end - get '/' - assert_equal 'home', @request.params[:id] + get "/" + assert_equal "home", @request.params[:id] end def test_resource_constraints draw do - resources :products, :constraints => { :id => /\d{4}/ } do - root :to => "products#root" - get :favorite, :on => :collection + resources :products, constraints: { id: /\d{4}/ } do + root to: "products#root" + get :favorite, on: :collection resources :images end - resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ } + resource :dashboard, constraints: { ip: /192\.168\.1\.\d{1,3}/ } end - get '/products/1' - assert_equal 'pass', @response.headers['X-Cascade'] - get '/products' - assert_equal 'products#root', @response.body - get '/products/favorite' - assert_equal 'products#favorite', @response.body - get '/products/0001' - assert_equal 'products#show', @response.body + get "/products/1" + assert_equal "pass", @response.headers["X-Cascade"] + get "/products" + assert_equal "products#root", @response.body + get "/products/favorite" + assert_equal "products#favorite", @response.body + get "/products/0001" + assert_equal "products#show", @response.body - get '/products/1/images' - assert_equal 'pass', @response.headers['X-Cascade'] - get '/products/0001/images' - assert_equal 'images#index', @response.body - get '/products/0001/images/0001' - assert_equal 'images#show', @response.body + get "/products/1/images" + assert_equal "pass", @response.headers["X-Cascade"] + get "/products/0001/images" + assert_equal "images#index", @response.body + get "/products/0001/images/0001" + assert_equal "images#show", @response.body - get '/dashboard', headers: { 'REMOTE_ADDR' => '10.0.0.100' } - assert_equal 'pass', @response.headers['X-Cascade'] - get '/dashboard', headers: { 'REMOTE_ADDR' => '192.168.1.100' } - assert_equal 'dashboards#show', @response.body + get "/dashboard", headers: { "REMOTE_ADDR" => "10.0.0.100" } + assert_equal "pass", @response.headers["X-Cascade"] + get "/dashboard", headers: { "REMOTE_ADDR" => "192.168.1.100" } + assert_equal "dashboards#show", @response.body end def test_root_works_in_the_resources_scope draw do resources :products do - root :to => "products#root" + root to: "products#root" end end - get '/products' - assert_equal 'products#root', @response.body - assert_equal '/products', products_root_path + get "/products" + assert_equal "products#root", @response.body + assert_equal "/products", products_root_path end def test_module_scope draw do - resource :token, :module => :api + resource :token, module: :api end - get '/token' - assert_equal 'api/tokens#show', @response.body - assert_equal '/token', token_path + get "/token" + assert_equal "api/tokens#show", @response.body + assert_equal "/token", token_path end def test_path_scope draw do - scope :path => 'api' do + scope path: "api" do resource :me - get '/' => 'mes#index' + get "/" => "mes#index" end end - get '/api/me' - assert_equal 'mes#show', @response.body - assert_equal '/api/me', me_path + get "/api/me" + assert_equal "mes#show", @response.body + assert_equal "/api/me", me_path - get '/api' - assert_equal 'mes#index', @response.body + get "/api" + assert_equal "mes#index", @response.body end def test_symbol_scope draw do - scope :path => 'api' do + scope path: "api" do scope :v2 do - resource :me, as: 'v2_me' - get '/' => 'mes#index' + resource :me, as: "v2_me" + get "/" => "mes#index" end scope :v3, :admin do - resource :me, as: 'v3_me' + resource :me, as: "v3_me" end end end - get '/api/v2/me' - assert_equal 'mes#show', @response.body - assert_equal '/api/v2/me', v2_me_path + get "/api/v2/me" + assert_equal "mes#show", @response.body + assert_equal "/api/v2/me", v2_me_path - get '/api/v2' - assert_equal 'mes#index', @response.body + get "/api/v2" + assert_equal "mes#index", @response.body - get '/api/v3/admin/me' - assert_equal 'mes#show', @response.body + get "/api/v3/admin/me" + assert_equal "mes#show", @response.body end def test_url_generator_for_generic_route @@ -1880,31 +1898,31 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/whatever/foo/bar' - assert_equal 'foo#bar', @response.body + get "/whatever/foo/bar" + assert_equal "foo#bar", @response.body - assert_equal 'http://www.example.com/whatever/foo/bar/1', - url_for(:controller => "foo", :action => "bar", :id => 1) + assert_equal "http://www.example.com/whatever/foo/bar/1", + url_for(controller: "foo", action: "bar", id: 1) end def test_url_generator_for_namespaced_generic_route draw do ActiveSupport::Deprecation.silence do - get "whatever/:controller(/:action(/:id))", :id => /\d+/ + get "whatever/:controller(/:action(/:id))", id: /\d+/ end end - get '/whatever/foo/bar/show' - assert_equal 'foo/bar#show', @response.body + get "/whatever/foo/bar/show" + assert_equal "foo/bar#show", @response.body - get '/whatever/foo/bar/show/1' - assert_equal 'foo/bar#show', @response.body + get "/whatever/foo/bar/show/1" + assert_equal "foo/bar#show", @response.body - assert_equal 'http://www.example.com/whatever/foo/bar/show', - url_for(:controller => "foo/bar", :action => "show") + assert_equal "http://www.example.com/whatever/foo/bar/show", + url_for(controller: "foo/bar", action: "show") - assert_equal 'http://www.example.com/whatever/foo/bar/show/1', - url_for(:controller => "foo/bar", :action => "show", :id => '1') + assert_equal "http://www.example.com/whatever/foo/bar/show/1", + url_for(controller: "foo/bar", action: "show", id: "1") end def test_resource_new_actions @@ -1915,16 +1933,16 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - scope 'pt', :as => 'pt' do - resources :projects, :path_names => { :new => 'novo' }, :path => 'projetos' do - post :preview, :on => :new + scope "pt", as: "pt" do + resources :projects, path_names: { new: "novo" }, path: "projetos" do + post :preview, on: :new end - resource :admin, :path_names => { :new => 'novo' }, :path => 'administrador' do - post :preview, :on => :new + resource :admin, path_names: { new: "novo" }, path: "administrador" do + post :preview, on: :new end - resources :products, :path_names => { :new => 'novo' } do + resources :products, path_names: { new: "novo" } do new do post :preview end @@ -1938,58 +1956,58 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - assert_equal '/replies/new/preview', preview_new_reply_path - assert_equal '/pt/projetos/novo/preview', preview_new_pt_project_path - assert_equal '/pt/administrador/novo/preview', preview_new_pt_admin_path - assert_equal '/pt/products/novo/preview', preview_new_pt_product_path - assert_equal '/profile/new/preview', preview_new_profile_path + assert_equal "/replies/new/preview", preview_new_reply_path + assert_equal "/pt/projetos/novo/preview", preview_new_pt_project_path + assert_equal "/pt/administrador/novo/preview", preview_new_pt_admin_path + assert_equal "/pt/products/novo/preview", preview_new_pt_product_path + assert_equal "/profile/new/preview", preview_new_profile_path - post '/replies/new/preview' - assert_equal 'replies#preview', @response.body + post "/replies/new/preview" + assert_equal "replies#preview", @response.body - post '/pt/projetos/novo/preview' - assert_equal 'projects#preview', @response.body + post "/pt/projetos/novo/preview" + assert_equal "projects#preview", @response.body - post '/pt/administrador/novo/preview' - assert_equal 'admins#preview', @response.body + post "/pt/administrador/novo/preview" + assert_equal "admins#preview", @response.body - post '/pt/products/novo/preview' - assert_equal 'products#preview', @response.body + post "/pt/products/novo/preview" + assert_equal "products#preview", @response.body - post '/profile/new/preview' - assert_equal 'profiles#preview', @response.body + post "/profile/new/preview" + assert_equal "profiles#preview", @response.body end def test_resource_merges_options_from_scope draw do - scope :only => :show do + scope only: :show do resource :account end end assert_raise(NoMethodError) { new_account_path } - get '/account/new' + get "/account/new" assert_equal 404, status end def test_resources_merges_options_from_scope draw do - scope :only => [:index, :show] do + scope only: [:index, :show] do resources :products do resources :images end end end - assert_raise(NoMethodError) { edit_product_path('1') } + assert_raise(NoMethodError) { edit_product_path("1") } - get '/products/1/edit' + get "/products/1/edit" assert_equal 404, status - assert_raise(NoMethodError) { edit_product_image_path('1', '2') } + assert_raise(NoMethodError) { edit_product_image_path("1", "2") } - post '/products/1/images/2/edit' + post "/products/1/images/2/edit" assert_equal 404, status end @@ -2004,7 +2022,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - resources :threads, :shallow => true do + resources :threads, shallow: true do resource :owner resources :messages do resources :comments do @@ -2016,105 +2034,105 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/api/teams' - assert_equal 'api/teams#index', @response.body - assert_equal '/api/teams', api_teams_path + get "/api/teams" + assert_equal "api/teams#index", @response.body + assert_equal "/api/teams", api_teams_path - get '/api/teams/new' - assert_equal 'api/teams#new', @response.body - assert_equal '/api/teams/new', new_api_team_path + get "/api/teams/new" + assert_equal "api/teams#new", @response.body + assert_equal "/api/teams/new", new_api_team_path - get '/api/teams/1' - assert_equal 'api/teams#show', @response.body - assert_equal '/api/teams/1', api_team_path(:id => '1') + get "/api/teams/1" + assert_equal "api/teams#show", @response.body + assert_equal "/api/teams/1", api_team_path(id: "1") - get '/api/teams/1/edit' - assert_equal 'api/teams#edit', @response.body - assert_equal '/api/teams/1/edit', edit_api_team_path(:id => '1') + get "/api/teams/1/edit" + assert_equal "api/teams#edit", @response.body + assert_equal "/api/teams/1/edit", edit_api_team_path(id: "1") - get '/api/teams/1/players' - assert_equal 'api/players#index', @response.body - assert_equal '/api/teams/1/players', api_team_players_path(:team_id => '1') + get "/api/teams/1/players" + assert_equal "api/players#index", @response.body + assert_equal "/api/teams/1/players", api_team_players_path(team_id: "1") - get '/api/teams/1/players/new' - assert_equal 'api/players#new', @response.body - assert_equal '/api/teams/1/players/new', new_api_team_player_path(:team_id => '1') + get "/api/teams/1/players/new" + assert_equal "api/players#new", @response.body + assert_equal "/api/teams/1/players/new", new_api_team_player_path(team_id: "1") - get '/api/players/2' - assert_equal 'api/players#show', @response.body - assert_equal '/api/players/2', api_player_path(:id => '2') + get "/api/players/2" + assert_equal "api/players#show", @response.body + assert_equal "/api/players/2", api_player_path(id: "2") - get '/api/players/2/edit' - assert_equal 'api/players#edit', @response.body - assert_equal '/api/players/2/edit', edit_api_player_path(:id => '2') + get "/api/players/2/edit" + assert_equal "api/players#edit", @response.body + assert_equal "/api/players/2/edit", edit_api_player_path(id: "2") - get '/api/teams/1/captain' - assert_equal 'api/captains#show', @response.body - assert_equal '/api/teams/1/captain', api_team_captain_path(:team_id => '1') + get "/api/teams/1/captain" + assert_equal "api/captains#show", @response.body + assert_equal "/api/teams/1/captain", api_team_captain_path(team_id: "1") - get '/api/teams/1/captain/new' - assert_equal 'api/captains#new', @response.body - assert_equal '/api/teams/1/captain/new', new_api_team_captain_path(:team_id => '1') + get "/api/teams/1/captain/new" + assert_equal "api/captains#new", @response.body + assert_equal "/api/teams/1/captain/new", new_api_team_captain_path(team_id: "1") - get '/api/teams/1/captain/edit' - assert_equal 'api/captains#edit', @response.body - assert_equal '/api/teams/1/captain/edit', edit_api_team_captain_path(:team_id => '1') + get "/api/teams/1/captain/edit" + assert_equal "api/captains#edit", @response.body + assert_equal "/api/teams/1/captain/edit", edit_api_team_captain_path(team_id: "1") - get '/threads' - assert_equal 'threads#index', @response.body - assert_equal '/threads', threads_path + get "/threads" + assert_equal "threads#index", @response.body + assert_equal "/threads", threads_path - get '/threads/new' - assert_equal 'threads#new', @response.body - assert_equal '/threads/new', new_thread_path + get "/threads/new" + assert_equal "threads#new", @response.body + assert_equal "/threads/new", new_thread_path - get '/threads/1' - assert_equal 'threads#show', @response.body - assert_equal '/threads/1', thread_path(:id => '1') + get "/threads/1" + assert_equal "threads#show", @response.body + assert_equal "/threads/1", thread_path(id: "1") - get '/threads/1/edit' - assert_equal 'threads#edit', @response.body - assert_equal '/threads/1/edit', edit_thread_path(:id => '1') + get "/threads/1/edit" + assert_equal "threads#edit", @response.body + assert_equal "/threads/1/edit", edit_thread_path(id: "1") - get '/threads/1/owner' - assert_equal 'owners#show', @response.body - assert_equal '/threads/1/owner', thread_owner_path(:thread_id => '1') + get "/threads/1/owner" + assert_equal "owners#show", @response.body + assert_equal "/threads/1/owner", thread_owner_path(thread_id: "1") - get '/threads/1/messages' - assert_equal 'messages#index', @response.body - assert_equal '/threads/1/messages', thread_messages_path(:thread_id => '1') + get "/threads/1/messages" + assert_equal "messages#index", @response.body + assert_equal "/threads/1/messages", thread_messages_path(thread_id: "1") - get '/threads/1/messages/new' - assert_equal 'messages#new', @response.body - assert_equal '/threads/1/messages/new', new_thread_message_path(:thread_id => '1') + get "/threads/1/messages/new" + assert_equal "messages#new", @response.body + assert_equal "/threads/1/messages/new", new_thread_message_path(thread_id: "1") - get '/messages/2' - assert_equal 'messages#show', @response.body - assert_equal '/messages/2', message_path(:id => '2') + get "/messages/2" + assert_equal "messages#show", @response.body + assert_equal "/messages/2", message_path(id: "2") - get '/messages/2/edit' - assert_equal 'messages#edit', @response.body - assert_equal '/messages/2/edit', edit_message_path(:id => '2') + get "/messages/2/edit" + assert_equal "messages#edit", @response.body + assert_equal "/messages/2/edit", edit_message_path(id: "2") - get '/messages/2/comments' - assert_equal 'comments#index', @response.body - assert_equal '/messages/2/comments', message_comments_path(:message_id => '2') + get "/messages/2/comments" + assert_equal "comments#index", @response.body + assert_equal "/messages/2/comments", message_comments_path(message_id: "2") - get '/messages/2/comments/new' - assert_equal 'comments#new', @response.body - assert_equal '/messages/2/comments/new', new_message_comment_path(:message_id => '2') + get "/messages/2/comments/new" + assert_equal "comments#new", @response.body + assert_equal "/messages/2/comments/new", new_message_comment_path(message_id: "2") - get '/comments/3' - assert_equal 'comments#show', @response.body - assert_equal '/comments/3', comment_path(:id => '3') + get "/comments/3" + assert_equal "comments#show", @response.body + assert_equal "/comments/3", comment_path(id: "3") - get '/comments/3/edit' - assert_equal 'comments#edit', @response.body - assert_equal '/comments/3/edit', edit_comment_path(:id => '3') + get "/comments/3/edit" + assert_equal "comments#edit", @response.body + assert_equal "/comments/3/edit", edit_comment_path(id: "3") - post '/comments/3/preview' - assert_equal 'comments#preview', @response.body - assert_equal '/comments/3/preview', preview_comment_path(:id => '3') + post "/comments/3/preview" + assert_equal "comments#preview", @response.body + assert_equal "/comments/3/preview", preview_comment_path(id: "3") end def test_shallow_nested_resources_inside_resource @@ -2124,33 +2142,33 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/membership/cards' - assert_equal 'cards#index', @response.body - assert_equal '/membership/cards', membership_cards_path + get "/membership/cards" + assert_equal "cards#index", @response.body + assert_equal "/membership/cards", membership_cards_path - get '/membership/cards/new' - assert_equal 'cards#new', @response.body - assert_equal '/membership/cards/new', new_membership_card_path + get "/membership/cards/new" + assert_equal "cards#new", @response.body + assert_equal "/membership/cards/new", new_membership_card_path - post '/membership/cards' - assert_equal 'cards#create', @response.body + post "/membership/cards" + assert_equal "cards#create", @response.body - get '/cards/1' - assert_equal 'cards#show', @response.body - assert_equal '/cards/1', card_path('1') + get "/cards/1" + assert_equal "cards#show", @response.body + assert_equal "/cards/1", card_path("1") - get '/cards/1/edit' - assert_equal 'cards#edit', @response.body - assert_equal '/cards/1/edit', edit_card_path('1') + get "/cards/1/edit" + assert_equal "cards#edit", @response.body + assert_equal "/cards/1/edit", edit_card_path("1") - put '/cards/1' - assert_equal 'cards#update', @response.body + put "/cards/1" + assert_equal "cards#update", @response.body - patch '/cards/1' - assert_equal 'cards#update', @response.body + patch "/cards/1" + assert_equal "cards#update", @response.body - delete '/cards/1' - assert_equal 'cards#destroy', @response.body + delete "/cards/1" + assert_equal "cards#destroy", @response.body end def test_shallow_deeply_nested_resources @@ -2162,13 +2180,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/comments/1' - assert_equal 'comments#show', @response.body + get "/comments/1" + assert_equal "comments#show", @response.body - assert_equal '/comments/1', comment_path('1') - assert_equal '/blogs/new', new_blog_path - assert_equal '/blogs/1/posts/new', new_blog_post_path(:blog_id => 1) - assert_equal '/blogs/1/posts/2/comments/new', new_blog_post_comment_path(:blog_id => 1, :post_id => 2) + assert_equal "/comments/1", comment_path("1") + assert_equal "/blogs/new", new_blog_path + assert_equal "/blogs/1/posts/new", new_blog_post_path(blog_id: 1) + assert_equal "/blogs/1/posts/2/comments/new", new_blog_post_comment_path(blog_id: 1, post_id: 2) end def test_direct_children_of_shallow_resources @@ -2180,22 +2198,22 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - post '/posts/1/comments' - assert_equal 'comments#create', @response.body - assert_equal '/posts/1/comments', post_comments_path('1') + post "/posts/1/comments" + assert_equal "comments#create", @response.body + assert_equal "/posts/1/comments", post_comments_path("1") - get '/posts/2/comments/new' - assert_equal 'comments#new', @response.body - assert_equal '/posts/2/comments/new', new_post_comment_path('2') + get "/posts/2/comments/new" + assert_equal "comments#new", @response.body + assert_equal "/posts/2/comments/new", new_post_comment_path("2") - get '/posts/1/comments' - assert_equal 'comments#index', @response.body - assert_equal '/posts/1/comments', post_comments_path('1') + get "/posts/1/comments" + assert_equal "comments#index", @response.body + assert_equal "/posts/1/comments", post_comments_path("1") end def test_shallow_nested_resources_within_scope draw do - scope '/hello' do + scope "/hello" do shallow do resources :notes do resources :trackbacks @@ -2204,120 +2222,120 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/hello/notes/1/trackbacks' - assert_equal 'trackbacks#index', @response.body - assert_equal '/hello/notes/1/trackbacks', note_trackbacks_path(:note_id => 1) + get "/hello/notes/1/trackbacks" + assert_equal "trackbacks#index", @response.body + assert_equal "/hello/notes/1/trackbacks", note_trackbacks_path(note_id: 1) - get '/hello/notes/1/edit' - assert_equal 'notes#edit', @response.body - assert_equal '/hello/notes/1/edit', edit_note_path(:id => '1') + get "/hello/notes/1/edit" + assert_equal "notes#edit", @response.body + assert_equal "/hello/notes/1/edit", edit_note_path(id: "1") - get '/hello/notes/1/trackbacks/new' - assert_equal 'trackbacks#new', @response.body - assert_equal '/hello/notes/1/trackbacks/new', new_note_trackback_path(:note_id => 1) + get "/hello/notes/1/trackbacks/new" + assert_equal "trackbacks#new", @response.body + assert_equal "/hello/notes/1/trackbacks/new", new_note_trackback_path(note_id: 1) - get '/hello/trackbacks/1' - assert_equal 'trackbacks#show', @response.body - assert_equal '/hello/trackbacks/1', trackback_path(:id => '1') + get "/hello/trackbacks/1" + assert_equal "trackbacks#show", @response.body + assert_equal "/hello/trackbacks/1", trackback_path(id: "1") - get '/hello/trackbacks/1/edit' - assert_equal 'trackbacks#edit', @response.body - assert_equal '/hello/trackbacks/1/edit', edit_trackback_path(:id => '1') + get "/hello/trackbacks/1/edit" + assert_equal "trackbacks#edit", @response.body + assert_equal "/hello/trackbacks/1/edit", edit_trackback_path(id: "1") - put '/hello/trackbacks/1' - assert_equal 'trackbacks#update', @response.body + put "/hello/trackbacks/1" + assert_equal "trackbacks#update", @response.body - post '/hello/notes/1/trackbacks' - assert_equal 'trackbacks#create', @response.body + post "/hello/notes/1/trackbacks" + assert_equal "trackbacks#create", @response.body - delete '/hello/trackbacks/1' - assert_equal 'trackbacks#destroy', @response.body + delete "/hello/trackbacks/1" + assert_equal "trackbacks#destroy", @response.body - get '/hello/notes' - assert_equal 'notes#index', @response.body + get "/hello/notes" + assert_equal "notes#index", @response.body - post '/hello/notes' - assert_equal 'notes#create', @response.body + post "/hello/notes" + assert_equal "notes#create", @response.body - get '/hello/notes/new' - assert_equal 'notes#new', @response.body - assert_equal '/hello/notes/new', new_note_path + get "/hello/notes/new" + assert_equal "notes#new", @response.body + assert_equal "/hello/notes/new", new_note_path - get '/hello/notes/1' - assert_equal 'notes#show', @response.body - assert_equal '/hello/notes/1', note_path(:id => 1) + get "/hello/notes/1" + assert_equal "notes#show", @response.body + assert_equal "/hello/notes/1", note_path(id: 1) - put '/hello/notes/1' - assert_equal 'notes#update', @response.body + put "/hello/notes/1" + assert_equal "notes#update", @response.body - delete '/hello/notes/1' - assert_equal 'notes#destroy', @response.body + delete "/hello/notes/1" + assert_equal "notes#destroy", @response.body end def test_shallow_option_nested_resources_within_scope draw do - scope '/hello' do - resources :notes, :shallow => true do + scope "/hello" do + resources :notes, shallow: true do resources :trackbacks end end end - get '/hello/notes/1/trackbacks' - assert_equal 'trackbacks#index', @response.body - assert_equal '/hello/notes/1/trackbacks', note_trackbacks_path(:note_id => 1) + get "/hello/notes/1/trackbacks" + assert_equal "trackbacks#index", @response.body + assert_equal "/hello/notes/1/trackbacks", note_trackbacks_path(note_id: 1) - get '/hello/notes/1/edit' - assert_equal 'notes#edit', @response.body - assert_equal '/hello/notes/1/edit', edit_note_path(:id => '1') + get "/hello/notes/1/edit" + assert_equal "notes#edit", @response.body + assert_equal "/hello/notes/1/edit", edit_note_path(id: "1") - get '/hello/notes/1/trackbacks/new' - assert_equal 'trackbacks#new', @response.body - assert_equal '/hello/notes/1/trackbacks/new', new_note_trackback_path(:note_id => 1) + get "/hello/notes/1/trackbacks/new" + assert_equal "trackbacks#new", @response.body + assert_equal "/hello/notes/1/trackbacks/new", new_note_trackback_path(note_id: 1) - get '/hello/trackbacks/1' - assert_equal 'trackbacks#show', @response.body - assert_equal '/hello/trackbacks/1', trackback_path(:id => '1') + get "/hello/trackbacks/1" + assert_equal "trackbacks#show", @response.body + assert_equal "/hello/trackbacks/1", trackback_path(id: "1") - get '/hello/trackbacks/1/edit' - assert_equal 'trackbacks#edit', @response.body - assert_equal '/hello/trackbacks/1/edit', edit_trackback_path(:id => '1') + get "/hello/trackbacks/1/edit" + assert_equal "trackbacks#edit", @response.body + assert_equal "/hello/trackbacks/1/edit", edit_trackback_path(id: "1") - put '/hello/trackbacks/1' - assert_equal 'trackbacks#update', @response.body + put "/hello/trackbacks/1" + assert_equal "trackbacks#update", @response.body - post '/hello/notes/1/trackbacks' - assert_equal 'trackbacks#create', @response.body + post "/hello/notes/1/trackbacks" + assert_equal "trackbacks#create", @response.body - delete '/hello/trackbacks/1' - assert_equal 'trackbacks#destroy', @response.body + delete "/hello/trackbacks/1" + assert_equal "trackbacks#destroy", @response.body - get '/hello/notes' - assert_equal 'notes#index', @response.body + get "/hello/notes" + assert_equal "notes#index", @response.body - post '/hello/notes' - assert_equal 'notes#create', @response.body + post "/hello/notes" + assert_equal "notes#create", @response.body - get '/hello/notes/new' - assert_equal 'notes#new', @response.body - assert_equal '/hello/notes/new', new_note_path + get "/hello/notes/new" + assert_equal "notes#new", @response.body + assert_equal "/hello/notes/new", new_note_path - get '/hello/notes/1' - assert_equal 'notes#show', @response.body - assert_equal '/hello/notes/1', note_path(:id => 1) + get "/hello/notes/1" + assert_equal "notes#show", @response.body + assert_equal "/hello/notes/1", note_path(id: 1) - put '/hello/notes/1' - assert_equal 'notes#update', @response.body + put "/hello/notes/1" + assert_equal "notes#update", @response.body - delete '/hello/notes/1' - assert_equal 'notes#destroy', @response.body + delete "/hello/notes/1" + assert_equal "notes#destroy", @response.body end def test_custom_resource_routes_are_scoped draw do resources :customers do - get :recent, :on => :collection - get "profile", :on => :member + get :recent, on: :collection + get "profile", on: :member get "secret/profile" => "customers#secret", :on => :member post "preview" => "customers#preview", :as => :another_preview, :on => :new resource :avatar do @@ -2325,11 +2343,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end resources :invoices do get "outstanding" => "invoices#outstanding", :on => :collection - get "overdue", :action => :overdue, :on => :collection + get "overdue", action: :overdue, on: :collection get "print" => "invoices#print", :as => :print, :on => :member post "preview" => "invoices#preview", :as => :preview, :on => :new end - resources :notes, :shallow => true do + resources :notes, shallow: true do get "preview" => "notes#preview", :as => :preview, :on => :new get "print" => "notes#print", :as => :print, :on => :member end @@ -2344,79 +2362,79 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - assert_equal '/customers/recent', recent_customers_path - assert_equal '/customers/1/profile', profile_customer_path(:id => '1') - assert_equal '/customers/1/secret/profile', secret_profile_customer_path(:id => '1') - assert_equal '/customers/new/preview', another_preview_new_customer_path - assert_equal '/customers/1/avatar/thumbnail.jpg', thumbnail_customer_avatar_path(:customer_id => '1', :format => :jpg) - assert_equal '/customers/1/invoices/outstanding', outstanding_customer_invoices_path(:customer_id => '1') - assert_equal '/customers/1/invoices/2/print', print_customer_invoice_path(:customer_id => '1', :id => '2') - assert_equal '/customers/1/invoices/new/preview', preview_new_customer_invoice_path(:customer_id => '1') - assert_equal '/customers/1/notes/new/preview', preview_new_customer_note_path(:customer_id => '1') - assert_equal '/notes/1/print', print_note_path(:id => '1') - assert_equal '/api/customers/recent', recent_api_customers_path - assert_equal '/api/customers/1/profile', profile_api_customer_path(:id => '1') - assert_equal '/api/customers/new/preview', preview_new_api_customer_path + assert_equal "/customers/recent", recent_customers_path + assert_equal "/customers/1/profile", profile_customer_path(id: "1") + assert_equal "/customers/1/secret/profile", secret_profile_customer_path(id: "1") + assert_equal "/customers/new/preview", another_preview_new_customer_path + assert_equal "/customers/1/avatar/thumbnail.jpg", thumbnail_customer_avatar_path(customer_id: "1", format: :jpg) + assert_equal "/customers/1/invoices/outstanding", outstanding_customer_invoices_path(customer_id: "1") + assert_equal "/customers/1/invoices/2/print", print_customer_invoice_path(customer_id: "1", id: "2") + assert_equal "/customers/1/invoices/new/preview", preview_new_customer_invoice_path(customer_id: "1") + assert_equal "/customers/1/notes/new/preview", preview_new_customer_note_path(customer_id: "1") + assert_equal "/notes/1/print", print_note_path(id: "1") + assert_equal "/api/customers/recent", recent_api_customers_path + assert_equal "/api/customers/1/profile", profile_api_customer_path(id: "1") + assert_equal "/api/customers/new/preview", preview_new_api_customer_path - get '/customers/1/invoices/overdue' - assert_equal 'invoices#overdue', @response.body + get "/customers/1/invoices/overdue" + assert_equal "invoices#overdue", @response.body - get '/customers/1/secret/profile' - assert_equal 'customers#secret', @response.body + get "/customers/1/secret/profile" + assert_equal "customers#secret", @response.body end def test_shallow_nested_routes_ignore_module draw do - scope :module => :api do - resources :errors, :shallow => true do + scope module: :api do + resources :errors, shallow: true do resources :notices end end end - get '/errors/1/notices' - assert_equal 'api/notices#index', @response.body - assert_equal '/errors/1/notices', error_notices_path(:error_id => '1') + get "/errors/1/notices" + assert_equal "api/notices#index", @response.body + assert_equal "/errors/1/notices", error_notices_path(error_id: "1") - get '/notices/1' - assert_equal 'api/notices#show', @response.body - assert_equal '/notices/1', notice_path(:id => '1') + get "/notices/1" + assert_equal "api/notices#show", @response.body + assert_equal "/notices/1", notice_path(id: "1") end def test_non_greedy_regexp draw do namespace :api do - scope(':version', :version => /.+/) do - resources :users, :id => /.+?/, :format => /json|xml/ + scope(":version", version: /.+/) do + resources :users, id: /.+?/, format: /json|xml/ end end end - get '/api/1.0/users' - assert_equal 'api/users#index', @response.body - assert_equal '/api/1.0/users', api_users_path(:version => '1.0') + get "/api/1.0/users" + assert_equal "api/users#index", @response.body + assert_equal "/api/1.0/users", api_users_path(version: "1.0") - get '/api/1.0/users.json' - assert_equal 'api/users#index', @response.body + get "/api/1.0/users.json" + assert_equal "api/users#index", @response.body assert_equal true, @request.format.json? - assert_equal '/api/1.0/users.json', api_users_path(:version => '1.0', :format => :json) + assert_equal "/api/1.0/users.json", api_users_path(version: "1.0", format: :json) - get '/api/1.0/users/first.last' - assert_equal 'api/users#show', @response.body - assert_equal 'first.last', @request.params[:id] - assert_equal '/api/1.0/users/first.last', api_user_path(:version => '1.0', :id => 'first.last') + get "/api/1.0/users/first.last" + assert_equal "api/users#show", @response.body + assert_equal "first.last", @request.params[:id] + assert_equal "/api/1.0/users/first.last", api_user_path(version: "1.0", id: "first.last") - get '/api/1.0/users/first.last.xml' - assert_equal 'api/users#show', @response.body - assert_equal 'first.last', @request.params[:id] + get "/api/1.0/users/first.last.xml" + assert_equal "api/users#show", @response.body + assert_equal "first.last", @request.params[:id] assert_equal true, @request.format.xml? - assert_equal '/api/1.0/users/first.last.xml', api_user_path(:version => '1.0', :id => 'first.last', :format => :xml) + assert_equal "/api/1.0/users/first.last.xml", api_user_path(version: "1.0", id: "first.last", format: :xml) end def test_match_without_via assert_raises(ArgumentError) do draw do - match '/foo/bar', :to => 'files#show' + match "/foo/bar", to: "files#show" end end end @@ -2424,17 +2442,17 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_match_with_empty_via assert_raises(ArgumentError) do draw do - match '/foo/bar', :to => 'files#show', :via => [] + match "/foo/bar", to: "files#show", via: [] end end end def test_glob_parameter_accepts_regexp draw do - get '/:locale/*file.:format', :to => 'files#show', :file => /path\/to\/existing\/file/ + get "/:locale/*file.:format", to: "files#show", file: /path\/to\/existing\/file/ end - get '/en/path/to/existing/file.html' + get "/en/path/to/existing/file.html" assert_equal 200, @response.status end @@ -2443,8 +2461,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :content end - get '/content' - assert_equal 'content#index', @response.body + get "/content" + assert_equal "content#index", @response.body end def test_url_generator_for_optional_prefix_dynamic_segment @@ -2452,15 +2470,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "(/:username)/followers" => "followers#index" end - get '/bob/followers' - assert_equal 'followers#index', @response.body - assert_equal 'http://www.example.com/bob/followers', - url_for(:controller => "followers", :action => "index", :username => "bob") + get "/bob/followers" + assert_equal "followers#index", @response.body + assert_equal "http://www.example.com/bob/followers", + url_for(controller: "followers", action: "index", username: "bob") - get '/followers' - assert_equal 'followers#index', @response.body - assert_equal 'http://www.example.com/followers', - url_for(:controller => "followers", :action => "index", :username => nil) + get "/followers" + assert_equal "followers#index", @response.body + assert_equal "http://www.example.com/followers", + url_for(controller: "followers", action: "index", username: nil) end def test_url_generator_for_optional_suffix_static_and_dynamic_segment @@ -2468,15 +2486,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/groups(/user/:username)" => "groups#index" end - get '/groups/user/bob' - assert_equal 'groups#index', @response.body - assert_equal 'http://www.example.com/groups/user/bob', - url_for(:controller => "groups", :action => "index", :username => "bob") + get "/groups/user/bob" + assert_equal "groups#index", @response.body + assert_equal "http://www.example.com/groups/user/bob", + url_for(controller: "groups", action: "index", username: "bob") - get '/groups' - assert_equal 'groups#index', @response.body - assert_equal 'http://www.example.com/groups', - url_for(:controller => "groups", :action => "index", :username => nil) + get "/groups" + assert_equal "groups#index", @response.body + assert_equal "http://www.example.com/groups", + url_for(controller: "groups", action: "index", username: nil) end def test_url_generator_for_optional_prefix_static_and_dynamic_segment @@ -2484,66 +2502,66 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "(/user/:username)/photos" => "photos#index" end - get '/user/bob/photos' - assert_equal 'photos#index', @response.body - assert_equal 'http://www.example.com/user/bob/photos', - url_for(:controller => "photos", :action => "index", :username => "bob") + get "/user/bob/photos" + assert_equal "photos#index", @response.body + assert_equal "http://www.example.com/user/bob/photos", + url_for(controller: "photos", action: "index", username: "bob") - get '/photos' - assert_equal 'photos#index', @response.body - assert_equal 'http://www.example.com/photos', - url_for(:controller => "photos", :action => "index", :username => nil) + get "/photos" + assert_equal "photos#index", @response.body + assert_equal "http://www.example.com/photos", + url_for(controller: "photos", action: "index", username: nil) end def test_url_recognition_for_optional_static_segments draw do - scope '(groups)' do - scope '(discussions)' do + scope "(groups)" do + scope "(discussions)" do resources :messages end end end - get '/groups/discussions/messages' - assert_equal 'messages#index', @response.body + get "/groups/discussions/messages" + assert_equal "messages#index", @response.body - get '/groups/discussions/messages/1' - assert_equal 'messages#show', @response.body + get "/groups/discussions/messages/1" + assert_equal "messages#show", @response.body - get '/groups/messages' - assert_equal 'messages#index', @response.body + get "/groups/messages" + assert_equal "messages#index", @response.body - get '/groups/messages/1' - assert_equal 'messages#show', @response.body + get "/groups/messages/1" + assert_equal "messages#show", @response.body - get '/discussions/messages' - assert_equal 'messages#index', @response.body + get "/discussions/messages" + assert_equal "messages#index", @response.body - get '/discussions/messages/1' - assert_equal 'messages#show', @response.body + get "/discussions/messages/1" + assert_equal "messages#show", @response.body - get '/messages' - assert_equal 'messages#index', @response.body + get "/messages" + assert_equal "messages#index", @response.body - get '/messages/1' - assert_equal 'messages#show', @response.body + get "/messages/1" + assert_equal "messages#show", @response.body end def test_router_removes_invalid_conditions draw do - scope :constraints => { :id => /\d+/ } do - get '/tickets', :to => 'tickets#index', :as => :tickets + scope constraints: { id: /\d+/ } do + get "/tickets", to: "tickets#index", as: :tickets end end - get '/tickets' - assert_equal 'tickets#index', @response.body - assert_equal '/tickets', tickets_path + get "/tickets" + assert_equal "tickets#index", @response.body + assert_equal "/tickets", tickets_path end def test_constraints_are_merged_from_scope draw do - scope :constraints => { :id => /\d{4}/ } do + scope constraints: { id: /\d{4}/ } do resources :movies do resources :reviews resource :trailer @@ -2551,42 +2569,42 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/movies/0001' - assert_equal 'movies#show', @response.body - assert_equal '/movies/0001', movie_path(:id => '0001') + get "/movies/0001" + assert_equal "movies#show", @response.body + assert_equal "/movies/0001", movie_path(id: "0001") - get '/movies/00001' - assert_equal 'Not Found', @response.body - assert_raises(ActionController::UrlGenerationError){ movie_path(:id => '00001') } + get "/movies/00001" + assert_equal "Not Found", @response.body + assert_raises(ActionController::UrlGenerationError) { movie_path(id: "00001") } - get '/movies/0001/reviews' - assert_equal 'reviews#index', @response.body - assert_equal '/movies/0001/reviews', movie_reviews_path(:movie_id => '0001') + get "/movies/0001/reviews" + assert_equal "reviews#index", @response.body + assert_equal "/movies/0001/reviews", movie_reviews_path(movie_id: "0001") - get '/movies/00001/reviews' - assert_equal 'Not Found', @response.body - assert_raises(ActionController::UrlGenerationError){ movie_reviews_path(:movie_id => '00001') } + get "/movies/00001/reviews" + assert_equal "Not Found", @response.body + assert_raises(ActionController::UrlGenerationError) { movie_reviews_path(movie_id: "00001") } - get '/movies/0001/reviews/0001' - assert_equal 'reviews#show', @response.body - assert_equal '/movies/0001/reviews/0001', movie_review_path(:movie_id => '0001', :id => '0001') + get "/movies/0001/reviews/0001" + assert_equal "reviews#show", @response.body + assert_equal "/movies/0001/reviews/0001", movie_review_path(movie_id: "0001", id: "0001") - get '/movies/00001/reviews/0001' - assert_equal 'Not Found', @response.body - assert_raises(ActionController::UrlGenerationError){ movie_path(:movie_id => '00001', :id => '00001') } + get "/movies/00001/reviews/0001" + assert_equal "Not Found", @response.body + assert_raises(ActionController::UrlGenerationError) { movie_path(movie_id: "00001", id: "00001") } - get '/movies/0001/trailer' - assert_equal 'trailers#show', @response.body - assert_equal '/movies/0001/trailer', movie_trailer_path(:movie_id => '0001') + get "/movies/0001/trailer" + assert_equal "trailers#show", @response.body + assert_equal "/movies/0001/trailer", movie_trailer_path(movie_id: "0001") - get '/movies/00001/trailer' - assert_equal 'Not Found', @response.body - assert_raises(ActionController::UrlGenerationError){ movie_trailer_path(:movie_id => '00001') } + get "/movies/00001/trailer" + assert_equal "Not Found", @response.body + assert_raises(ActionController::UrlGenerationError) { movie_trailer_path(movie_id: "00001") } end def test_only_should_be_read_from_scope draw do - scope :only => [:index, :show] do + scope only: [:index, :show] do namespace :only do resources :clubs do resources :players @@ -2596,34 +2614,34 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/only/clubs' - assert_equal 'only/clubs#index', @response.body - assert_equal '/only/clubs', only_clubs_path + get "/only/clubs" + assert_equal "only/clubs#index", @response.body + assert_equal "/only/clubs", only_clubs_path - get '/only/clubs/1/edit' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { edit_only_club_path(:id => '1') } + get "/only/clubs/1/edit" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { edit_only_club_path(id: "1") } - get '/only/clubs/1/players' - assert_equal 'only/players#index', @response.body - assert_equal '/only/clubs/1/players', only_club_players_path(:club_id => '1') + get "/only/clubs/1/players" + assert_equal "only/players#index", @response.body + assert_equal "/only/clubs/1/players", only_club_players_path(club_id: "1") - get '/only/clubs/1/players/2/edit' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { edit_only_club_player_path(:club_id => '1', :id => '2') } + get "/only/clubs/1/players/2/edit" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { edit_only_club_player_path(club_id: "1", id: "2") } - get '/only/clubs/1/chairman' - assert_equal 'only/chairmen#show', @response.body - assert_equal '/only/clubs/1/chairman', only_club_chairman_path(:club_id => '1') + get "/only/clubs/1/chairman" + assert_equal "only/chairmen#show", @response.body + assert_equal "/only/clubs/1/chairman", only_club_chairman_path(club_id: "1") - get '/only/clubs/1/chairman/edit' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { edit_only_club_chairman_path(:club_id => '1') } + get "/only/clubs/1/chairman/edit" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { edit_only_club_chairman_path(club_id: "1") } end def test_except_should_be_read_from_scope draw do - scope :except => [:new, :create, :edit, :update, :destroy] do + scope except: [:new, :create, :edit, :update, :destroy] do namespace :except do resources :clubs do resources :players @@ -2633,54 +2651,54 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/except/clubs' - assert_equal 'except/clubs#index', @response.body - assert_equal '/except/clubs', except_clubs_path + get "/except/clubs" + assert_equal "except/clubs#index", @response.body + assert_equal "/except/clubs", except_clubs_path - get '/except/clubs/1/edit' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { edit_except_club_path(:id => '1') } + get "/except/clubs/1/edit" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { edit_except_club_path(id: "1") } - get '/except/clubs/1/players' - assert_equal 'except/players#index', @response.body - assert_equal '/except/clubs/1/players', except_club_players_path(:club_id => '1') + get "/except/clubs/1/players" + assert_equal "except/players#index", @response.body + assert_equal "/except/clubs/1/players", except_club_players_path(club_id: "1") - get '/except/clubs/1/players/2/edit' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { edit_except_club_player_path(:club_id => '1', :id => '2') } + get "/except/clubs/1/players/2/edit" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { edit_except_club_player_path(club_id: "1", id: "2") } - get '/except/clubs/1/chairman' - assert_equal 'except/chairmen#show', @response.body - assert_equal '/except/clubs/1/chairman', except_club_chairman_path(:club_id => '1') + get "/except/clubs/1/chairman" + assert_equal "except/chairmen#show", @response.body + assert_equal "/except/clubs/1/chairman", except_club_chairman_path(club_id: "1") - get '/except/clubs/1/chairman/edit' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { edit_except_club_chairman_path(:club_id => '1') } + get "/except/clubs/1/chairman/edit" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { edit_except_club_chairman_path(club_id: "1") } end def test_only_option_should_override_scope draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index + resources :sectors, only: :index end end end - get '/only/sectors' - assert_equal 'only/sectors#index', @response.body - assert_equal '/only/sectors', only_sectors_path + get "/only/sectors" + assert_equal "only/sectors#index", @response.body + assert_equal "/only/sectors", only_sectors_path - get '/only/sectors/1' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { only_sector_path(:id => '1') } + get "/only/sectors/1" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { only_sector_path(id: "1") } end def test_only_option_should_not_inherit draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index do + resources :sectors, only: :index do resources :companies resource :leader end @@ -2688,38 +2706,38 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/only/sectors/1/companies/2' - assert_equal 'only/companies#show', @response.body - assert_equal '/only/sectors/1/companies/2', only_sector_company_path(:sector_id => '1', :id => '2') + get "/only/sectors/1/companies/2" + assert_equal "only/companies#show", @response.body + assert_equal "/only/sectors/1/companies/2", only_sector_company_path(sector_id: "1", id: "2") - get '/only/sectors/1/leader' - assert_equal 'only/leaders#show', @response.body - assert_equal '/only/sectors/1/leader', only_sector_leader_path(:sector_id => '1') + get "/only/sectors/1/leader" + assert_equal "only/leaders#show", @response.body + assert_equal "/only/sectors/1/leader", only_sector_leader_path(sector_id: "1") end def test_except_option_should_override_scope draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] + resources :sectors, except: [:show, :update, :destroy] end end end - get '/except/sectors' - assert_equal 'except/sectors#index', @response.body - assert_equal '/except/sectors', except_sectors_path + get "/except/sectors" + assert_equal "except/sectors#index", @response.body + assert_equal "/except/sectors", except_sectors_path - get '/except/sectors/1' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { except_sector_path(:id => '1') } + get "/except/sectors/1" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { except_sector_path(id: "1") } end def test_except_option_should_not_inherit draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] do + resources :sectors, except: [:show, :update, :destroy] do resources :companies resource :leader end @@ -2727,62 +2745,62 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/except/sectors/1/companies/2' - assert_equal 'except/companies#show', @response.body - assert_equal '/except/sectors/1/companies/2', except_sector_company_path(:sector_id => '1', :id => '2') + get "/except/sectors/1/companies/2" + assert_equal "except/companies#show", @response.body + assert_equal "/except/sectors/1/companies/2", except_sector_company_path(sector_id: "1", id: "2") - get '/except/sectors/1/leader' - assert_equal 'except/leaders#show', @response.body - assert_equal '/except/sectors/1/leader', except_sector_leader_path(:sector_id => '1') + get "/except/sectors/1/leader" + assert_equal "except/leaders#show", @response.body + assert_equal "/except/sectors/1/leader", except_sector_leader_path(sector_id: "1") end def test_except_option_should_override_scoped_only draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index do - resources :managers, :except => [:show, :update, :destroy] + resources :sectors, only: :index do + resources :managers, except: [:show, :update, :destroy] end end end end - get '/only/sectors/1/managers' - assert_equal 'only/managers#index', @response.body - assert_equal '/only/sectors/1/managers', only_sector_managers_path(:sector_id => '1') + get "/only/sectors/1/managers" + assert_equal "only/managers#index", @response.body + assert_equal "/only/sectors/1/managers", only_sector_managers_path(sector_id: "1") - get '/only/sectors/1/managers/2' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { only_sector_manager_path(:sector_id => '1', :id => '2') } + get "/only/sectors/1/managers/2" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { only_sector_manager_path(sector_id: "1", id: "2") } end def test_only_option_should_override_scoped_except draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] do - resources :managers, :only => :index + resources :sectors, except: [:show, :update, :destroy] do + resources :managers, only: :index end end end end - get '/except/sectors/1/managers' - assert_equal 'except/managers#index', @response.body - assert_equal '/except/sectors/1/managers', except_sector_managers_path(:sector_id => '1') + get "/except/sectors/1/managers" + assert_equal "except/managers#index", @response.body + assert_equal "/except/sectors/1/managers", except_sector_managers_path(sector_id: "1") - get '/except/sectors/1/managers/2' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { except_sector_manager_path(:sector_id => '1', :id => '2') } + get "/except/sectors/1/managers/2" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { except_sector_manager_path(sector_id: "1", id: "2") } end def test_only_scope_should_override_parent_scope draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index do + resources :sectors, only: :index do resources :companies do - scope :only => :index do + scope only: :index do resources :divisions end end @@ -2791,22 +2809,22 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/only/sectors/1/companies/2/divisions' - assert_equal 'only/divisions#index', @response.body - assert_equal '/only/sectors/1/companies/2/divisions', only_sector_company_divisions_path(:sector_id => '1', :company_id => '2') + get "/only/sectors/1/companies/2/divisions" + assert_equal "only/divisions#index", @response.body + assert_equal "/only/sectors/1/companies/2/divisions", only_sector_company_divisions_path(sector_id: "1", company_id: "2") - get '/only/sectors/1/companies/2/divisions/3' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { only_sector_company_division_path(:sector_id => '1', :company_id => '2', :id => '3') } + get "/only/sectors/1/companies/2/divisions/3" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { only_sector_company_division_path(sector_id: "1", company_id: "2", id: "3") } end def test_except_scope_should_override_parent_scope draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] do + resources :sectors, except: [:show, :update, :destroy] do resources :companies do - scope :except => [:show, :update, :destroy] do + scope except: [:show, :update, :destroy] do resources :divisions end end @@ -2815,22 +2833,22 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/except/sectors/1/companies/2/divisions' - assert_equal 'except/divisions#index', @response.body - assert_equal '/except/sectors/1/companies/2/divisions', except_sector_company_divisions_path(:sector_id => '1', :company_id => '2') + get "/except/sectors/1/companies/2/divisions" + assert_equal "except/divisions#index", @response.body + assert_equal "/except/sectors/1/companies/2/divisions", except_sector_company_divisions_path(sector_id: "1", company_id: "2") - get '/except/sectors/1/companies/2/divisions/3' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { except_sector_company_division_path(:sector_id => '1', :company_id => '2', :id => '3') } + get "/except/sectors/1/companies/2/divisions/3" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { except_sector_company_division_path(sector_id: "1", company_id: "2", id: "3") } end def test_except_scope_should_override_parent_only_scope draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index do + resources :sectors, only: :index do resources :companies do - scope :except => [:show, :update, :destroy] do + scope except: [:show, :update, :destroy] do resources :departments end end @@ -2839,22 +2857,22 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/only/sectors/1/companies/2/departments' - assert_equal 'only/departments#index', @response.body - assert_equal '/only/sectors/1/companies/2/departments', only_sector_company_departments_path(:sector_id => '1', :company_id => '2') + get "/only/sectors/1/companies/2/departments" + assert_equal "only/departments#index", @response.body + assert_equal "/only/sectors/1/companies/2/departments", only_sector_company_departments_path(sector_id: "1", company_id: "2") - get '/only/sectors/1/companies/2/departments/3' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { only_sector_company_department_path(:sector_id => '1', :company_id => '2', :id => '3') } + get "/only/sectors/1/companies/2/departments/3" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { only_sector_company_department_path(sector_id: "1", company_id: "2", id: "3") } end def test_only_scope_should_override_parent_except_scope draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] do + resources :sectors, except: [:show, :update, :destroy] do resources :companies do - scope :only => :index do + scope only: :index do resources :departments end end @@ -2863,13 +2881,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/except/sectors/1/companies/2/departments' - assert_equal 'except/departments#index', @response.body - assert_equal '/except/sectors/1/companies/2/departments', except_sector_company_departments_path(:sector_id => '1', :company_id => '2') + get "/except/sectors/1/companies/2/departments" + assert_equal "except/departments#index", @response.body + assert_equal "/except/sectors/1/companies/2/departments", except_sector_company_departments_path(sector_id: "1", company_id: "2") - get '/except/sectors/1/companies/2/departments/3' - assert_equal 'Not Found', @response.body - assert_raise(NoMethodError) { except_sector_company_department_path(:sector_id => '1', :company_id => '2', :id => '3') } + get "/except/sectors/1/companies/2/departments/3" + assert_equal "Not Found", @response.body + assert_raise(NoMethodError) { except_sector_company_department_path(sector_id: "1", company_id: "2", id: "3") } end def test_resources_are_not_pluralized @@ -2879,30 +2897,30 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/transport/taxis' - assert_equal 'transport/taxis#index', @response.body - assert_equal '/transport/taxis', transport_taxis_path + get "/transport/taxis" + assert_equal "transport/taxis#index", @response.body + assert_equal "/transport/taxis", transport_taxis_path - get '/transport/taxis/new' - assert_equal 'transport/taxis#new', @response.body - assert_equal '/transport/taxis/new', new_transport_taxi_path + get "/transport/taxis/new" + assert_equal "transport/taxis#new", @response.body + assert_equal "/transport/taxis/new", new_transport_taxi_path - post '/transport/taxis' - assert_equal 'transport/taxis#create', @response.body + post "/transport/taxis" + assert_equal "transport/taxis#create", @response.body - get '/transport/taxis/1' - assert_equal 'transport/taxis#show', @response.body - assert_equal '/transport/taxis/1', transport_taxi_path(:id => '1') + get "/transport/taxis/1" + assert_equal "transport/taxis#show", @response.body + assert_equal "/transport/taxis/1", transport_taxi_path(id: "1") - get '/transport/taxis/1/edit' - assert_equal 'transport/taxis#edit', @response.body - assert_equal '/transport/taxis/1/edit', edit_transport_taxi_path(:id => '1') + get "/transport/taxis/1/edit" + assert_equal "transport/taxis#edit", @response.body + assert_equal "/transport/taxis/1/edit", edit_transport_taxi_path(id: "1") - put '/transport/taxis/1' - assert_equal 'transport/taxis#update', @response.body + put "/transport/taxis/1" + assert_equal "transport/taxis#update", @response.body - delete '/transport/taxis/1' - assert_equal 'transport/taxis#destroy', @response.body + delete "/transport/taxis/1" + assert_equal "transport/taxis#destroy", @response.body end def test_singleton_resources_are_not_singularized @@ -2912,169 +2930,169 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/medical/taxis/new' - assert_equal 'medical/taxis#new', @response.body - assert_equal '/medical/taxis/new', new_medical_taxis_path + get "/medical/taxis/new" + assert_equal "medical/taxis#new", @response.body + assert_equal "/medical/taxis/new", new_medical_taxis_path - post '/medical/taxis' - assert_equal 'medical/taxis#create', @response.body + post "/medical/taxis" + assert_equal "medical/taxis#create", @response.body - get '/medical/taxis' - assert_equal 'medical/taxis#show', @response.body - assert_equal '/medical/taxis', medical_taxis_path + get "/medical/taxis" + assert_equal "medical/taxis#show", @response.body + assert_equal "/medical/taxis", medical_taxis_path - get '/medical/taxis/edit' - assert_equal 'medical/taxis#edit', @response.body - assert_equal '/medical/taxis/edit', edit_medical_taxis_path + get "/medical/taxis/edit" + assert_equal "medical/taxis#edit", @response.body + assert_equal "/medical/taxis/edit", edit_medical_taxis_path - put '/medical/taxis' - assert_equal 'medical/taxis#update', @response.body + put "/medical/taxis" + assert_equal "medical/taxis#update", @response.body - delete '/medical/taxis' - assert_equal 'medical/taxis#destroy', @response.body + delete "/medical/taxis" + assert_equal "medical/taxis#destroy", @response.body end def test_greedy_resource_id_regexp_doesnt_match_edit_and_custom_action draw do - resources :sections, :id => /.+/ do - get :preview, :on => :member + resources :sections, id: /.+/ do + get :preview, on: :member end end - get '/sections/1/edit' - assert_equal 'sections#edit', @response.body - assert_equal '/sections/1/edit', edit_section_path(:id => '1') + get "/sections/1/edit" + assert_equal "sections#edit", @response.body + assert_equal "/sections/1/edit", edit_section_path(id: "1") - get '/sections/1/preview' - assert_equal 'sections#preview', @response.body - assert_equal '/sections/1/preview', preview_section_path(:id => '1') + get "/sections/1/preview" + assert_equal "sections#preview", @response.body + assert_equal "/sections/1/preview", preview_section_path(id: "1") end def test_resource_constraints_are_pushed_to_scope draw do namespace :wiki do - resources :articles, :id => /[^\/]+/ do - resources :comments, :only => [:create, :new] + resources :articles, id: /[^\/]+/ do + resources :comments, only: [:create, :new] end end end - get '/wiki/articles/Ruby_on_Rails_3.0' - assert_equal 'wiki/articles#show', @response.body - assert_equal '/wiki/articles/Ruby_on_Rails_3.0', wiki_article_path(:id => 'Ruby_on_Rails_3.0') + get "/wiki/articles/Ruby_on_Rails_3.0" + assert_equal "wiki/articles#show", @response.body + assert_equal "/wiki/articles/Ruby_on_Rails_3.0", wiki_article_path(id: "Ruby_on_Rails_3.0") - get '/wiki/articles/Ruby_on_Rails_3.0/comments/new' - assert_equal 'wiki/comments#new', @response.body - assert_equal '/wiki/articles/Ruby_on_Rails_3.0/comments/new', new_wiki_article_comment_path(:article_id => 'Ruby_on_Rails_3.0') + get "/wiki/articles/Ruby_on_Rails_3.0/comments/new" + assert_equal "wiki/comments#new", @response.body + assert_equal "/wiki/articles/Ruby_on_Rails_3.0/comments/new", new_wiki_article_comment_path(article_id: "Ruby_on_Rails_3.0") - post '/wiki/articles/Ruby_on_Rails_3.0/comments' - assert_equal 'wiki/comments#create', @response.body - assert_equal '/wiki/articles/Ruby_on_Rails_3.0/comments', wiki_article_comments_path(:article_id => 'Ruby_on_Rails_3.0') + post "/wiki/articles/Ruby_on_Rails_3.0/comments" + assert_equal "wiki/comments#create", @response.body + assert_equal "/wiki/articles/Ruby_on_Rails_3.0/comments", wiki_article_comments_path(article_id: "Ruby_on_Rails_3.0") end def test_resources_path_can_be_a_symbol draw do - resources :wiki_pages, :path => :pages - resource :wiki_account, :path => :my_account + resources :wiki_pages, path: :pages + resource :wiki_account, path: :my_account end - get '/pages' - assert_equal 'wiki_pages#index', @response.body - assert_equal '/pages', wiki_pages_path + get "/pages" + assert_equal "wiki_pages#index", @response.body + assert_equal "/pages", wiki_pages_path - get '/pages/Ruby_on_Rails' - assert_equal 'wiki_pages#show', @response.body - assert_equal '/pages/Ruby_on_Rails', wiki_page_path(:id => 'Ruby_on_Rails') + get "/pages/Ruby_on_Rails" + assert_equal "wiki_pages#show", @response.body + assert_equal "/pages/Ruby_on_Rails", wiki_page_path(id: "Ruby_on_Rails") - get '/my_account' - assert_equal 'wiki_accounts#show', @response.body - assert_equal '/my_account', wiki_account_path + get "/my_account" + assert_equal "wiki_accounts#show", @response.body + assert_equal "/my_account", wiki_account_path end def test_redirect_https draw do - get 'secure', :to => redirect("/secure/login") + get "secure", to: redirect("/secure/login") end with_https do - get '/secure' - verify_redirect 'https://www.example.com/secure/login' + get "/secure" + verify_redirect "https://www.example.com/secure/login" end end def test_path_parameters_is_not_stale draw do - scope '/countries/:country', :constraints => lambda { |params, req| %w(all France).include?(params[:country]) } do - get '/', :to => 'countries#index' - get '/cities', :to => 'countries#cities' + scope "/countries/:country", constraints: lambda { |params, req| %w(all France).include?(params[:country]) } do + get "/", to: "countries#index" + get "/cities", to: "countries#cities" end - get '/countries/:country/(*other)', :to => redirect{ |params, req| params[:other] ? "/countries/all/#{params[:other]}" : '/countries/all' } + get "/countries/:country/(*other)", to: redirect { |params, req| params[:other] ? "/countries/all/#{params[:other]}" : "/countries/all" } end - get '/countries/France' - assert_equal 'countries#index', @response.body + get "/countries/France" + assert_equal "countries#index", @response.body - get '/countries/France/cities' - assert_equal 'countries#cities', @response.body + get "/countries/France/cities" + assert_equal "countries#cities", @response.body - get '/countries/UK' - verify_redirect 'http://www.example.com/countries/all' + get "/countries/UK" + verify_redirect "http://www.example.com/countries/all" - get '/countries/UK/cities' - verify_redirect 'http://www.example.com/countries/all/cities' + get "/countries/UK/cities" + verify_redirect "http://www.example.com/countries/all/cities" end def test_constraints_block_not_carried_to_following_routes draw do - scope '/italians' do - get '/writers', :to => 'italians#writers', :constraints => ::TestRoutingMapper::IpRestrictor - get '/sculptors', :to => 'italians#sculptors' - get '/painters/:painter', :to => 'italians#painters', :constraints => {:painter => /michelangelo/} + scope "/italians" do + get "/writers", to: "italians#writers", constraints: ::TestRoutingMapper::IpRestrictor + get "/sculptors", to: "italians#sculptors" + get "/painters/:painter", to: "italians#painters", constraints: { painter: /michelangelo/ } end end - get '/italians/writers' - assert_equal 'Not Found', @response.body + get "/italians/writers" + assert_equal "Not Found", @response.body - get '/italians/sculptors' - assert_equal 'italians#sculptors', @response.body + get "/italians/sculptors" + assert_equal "italians#sculptors", @response.body - get '/italians/painters/botticelli' - assert_equal 'Not Found', @response.body + get "/italians/painters/botticelli" + assert_equal "Not Found", @response.body - get '/italians/painters/michelangelo' - assert_equal 'italians#painters', @response.body + get "/italians/painters/michelangelo" + assert_equal "italians#painters", @response.body end def test_custom_resource_actions_defined_using_string draw do resources :customers do resources :invoices do - get "aged/:months", :on => :collection, :action => :aged, :as => :aged + get "aged/:months", on: :collection, action: :aged, as: :aged end - get "inactive", :on => :collection - post "deactivate", :on => :member - get "old", :on => :collection, :as => :stale + get "inactive", on: :collection + post "deactivate", on: :member + get "old", on: :collection, as: :stale end end - get '/customers/inactive' - assert_equal 'customers#inactive', @response.body - assert_equal '/customers/inactive', inactive_customers_path + get "/customers/inactive" + assert_equal "customers#inactive", @response.body + assert_equal "/customers/inactive", inactive_customers_path - post '/customers/1/deactivate' - assert_equal 'customers#deactivate', @response.body - assert_equal '/customers/1/deactivate', deactivate_customer_path(:id => '1') + post "/customers/1/deactivate" + assert_equal "customers#deactivate", @response.body + assert_equal "/customers/1/deactivate", deactivate_customer_path(id: "1") - get '/customers/old' - assert_equal 'customers#old', @response.body - assert_equal '/customers/old', stale_customers_path + get "/customers/old" + assert_equal "customers#old", @response.body + assert_equal "/customers/old", stale_customers_path - get '/customers/1/invoices/aged/3' - assert_equal 'invoices#aged', @response.body - assert_equal '/customers/1/invoices/aged/3', aged_customer_invoices_path(:customer_id => '1', :months => '3') + get "/customers/1/invoices/aged/3" + assert_equal "invoices#aged", @response.body + assert_equal "/customers/1/invoices/aged/3", aged_customer_invoices_path(customer_id: "1", months: "3") end def test_route_defined_in_resources_scope_level @@ -3084,43 +3102,43 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/customers/1/export' - assert_equal 'customers#export', @response.body - assert_equal '/customers/1/export', customer_export_path(:customer_id => '1') + get "/customers/1/export" + assert_equal "customers#export", @response.body + assert_equal "/customers/1/export", customer_export_path(customer_id: "1") end def test_named_character_classes_in_regexp_constraints draw do - get '/purchases/:token/:filename', - :to => 'purchases#fetch', - :token => /[[:alnum:]]{10}/, - :filename => /(.+)/, - :as => :purchase + get "/purchases/:token/:filename", + to: "purchases#fetch", + token: /[[:alnum:]]{10}/, + filename: /(.+)/, + as: :purchase end - get '/purchases/315004be7e/Ruby_on_Rails_3.pdf' - assert_equal 'purchases#fetch', @response.body - assert_equal '/purchases/315004be7e/Ruby_on_Rails_3.pdf', purchase_path(:token => '315004be7e', :filename => 'Ruby_on_Rails_3.pdf') + get "/purchases/315004be7e/Ruby_on_Rails_3.pdf" + assert_equal "purchases#fetch", @response.body + assert_equal "/purchases/315004be7e/Ruby_on_Rails_3.pdf", purchase_path(token: "315004be7e", filename: "Ruby_on_Rails_3.pdf") end def test_nested_resource_constraints draw do - resources :lists, :id => /([A-Za-z0-9]{25})|default/ do - resources :todos, :id => /\d+/ + resources :lists, id: /([A-Za-z0-9]{25})|default/ do + resources :todos, id: /\d+/ end end - get '/lists/01234012340123401234fffff' - assert_equal 'lists#show', @response.body - assert_equal '/lists/01234012340123401234fffff', list_path(:id => '01234012340123401234fffff') + get "/lists/01234012340123401234fffff" + assert_equal "lists#show", @response.body + assert_equal "/lists/01234012340123401234fffff", list_path(id: "01234012340123401234fffff") - get '/lists/01234012340123401234fffff/todos/1' - assert_equal 'todos#show', @response.body - assert_equal '/lists/01234012340123401234fffff/todos/1', list_todo_path(:list_id => '01234012340123401234fffff', :id => '1') + get "/lists/01234012340123401234fffff/todos/1" + assert_equal "todos#show", @response.body + assert_equal "/lists/01234012340123401234fffff/todos/1", list_todo_path(list_id: "01234012340123401234fffff", id: "1") - get '/lists/2/todos/1' - assert_equal 'Not Found', @response.body - assert_raises(ActionController::UrlGenerationError){ list_todo_path(:list_id => '2', :id => '1') } + get "/lists/2/todos/1" + assert_equal "Not Found", @response.body + assert_raises(ActionController::UrlGenerationError) { list_todo_path(list_id: "2", id: "1") } end def test_redirect_argument_error @@ -3143,10 +3161,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_explicitly_avoiding_the_named_route draw do - scope :as => "routes" do - get "/c/:id", :as => :collision, :to => "collision#show" - get "/collision", :to => "collision#show" - get "/no_collision", :to => "collision#show", :as => nil + scope as: "routes" do + get "/c/:id", as: :collision, to: "collision#show" + get "/collision", to: "collision#show" + get "/no_collision", to: "collision#show", as: nil end end @@ -3155,49 +3173,49 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_controller_name_with_leading_slash_raise_error assert_raise(ArgumentError) do - draw { get '/feeds/:service', :to => '/feeds#show' } + draw { get "/feeds/:service", to: "/feeds#show" } end assert_raise(ArgumentError) do - draw { get '/feeds/:service', :controller => '/feeds', :action => 'show' } + draw { get "/feeds/:service", controller: "/feeds", action: "show" } end assert_raise(ArgumentError) do - draw { get '/api/feeds/:service', :to => '/api/feeds#show' } + draw { get "/api/feeds/:service", to: "/api/feeds#show" } end assert_raise(ArgumentError) do - draw { resources :feeds, :controller => '/feeds' } + draw { resources :feeds, controller: "/feeds" } end end def test_invalid_route_name_raises_error assert_raise(ArgumentError) do - draw { get '/products', :to => 'products#index', :as => 'products ' } + draw { get "/products", to: "products#index", as: "products " } end assert_raise(ArgumentError) do - draw { get '/products', :to => 'products#index', :as => ' products' } + draw { get "/products", to: "products#index", as: " products" } end assert_raise(ArgumentError) do - draw { get '/products', :to => 'products#index', :as => 'products!' } + draw { get "/products", to: "products#index", as: "products!" } end assert_raise(ArgumentError) do - draw { get '/products', :to => 'products#index', :as => 'products index' } + draw { get "/products", to: "products#index", as: "products index" } end assert_raise(ArgumentError) do - draw { get '/products', :to => 'products#index', :as => '1products' } + draw { get "/products", to: "products#index", as: "1products" } end end def test_duplicate_route_name_raises_error assert_raise(ArgumentError) do draw do - get '/collision', :to => 'collision#show', :as => 'collision' - get '/duplicate', :to => 'duplicate#show', :as => 'collision' + get "/collision", to: "collision#show", as: "collision" + get "/duplicate", to: "duplicate#show", as: "collision" end end end @@ -3206,15 +3224,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_raise(ArgumentError) do draw do resources :collisions - get '/collision', :to => 'collision#show', :as => 'collision' + get "/collision", to: "collision#show", as: "collision" end end end def test_nested_route_in_nested_resource draw do - resources :posts, :only => [:index, :show] do - resources :comments, :except => :destroy do + resources :posts, only: [:index, :show] do + resources :comments, except: :destroy do get "views" => "comments#views", :as => :views end end @@ -3222,124 +3240,124 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/posts/1/comments/2/views" assert_equal "comments#views", @response.body - assert_equal "/posts/1/comments/2/views", post_comment_views_path(:post_id => '1', :comment_id => '2') + assert_equal "/posts/1/comments/2/views", post_comment_views_path(post_id: "1", comment_id: "2") end def test_root_in_deeply_nested_scope draw do - resources :posts, :only => [:index, :show] do + resources :posts, only: [:index, :show] do namespace :admin do - root :to => "index#index" + root to: "index#index" end end end get "/posts/1/admin" assert_equal "admin/index#index", @response.body - assert_equal "/posts/1/admin", post_admin_root_path(:post_id => '1') + assert_equal "/posts/1/admin", post_admin_root_path(post_id: "1") end def test_custom_param draw do - resources :profiles, :param => :username do - get :details, :on => :member + resources :profiles, param: :username do + get :details, on: :member resources :messages end end - get '/profiles/bob' - assert_equal 'profiles#show', @response.body - assert_equal 'bob', @request.params[:username] + get "/profiles/bob" + assert_equal "profiles#show", @response.body + assert_equal "bob", @request.params[:username] - get '/profiles/bob/details' - assert_equal 'bob', @request.params[:username] + get "/profiles/bob/details" + assert_equal "bob", @request.params[:username] - get '/profiles/bob/messages/34' - assert_equal 'bob', @request.params[:profile_username] - assert_equal '34', @request.params[:id] + get "/profiles/bob/messages/34" + assert_equal "bob", @request.params[:profile_username] + assert_equal "34", @request.params[:id] end def test_custom_param_constraint draw do - resources :profiles, :param => :username, :username => /[a-z]+/ do - get :details, :on => :member + resources :profiles, param: :username, username: /[a-z]+/ do + get :details, on: :member resources :messages end end - get '/profiles/bob1' + get "/profiles/bob1" assert_equal 404, @response.status - get '/profiles/bob1/details' + get "/profiles/bob1/details" assert_equal 404, @response.status - get '/profiles/bob1/messages/34' + get "/profiles/bob1/messages/34" assert_equal 404, @response.status end def test_shallow_custom_param draw do resources :orders do - constraints :download => /[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/ do - resources :downloads, :param => :download, :shallow => true + constraints download: /[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/ do + resources :downloads, param: :download, shallow: true end end end - get '/downloads/0c0c0b68-d24b-11e1-a861-001ff3fffe6f.zip' - assert_equal 'downloads#show', @response.body - assert_equal '0c0c0b68-d24b-11e1-a861-001ff3fffe6f', @request.params[:download] + get "/downloads/0c0c0b68-d24b-11e1-a861-001ff3fffe6f.zip" + assert_equal "downloads#show", @response.body + assert_equal "0c0c0b68-d24b-11e1-a861-001ff3fffe6f", @request.params[:download] end def test_action_from_path_is_not_frozen draw do - get 'search' => 'search' + get "search" => "search" end - get '/search' + get "/search" assert !@request.params[:action].frozen? end def test_multiple_positional_args_with_the_same_name draw do - get '/downloads/:id/:id.tar' => 'downloads#show', as: :download, format: false + get "/downloads/:id/:id.tar" => "downloads#show", as: :download, format: false end expected_params = { - controller: 'downloads', - action: 'show', - id: '1' + controller: "downloads", + action: "show", + id: "1" } - get '/downloads/1/1.tar' - assert_equal 'downloads#show', @response.body + get "/downloads/1/1.tar" + assert_equal "downloads#show", @response.body assert_equal expected_params, @request.path_parameters - assert_equal '/downloads/1/1.tar', download_path('1') - assert_equal '/downloads/1/1.tar', download_path('1', '1') + assert_equal "/downloads/1/1.tar", download_path("1") + assert_equal "/downloads/1/1.tar", download_path("1", "1") end def test_absolute_controller_namespace draw do namespace :foo do - get '/', to: '/bar#index', as: 'root' + get "/", to: "/bar#index", as: "root" end end - get '/foo' - assert_equal 'bar#index', @response.body - assert_equal '/foo', foo_root_path + get "/foo" + assert_equal "bar#index", @response.body + assert_equal "/foo", foo_root_path end def test_namespace_as_controller draw do namespace :foo do - get '/', to: '/bar#index', as: 'root' + get "/", to: "/bar#index", as: "root" end end - get '/foo' - assert_equal 'bar#index', @response.body - assert_equal '/foo', foo_root_path + get "/foo" + assert_equal "bar#index", @response.body + assert_equal "/foo", foo_root_path end def test_trailing_slash @@ -3347,63 +3365,63 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :streams end - get '/streams' - assert @response.ok?, 'route without trailing slash should work' + get "/streams" + assert @response.ok?, "route without trailing slash should work" - get '/streams/' - assert @response.ok?, 'route with trailing slash should work' + get "/streams/" + assert @response.ok?, "route with trailing slash should work" - get '/streams?foobar' - assert @response.ok?, 'route without trailing slash and with QUERY_STRING should work' + get "/streams?foobar" + assert @response.ok?, "route without trailing slash and with QUERY_STRING should work" - get '/streams/?foobar' - assert @response.ok?, 'route with trailing slash and with QUERY_STRING should work' + get "/streams/?foobar" + assert @response.ok?, "route with trailing slash and with QUERY_STRING should work" end def test_route_with_dashes_in_path draw do - get '/contact-us', to: 'pages#contact_us' + get "/contact-us", to: "pages#contact_us" end - get '/contact-us' - assert_equal 'pages#contact_us', @response.body - assert_equal '/contact-us', contact_us_path + get "/contact-us" + assert_equal "pages#contact_us", @response.body + assert_equal "/contact-us", contact_us_path end def test_shorthand_route_with_dashes_in_path draw do - get '/about-us/index' + get "/about-us/index" end - get '/about-us/index' - assert_equal 'about_us#index', @response.body - assert_equal '/about-us/index', about_us_index_path + get "/about-us/index" + assert_equal "about_us#index", @response.body + assert_equal "/about-us/index", about_us_index_path end def test_resource_routes_with_dashes_in_path draw do resources :photos, only: [:show] do - get 'user-favorites', on: :collection - get 'preview-photo', on: :member - get 'summary-text' + get "user-favorites", on: :collection + get "preview-photo", on: :member + get "summary-text" end end - get '/photos/user-favorites' - assert_equal 'photos#user_favorites', @response.body - assert_equal '/photos/user-favorites', user_favorites_photos_path + get "/photos/user-favorites" + assert_equal "photos#user_favorites", @response.body + assert_equal "/photos/user-favorites", user_favorites_photos_path - get '/photos/1/preview-photo' - assert_equal 'photos#preview_photo', @response.body - assert_equal '/photos/1/preview-photo', preview_photo_photo_path('1') + get "/photos/1/preview-photo" + assert_equal "photos#preview_photo", @response.body + assert_equal "/photos/1/preview-photo", preview_photo_photo_path("1") - get '/photos/1/summary-text' - assert_equal 'photos#summary_text', @response.body - assert_equal '/photos/1/summary-text', photo_summary_text_path('1') + get "/photos/1/summary-text" + assert_equal "photos#summary_text", @response.body + assert_equal "/photos/1/summary-text", photo_summary_text_path("1") - get '/photos/1' - assert_equal 'photos#show', @response.body - assert_equal '/photos/1', photo_path('1') + get "/photos/1" + assert_equal "photos#show", @response.body + assert_equal "/photos/1", photo_path("1") end def test_shallow_path_inside_namespace_is_not_added_twice @@ -3417,208 +3435,208 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - get '/admin/posts/1/comments' - assert_equal 'admin/comments#index', @response.body - assert_equal '/admin/posts/1/comments', admin_post_comments_path('1') + get "/admin/posts/1/comments" + assert_equal "admin/comments#index", @response.body + assert_equal "/admin/posts/1/comments", admin_post_comments_path("1") end def test_mix_string_to_controller_action draw do - get '/projects', controller: 'project_files', - action: 'index', - to: 'comments#index' + get "/projects", controller: "project_files", + action: "index", + to: "comments#index" end - get '/projects' - assert_equal 'comments#index', @response.body + get "/projects" + assert_equal "comments#index", @response.body end def test_mix_string_to_controller draw do - get '/projects', controller: 'project_files', - to: 'comments#index' + get "/projects", controller: "project_files", + to: "comments#index" end - get '/projects' - assert_equal 'comments#index', @response.body + get "/projects" + assert_equal "comments#index", @response.body end def test_mix_string_to_action draw do - get '/projects', action: 'index', - to: 'comments#index' + get "/projects", action: "index", + to: "comments#index" end - get '/projects' - assert_equal 'comments#index', @response.body + get "/projects" + assert_equal "comments#index", @response.body end def test_shallow_path_and_prefix_are_not_added_to_non_shallow_routes draw do - scope shallow_path: 'projects', shallow_prefix: 'project' do + scope shallow_path: "projects", shallow_prefix: "project" do resources :projects do - resources :files, controller: 'project_files', shallow: true + resources :files, controller: "project_files", shallow: true end end end - get '/projects' - assert_equal 'projects#index', @response.body - assert_equal '/projects', projects_path + get "/projects" + assert_equal "projects#index", @response.body + assert_equal "/projects", projects_path - get '/projects/new' - assert_equal 'projects#new', @response.body - assert_equal '/projects/new', new_project_path + get "/projects/new" + assert_equal "projects#new", @response.body + assert_equal "/projects/new", new_project_path - post '/projects' - assert_equal 'projects#create', @response.body + post "/projects" + assert_equal "projects#create", @response.body - get '/projects/1' - assert_equal 'projects#show', @response.body - assert_equal '/projects/1', project_path('1') + get "/projects/1" + assert_equal "projects#show", @response.body + assert_equal "/projects/1", project_path("1") - get '/projects/1/edit' - assert_equal 'projects#edit', @response.body - assert_equal '/projects/1/edit', edit_project_path('1') + get "/projects/1/edit" + assert_equal "projects#edit", @response.body + assert_equal "/projects/1/edit", edit_project_path("1") - patch '/projects/1' - assert_equal 'projects#update', @response.body + patch "/projects/1" + assert_equal "projects#update", @response.body - delete '/projects/1' - assert_equal 'projects#destroy', @response.body + delete "/projects/1" + assert_equal "projects#destroy", @response.body - get '/projects/1/files' - assert_equal 'project_files#index', @response.body - assert_equal '/projects/1/files', project_files_path('1') + get "/projects/1/files" + assert_equal "project_files#index", @response.body + assert_equal "/projects/1/files", project_files_path("1") - get '/projects/1/files/new' - assert_equal 'project_files#new', @response.body - assert_equal '/projects/1/files/new', new_project_file_path('1') + get "/projects/1/files/new" + assert_equal "project_files#new", @response.body + assert_equal "/projects/1/files/new", new_project_file_path("1") - post '/projects/1/files' - assert_equal 'project_files#create', @response.body + post "/projects/1/files" + assert_equal "project_files#create", @response.body - get '/projects/files/2' - assert_equal 'project_files#show', @response.body - assert_equal '/projects/files/2', project_file_path('2') + get "/projects/files/2" + assert_equal "project_files#show", @response.body + assert_equal "/projects/files/2", project_file_path("2") - get '/projects/files/2/edit' - assert_equal 'project_files#edit', @response.body - assert_equal '/projects/files/2/edit', edit_project_file_path('2') + get "/projects/files/2/edit" + assert_equal "project_files#edit", @response.body + assert_equal "/projects/files/2/edit", edit_project_file_path("2") - patch '/projects/files/2' - assert_equal 'project_files#update', @response.body + patch "/projects/files/2" + assert_equal "project_files#update", @response.body - delete '/projects/files/2' - assert_equal 'project_files#destroy', @response.body + delete "/projects/files/2" + assert_equal "project_files#destroy", @response.body end def test_scope_path_is_copied_to_shallow_path draw do - scope path: 'foo' do + scope path: "foo" do resources :posts do resources :comments, shallow: true end end end - assert_equal '/foo/comments/1', comment_path('1') + assert_equal "/foo/comments/1", comment_path("1") end def test_scope_as_is_copied_to_shallow_prefix draw do - scope as: 'foo' do + scope as: "foo" do resources :posts do resources :comments, shallow: true end end end - assert_equal '/comments/1', foo_comment_path('1') + assert_equal "/comments/1", foo_comment_path("1") end def test_scope_shallow_prefix_is_not_overwritten_by_as draw do - scope as: 'foo', shallow_prefix: 'bar' do + scope as: "foo", shallow_prefix: "bar" do resources :posts do resources :comments, shallow: true end end end - assert_equal '/comments/1', bar_comment_path('1') + assert_equal "/comments/1", bar_comment_path("1") end def test_scope_shallow_path_is_not_overwritten_by_path draw do - scope path: 'foo', shallow_path: 'bar' do + scope path: "foo", shallow_path: "bar" do resources :posts do resources :comments, shallow: true end end end - assert_equal '/bar/comments/1', comment_path('1') + assert_equal "/bar/comments/1", comment_path("1") end def test_resource_where_as_is_empty draw do - resource :post, as: '' + resource :post, as: "" - scope 'post', as: 'post' do - resource :comment, as: '' + scope "post", as: "post" do + resource :comment, as: "" end end - assert_equal '/post/new', new_path - assert_equal '/post/comment/new', new_post_path + assert_equal "/post/new", new_path + assert_equal "/post/comment/new", new_post_path end def test_resources_where_as_is_empty draw do - resources :posts, as: '' + resources :posts, as: "" - scope 'posts', as: 'posts' do - resources :comments, as: '' + scope "posts", as: "posts" do + resources :comments, as: "" end end - assert_equal '/posts/new', new_path - assert_equal '/posts/comments/new', new_posts_path + assert_equal "/posts/new", new_path + assert_equal "/posts/comments/new", new_posts_path end def test_scope_where_as_is_empty draw do - scope 'post', as: '' do + scope "post", as: "" do resource :user resources :comments end end - assert_equal '/post/user/new', new_user_path - assert_equal '/post/comments/new', new_comment_path + assert_equal "/post/user/new", new_user_path + assert_equal "/post/comments/new", new_comment_path end def test_head_fetch_with_mount_on_root draw do - get '/home' => 'test#index' - mount lambda { |env| [200, {}, [env['REQUEST_METHOD']]] }, at: '/' + get "/home" => "test#index" + mount lambda { |env| [200, {}, [env["REQUEST_METHOD"]]] }, at: "/" end # HEAD request should match `get /home` rather than the # lower-precedence Rack app mounted at `/`. - head '/home' + head "/home" assert_response :ok - assert_equal 'test#index', @response.body + assert_equal "test#index", @response.body # But the Rack app can still respond to its own HEAD requests. - head '/foobar' + head "/foobar" assert_response :ok - assert_equal 'HEAD', @response.body + assert_equal "HEAD", @response.body end def test_passing_action_parameters_to_url_helpers_raises_error_if_parameters_are_not_permitted draw do - root :to => 'projects#index' + root to: "projects#index" end - params = ActionController::Parameters.new(id: '1') + params = ActionController::Parameters.new(id: "1") assert_raises ArgumentError do root_path(params) @@ -3627,18 +3645,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_passing_action_parameters_to_url_helpers_is_allowed_if_parameters_are_permitted draw do - root :to => 'projects#index' + root to: "projects#index" end - params = ActionController::Parameters.new(id: '1') + params = ActionController::Parameters.new(id: "1") params.permit! - assert_equal '/?id=1', root_path(params) + assert_equal "/?id=1", root_path(params) end def test_dynamic_controller_segments_are_deprecated assert_deprecated do draw do - get '/:controller', action: 'index' + get "/:controller", action: "index" end end end @@ -3646,16 +3664,58 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_dynamic_action_segments_are_deprecated assert_deprecated do draw do - get '/pages/:action', controller: 'pages' + get "/pages/:action", controller: "pages" + end + end + end + + def test_multiple_roots + draw do + namespace :foo do + root "pages#index", constraints: { host: "www.example.com" } + root "admin/pages#index", constraints: { host: "admin.example.com" } + end + + root "pages#index", constraints: { host: "www.example.com" } + root "admin/pages#index", constraints: { host: "admin.example.com" } + end + + get "http://www.example.com/foo" + assert_equal "foo/pages#index", @response.body + + get "http://admin.example.com/foo" + assert_equal "foo/admin/pages#index", @response.body + + get "http://www.example.com/" + assert_equal "pages#index", @response.body + + get "http://admin.example.com/" + assert_equal "admin/pages#index", @response.body + end + + def test_multiple_namespaced_roots + draw do + namespace :foo do + root "test#index" + end + + root "test#index" + + namespace :bar do + root "test#index" end end + + assert_equal "/foo", foo_root_path + assert_equal "/", root_path + assert_equal "/bar", bar_root_path end private def draw(&block) self.class.stub_controllers do |routes| - routes.default_url_options = { host: 'www.example.com' } + routes.default_url_options = { host: "www.example.com" } routes.draw(&block) @app = RoutedRackApp.new routes end @@ -3683,7 +3743,7 @@ private def verify_redirect(url, status=301) assert_equal status, @response.status - assert_equal url, @response.headers['Location'] + assert_equal url, @response.headers["Location"] assert_equal expected_redirect_body(url), @response.body end @@ -3720,13 +3780,13 @@ class TestAltApp < ActionDispatch::IntegrationTest class XHeader def call(env) - [200, {"Content-Type" => "text/html"}, ["XHeader"]] + [200, { "Content-Type" => "text/html" }, ["XHeader"]] end end class AltApp def call(env) - [200, {"Content-Type" => "text/html"}, ["Alternative App"]] + [200, { "Content-Type" => "text/html" }, ["Alternative App"]] end end @@ -3736,7 +3796,7 @@ class TestAltApp < ActionDispatch::IntegrationTest end }.new AltRoutes.draw do - get "/" => TestAltApp::XHeader.new, :constraints => {:x_header => /HEADER/} + get "/" => TestAltApp::XHeader.new, :constraints => { x_header: /HEADER/ } get "/" => TestAltApp::AltApp.new end @@ -3764,7 +3824,7 @@ end class TestAppendingRoutes < ActionDispatch::IntegrationTest def simple_app(resp) - lambda { |e| [ 200, { 'Content-Type' => 'text/plain' }, [resp] ] } + lambda { |e| [ 200, { "Content-Type" => "text/plain" }, [resp] ] } end def setup @@ -3772,28 +3832,28 @@ class TestAppendingRoutes < ActionDispatch::IntegrationTest s = self routes = ActionDispatch::Routing::RouteSet.new routes.append do - get '/hello' => s.simple_app('fail') - get '/goodbye' => s.simple_app('goodbye') + get "/hello" => s.simple_app("fail") + get "/goodbye" => s.simple_app("goodbye") end routes.draw do - get '/hello' => s.simple_app('hello') + get "/hello" => s.simple_app("hello") end @app = self.class.build_app routes end def test_goodbye_should_be_available - get '/goodbye' - assert_equal 'goodbye', @response.body + get "/goodbye" + assert_equal "goodbye", @response.body end def test_hello_should_not_be_overwritten - get '/hello' - assert_equal 'hello', @response.body + get "/hello" + assert_equal "hello", @response.body end def test_missing_routes_are_still_missing - get '/random' + get "/random" assert_equal 404, @response.status end end @@ -3816,7 +3876,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_missing_controller ex = assert_raises(ArgumentError) { draw do - get '/foo/bar', :action => :index + get "/foo/bar", action: :index end } assert_match(/Missing :controller/, ex.message) @@ -3825,7 +3885,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_missing_controller_with_to ex = assert_raises(ArgumentError) { draw do - get '/foo/bar', :to => 'foo' + get "/foo/bar", to: "foo" end } assert_match(/Missing :controller/, ex.message) @@ -3834,7 +3894,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_missing_action_on_hash ex = assert_raises(ArgumentError) { draw do - get '/foo/bar', :to => 'foo#' + get "/foo/bar", to: "foo#" end } assert_match(/Missing :action/, ex.message) @@ -3843,20 +3903,20 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_valid_controller_options_inside_namespace draw do namespace :admin do - resources :storage_files, :controller => "storage_files" + resources :storage_files, controller: "storage_files" end end - get '/admin/storage_files' + get "/admin/storage_files" assert_equal "admin/storage_files#index", @response.body end def test_resources_with_valid_namespaced_controller_option draw do - resources :storage_files, :controller => 'admin/storage_files' + resources :storage_files, controller: "admin/storage_files" end - get '/storage_files' + get "/storage_files" assert_equal "admin/storage_files#index", @response.body end @@ -3864,7 +3924,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest e = assert_raise(ArgumentError) do draw do namespace :admin do - resources :storage_files, :controller => "StorageFiles" + resources :storage_files, controller: "StorageFiles" end end end @@ -3875,7 +3935,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_warn_with_ruby_constant_syntax_namespaced_controller_option e = assert_raise(ArgumentError) do draw do - resources :storage_files, :controller => 'Admin::StorageFiles' + resources :storage_files, controller: "Admin::StorageFiles" end end @@ -3885,7 +3945,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_warn_with_ruby_constant_syntax_no_colons e = assert_raise(ArgumentError) do draw do - resources :storage_files, :controller => 'Admin' + resources :storage_files, controller: "Admin" end end @@ -3903,7 +3963,7 @@ class TestDefaultScope < ActionDispatch::IntegrationTest end DefaultScopeRoutes = ActionDispatch::Routing::RouteSet.new - DefaultScopeRoutes.default_scope = {:module => :blog} + DefaultScopeRoutes.default_scope = { module: :blog } DefaultScopeRoutes.draw do resources :posts end @@ -3917,7 +3977,7 @@ class TestDefaultScope < ActionDispatch::IntegrationTest include DefaultScopeRoutes.url_helpers def test_default_scope - get '/posts' + get "/posts" assert_equal "blog/posts#index", @response.body end end @@ -3933,7 +3993,7 @@ class TestHttpMethods < ActionDispatch::IntegrationTest RFC5789 = %w(PATCH) def simple_app(response) - lambda { |env| [ 200, { 'Content-Type' => 'text/plain' }, [response] ] } + lambda { |env| [ 200, { "Content-Type" => "text/plain" }, [response] ] } end attr_reader :app @@ -3945,14 +4005,14 @@ class TestHttpMethods < ActionDispatch::IntegrationTest routes.draw do (RFC2616 + RFC2518 + RFC3253 + RFC3648 + RFC3744 + RFC5323 + RFC4791 + RFC5789).each do |method| - match '/' => s.simple_app(method), :via => method.underscore.to_sym + match "/" => s.simple_app(method), :via => method.underscore.to_sym end end end (RFC2616 + RFC2518 + RFC3253 + RFC3648 + RFC3744 + RFC5323 + RFC4791 + RFC5789).each do |method| test "request method #{method.underscore} can be matched" do - get '/', headers: { 'REQUEST_METHOD' => method } + get "/", headers: { "REQUEST_METHOD" => method } assert_equal method, @response.body end end @@ -3961,14 +4021,14 @@ end class TestUriPathEscaping < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - get '/:segment' => lambda { |env| - path_params = env['action_dispatch.request.path_parameters'] - [200, { 'Content-Type' => 'text/plain' }, [path_params[:segment]]] + get "/:segment" => lambda { |env| + path_params = env["action_dispatch.request.path_parameters"] + [200, { "Content-Type" => "text/plain" }, [path_params[:segment]]] }, :as => :segment - get '/*splat' => lambda { |env| - path_params = env['action_dispatch.request.path_parameters'] - [200, { 'Content-Type' => 'text/plain' }, [path_params[:splat]]] + get "/*splat" => lambda { |env| + path_params = env["action_dispatch.request.path_parameters"] + [200, { "Content-Type" => "text/plain" }, [path_params[:splat]]] }, :as => :splat end end @@ -3977,22 +4037,22 @@ class TestUriPathEscaping < ActionDispatch::IntegrationTest APP = build_app Routes def app; APP end - test 'escapes slash in generated path segment' do - assert_equal '/a%20b%2Fc+d', segment_path(:segment => 'a b/c+d') + test "escapes slash in generated path segment" do + assert_equal "/a%20b%2Fc+d", segment_path(segment: "a b/c+d") end - test 'unescapes recognized path segment' do - get '/a%20b%2Fc+d' - assert_equal 'a b/c+d', @response.body + test "unescapes recognized path segment" do + get "/a%20b%2Fc+d" + assert_equal "a b/c+d", @response.body end - test 'does not escape slash in generated path splat' do - assert_equal '/a%20b/c+d', splat_path(:splat => 'a b/c+d') + test "does not escape slash in generated path splat" do + assert_equal "/a%20b/c+d", splat_path(splat: "a b/c+d") end - test 'unescapes recognized path splat' do - get '/a%20b/c+d' - assert_equal 'a b/c+d', @response.body + test "unescapes recognized path splat" do + get "/a%20b/c+d" + assert_equal "a b/c+d", @response.body end end @@ -4000,7 +4060,7 @@ class TestUnicodePaths < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do get "/ほげ" => lambda { |env| - [200, { 'Content-Type' => 'text/plain' }, []] + [200, { "Content-Type" => "text/plain" }, []] }, :as => :unicode_path end end @@ -4009,7 +4069,7 @@ class TestUnicodePaths < ActionDispatch::IntegrationTest APP = build_app Routes def app; APP end - test 'recognizes unicode path' do + test "recognizes unicode path" do get "/#{Rack::Utils.escape("ほげ")}" assert_equal "200", @response.code end @@ -4033,7 +4093,7 @@ class TestMultipleNestedController < ActionDispatch::IntegrationTest include Routes.url_helpers def index - render :inline => "<%= url_for :controller => '/pooh', :action => 'index' %>" + render inline: "<%= url_for :controller => '/pooh', :action => 'index' %>" end end end @@ -4051,7 +4111,7 @@ end class TestTildeAndMinusPaths < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } get "/~user" => ok get "/young-and-fine" => ok @@ -4062,25 +4122,24 @@ class TestTildeAndMinusPaths < ActionDispatch::IntegrationTest APP = build_app Routes def app; APP end - test 'recognizes tilde path' do + test "recognizes tilde path" do get "/~user" assert_equal "200", @response.code end - test 'recognizes minus path' do + test "recognizes minus path" do get "/young-and-fine" assert_equal "200", @response.code end - end class TestRedirectInterpolation < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } get "/foo/:id" => redirect("/foo/bar/%{id}") - get "/bar/:id" => redirect(:path => "/foo/bar/%{id}") + get "/bar/:id" => redirect(path: "/foo/bar/%{id}") get "/baz/:id" => redirect("/baz?id=%{id}&foo=?&bar=1#id-%{id}") get "/foo/bar/:id" => ok get "/baz" => ok @@ -4111,7 +4170,7 @@ class TestRedirectInterpolation < ActionDispatch::IntegrationTest private def verify_redirect(url, status=301) assert_equal status, @response.status - assert_equal url, @response.headers['Location'] + assert_equal url, @response.headers["Location"] assert_equal expected_redirect_body(url), @response.body end @@ -4123,9 +4182,9 @@ end class TestConstraintsAccessingParameters < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } - get "/:foo" => ok, :constraints => lambda { |r| r.params[:foo] == 'foo' } + get "/:foo" => ok, :constraints => lambda { |r| r.params[:foo] == "foo" } get "/:bar" => ok end end @@ -4143,9 +4202,9 @@ end class TestGlobRoutingMapper < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } - get "/*id" => redirect("/not_cars"), :constraints => {id: /dummy/} + get "/*id" => redirect("/not_cars"), :constraints => { id: /dummy/ } get "/cars" => ok end end @@ -4157,7 +4216,7 @@ class TestGlobRoutingMapper < ActionDispatch::IntegrationTest def test_glob_constraint get "/dummy" assert_equal "301", @response.code - assert_equal "/not_cars", @response.header['Location'].match('/[^/]+$')[0] + assert_equal "/not_cars", @response.header["Location"].match("/[^/]+$")[0] end def test_glob_constraint_skip_route @@ -4173,17 +4232,17 @@ end class TestOptimizedNamedRoutes < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } - get '/foo' => ok, as: :foo + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } + get "/foo" => ok, as: :foo ActiveSupport::Deprecation.silence do - get '/post(/:action(/:id))' => ok, as: :posts + get "/post(/:action(/:id))" => ok, as: :posts end - get '/:foo/:foo_type/bars/:id' => ok, as: :bar - get '/projects/:id.:format' => ok, as: :project - get '/pages/:id' => ok, as: :page - get '/wiki/*page' => ok, as: :wiki + get "/:foo/:foo_type/bars/:id" => ok, as: :bar + get "/projects/:id.:format" => ok, as: :project + get "/pages/:id" => ok, as: :page + get "/wiki/*page" => ok, as: :wiki end end @@ -4191,51 +4250,51 @@ class TestOptimizedNamedRoutes < ActionDispatch::IntegrationTest APP = build_app Routes def app; APP end - test 'enabled when not mounted and default_url_options is empty' do + test "enabled when not mounted and default_url_options is empty" do assert Routes.url_helpers.optimize_routes_generation? end - test 'named route called as singleton method' do - assert_equal '/foo', Routes.url_helpers.foo_path + test "named route called as singleton method" do + assert_equal "/foo", Routes.url_helpers.foo_path end - test 'named route called on included module' do - assert_equal '/foo', foo_path + test "named route called on included module" do + assert_equal "/foo", foo_path end - test 'nested optional segments are removed' do - assert_equal '/post', Routes.url_helpers.posts_path - assert_equal '/post', posts_path + test "nested optional segments are removed" do + assert_equal "/post", Routes.url_helpers.posts_path + assert_equal "/post", posts_path end - test 'segments with same prefix are replaced correctly' do - assert_equal '/foo/baz/bars/1', Routes.url_helpers.bar_path('foo', 'baz', '1') - assert_equal '/foo/baz/bars/1', bar_path('foo', 'baz', '1') + test "segments with same prefix are replaced correctly" do + assert_equal "/foo/baz/bars/1", Routes.url_helpers.bar_path("foo", "baz", "1") + assert_equal "/foo/baz/bars/1", bar_path("foo", "baz", "1") end - test 'segments separated with a period are replaced correctly' do - assert_equal '/projects/1.json', Routes.url_helpers.project_path(1, :json) - assert_equal '/projects/1.json', project_path(1, :json) + test "segments separated with a period are replaced correctly" do + assert_equal "/projects/1.json", Routes.url_helpers.project_path(1, :json) + assert_equal "/projects/1.json", project_path(1, :json) end - test 'segments with question marks are escaped' do - assert_equal '/pages/foo%3Fbar', Routes.url_helpers.page_path('foo?bar') - assert_equal '/pages/foo%3Fbar', page_path('foo?bar') + test "segments with question marks are escaped" do + assert_equal "/pages/foo%3Fbar", Routes.url_helpers.page_path("foo?bar") + assert_equal "/pages/foo%3Fbar", page_path("foo?bar") end - test 'segments with slashes are escaped' do - assert_equal '/pages/foo%2Fbar', Routes.url_helpers.page_path('foo/bar') - assert_equal '/pages/foo%2Fbar', page_path('foo/bar') + test "segments with slashes are escaped" do + assert_equal "/pages/foo%2Fbar", Routes.url_helpers.page_path("foo/bar") + assert_equal "/pages/foo%2Fbar", page_path("foo/bar") end - test 'glob segments with question marks are escaped' do - assert_equal '/wiki/foo%3Fbar', Routes.url_helpers.wiki_path('foo?bar') - assert_equal '/wiki/foo%3Fbar', wiki_path('foo?bar') + test "glob segments with question marks are escaped" do + assert_equal "/wiki/foo%3Fbar", Routes.url_helpers.wiki_path("foo?bar") + assert_equal "/wiki/foo%3Fbar", wiki_path("foo?bar") end - test 'glob segments with slashes are not escaped' do - assert_equal '/wiki/foo/bar', Routes.url_helpers.wiki_path('foo/bar') - assert_equal '/wiki/foo/bar', wiki_path('foo/bar') + test "glob segments with slashes are not escaped" do + assert_equal "/wiki/foo/bar", Routes.url_helpers.wiki_path("foo/bar") + assert_equal "/wiki/foo/bar", wiki_path("foo/bar") end end @@ -4254,9 +4313,9 @@ class TestNamedRouteUrlHelpers < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - scope :module => "test_named_route_url_helpers" do - get "/categories/:id" => 'categories#show', :as => :category - get "/products/:id" => 'products#show', :as => :product + scope module: "test_named_route_url_helpers" do + get "/categories/:id" => "categories#show", :as => :category + get "/products/:id" => "products#show", :as => :product end end end @@ -4278,21 +4337,21 @@ end class TestUrlConstraints < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } - constraints :subdomain => 'admin' do - get '/' => ok, :as => :admin_root + constraints subdomain: "admin" do + get "/" => ok, :as => :admin_root end - scope :constraints => { :protocol => 'https://' } do - get '/' => ok, :as => :secure_root + scope constraints: { protocol: "https://" } do + get "/" => ok, :as => :secure_root end - get '/' => ok, :as => :alternate_root, :constraints => { :port => 8080 } + get "/" => ok, :as => :alternate_root, :constraints => { port: 8080 } - get '/search' => ok, :constraints => { :subdomain => false } + get "/search" => ok, :constraints => { subdomain: false } - get '/logs' => ok, :constraints => { :subdomain => true } + get "/logs" => ok, :constraints => { subdomain: true } end end @@ -4301,41 +4360,41 @@ class TestUrlConstraints < ActionDispatch::IntegrationTest def app; APP end test "constraints are copied to defaults when using constraints method" do - assert_equal 'http://admin.example.com/', admin_root_url + assert_equal "http://admin.example.com/", admin_root_url - get 'http://admin.example.com/' + get "http://admin.example.com/" assert_response :success end test "constraints are copied to defaults when using scope constraints hash" do - assert_equal 'https://www.example.com/', secure_root_url + assert_equal "https://www.example.com/", secure_root_url - get 'https://www.example.com/' + get "https://www.example.com/" assert_response :success end test "constraints are copied to defaults when using route constraints hash" do - assert_equal 'http://www.example.com:8080/', alternate_root_url + assert_equal "http://www.example.com:8080/", alternate_root_url - get 'http://www.example.com:8080/' + get "http://www.example.com:8080/" assert_response :success end test "false constraint expressions check for absence of values" do - get 'http://example.com/search' + get "http://example.com/search" assert_response :success - assert_equal 'http://example.com/search', search_url + assert_equal "http://example.com/search", search_url - get 'http://api.example.com/search' + get "http://api.example.com/search" assert_response :not_found end test "true constraint expressions check for presence of values" do - get 'http://api.example.com/logs' + get "http://api.example.com/logs" assert_response :success - assert_equal 'http://api.example.com/logs', logs_url + assert_equal "http://api.example.com/logs", logs_url - get 'http://example.com/logs' + get "http://example.com/logs" assert_response :not_found end end @@ -4350,14 +4409,14 @@ class TestInvalidUrls < ActionDispatch::IntegrationTest test "invalid UTF-8 encoding returns a 400 Bad Request" do with_routing do |set| set.draw do - get "/bar/:id", :to => redirect("/foo/show/%{id}") - get "/foo/show(/:id)", :to => "test_invalid_urls/foo#show" + get "/bar/:id", to: redirect("/foo/show/%{id}") + get "/foo/show(/:id)", to: "test_invalid_urls/foo#show" - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } - get '/foobar/:id', to: ok + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } + get "/foobar/:id", to: ok ActiveSupport::Deprecation.silence do - get "/foo(/:action(/:id))", :controller => "test_invalid_urls/foo" + get "/foo(/:action(/:id))", controller: "test_invalid_urls/foo" get "/:controller(/:action(/:id))" end end @@ -4384,7 +4443,7 @@ class TestOptionalRootSegments < ActionDispatch::IntegrationTest stub_controllers do |routes| Routes = routes Routes.draw do - get '/(page/:page)', :to => 'pages#index', :as => :root + get "/(page/:page)", to: "pages#index", as: :root end end @@ -4396,27 +4455,27 @@ class TestOptionalRootSegments < ActionDispatch::IntegrationTest include Routes.url_helpers def test_optional_root_segments - get '/' - assert_equal 'pages#index', @response.body - assert_equal '/', root_path + get "/" + assert_equal "pages#index", @response.body + assert_equal "/", root_path - get '/page/1' - assert_equal 'pages#index', @response.body - assert_equal '1', @request.params[:page] - assert_equal '/page/1', root_path('1') - assert_equal '/page/1', root_path(:page => '1') + get "/page/1" + assert_equal "pages#index", @response.body + assert_equal "1", @request.params[:page] + assert_equal "/page/1", root_path("1") + assert_equal "/page/1", root_path(page: "1") end end class TestPortConstraints < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } - get '/integer', to: ok, constraints: { :port => 8080 } - get '/string', to: ok, constraints: { :port => '8080' } - get '/array', to: ok, constraints: { :port => [8080] } - get '/regexp', to: ok, constraints: { :port => /8080/ } + get "/integer", to: ok, constraints: { port: 8080 } + get "/string", to: ok, constraints: { port: "8080" } + get "/array", to: ok, constraints: { port: [8080] } + get "/regexp", to: ok, constraints: { port: /8080/ } end end @@ -4425,34 +4484,34 @@ class TestPortConstraints < ActionDispatch::IntegrationTest def app; APP end def test_integer_port_constraints - get 'http://www.example.com/integer' + get "http://www.example.com/integer" assert_response :not_found - get 'http://www.example.com:8080/integer' + get "http://www.example.com:8080/integer" assert_response :success end def test_string_port_constraints - get 'http://www.example.com/string' + get "http://www.example.com/string" assert_response :not_found - get 'http://www.example.com:8080/string' + get "http://www.example.com:8080/string" assert_response :success end def test_array_port_constraints - get 'http://www.example.com/array' + get "http://www.example.com/array" assert_response :not_found - get 'http://www.example.com:8080/array' + get "http://www.example.com:8080/array" assert_response :success end def test_regexp_port_constraints - get 'http://www.example.com/regexp' + get "http://www.example.com/regexp" assert_response :not_found - get 'http://www.example.com:8080/regexp' + get "http://www.example.com:8080/regexp" assert_response :success end end @@ -4460,12 +4519,12 @@ end class TestFormatConstraints < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } - get '/string', to: ok, constraints: { format: 'json' } - get '/regexp', to: ok, constraints: { format: /json/ } - get '/json_only', to: ok, format: true, constraints: { format: /json/ } - get '/xml_only', to: ok, format: 'xml' + get "/string", to: ok, constraints: { format: "json" } + get "/regexp", to: ok, constraints: { format: /json/ } + get "/json_only", to: ok, format: true, constraints: { format: /json/ } + get "/xml_only", to: ok, format: "xml" end end @@ -4474,46 +4533,46 @@ class TestFormatConstraints < ActionDispatch::IntegrationTest def app; APP end def test_string_format_constraints - get 'http://www.example.com/string' + get "http://www.example.com/string" assert_response :success - get 'http://www.example.com/string.json' + get "http://www.example.com/string.json" assert_response :success - get 'http://www.example.com/string.html' + get "http://www.example.com/string.html" assert_response :not_found end def test_regexp_format_constraints - get 'http://www.example.com/regexp' + get "http://www.example.com/regexp" assert_response :success - get 'http://www.example.com/regexp.json' + get "http://www.example.com/regexp.json" assert_response :success - get 'http://www.example.com/regexp.html' + get "http://www.example.com/regexp.html" assert_response :not_found end def test_enforce_with_format_true_with_constraint - get 'http://www.example.com/json_only.json' + get "http://www.example.com/json_only.json" assert_response :success - get 'http://www.example.com/json_only.html' + get "http://www.example.com/json_only.html" assert_response :not_found - get 'http://www.example.com/json_only' + get "http://www.example.com/json_only" assert_response :not_found end def test_enforce_with_string - get 'http://www.example.com/xml_only.xml' + get "http://www.example.com/xml_only.xml" assert_response :success - get 'http://www.example.com/xml_only' + get "http://www.example.com/xml_only" assert_response :success - get 'http://www.example.com/xml_only.json' + get "http://www.example.com/xml_only.json" assert_response :not_found end end @@ -4522,8 +4581,8 @@ class TestCallableConstraintValidation < ActionDispatch::IntegrationTest def test_constraint_with_object_not_callable assert_raises(ArgumentError) do ActionDispatch::Routing::RouteSet.new.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } - get '/test', to: ok, constraints: Object.new + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } + get "/test", to: ok, constraints: Object.new end end end @@ -4533,8 +4592,8 @@ class TestRouteDefaults < ActionDispatch::IntegrationTest stub_controllers do |routes| Routes = routes Routes.draw do - resources :posts, bucket_type: 'post' - resources :projects, defaults: { bucket_type: 'project' } + resources :posts, bucket_type: "post" + resources :projects, defaults: { bucket_type: "project" } end end @@ -4547,14 +4606,14 @@ class TestRouteDefaults < ActionDispatch::IntegrationTest def test_route_options_are_required_for_url_for assert_raises(ActionController::UrlGenerationError) do - assert_equal '/posts/1', url_for(controller: 'posts', action: 'show', id: 1, only_path: true) + assert_equal "/posts/1", url_for(controller: "posts", action: "show", id: 1, only_path: true) end - assert_equal '/posts/1', url_for(controller: 'posts', action: 'show', id: 1, bucket_type: 'post', only_path: true) + assert_equal "/posts/1", url_for(controller: "posts", action: "show", id: 1, bucket_type: "post", only_path: true) end def test_route_defaults_are_not_required_for_url_for - assert_equal '/projects/1', url_for(controller: 'projects', action: 'show', id: 1, only_path: true) + assert_equal "/projects/1", url_for(controller: "projects", action: "show", id: 1, only_path: true) end end @@ -4562,9 +4621,9 @@ class TestRackAppRouteGeneration < ActionDispatch::IntegrationTest stub_controllers do |routes| Routes = routes Routes.draw do - rack_app = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } - mount rack_app, at: '/account', as: 'account' - mount rack_app, at: '/:locale/account', as: 'localized_account' + rack_app = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } + mount rack_app, at: "/account", as: "account" + mount rack_app, at: "/:locale/account", as: "localized_account" end end @@ -4577,11 +4636,11 @@ class TestRackAppRouteGeneration < ActionDispatch::IntegrationTest def test_mounted_application_doesnt_match_unnamed_route assert_raise(ActionController::UrlGenerationError) do - assert_equal '/account?controller=products', url_for(controller: 'products', action: 'index', only_path: true) + assert_equal "/account?controller=products", url_for(controller: "products", action: "index", only_path: true) end assert_raise(ActionController::UrlGenerationError) do - assert_equal '/de/account?controller=products', url_for(controller: 'products', action: 'index', :locale => 'de', only_path: true) + assert_equal "/de/account?controller=products", url_for(controller: "products", action: "index", locale: "de", only_path: true) end end end @@ -4590,8 +4649,8 @@ class TestRedirectRouteGeneration < ActionDispatch::IntegrationTest stub_controllers do |routes| Routes = routes Routes.draw do - get '/account', to: redirect('/myaccount'), as: 'account' - get '/:locale/account', to: redirect('/%{locale}/myaccount'), as: 'localized_account' + get "/account", to: redirect("/myaccount"), as: "account" + get "/:locale/account", to: redirect("/%{locale}/myaccount"), as: "localized_account" end end @@ -4604,11 +4663,11 @@ class TestRedirectRouteGeneration < ActionDispatch::IntegrationTest def test_redirect_doesnt_match_unnamed_route assert_raise(ActionController::UrlGenerationError) do - assert_equal '/account?controller=products', url_for(controller: 'products', action: 'index', only_path: true) + assert_equal "/account?controller=products", url_for(controller: "products", action: "index", only_path: true) end assert_raise(ActionController::UrlGenerationError) do - assert_equal '/de/account?controller=products', url_for(controller: 'products', action: 'index', :locale => 'de', only_path: true) + assert_equal "/de/account?controller=products", url_for(controller: "products", action: "index", locale: "de", only_path: true) end end end @@ -4616,7 +4675,7 @@ end class TestUrlGenerationErrors < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - get "/products/:id" => 'products#show', :as => :product + get "/products/:id" => "products#show", :as => :product end end @@ -4626,28 +4685,28 @@ class TestUrlGenerationErrors < ActionDispatch::IntegrationTest include Routes.url_helpers test "url helpers raise a helpful error message when generation fails" do - url, missing = { action: 'show', controller: 'products', id: nil }, [:id] + url, missing = { action: "show", controller: "products", id: nil }, [:id] message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" # Optimized url helper - error = assert_raises(ActionController::UrlGenerationError){ product_path(nil) } + error = assert_raises(ActionController::UrlGenerationError) { product_path(nil) } assert_equal message, error.message # Non-optimized url helper - error = assert_raises(ActionController::UrlGenerationError, message){ product_path(id: nil) } + error = assert_raises(ActionController::UrlGenerationError, message) { product_path(id: nil) } assert_equal message, error.message end test "url helpers raise message with mixed parameters when generation fails " do - url, missing = { action: 'show', controller: 'products', id: nil, "id"=>"url-tested"}, [:id] + url, missing = { action: "show", controller: "products", id: nil, "id"=>"url-tested" }, [:id] message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" # Optimized url helper - error = assert_raises(ActionController::UrlGenerationError){ product_path(nil, 'id'=>'url-tested') } + error = assert_raises(ActionController::UrlGenerationError) { product_path(nil, "id"=>"url-tested") } assert_equal message, error.message # Non-optimized url helper - error = assert_raises(ActionController::UrlGenerationError, message){ product_path(id: nil, 'id'=>'url-tested') } + error = assert_raises(ActionController::UrlGenerationError, message) { product_path(id: nil, "id"=>"url-tested") } assert_equal message, error.message end end @@ -4661,9 +4720,9 @@ class TestDefaultUrlOptions < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new Routes.draw do - default_url_options locale: 'en' - scope ':locale', format: false do - get '/posts/:year/:month/:day', to: 'posts#archive', as: 'archived_posts' + default_url_options locale: "en" + scope ":locale", format: false do + get "/posts/:year/:month/:day", to: "posts#archive", as: "archived_posts" end end @@ -4676,7 +4735,7 @@ class TestDefaultUrlOptions < ActionDispatch::IntegrationTest include Routes.url_helpers def test_positional_args_with_format_false - assert_equal '/en/posts/2014/12/13', archived_posts_path(2014, 12, 13) + assert_equal "/en/posts/2014/12/13", archived_posts_path(2014, 12, 13) end end @@ -4694,7 +4753,7 @@ class TestErrorsInController < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new Routes.draw do ActiveSupport::Deprecation.silence do - get '/:controller(/:action)' + get "/:controller(/:action)" end end @@ -4705,20 +4764,20 @@ class TestErrorsInController < ActionDispatch::IntegrationTest end def test_legit_no_method_errors_are_not_caught - get '/posts/foo' + get "/posts/foo" assert_equal 500, response.status end def test_legit_name_errors_are_not_caught - get '/posts/bar' + get "/posts/bar" assert_equal 500, response.status end def test_legit_routing_not_found_responses - get '/posts/baz' + get "/posts/baz" assert_equal 404, response.status - get '/i_do_not_exist' + get "/i_do_not_exist" assert_equal 404, response.status end end @@ -4726,17 +4785,17 @@ end class TestPartialDynamicPathSegments < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new Routes.draw do - ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } - get '/songs/song-:song', to: ok - get '/songs/:song-song', to: ok - get '/:artist/song-:song', to: ok - get '/:artist/:song-song', to: ok + get "/songs/song-:song", to: ok + get "/songs/:song-song", to: ok + get "/:artist/song-:song", to: ok + get "/:artist/:song-song", to: ok - get '/optional/songs(/song-:song)', to: ok - get '/optional/songs(/:song-song)', to: ok - get '/optional/:artist(/song-:song)', to: ok - get '/optional/:artist(/:song-song)', to: ok + get "/optional/songs(/song-:song)", to: ok + get "/optional/songs(/:song-song)", to: ok + get "/optional/:artist(/song-:song)", to: ok + get "/optional/:artist(/:song-song)", to: ok end APP = build_app Routes @@ -4746,58 +4805,58 @@ class TestPartialDynamicPathSegments < ActionDispatch::IntegrationTest end def test_paths_with_partial_dynamic_segments_are_recognised - get '/david-bowie/changes-song' + get "/david-bowie/changes-song" assert_equal 200, response.status - assert_params artist: 'david-bowie', song: 'changes' + assert_params artist: "david-bowie", song: "changes" - get '/david-bowie/song-changes' + get "/david-bowie/song-changes" assert_equal 200, response.status - assert_params artist: 'david-bowie', song: 'changes' + assert_params artist: "david-bowie", song: "changes" - get '/songs/song-changes' + get "/songs/song-changes" assert_equal 200, response.status - assert_params song: 'changes' + assert_params song: "changes" - get '/songs/changes-song' + get "/songs/changes-song" assert_equal 200, response.status - assert_params song: 'changes' + assert_params song: "changes" - get '/optional/songs/song-changes' + get "/optional/songs/song-changes" assert_equal 200, response.status - assert_params song: 'changes' + assert_params song: "changes" - get '/optional/songs/changes-song' + get "/optional/songs/changes-song" assert_equal 200, response.status - assert_params song: 'changes' + assert_params song: "changes" - get '/optional/david-bowie/changes-song' + get "/optional/david-bowie/changes-song" assert_equal 200, response.status - assert_params artist: 'david-bowie', song: 'changes' + assert_params artist: "david-bowie", song: "changes" - get '/optional/david-bowie/song-changes' + get "/optional/david-bowie/song-changes" assert_equal 200, response.status - assert_params artist: 'david-bowie', song: 'changes' + assert_params artist: "david-bowie", song: "changes" end private - def assert_params(params) - assert_equal(params, request.path_parameters) - end + def assert_params(params) + assert_equal(params, request.path_parameters) + end end class TestPathParameters < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - scope module: 'test_path_parameters' do - scope ':locale', locale: /en|ar/ do - root to: 'home#index' - get '/about', to: 'pages#about' + scope module: "test_path_parameters" do + scope ":locale", locale: /en|ar/ do + root to: "home#index" + get "/about", to: "pages#about" end end ActiveSupport::Deprecation.silence do - get ':controller(/:action/(:id))' + get ":controller(/:action/(:id))" end end end @@ -4822,7 +4881,7 @@ class TestPathParameters < ActionDispatch::IntegrationTest def app; APP end def test_path_parameters_are_not_mutated - get '/en/about' + get "/en/about" assert_equal "/ar | /ar/about", @response.body end end @@ -4830,7 +4889,7 @@ end class TestInternalRoutingParams < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - get '/test_internal/:internal' => 'internal#internal' + get "/test_internal/:internal" => "internal#internal" end end @@ -4847,11 +4906,11 @@ class TestInternalRoutingParams < ActionDispatch::IntegrationTest end def test_paths_with_partial_dynamic_segments_are_recognised - get '/test_internal/123' + get "/test_internal/123" assert_equal 200, response.status assert_equal( - { controller: 'internal', action: 'internal', internal: '123' }, + { controller: "internal", action: "internal", internal: "123" }, request.path_parameters ) end diff --git a/actionpack/test/dispatch/runner_test.rb b/actionpack/test/dispatch/runner_test.rb new file mode 100644 index 0000000000..969933c9ed --- /dev/null +++ b/actionpack/test/dispatch/runner_test.rb @@ -0,0 +1,18 @@ +require "abstract_unit" + +class RunnerTest < ActiveSupport::TestCase + test "runner preserves the setting of integration_session" do + runner = Class.new do + def before_setup + + end + end.new + + runner.extend(ActionDispatch::Integration::Runner) + runner.integration_session.host! "lvh.me" + + runner.before_setup + + assert_equal "lvh.me", runner.integration_session.host + end +end diff --git a/actionpack/test/dispatch/session/abstract_store_test.rb b/actionpack/test/dispatch/session/abstract_store_test.rb index d38d1bbce6..fd4d359cf8 100644 --- a/actionpack/test/dispatch/session/abstract_store_test.rb +++ b/actionpack/test/dispatch/session/abstract_store_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'action_dispatch/middleware/session/abstract_store' +require "abstract_unit" +require "action_dispatch/middleware/session/abstract_store" module ActionDispatch module Session @@ -37,7 +37,7 @@ module ActionDispatch assert @env session = Request::Session.find ActionDispatch::Request.new @env - session['foo'] = 'bar' + session["foo"] = "bar" as.call(@env) session1 = Request::Session.find ActionDispatch::Request.new @env @@ -47,10 +47,10 @@ module ActionDispatch end private - def app(&block) - @env = nil - lambda { |env| @env = env } - end + def app(&block) + @env = nil + lambda { |env| @env = env } + end end end end diff --git a/actionpack/test/dispatch/session/cache_store_test.rb b/actionpack/test/dispatch/session/cache_store_test.rb index 769de1a1e0..a60629a7ee 100644 --- a/actionpack/test/dispatch/session/cache_store_test.rb +++ b/actionpack/test/dispatch/session/cache_store_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'fixtures/session_autoload_test/session_autoload_test/foo' +require "abstract_unit" +require "fixtures/session_autoload_test/session_autoload_test/foo" class CacheStoreTest < ActionDispatch::IntegrationTest class TestController < ActionController::Base @@ -35,11 +35,11 @@ class CacheStoreTest < ActionDispatch::IntegrationTest def test_setting_and_getting_session_value with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] + assert cookies["_session_id"] - get '/get_session_value' + get "/get_session_value" assert_response :success assert_equal 'foo: "bar"', response.body end @@ -47,56 +47,56 @@ class CacheStoreTest < ActionDispatch::IntegrationTest def test_getting_nil_session_value with_test_route_set do - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body + assert_equal "foo: nil", response.body end end def test_getting_session_value_after_session_reset with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] - session_cookie = cookies.send(:hash_for)['_session_id'] + assert cookies["_session_id"] + session_cookie = cookies.send(:hash_for)["_session_id"] - get '/call_reset_session' + get "/call_reset_session" assert_response :success - assert_not_equal [], headers['Set-Cookie'] + assert_not_equal [], headers["Set-Cookie"] cookies << session_cookie # replace our new session_id with our old, pre-reset session_id - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body, "data for this session should have been obliterated from cache" + assert_equal "foo: nil", response.body, "data for this session should have been obliterated from cache" end end def test_getting_from_nonexistent_session with_test_route_set do - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body - assert_nil cookies['_session_id'], "should only create session on write, not read" + assert_equal "foo: nil", response.body + assert_nil cookies["_session_id"], "should only create session on write, not read" end end def test_setting_session_value_after_session_reset with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] - session_id = cookies['_session_id'] + assert cookies["_session_id"] + session_id = cookies["_session_id"] - get '/call_reset_session' + get "/call_reset_session" assert_response :success - assert_not_equal [], headers['Set-Cookie'] + assert_not_equal [], headers["Set-Cookie"] - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body + assert_equal "foo: nil", response.body - get '/get_session_id' + get "/get_session_id" assert_response :success assert_not_equal session_id, response.body end @@ -104,12 +104,12 @@ class CacheStoreTest < ActionDispatch::IntegrationTest def test_getting_session_id with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] - session_id = cookies['_session_id'] + assert cookies["_session_id"] + session_id = cookies["_session_id"] - get '/get_session_id' + get "/get_session_id" assert_response :success assert_equal session_id, response.body, "should be able to read session id without accessing the session hash" end @@ -118,16 +118,16 @@ class CacheStoreTest < ActionDispatch::IntegrationTest def test_deserializes_unloaded_class with_test_route_set do with_autoload_path "session_autoload_test" do - get '/set_serialized_session_value' + get "/set_serialized_session_value" assert_response :success - assert cookies['_session_id'] + assert cookies["_session_id"] end with_autoload_path "session_autoload_test" do - get '/get_session_id' + get "/get_session_id" assert_response :success end with_autoload_path "session_autoload_test" do - get '/get_session_value' + get "/get_session_value" assert_response :success assert_equal 'foo: #<SessionAutoloadTest::Foo bar:"baz">', response.body, "should auto-load unloaded class" end @@ -136,27 +136,27 @@ class CacheStoreTest < ActionDispatch::IntegrationTest def test_doesnt_write_session_cookie_if_session_id_is_already_exists with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] + assert cookies["_session_id"] - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal nil, headers['Set-Cookie'], "should not resend the cookie again if session_id cookie is already exists" + assert_equal nil, headers["Set-Cookie"], "should not resend the cookie again if session_id cookie is already exists" end end def test_prevents_session_fixation with_test_route_set do - assert_equal nil, @cache.read('_session_id:0xhax') + assert_equal nil, @cache.read("_session_id:0xhax") - cookies['_session_id'] = '0xhax' - get '/set_session_value' + cookies["_session_id"] = "0xhax" + get "/set_session_value" assert_response :success - assert_not_equal '0xhax', cookies['_session_id'] - assert_equal nil, @cache.read('_session_id:0xhax') - assert_equal({'foo' => 'bar'}, @cache.read("_session_id:#{cookies['_session_id']}")) + assert_not_equal "0xhax", cookies["_session_id"] + assert_equal nil, @cache.read("_session_id:0xhax") + assert_equal({ "foo" => "bar" }, @cache.read("_session_id:#{cookies['_session_id']}")) end end @@ -165,13 +165,13 @@ class CacheStoreTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ':action', :to => ::CacheStoreTest::TestController + get ":action", to: ::CacheStoreTest::TestController end end @app = self.class.build_app(set) do |middleware| @cache = ActiveSupport::Cache::MemoryStore.new - middleware.use ActionDispatch::Session::CacheStore, :key => '_session_id', :cache => @cache + middleware.use ActionDispatch::Session::CacheStore, key: "_session_id", cache: @cache middleware.delete ActionDispatch::ShowExceptions end diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index 09cb1d925f..013d289c6d 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -1,14 +1,14 @@ -require 'abstract_unit' -require 'stringio' -require 'active_support/key_generator' +require "abstract_unit" +require "stringio" +require "active_support/key_generator" class CookieStoreTest < ActionDispatch::IntegrationTest - SessionKey = '_myapp_session' - SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33' + SessionKey = "_myapp_session" + SessionSecret = "b3c631c314c0bbca50c1b2843150fe33" Generator = ActiveSupport::LegacyKeyGenerator.new(SessionSecret) - Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, :digest => 'SHA1') - SignedBar = Verifier.generate(:foo => "bar", :session_id => SecureRandom.hex(16)) + Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, digest: "SHA1") + SignedBar = Verifier.generate(foo: "bar", session_id: SecureRandom.hex(16)) class TestController < ActionController::Base def no_session_access @@ -48,7 +48,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest end def raise_data_overflow - session[:foo] = 'bye!' * 1024 + session[:foo] = "bye!" * 1024 head :ok end @@ -65,17 +65,17 @@ class CookieStoreTest < ActionDispatch::IntegrationTest def test_setting_session_value with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", - headers['Set-Cookie'] + headers["Set-Cookie"] end end def test_getting_session_value with_test_route_set do cookies[SessionKey] = SignedBar - get '/get_session_value' + get "/get_session_value" assert_response :success assert_equal 'foo: "bar"', response.body end @@ -84,12 +84,12 @@ class CookieStoreTest < ActionDispatch::IntegrationTest def test_getting_session_id with_test_route_set do cookies[SessionKey] = SignedBar - get '/persistent_session_id' + get "/persistent_session_id" assert_response :success assert_equal 32, response.body.size session_id = response.body - get '/get_session_id' + get "/get_session_id" assert_response :success assert_equal "id: #{session_id}", response.body, "should be able to read session id without accessing the session hash" end @@ -98,37 +98,37 @@ class CookieStoreTest < ActionDispatch::IntegrationTest def test_disregards_tampered_sessions with_test_route_set do cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--123456780" - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body + assert_equal "foo: nil", response.body end end def test_does_not_set_secure_cookies_over_http - with_test_route_set(:secure => true) do - get '/set_session_value' + with_test_route_set(secure: true) do + get "/set_session_value" assert_response :success - assert_equal nil, headers['Set-Cookie'] + assert_equal nil, headers["Set-Cookie"] end end def test_properly_renew_cookies with_test_route_set do - get '/set_session_value' - get '/persistent_session_id' + get "/set_session_value" + get "/persistent_session_id" session_id = response.body - get '/renew_session_id' - get '/persistent_session_id' + get "/renew_session_id" + get "/persistent_session_id" assert_not_equal response.body, session_id end end def test_does_set_secure_cookies_over_https - with_test_route_set(:secure => true) do - get '/set_session_value', headers: { 'HTTPS' => 'on' } + with_test_route_set(secure: true) do + get "/set_session_value", headers: { "HTTPS" => "on" } assert_response :success assert_equal "_myapp_session=#{response.body}; path=/; secure; HttpOnly", - headers['Set-Cookie'] + headers["Set-Cookie"] end end @@ -139,9 +139,9 @@ class CookieStoreTest < ActionDispatch::IntegrationTest with_test_route_set do with_autoload_path "session_autoload_test" do cookies[SessionKey] = SignedSerializedCookie - get '/get_session_id' + get "/get_session_id" assert_response :success - assert_equal 'id: ce8b0752a6ab7c7af3cdb8a80e6b9e46', response.body, "should auto-load unloaded class" + assert_equal "id: ce8b0752a6ab7c7af3cdb8a80e6b9e46", response.body, "should auto-load unloaded class" end end end @@ -150,7 +150,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest with_test_route_set do with_autoload_path "session_autoload_test" do cookies[SessionKey] = SignedSerializedCookie - get '/get_session_value' + get "/get_session_value" assert_response :success assert_equal 'foo: #<SessionAutoloadTest::Foo bar:"baz">', response.body, "should auto-load unloaded class" end @@ -160,16 +160,16 @@ class CookieStoreTest < ActionDispatch::IntegrationTest def test_close_raises_when_data_overflows with_test_route_set do assert_raise(ActionDispatch::Cookies::CookieOverflow) { - get '/raise_data_overflow' + get "/raise_data_overflow" } end end def test_doesnt_write_session_cookie_if_session_is_not_accessed with_test_route_set do - get '/no_session_access' + get "/no_session_access" assert_response :success - assert_equal nil, headers['Set-Cookie'] + assert_equal nil, headers["Set-Cookie"] end end @@ -177,82 +177,82 @@ class CookieStoreTest < ActionDispatch::IntegrationTest with_test_route_set do cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--" + "fef868465920f415f2c0652d6910d3af288a0367" - get '/no_session_access' + get "/no_session_access" assert_response :success - assert_equal nil, headers['Set-Cookie'] + assert_equal nil, headers["Set-Cookie"] end end def test_setting_session_value_after_session_reset with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success session_payload = response.body assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", - headers['Set-Cookie'] + headers["Set-Cookie"] - get '/call_reset_session' + get "/call_reset_session" assert_response :success - assert_not_equal [], headers['Set-Cookie'] + assert_not_equal [], headers["Set-Cookie"] assert_not_nil session_payload assert_not_equal session_payload, cookies[SessionKey] - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body + assert_equal "foo: nil", response.body end end def test_class_type_after_session_reset with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", - headers['Set-Cookie'] + headers["Set-Cookie"] - get '/get_class_after_reset_session' + get "/get_class_after_reset_session" assert_response :success - assert_not_equal [], headers['Set-Cookie'] - assert_equal 'class: ActionDispatch::Request::Session', response.body + assert_not_equal [], headers["Set-Cookie"] + assert_equal "class: ActionDispatch::Request::Session", response.body end end def test_getting_from_nonexistent_session with_test_route_set do - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body - assert_nil headers['Set-Cookie'], "should only create session on write, not read" + assert_equal "foo: nil", response.body + assert_nil headers["Set-Cookie"], "should only create session on write, not read" end end def test_setting_session_value_after_session_clear with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", - headers['Set-Cookie'] + headers["Set-Cookie"] - get '/call_session_clear' + get "/call_session_clear" assert_response :success - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body + assert_equal "foo: nil", response.body end end def test_persistent_session_id with_test_route_set do cookies[SessionKey] = SignedBar - get '/persistent_session_id' + get "/persistent_session_id" assert_response :success assert_equal 32, response.body.size session_id = response.body - get '/persistent_session_id' + get "/persistent_session_id" assert_equal session_id, response.body reset! - get '/persistent_session_id' + get "/persistent_session_id" assert_not_equal session_id, response.body end end @@ -271,7 +271,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest end def test_session_store_with_expire_after - with_test_route_set(:expire_after => 5.hours) do + with_test_route_set(expire_after: 5.hours) do # First request accesses the session time = Time.local(2008, 4, 24) cookie_body = nil @@ -281,12 +281,12 @@ class CookieStoreTest < ActionDispatch::IntegrationTest cookies[SessionKey] = SignedBar - get '/set_session_value' + get "/set_session_value" assert_response :success cookie_body = response.body assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly", - headers['Set-Cookie'] + headers["Set-Cookie"] end # Second request does not access the session @@ -294,41 +294,41 @@ class CookieStoreTest < ActionDispatch::IntegrationTest Time.stub :now, time do expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d %b %Y %H:%M:%S -0000") - get '/no_session_access' + get "/no_session_access" assert_response :success assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly", - headers['Set-Cookie'] + headers["Set-Cookie"] end end end def test_session_store_with_explicit_domain - with_test_route_set(:domain => "example.es") do - get '/set_session_value' - assert_match(/domain=example\.es/, headers['Set-Cookie']) - headers['Set-Cookie'] + with_test_route_set(domain: "example.es") do + get "/set_session_value" + assert_match(/domain=example\.es/, headers["Set-Cookie"]) + headers["Set-Cookie"] end end def test_session_store_without_domain with_test_route_set do - get '/set_session_value' - assert_no_match(/domain\=/, headers['Set-Cookie']) + get "/set_session_value" + assert_no_match(/domain\=/, headers["Set-Cookie"]) end end def test_session_store_with_nil_domain - with_test_route_set(:domain => nil) do - get '/set_session_value' - assert_no_match(/domain\=/, headers['Set-Cookie']) + with_test_route_set(domain: nil) do + get "/set_session_value" + assert_no_match(/domain\=/, headers["Set-Cookie"]) end end def test_session_store_with_all_domains - with_test_route_set(:domain => :all) do - get '/set_session_value' - assert_match(/domain=\.example\.com/, headers['Set-Cookie']) + with_test_route_set(domain: :all) do + get "/set_session_value" + assert_match(/domain=\.example\.com/, headers["Set-Cookie"]) end end @@ -346,11 +346,11 @@ class CookieStoreTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ':action', :to => ::CookieStoreTest::TestController + get ":action", to: ::CookieStoreTest::TestController end end - options = { :key => SessionKey }.merge!(options) + options = { key: SessionKey }.merge!(options) @app = self.class.build_app(set) do |middleware| middleware.use ActionDispatch::Session::CookieStore, options @@ -360,5 +360,4 @@ class CookieStoreTest < ActionDispatch::IntegrationTest yield end end - end diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb index 18cb227dad..c2d0719b4e 100644 --- a/actionpack/test/dispatch/session/mem_cache_store_test.rb +++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'securerandom' +require "abstract_unit" +require "securerandom" # You need to start a memcached server inorder to run these tests class MemCacheStoreTest < ActionDispatch::IntegrationTest @@ -35,17 +35,17 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest end begin - require 'dalli' - ss = Dalli::Client.new('localhost:11211').stats - raise Dalli::DalliError unless ss['localhost:11211'] + require "dalli" + ss = Dalli::Client.new("localhost:11211").stats + raise Dalli::DalliError unless ss["localhost:11211"] def test_setting_and_getting_session_value with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] + assert cookies["_session_id"] - get '/get_session_value' + get "/get_session_value" assert_response :success assert_equal 'foo: "bar"', response.body end @@ -55,9 +55,9 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest def test_getting_nil_session_value with_test_route_set do - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body + assert_equal "foo: nil", response.body end rescue Dalli::RingError => ex skip ex.message, ex.backtrace @@ -65,20 +65,20 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest def test_getting_session_value_after_session_reset with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] - session_cookie = cookies.send(:hash_for)['_session_id'] + assert cookies["_session_id"] + session_cookie = cookies.send(:hash_for)["_session_id"] - get '/call_reset_session' + get "/call_reset_session" assert_response :success - assert_not_equal [], headers['Set-Cookie'] + assert_not_equal [], headers["Set-Cookie"] cookies << session_cookie # replace our new session_id with our old, pre-reset session_id - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body, "data for this session should have been obliterated from memcached" + assert_equal "foo: nil", response.body, "data for this session should have been obliterated from memcached" end rescue Dalli::RingError => ex skip ex.message, ex.backtrace @@ -86,10 +86,10 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest def test_getting_from_nonexistent_session with_test_route_set do - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body - assert_nil cookies['_session_id'], "should only create session on write, not read" + assert_equal "foo: nil", response.body + assert_nil cookies["_session_id"], "should only create session on write, not read" end rescue Dalli::RingError => ex skip ex.message, ex.backtrace @@ -97,20 +97,20 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest def test_setting_session_value_after_session_reset with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] - session_id = cookies['_session_id'] + assert cookies["_session_id"] + session_id = cookies["_session_id"] - get '/call_reset_session' + get "/call_reset_session" assert_response :success - assert_not_equal [], headers['Set-Cookie'] + assert_not_equal [], headers["Set-Cookie"] - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body + assert_equal "foo: nil", response.body - get '/get_session_id' + get "/get_session_id" assert_response :success assert_not_equal session_id, response.body end @@ -120,12 +120,12 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest def test_getting_session_id with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] - session_id = cookies['_session_id'] + assert cookies["_session_id"] + session_id = cookies["_session_id"] - get '/get_session_id' + get "/get_session_id" assert_response :success assert_equal session_id, response.body, "should be able to read session id without accessing the session hash" end @@ -136,12 +136,12 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest def test_deserializes_unloaded_class with_test_route_set do with_autoload_path "session_autoload_test" do - get '/set_serialized_session_value' + get "/set_serialized_session_value" assert_response :success - assert cookies['_session_id'] + assert cookies["_session_id"] end with_autoload_path "session_autoload_test" do - get '/get_session_id' + get "/get_session_id" assert_response :success end end @@ -151,13 +151,13 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest def test_doesnt_write_session_cookie_if_session_id_is_already_exists with_test_route_set do - get '/set_session_value' + get "/set_session_value" assert_response :success - assert cookies['_session_id'] + assert cookies["_session_id"] - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal nil, headers['Set-Cookie'], "should not resend the cookie again if session_id cookie is already exists" + assert_equal nil, headers["Set-Cookie"], "should not resend the cookie again if session_id cookie is already exists" end rescue Dalli::RingError => ex skip ex.message, ex.backtrace @@ -165,16 +165,16 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest def test_prevents_session_fixation with_test_route_set do - get '/get_session_value' + get "/get_session_value" assert_response :success - assert_equal 'foo: nil', response.body - session_id = cookies['_session_id'] + assert_equal "foo: nil", response.body + session_id = cookies["_session_id"] reset! - get '/set_session_value', params: { _session_id: session_id } + get "/set_session_value", params: { _session_id: session_id } assert_response :success - assert_not_equal session_id, cookies['_session_id'] + assert_not_equal session_id, cookies["_session_id"] end rescue Dalli::RingError => ex skip ex.message, ex.backtrace @@ -188,12 +188,12 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ':action', :to => ::MemCacheStoreTest::TestController + get ":action", to: ::MemCacheStoreTest::TestController end end @app = self.class.build_app(set) do |middleware| - middleware.use ActionDispatch::Session::MemCacheStore, :key => '_session_id', :namespace => "mem_cache_store_test:#{SecureRandom.hex(10)}" + middleware.use ActionDispatch::Session::MemCacheStore, key: "_session_id", namespace: "mem_cache_store_test:#{SecureRandom.hex(10)}" middleware.delete ActionDispatch::ShowExceptions end diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb index 3e61d123e3..0bf3a8b3ee 100644 --- a/actionpack/test/dispatch/session/test_session_test.rb +++ b/actionpack/test/dispatch/session/test_session_test.rb @@ -1,63 +1,63 @@ -require 'abstract_unit' -require 'stringio' +require "abstract_unit" +require "stringio" class ActionController::TestSessionTest < ActiveSupport::TestCase def test_initialize_with_values - session = ActionController::TestSession.new(one: 'one', two: 'two') - assert_equal('one', session[:one]) - assert_equal('two', session[:two]) + session = ActionController::TestSession.new(one: "one", two: "two") + assert_equal("one", session[:one]) + assert_equal("two", session[:two]) end def test_setting_session_item_sets_item session = ActionController::TestSession.new - session[:key] = 'value' - assert_equal('value', session[:key]) + session[:key] = "value" + assert_equal("value", session[:key]) end def test_calling_delete_removes_item_and_returns_its_value session = ActionController::TestSession.new - session[:key] = 'value' - assert_equal('value', session[:key]) - assert_equal('value', session.delete(:key)) + session[:key] = "value" + assert_equal("value", session[:key]) + assert_equal("value", session.delete(:key)) assert_nil(session[:key]) end def test_calling_update_with_params_passes_to_attributes session = ActionController::TestSession.new - session.update('key' => 'value') - assert_equal('value', session[:key]) + session.update("key" => "value") + assert_equal("value", session[:key]) end def test_clear_empties_session - session = ActionController::TestSession.new(one: 'one', two: 'two') + session = ActionController::TestSession.new(one: "one", two: "two") session.clear assert_nil(session[:one]) assert_nil(session[:two]) end def test_keys_and_values - session = ActionController::TestSession.new(one: '1', two: '2') + session = ActionController::TestSession.new(one: "1", two: "2") assert_equal %w(one two), session.keys assert_equal %w(1 2), session.values end def test_fetch_returns_default - session = ActionController::TestSession.new(one: '1') - assert_equal('2', session.fetch(:two, '2')) + session = ActionController::TestSession.new(one: "1") + assert_equal("2", session.fetch(:two, "2")) end def test_fetch_on_symbol_returns_value - session = ActionController::TestSession.new(one: '1') - assert_equal('1', session.fetch(:one)) + session = ActionController::TestSession.new(one: "1") + assert_equal("1", session.fetch(:one)) end def test_fetch_on_string_returns_value - session = ActionController::TestSession.new(one: '1') - assert_equal('1', session.fetch('one')) + session = ActionController::TestSession.new(one: "1") + assert_equal("1", session.fetch("one")) end def test_fetch_returns_block_value - session = ActionController::TestSession.new(one: '1') - assert_equal(2, session.fetch('2') { |key| key.to_i }) + session = ActionController::TestSession.new(one: "1") + assert_equal(2, session.fetch("2") { |key| key.to_i }) end end diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 14894d4b82..d8f673c212 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -1,7 +1,6 @@ -require 'abstract_unit' +require "abstract_unit" class ShowExceptionsTest < ActionDispatch::IntegrationTest - class Boomer def call(env) req = ActionDispatch::Request.new(env) @@ -15,14 +14,14 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest raise ActionDispatch::ParamsParser::ParseError end when "/method_not_allowed" - raise ActionController::MethodNotAllowed, 'PUT' + raise ActionController::MethodNotAllowed, "PUT" when "/unknown_http_method" raise ActionController::UnknownHttpMethod when "/not_found_original_exception" begin raise AbstractController::ActionNotFound.new rescue - raise ActionView::Template::Error.new('template') + raise ActionView::Template::Error.new("template") end else raise "puke!" @@ -35,30 +34,30 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest test "skip exceptions app if not showing exceptions" do @app = ProductionApp assert_raise RuntimeError do - get "/", headers: { 'action_dispatch.show_exceptions' => false } + get "/", headers: { "action_dispatch.show_exceptions" => false } end end test "rescue with error page" do @app = ProductionApp - get "/", headers: { 'action_dispatch.show_exceptions' => true } + get "/", headers: { "action_dispatch.show_exceptions" => true } assert_response 500 assert_equal "500 error fixture\n", body - get "/bad_params", headers: { 'action_dispatch.show_exceptions' => true } + get "/bad_params", headers: { "action_dispatch.show_exceptions" => true } assert_response 400 assert_equal "400 error fixture\n", body - get "/not_found", headers: { 'action_dispatch.show_exceptions' => true } + get "/not_found", headers: { "action_dispatch.show_exceptions" => true } assert_response 404 assert_equal "404 error fixture\n", body - get "/method_not_allowed", headers: { 'action_dispatch.show_exceptions' => true } + get "/method_not_allowed", headers: { "action_dispatch.show_exceptions" => true } assert_response 405 assert_equal "", body - get "/unknown_http_method", headers: { 'action_dispatch.show_exceptions' => true } + get "/unknown_http_method", headers: { "action_dispatch.show_exceptions" => true } assert_response 405 assert_equal "", body end @@ -69,11 +68,11 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest begin @app = ProductionApp - get "/", headers: { 'action_dispatch.show_exceptions' => true } + get "/", headers: { "action_dispatch.show_exceptions" => true } assert_response 500 assert_equal "500 localized error fixture\n", body - get "/not_found", headers: { 'action_dispatch.show_exceptions' => true } + get "/not_found", headers: { "action_dispatch.show_exceptions" => true } assert_response 404 assert_equal "404 error fixture\n", body ensure @@ -84,14 +83,14 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest test "sets the HTTP charset parameter" do @app = ProductionApp - get "/", headers: { 'action_dispatch.show_exceptions' => true } + get "/", headers: { "action_dispatch.show_exceptions" => true } assert_equal "text/html; charset=utf-8", response.headers["Content-Type"] end test "show registered original exception for wrapped exceptions" do @app = ProductionApp - get "/not_found_original_exception", headers: { 'action_dispatch.show_exceptions' => true } + get "/not_found_original_exception", headers: { "action_dispatch.show_exceptions" => true } assert_response 404 assert_match(/404 error/, body) end @@ -105,7 +104,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end @app = ActionDispatch::ShowExceptions.new(Boomer.new, exceptions_app) - get "/not_found_original_exception", headers: { 'action_dispatch.show_exceptions' => true } + get "/not_found_original_exception", headers: { "action_dispatch.show_exceptions" => true } assert_response 404 assert_equal "YOU FAILED", body end @@ -116,7 +115,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end @app = ActionDispatch::ShowExceptions.new(Boomer.new, exceptions_app) - get "/method_not_allowed", headers: { 'action_dispatch.show_exceptions' => true } + get "/method_not_allowed", headers: { "action_dispatch.show_exceptions" => true } assert_response 405 assert_equal "", body end @@ -124,12 +123,12 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest test "bad params exception is returned in the correct format" do @app = ProductionApp - get "/bad_params", headers: { 'action_dispatch.show_exceptions' => true } + get "/bad_params", headers: { "action_dispatch.show_exceptions" => true } assert_equal "text/html; charset=utf-8", response.headers["Content-Type"] assert_response 400 assert_match(/400 error/, body) - get "/bad_params.json", headers: { 'action_dispatch.show_exceptions' => true } + get "/bad_params.json", headers: { "action_dispatch.show_exceptions" => true } assert_equal "application/json; charset=utf-8", response.headers["Content-Type"] assert_response 400 assert_equal("{\"status\":400,\"error\":\"Bad Request\"}", body) diff --git a/actionpack/test/dispatch/ssl_test.rb b/actionpack/test/dispatch/ssl_test.rb index 668b2b6cfe..71b274bf1e 100644 --- a/actionpack/test/dispatch/ssl_test.rb +++ b/actionpack/test/dispatch/ssl_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' +require "abstract_unit" class SSLTest < ActionDispatch::IntegrationTest - HEADERS = Rack::Utils::HeaderHash.new 'Content-Type' => 'text/html' + HEADERS = Rack::Utils::HeaderHash.new "Content-Type" => "text/html" attr_accessor :app @@ -12,7 +12,6 @@ class SSLTest < ActionDispatch::IntegrationTest end class RedirectSSLTest < SSLTest - def assert_not_redirected(url, headers: {}, redirect: {}, deprecated_host: nil, deprecated_port: nil) @@ -25,7 +24,7 @@ class RedirectSSLTest < SSLTest end def assert_redirected(redirect: {}, deprecated_host: nil, deprecated_port: nil, - from: 'http://a/b?c=d', to: from.sub('http', 'https')) + from: "http://a/b?c=d", to: from.sub("http", "https")) redirect = { status: 301, body: [] }.merge(redirect) @@ -39,127 +38,141 @@ class RedirectSSLTest < SSLTest assert_equal redirect[:body].join, @response.body end - test 'exclude can avoid redirect' do + def assert_post_redirected(redirect: {}, from: "http://a/b?c=d", + to: from.sub("http", "https")) + + self.app = build_app ssl_options: { redirect: redirect } + + post from + assert_response redirect[:status] || 307 + assert_redirected_to to + end + + test "exclude can avoid redirect" do excluding = { exclude: -> request { request.path =~ /healthcheck/ } } - assert_not_redirected 'http://example.org/healthcheck', redirect: excluding - assert_redirected from: 'http://example.org/', redirect: excluding + assert_not_redirected "http://example.org/healthcheck", redirect: excluding + assert_redirected from: "http://example.org/", redirect: excluding end - test 'https is not redirected' do - assert_not_redirected 'https://example.org' + test "https is not redirected" do + assert_not_redirected "https://example.org" end - test 'proxied https is not redirected' do - assert_not_redirected 'http://example.org', headers: { 'HTTP_X_FORWARDED_PROTO' => 'https' } + test "proxied https is not redirected" do + assert_not_redirected "http://example.org", headers: { "HTTP_X_FORWARDED_PROTO" => "https" } end - test 'http is redirected to https' do + test "http is redirected to https" do assert_redirected end - test 'redirect with non-301 status' do + test "http POST is redirected to https with status 307" do + assert_post_redirected + end + + test "redirect with non-301 status" do assert_redirected redirect: { status: 307 } end - test 'redirect with custom body' do - assert_redirected redirect: { body: ['foo'] } + test "redirect with custom body" do + assert_redirected redirect: { body: ["foo"] } end - test 'redirect to specific host' do - assert_redirected redirect: { host: 'ssl' }, to: 'https://ssl/b?c=d' + test "redirect to specific host" do + assert_redirected redirect: { host: "ssl" }, to: "https://ssl/b?c=d" end - test 'redirect to default port' do + test "redirect to default port" do assert_redirected redirect: { port: 443 } end - test 'redirect to non-default port' do - assert_redirected redirect: { port: 8443 }, to: 'https://a:8443/b?c=d' + test "redirect to non-default port" do + assert_redirected redirect: { port: 8443 }, to: "https://a:8443/b?c=d" end - test 'redirect to different host and non-default port' do - assert_redirected redirect: { host: 'ssl', port: 8443 }, to: 'https://ssl:8443/b?c=d' + test "redirect to different host and non-default port" do + assert_redirected redirect: { host: "ssl", port: 8443 }, to: "https://ssl:8443/b?c=d" end - test 'redirect to different host including port' do - assert_redirected redirect: { host: 'ssl:443' }, to: 'https://ssl:443/b?c=d' + test "redirect to different host including port" do + assert_redirected redirect: { host: "ssl:443" }, to: "https://ssl:443/b?c=d" end - test ':host is deprecated, moved within redirect: { host: … }' do + test ":host is deprecated, moved within redirect: { host: … }" do assert_deprecated do - assert_redirected deprecated_host: 'foo', to: 'https://foo/b?c=d' + assert_redirected deprecated_host: "foo", to: "https://foo/b?c=d" end end - test ':port is deprecated, moved within redirect: { port: … }' do + test ":port is deprecated, moved within redirect: { port: … }" do assert_deprecated do - assert_redirected deprecated_port: 1, to: 'https://a:1/b?c=d' + assert_redirected deprecated_port: 1, to: "https://a:1/b?c=d" end end - test 'no redirect with redirect set to false' do - assert_not_redirected 'http://example.org', redirect: false + test "no redirect with redirect set to false" do + assert_not_redirected "http://example.org", redirect: false end end class StrictTransportSecurityTest < SSLTest - EXPECTED = 'max-age=15552000' - EXPECTED_WITH_SUBDOMAINS = 'max-age=15552000; includeSubDomains' + EXPECTED = "max-age=15552000" + EXPECTED_WITH_SUBDOMAINS = "max-age=15552000; includeSubDomains" - def assert_hsts(expected, url: 'https://example.org', hsts: { subdomains: true }, headers: {}) + def assert_hsts(expected, url: "https://example.org", hsts: { subdomains: true }, headers: {}) self.app = build_app ssl_options: { hsts: hsts }, headers: headers get url - assert_equal expected, response.headers['Strict-Transport-Security'] + assert_equal expected, response.headers["Strict-Transport-Security"] end - test 'enabled by default' do + test "enabled by default" do assert_hsts EXPECTED_WITH_SUBDOMAINS end - test 'not sent with http:// responses' do - assert_hsts nil, url: 'http://example.org' + test "not sent with http:// responses" do + assert_hsts nil, url: "http://example.org" end - test 'defers to app-provided header' do - assert_hsts 'app-provided', headers: { 'Strict-Transport-Security' => 'app-provided' } + test "defers to app-provided header" do + assert_hsts "app-provided", headers: { "Strict-Transport-Security" => "app-provided" } end - test 'hsts: true enables default settings' do + test "hsts: true enables default settings" do assert_hsts EXPECTED, hsts: true end - test 'hsts: false sets max-age to zero, clearing browser HSTS settings' do - assert_hsts 'max-age=0', hsts: false + test "hsts: false sets max-age to zero, clearing browser HSTS settings" do + assert_hsts "max-age=0", hsts: false end - test ':expires sets max-age' do + test ":expires sets max-age" do assert_deprecated do - assert_hsts 'max-age=500', hsts: { expires: 500 } + assert_hsts "max-age=500", hsts: { expires: 500 } end end - test ':expires supports AS::Duration arguments' do + test ":expires supports AS::Duration arguments" do assert_deprecated do - assert_hsts 'max-age=31557600', hsts: { expires: 1.year } + assert_hsts "max-age=31557600", hsts: { expires: 1.year } end end - test 'include subdomains' do + test "include subdomains" do assert_hsts "#{EXPECTED}; includeSubDomains", hsts: { subdomains: true } end - test 'exclude subdomains' do + test "exclude subdomains" do assert_hsts EXPECTED, hsts: { subdomains: false } end - test 'opt in to browser preload lists' do + test "opt in to browser preload lists" do assert_deprecated do assert_hsts "#{EXPECTED}; preload", hsts: { preload: true } end end - test 'opt out of browser preload lists' do + test "opt out of browser preload lists" do assert_deprecated do assert_hsts EXPECTED, hsts: { preload: false } end @@ -171,60 +184,60 @@ class SecureCookiesTest < SSLTest def get(**options) self.app = build_app(**options) - super 'https://example.org' + super "https://example.org" end def assert_cookies(*expected) - assert_equal expected, response.headers['Set-Cookie'].split("\n") + assert_equal expected, response.headers["Set-Cookie"].split("\n") end def test_flag_cookies_as_secure - get headers: { 'Set-Cookie' => DEFAULT } - assert_cookies 'id=1; path=/; secure', 'token=abc; path=/; secure; HttpOnly' + get headers: { "Set-Cookie" => DEFAULT } + assert_cookies "id=1; path=/; secure", "token=abc; path=/; secure; HttpOnly" end def test_flag_cookies_as_secure_at_end_of_line - get headers: { 'Set-Cookie' => 'problem=def; path=/; HttpOnly; secure' } - assert_cookies 'problem=def; path=/; HttpOnly; secure' + get headers: { "Set-Cookie" => "problem=def; path=/; HttpOnly; secure" } + assert_cookies "problem=def; path=/; HttpOnly; secure" end def test_flag_cookies_as_secure_with_more_spaces_before - get headers: { 'Set-Cookie' => 'problem=def; path=/; HttpOnly; secure' } - assert_cookies 'problem=def; path=/; HttpOnly; secure' + get headers: { "Set-Cookie" => "problem=def; path=/; HttpOnly; secure" } + assert_cookies "problem=def; path=/; HttpOnly; secure" end def test_flag_cookies_as_secure_with_more_spaces_after - get headers: { 'Set-Cookie' => 'problem=def; path=/; secure; HttpOnly' } - assert_cookies 'problem=def; path=/; secure; HttpOnly' + get headers: { "Set-Cookie" => "problem=def; path=/; secure; HttpOnly" } + assert_cookies "problem=def; path=/; secure; HttpOnly" end def test_flag_cookies_as_secure_with_has_not_spaces_before - get headers: { 'Set-Cookie' => 'problem=def; path=/;secure; HttpOnly' } - assert_cookies 'problem=def; path=/;secure; HttpOnly' + get headers: { "Set-Cookie" => "problem=def; path=/;secure; HttpOnly" } + assert_cookies "problem=def; path=/;secure; HttpOnly" end def test_flag_cookies_as_secure_with_has_not_spaces_after - get headers: { 'Set-Cookie' => 'problem=def; path=/; secure;HttpOnly' } - assert_cookies 'problem=def; path=/; secure;HttpOnly' + get headers: { "Set-Cookie" => "problem=def; path=/; secure;HttpOnly" } + assert_cookies "problem=def; path=/; secure;HttpOnly" end def test_flag_cookies_as_secure_with_ignore_case - get headers: { 'Set-Cookie' => 'problem=def; path=/; Secure; HttpOnly' } - assert_cookies 'problem=def; path=/; Secure; HttpOnly' + get headers: { "Set-Cookie" => "problem=def; path=/; Secure; HttpOnly" } + assert_cookies "problem=def; path=/; Secure; HttpOnly" end def test_cookies_as_not_secure_with_secure_cookies_disabled - get headers: { 'Set-Cookie' => DEFAULT }, ssl_options: { secure_cookies: false } + get headers: { "Set-Cookie" => DEFAULT }, ssl_options: { secure_cookies: false } assert_cookies(*DEFAULT.split("\n")) end def test_no_cookies get - assert_nil response.headers['Set-Cookie'] + assert_nil response.headers["Set-Cookie"] end def test_keeps_original_headers_behavior - get headers: { 'Connection' => %w[close] } - assert_equal 'close', response.headers['Connection'] + get headers: { "Connection" => %w[close] } + assert_equal "close", response.headers["Connection"] end end diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index 1036758f35..f72823a80e 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' -require 'zlib' +require "abstract_unit" +require "zlib" module StaticTests DummyApp = lambda { |env| - [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] + [200, { "Content-Type" => "text/plain" }, ["Hello, World!"]] } def setup @@ -29,7 +29,7 @@ module StaticTests end def test_handles_urls_with_ascii_8bit - assert_equal "Hello, World!", get("/doorkeeper%E3E4".force_encoding('ASCII-8BIT')).body + assert_equal "Hello, World!", get("/doorkeeper%E3E4".force_encoding("ASCII-8BIT")).body end def test_handles_urls_with_ascii_8bit_on_win_31j @@ -37,7 +37,7 @@ module StaticTests Encoding.default_internal = "Windows-31J" Encoding.default_external = "Windows-31J" end - assert_equal "Hello, World!", get("/doorkeeper%E3E4".force_encoding('ASCII-8BIT')).body + assert_equal "Hello, World!", get("/doorkeeper%E3E4".force_encoding("ASCII-8BIT")).body end def test_handles_urls_with_null_byte @@ -82,7 +82,6 @@ module StaticTests assert_html "means hello in Japanese\n", get("/foo/#{Rack::Utils.escape("こんにちは.html")}") end - def test_serves_static_file_with_exclamation_mark_in_filename with_static_file "/foo/foo!bar.html" do |file| assert_html file, get("/foo/foo%21bar.html") @@ -148,63 +147,63 @@ module StaticTests def test_serves_gzip_files_when_header_set file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js" - response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip') + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip") assert_gzip file_name, response - assert_equal 'application/javascript', response.headers['Content-Type'] - assert_equal 'Accept-Encoding', response.headers["Vary"] - assert_equal 'gzip', response.headers["Content-Encoding"] + assert_equal "application/javascript", response.headers["Content-Type"] + assert_equal "Accept-Encoding", response.headers["Vary"] + assert_equal "gzip", response.headers["Content-Encoding"] - response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'Gzip') + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "Gzip") assert_gzip file_name, response - response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'GZIP') + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "GZIP") assert_gzip file_name, response - response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'compress;q=0.5, gzip;q=1.0') + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "compress;q=0.5, gzip;q=1.0") assert_gzip file_name, response - response = get(file_name, 'HTTP_ACCEPT_ENCODING' => '') - assert_not_equal 'gzip', response.headers["Content-Encoding"] + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "") + assert_not_equal "gzip", response.headers["Content-Encoding"] end def test_does_not_modify_path_info file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js" - env = {'PATH_INFO' => file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip', "REQUEST_METHOD" => 'POST'} + env = { "PATH_INFO" => file_name, "HTTP_ACCEPT_ENCODING" => "gzip", "REQUEST_METHOD" => "POST" } @app.call(env) - assert_equal file_name, env['PATH_INFO'] + assert_equal file_name, env["PATH_INFO"] end def test_serves_gzip_with_propper_content_type_fallback file_name = "/gzip/foo.zoo" - response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip') + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip") assert_gzip file_name, response default_response = get(file_name) # no gzip - assert_equal default_response.headers['Content-Type'], response.headers['Content-Type'] + assert_equal default_response.headers["Content-Type"], response.headers["Content-Type"] end def test_serves_gzip_files_with_not_modified file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js" last_modified = File.mtime(File.join(@root, "#{file_name}.gz")) - response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip', 'HTTP_IF_MODIFIED_SINCE' => last_modified.httpdate) + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip", "HTTP_IF_MODIFIED_SINCE" => last_modified.httpdate) assert_equal 304, response.status - assert_equal nil, response.headers['Content-Type'] - assert_equal nil, response.headers['Content-Encoding'] - assert_equal nil, response.headers['Vary'] + assert_equal nil, response.headers["Content-Type"] + assert_equal nil, response.headers["Content-Encoding"] + assert_equal nil, response.headers["Vary"] end def test_serves_files_with_headers headers = { - "Access-Control-Allow-Origin" => 'http://rubyonrails.org', - "Cache-Control" => 'public, max-age=60', + "Access-Control-Allow-Origin" => "http://rubyonrails.org", + "Cache-Control" => "public, max-age=60", "X-Custom-Header" => "I'm a teapot" } app = ActionDispatch::Static.new(DummyApp, @root, headers: headers) response = Rack::MockRequest.new(app).request("GET", "/foo/bar.html") - assert_equal 'http://rubyonrails.org', response.headers["Access-Control-Allow-Origin"] - assert_equal 'public, max-age=60', response.headers["Cache-Control"] + assert_equal "http://rubyonrails.org", response.headers["Access-Control-Allow-Origin"] + assert_equal "public, max-age=60", response.headers["Cache-Control"] assert_equal "I'm a teapot", response.headers["X-Custom-Header"] end @@ -215,7 +214,7 @@ module StaticTests end # Windows doesn't allow \ / : * ? " < > | in filenames - unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ + unless RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ def test_serves_static_file_with_colon with_static_file "/foo/foo:bar.html" do |file| assert_html file, get("/foo/foo%3Abar.html") @@ -267,7 +266,7 @@ class StaticTest < ActiveSupport::TestCase def setup super @root = "#{FIXTURE_LOAD_PATH}/public" - @app = ActionDispatch::Static.new(DummyApp, @root, headers: {'Cache-Control' => "public, max-age=60"}) + @app = ActionDispatch::Static.new(DummyApp, @root, headers: { "Cache-Control" => "public, max-age=60" }) end def public_path @@ -277,8 +276,8 @@ class StaticTest < ActiveSupport::TestCase include StaticTests def test_custom_handler_called_when_file_is_outside_root - filename = 'shared.html.erb' - assert File.exist?(File.join(@root, '..', filename)) + filename = "shared.html.erb" + assert File.exist?(File.join(@root, "..", filename)) env = { "REQUEST_METHOD"=>"GET", "REQUEST_PATH"=>"/..%2F#{filename}", @@ -303,14 +302,13 @@ class StaticTest < ActiveSupport::TestCase assert_html "/foo/other-index.html", get("/foo/") assert_html "/foo/other-index.html", get("/foo") end - end class StaticEncodingTest < StaticTest def setup super @root = "#{FIXTURE_LOAD_PATH}/公共" - @app = ActionDispatch::Static.new(DummyApp, @root, headers: {'Cache-Control' => "public, max-age=60"}) + @app = ActionDispatch::Static.new(DummyApp, @root, headers: { "Cache-Control" => "public, max-age=60" }) end def public_path diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb index 3c19cbd68a..35af3076ba 100644 --- a/actionpack/test/dispatch/test_request_test.rb +++ b/actionpack/test/dispatch/test_request_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class TestRequestTest < ActiveSupport::TestCase test "sane defaults" do @@ -33,24 +33,24 @@ class TestRequestTest < ActiveSupport::TestCase assert_equal nil, req.env["HTTP_COOKIE"] req.cookie_jar["user_name"] = "david" - assert_cookies({"user_name" => "david"}, req.cookie_jar) + assert_cookies({ "user_name" => "david" }, req.cookie_jar) req.cookie_jar["login"] = "XJ-122" - assert_cookies({"user_name" => "david", "login" => "XJ-122"}, req.cookie_jar) + assert_cookies({ "user_name" => "david", "login" => "XJ-122" }, req.cookie_jar) assert_nothing_raised do req.cookie_jar["login"] = nil - assert_cookies({"user_name" => "david", "login" => nil}, req.cookie_jar) + assert_cookies({ "user_name" => "david", "login" => nil }, req.cookie_jar) end req.cookie_jar.delete(:login) - assert_cookies({"user_name" => "david"}, req.cookie_jar) + assert_cookies({ "user_name" => "david" }, req.cookie_jar) req.cookie_jar.clear assert_cookies({}, req.cookie_jar) - req.cookie_jar.update(:user_name => "david") - assert_cookies({"user_name" => "david"}, req.cookie_jar) + req.cookie_jar.update(user_name: "david") + assert_cookies({ "user_name" => "david" }, req.cookie_jar) end test "does not complain when there is no application config" do @@ -60,59 +60,59 @@ class TestRequestTest < ActiveSupport::TestCase test "default remote address is 0.0.0.0" do req = ActionDispatch::TestRequest.create({}) - assert_equal '0.0.0.0', req.remote_addr + assert_equal "0.0.0.0", req.remote_addr end test "allows remote address to be overridden" do - req = ActionDispatch::TestRequest.create('REMOTE_ADDR' => '127.0.0.1') - assert_equal '127.0.0.1', req.remote_addr + req = ActionDispatch::TestRequest.create("REMOTE_ADDR" => "127.0.0.1") + assert_equal "127.0.0.1", req.remote_addr end test "default host is test.host" do req = ActionDispatch::TestRequest.create({}) - assert_equal 'test.host', req.host + assert_equal "test.host", req.host end test "allows host to be overridden" do - req = ActionDispatch::TestRequest.create('HTTP_HOST' => 'www.example.com') - assert_equal 'www.example.com', req.host + req = ActionDispatch::TestRequest.create("HTTP_HOST" => "www.example.com") + assert_equal "www.example.com", req.host end test "default user agent is 'Rails Testing'" do req = ActionDispatch::TestRequest.create({}) - assert_equal 'Rails Testing', req.user_agent + assert_equal "Rails Testing", req.user_agent end test "allows user agent to be overridden" do - req = ActionDispatch::TestRequest.create('HTTP_USER_AGENT' => 'GoogleBot') - assert_equal 'GoogleBot', req.user_agent + req = ActionDispatch::TestRequest.create("HTTP_USER_AGENT" => "GoogleBot") + assert_equal "GoogleBot", req.user_agent end test "setter methods" do req = ActionDispatch::TestRequest.create({}) - get = 'GET' + get = "GET" [ - 'request_method=', 'host=', 'request_uri=', 'path=', 'if_modified_since=', 'if_none_match=', - 'remote_addr=', 'user_agent=', 'accept=' + "request_method=", "host=", "request_uri=", "path=", "if_modified_since=", "if_none_match=", + "remote_addr=", "user_agent=", "accept=" ].each do |method| req.send(method, get) end req.port = 8080 - req.accept = 'hello goodbye' - - assert_equal(get, req.get_header('REQUEST_METHOD')) - assert_equal(get, req.get_header('HTTP_HOST')) - assert_equal(8080, req.get_header('SERVER_PORT')) - assert_equal(get, req.get_header('REQUEST_URI')) - assert_equal(get, req.get_header('PATH_INFO')) - assert_equal(get, req.get_header('HTTP_IF_MODIFIED_SINCE')) - assert_equal(get, req.get_header('HTTP_IF_NONE_MATCH')) - assert_equal(get, req.get_header('REMOTE_ADDR')) - assert_equal(get, req.get_header('HTTP_USER_AGENT')) - assert_nil(req.get_header('action_dispatch.request.accepts')) - assert_equal('hello goodbye', req.get_header('HTTP_ACCEPT')) + req.accept = "hello goodbye" + + assert_equal(get, req.get_header("REQUEST_METHOD")) + assert_equal(get, req.get_header("HTTP_HOST")) + assert_equal(8080, req.get_header("SERVER_PORT")) + assert_equal(get, req.get_header("REQUEST_URI")) + assert_equal(get, req.get_header("PATH_INFO")) + assert_equal(get, req.get_header("HTTP_IF_MODIFIED_SINCE")) + assert_equal(get, req.get_header("HTTP_IF_NONE_MATCH")) + assert_equal(get, req.get_header("REMOTE_ADDR")) + assert_equal(get, req.get_header("HTTP_USER_AGENT")) + assert_nil(req.get_header("action_dispatch.request.accepts")) + assert_equal("hello goodbye", req.get_header("HTTP_ACCEPT")) end private diff --git a/actionpack/test/dispatch/test_response_test.rb b/actionpack/test/dispatch/test_response_test.rb index 72e06b4590..98eafb5119 100644 --- a/actionpack/test/dispatch/test_response_test.rb +++ b/actionpack/test/dispatch/test_response_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class TestResponseTest < ActiveSupport::TestCase def assert_response_code_range(range, predicate) @@ -19,10 +19,10 @@ class TestResponseTest < ActiveSupport::TestCase end test "response parsing" do - response = ActionDispatch::TestResponse.create(200, {}, '') + response = ActionDispatch::TestResponse.create(200, {}, "") assert_equal response.body, response.parsed_body - response = ActionDispatch::TestResponse.create(200, { 'Content-Type' => 'application/json' }, '{ "foo": "fighters" }') - assert_equal({ 'foo' => 'fighters' }, response.parsed_body) + response = ActionDispatch::TestResponse.create(200, { "Content-Type" => "application/json" }, '{ "foo": "fighters" }') + assert_equal({ "foo" => "fighters" }, response.parsed_body) end end diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb index 55ebbd5143..60d0246a68 100644 --- a/actionpack/test/dispatch/uploaded_file_test.rb +++ b/actionpack/test/dispatch/uploaded_file_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module ActionDispatch class UploadedFileTest < ActiveSupport::TestCase @@ -9,81 +9,81 @@ module ActionDispatch end def test_original_filename - uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new) - assert_equal 'foo', uf.original_filename + uf = Http::UploadedFile.new(filename: "foo", tempfile: Object.new) + assert_equal "foo", uf.original_filename end def test_filename_should_be_in_utf_8 - uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new) + uf = Http::UploadedFile.new(filename: "foo", tempfile: Object.new) assert_equal "UTF-8", uf.original_filename.encoding.to_s end def test_filename_should_always_be_in_utf_8 - uf = Http::UploadedFile.new(:filename => 'foo'.encode(Encoding::SHIFT_JIS), - :tempfile => Object.new) + uf = Http::UploadedFile.new(filename: "foo".encode(Encoding::SHIFT_JIS), + tempfile: Object.new) assert_equal "UTF-8", uf.original_filename.encoding.to_s end def test_content_type - uf = Http::UploadedFile.new(:type => 'foo', :tempfile => Object.new) - assert_equal 'foo', uf.content_type + uf = Http::UploadedFile.new(type: "foo", tempfile: Object.new) + assert_equal "foo", uf.content_type end def test_headers - uf = Http::UploadedFile.new(:head => 'foo', :tempfile => Object.new) - assert_equal 'foo', uf.headers + uf = Http::UploadedFile.new(head: "foo", tempfile: Object.new) + assert_equal "foo", uf.headers end def test_tempfile - uf = Http::UploadedFile.new(:tempfile => 'foo') - assert_equal 'foo', uf.tempfile + uf = Http::UploadedFile.new(tempfile: "foo") + assert_equal "foo", uf.tempfile end def test_to_io_returns_the_tempfile tf = Object.new - uf = Http::UploadedFile.new(:tempfile => tf) + uf = Http::UploadedFile.new(tempfile: tf) assert_equal tf, uf.to_io end def test_delegates_path_to_tempfile - tf = Class.new { def path; 'thunderhorse' end } - uf = Http::UploadedFile.new(:tempfile => tf.new) - assert_equal 'thunderhorse', uf.path + tf = Class.new { def path; "thunderhorse" end } + uf = Http::UploadedFile.new(tempfile: tf.new) + assert_equal "thunderhorse", uf.path end def test_delegates_open_to_tempfile - tf = Class.new { def open; 'thunderhorse' end } - uf = Http::UploadedFile.new(:tempfile => tf.new) - assert_equal 'thunderhorse', uf.open + tf = Class.new { def open; "thunderhorse" end } + uf = Http::UploadedFile.new(tempfile: tf.new) + assert_equal "thunderhorse", uf.open end def test_delegates_close_to_tempfile - tf = Class.new { def close(unlink_now=false); 'thunderhorse' end } - uf = Http::UploadedFile.new(:tempfile => tf.new) - assert_equal 'thunderhorse', uf.close + tf = Class.new { def close(unlink_now=false); "thunderhorse" end } + uf = Http::UploadedFile.new(tempfile: tf.new) + assert_equal "thunderhorse", uf.close end def test_close_accepts_parameter tf = Class.new { def close(unlink_now=false); "thunderhorse: #{unlink_now}" end } - uf = Http::UploadedFile.new(:tempfile => tf.new) - assert_equal 'thunderhorse: true', uf.close(true) + uf = Http::UploadedFile.new(tempfile: tf.new) + assert_equal "thunderhorse: true", uf.close(true) end def test_delegates_read_to_tempfile - tf = Class.new { def read(length=nil, buffer=nil); 'thunderhorse' end } - uf = Http::UploadedFile.new(:tempfile => tf.new) - assert_equal 'thunderhorse', uf.read + tf = Class.new { def read(length=nil, buffer=nil); "thunderhorse" end } + uf = Http::UploadedFile.new(tempfile: tf.new) + assert_equal "thunderhorse", uf.read end def test_delegates_read_to_tempfile_with_params tf = Class.new { def read(length=nil, buffer=nil); [length, buffer] end } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal %w{ thunder horse }, uf.read(*%w{ thunder horse }) end def test_delegate_respects_respond_to? tf = Class.new { def read; yield end; private :read } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_raises(NoMethodError) do uf.read end @@ -91,15 +91,15 @@ module ActionDispatch def test_delegate_eof_to_tempfile tf = Class.new { def eof?; true end; } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert uf.eof? end def test_respond_to? tf = Class.new { def read; yield end } - uf = Http::UploadedFile.new(:tempfile => tf.new) - assert uf.respond_to?(:headers), 'responds to headers' - assert uf.respond_to?(:read), 'responds to read' + uf = Http::UploadedFile.new(tempfile: tf.new) + assert uf.respond_to?(:headers), "responds to headers" + assert uf.respond_to?(:read), "responds to read" end end end diff --git a/actionpack/test/dispatch/url_generation_test.rb b/actionpack/test/dispatch/url_generation_test.rb index 8c9782bb90..5d81fd6834 100644 --- a/actionpack/test/dispatch/url_generation_test.rb +++ b/actionpack/test/dispatch/url_generation_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module TestUrlGeneration class WithMountPoint < ActionDispatch::IntegrationTest @@ -13,11 +13,11 @@ module TestUrlGeneration end Routes.draw do - get "/foo", :to => "my_route_generating#index", :as => :foo + get "/foo", to: "my_route_generating#index", as: :foo resources :bars - mount MyRouteGeneratingController.action(:index), at: '/bar' + mount MyRouteGeneratingController.action(:index), at: "/bar" end APP = build_app Routes @@ -35,22 +35,22 @@ module TestUrlGeneration end test "accepting a :script_name option" do - assert_equal "/bar/foo", foo_path(:script_name => "/bar") + assert_equal "/bar/foo", foo_path(script_name: "/bar") end test "the request's SCRIPT_NAME takes precedence over the route" do - get "/foo", headers: { 'SCRIPT_NAME' => "/new", 'action_dispatch.routes' => Routes } + get "/foo", headers: { "SCRIPT_NAME" => "/new", "action_dispatch.routes" => Routes } assert_equal "/new/foo", response.body end test "the request's SCRIPT_NAME wraps the mounted app's" do - get '/new/bar/foo', headers: { 'SCRIPT_NAME' => '/new', 'PATH_INFO' => '/bar/foo', 'action_dispatch.routes' => Routes } + get "/new/bar/foo", headers: { "SCRIPT_NAME" => "/new", "PATH_INFO" => "/bar/foo", "action_dispatch.routes" => Routes } assert_equal "/new/bar/foo", response.body end test "handling http protocol with https set" do https! - assert_equal "http://www.example.com/foo", foo_url(:protocol => "http") + assert_equal "http://www.example.com/foo", foo_url(protocol: "http") end test "extracting protocol from host when protocol not present" do @@ -117,25 +117,23 @@ module TestUrlGeneration test "generating URLs with trailing slashes" do assert_equal "/bars.json", bars_path( trailing_slash: true, - format: 'json' + format: "json" ) end test "generating URLS with querystring and trailing slashes" do assert_equal "/bars.json?a=b", bars_path( trailing_slash: true, - a: 'b', - format: 'json' + a: "b", + format: "json" ) end test "generating URLS with empty querystring" do assert_equal "/bars.json", bars_path( a: {}, - format: 'json' + format: "json" ) end - end end - |