1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Consistent usage of spaces in hashes across our codebase

This commit is contained in:
Rafael Mendonça França 2015-01-29 12:19:41 -02:00
parent 7814f901e1
commit bb6fe7e73a
25 changed files with 117 additions and 113 deletions

View file

@ -34,7 +34,7 @@ module ActionDispatch
# Example:
#
# get '/feed', params: { since: 201501011400 }
# post '/profile', headers: {"X-Test-Header" => "testvalue" }
# post '/profile', headers: { "X-Test-Header" => "testvalue" }
def get(path, *args)
process_with_kwargs(:get, path, *args)
end
@ -118,7 +118,7 @@ module ActionDispatch
#
# request_via_redirect :post, '/welcome',
# params: { ref_id: 14 },
# headers: {"X-Test-Header" => "testvalue"}
# headers: { "X-Test-Header" => "testvalue" }
def request_via_redirect(http_method, path, *args)
process_with_kwargs(http_method, path, *args)

View file

@ -178,7 +178,7 @@ class UrlOptionsTest < ActionController::TestCase
get ':controller/:action'
end
get :from_view, params: { route: "from_view_url"}
get :from_view, params: { route: "from_view_url" }
assert_equal 'http://www.override.com/from_view', @response.body
assert_equal 'http://www.override.com/from_view', @controller.send(:from_view_url)

View file

@ -38,7 +38,7 @@ class SessionTest < ActiveSupport::TestCase
end
def test_deprecated_request_via_redirect_uses_given_method
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
path = "/somepath"; args = { id: '1' }; headers = { "X-Test-Header" => "testvalue" }
@session.expects(:process).with(:put, path, params: args, headers: headers)
@session.stubs(:redirect?).returns(false)
assert_deprecated { @session.request_via_redirect(:put, path, args, headers) }
@ -65,7 +65,7 @@ class SessionTest < ActiveSupport::TestCase
end
def test_deprecated_get_via_redirect
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
path = "/somepath"; args = { id: '1' }; headers = { "X-Test-Header" => "testvalue" }
@session.expects(:request_via_redirect).with(:get, path, args, headers)
assert_deprecated do
@ -80,7 +80,7 @@ class SessionTest < ActiveSupport::TestCase
end
def test_deprecated_post_via_redirect
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
path = "/somepath"; args = { id: '1' }; headers = { "X-Test-Header" => "testvalue" }
@session.expects(:request_via_redirect).with(:post, path, args, headers)
assert_deprecated do
@ -95,7 +95,7 @@ class SessionTest < ActiveSupport::TestCase
end
def test_deprecated_patch_via_redirect
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
path = "/somepath"; args = { id: '1' }; headers = { "X-Test-Header" => "testvalue" }
@session.expects(:request_via_redirect).with(:patch, path, args, headers)
assert_deprecated do
@ -110,7 +110,7 @@ class SessionTest < ActiveSupport::TestCase
end
def test_deprecated_put_via_redirect
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
path = "/somepath"; args = { id: '1' }; headers = { "X-Test-Header" => "testvalue" }
@session.expects(:request_via_redirect).with(:put, path, args, headers)
assert_deprecated do
@ -125,7 +125,7 @@ class SessionTest < ActiveSupport::TestCase
end
def test_deprecated_delete_via_redirect
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
path = "/somepath"; args = { id: '1' }; headers = { "X-Test-Header" => "testvalue" }
@session.expects(:request_via_redirect).with(:delete, path, args, headers)
assert_deprecated do
@ -763,7 +763,7 @@ class MetalIntegrationTest < ActionDispatch::IntegrationTest
end
def test_pass_headers_and_env
get "/success", headers: {"X-Test-Header" => "value"}, env: {"HTTP_REFERER" => "http://test.com/", "HTTP_HOST" => "http://test.com"}
get "/success", headers: { "X-Test-Header" => "value" }, env: { "HTTP_REFERER" => "http://test.com/", "HTTP_HOST" => "http://test.com" }
assert_equal "http://test.com", @request.env["HTTP_HOST"]
assert_equal "http://test.com/", @request.env["HTTP_REFERER"]
@ -771,7 +771,7 @@ class MetalIntegrationTest < ActionDispatch::IntegrationTest
end
def test_pass_env
get "/success", env: {"HTTP_REFERER" => "http://test.com/", "HTTP_HOST" => "http://test.com"}
get "/success", env: { "HTTP_REFERER" => "http://test.com/", "HTTP_HOST" => "http://test.com" }
assert_equal "http://test.com", @request.env["HTTP_HOST"]
assert_equal "http://test.com/", @request.env["HTTP_REFERER"]
@ -891,7 +891,7 @@ class EnvironmentFilterIntegrationTest < ActionDispatch::IntegrationTest
end
test "filters rack request form vars" do
post "/post", params: {username: 'cjolly', password: 'secret'}
post "/post", params: { username: 'cjolly', password: 'secret' }
assert_equal 'cjolly', request.filtered_parameters['username']
assert_equal '[FILTERED]', request.filtered_parameters['password']

View file

@ -15,12 +15,12 @@ module ContentNegotiation
class TestContentNegotiation < Rack::TestCase
test "A */* Accept header will return HTML" do
get "/content_negotiation/basic/hello", headers: {"HTTP_ACCEPT" => "*/*"}
get "/content_negotiation/basic/hello", headers: { "HTTP_ACCEPT" => "*/*" }
assert_body "Hello world */*!"
end
test "Not all mimes are converted to symbol" do
get "/content_negotiation/basic/all", headers: {"HTTP_ACCEPT" => "text/plain, mime/another"}
get "/content_negotiation/basic/all", headers: { "HTTP_ACCEPT" => "text/plain, mime/another" }
assert_body '[:text, "mime/another"]'
end
end

View file

@ -76,7 +76,7 @@ module ContentType
end
test "sets Content-Type as application/xml when rendering *.xml.erb" do
get "/content_type/implied/i_am_xml_erb", params: {"format" => "xml"}
get "/content_type/implied/i_am_xml_erb", params: { "format" => "xml" }
assert_header "Content-Type", "application/xml; charset=utf-8"
end
@ -88,7 +88,7 @@ module ContentType
end
test "sets Content-Type as application/xml when rendering *.xml.builder" do
get "/content_type/implied/i_am_xml_builder", params: {"format" => "xml"}
get "/content_type/implied/i_am_xml_builder", params: { "format" => "xml" }
assert_header "Content-Type", "application/xml; charset=utf-8"
end

View file

@ -88,7 +88,7 @@ module RenderAction
test "rendering with layout => true" do
assert_raise(ArgumentError) do
get "/render_action/basic/hello_world_with_layout", headers: {"action_dispatch.show_exceptions" => false}
get "/render_action/basic/hello_world_with_layout", headers: { "action_dispatch.show_exceptions" => false }
end
end
@ -108,7 +108,7 @@ module RenderAction
test "rendering with layout => 'greetings'" do
assert_raise(ActionView::MissingTemplate) do
get "/render_action/basic/hello_world_with_custom_layout", headers: {"action_dispatch.show_exceptions" => false}
get "/render_action/basic/hello_world_with_custom_layout", headers: { "action_dispatch.show_exceptions" => false }
end
end
end

View file

@ -86,7 +86,7 @@ module ControllerLayouts
XML_INSTRUCT = %Q(<?xml version="1.0" encoding="UTF-8"?>\n)
test "if XML is selected, an HTML template is not also selected" do
get :index, params: {format: "xml"}
get :index, params: { format: "xml" }
assert_response XML_INSTRUCT
end
@ -96,7 +96,7 @@ module ControllerLayouts
end
test "a layout for JS is ignored even if explicitly provided for HTML" do
get :explicit, params: {format: "js"}
get :explicit, params: { format: "js" }
assert_response "alert('foo');"
end
end
@ -120,7 +120,7 @@ module ControllerLayouts
testing ControllerLayouts::FalseLayoutMethodController
test "access false layout returned by a method/proc" do
get :index, params: {format: "js"}
get :index, params: { format: "js" }
assert_response "alert('foo');"
end
end

View file

@ -97,7 +97,7 @@ module RenderStreaming
end
test "do not stream on HTTP/1.0" do
get "/render_streaming/basic/hello_world", headers: {"HTTP_VERSION" => "HTTP/1.0"}
get "/render_streaming/basic/hello_world", headers: { "HTTP_VERSION" => "HTTP/1.0" }
assert_body "Hello world, I'm here!"
assert_status 200
assert_equal "22", headers["Content-Length"]

View file

@ -111,7 +111,7 @@ module RenderTemplate
end
test "rendering a builder template" do
get :builder_template, params: {"format" => "xml"}
get :builder_template, params: { "format" => "xml" }
assert_response "<html>\n <p>Hello</p>\n</html>\n"
end
@ -126,7 +126,7 @@ module RenderTemplate
assert_body "Hello <strong>this is also raw</strong> in an html template"
assert_status 200
get :with_implicit_raw, params: {format: 'text'}
get :with_implicit_raw, params: { format: 'text' }
assert_body "Hello <strong>this is also raw</strong> in a text template"
assert_status 200

View file

@ -74,7 +74,7 @@ module Render
end
assert_raises(AbstractController::DoubleRenderError) do
get "/render/double_render", headers: {"action_dispatch.show_exceptions" => false}
get "/render/double_render", headers: { "action_dispatch.show_exceptions" => false }
end
end
end
@ -84,13 +84,13 @@ module Render
# Only public methods on actual controllers are callable actions
test "raises an exception when a method of Object is called" do
assert_raises(AbstractController::ActionNotFound) do
get "/render/blank_render/clone", headers: {"action_dispatch.show_exceptions" => false}
get "/render/blank_render/clone", headers: { "action_dispatch.show_exceptions" => false }
end
end
test "raises an exception when a private method is called" do
assert_raises(AbstractController::ActionNotFound) do
get "/render/blank_render/secretz", headers: {"action_dispatch.show_exceptions" => false}
get "/render/blank_render/secretz", headers: { "action_dispatch.show_exceptions" => false }
end
end
end

View file

@ -58,13 +58,13 @@ module ShowExceptions
class ShowExceptionsOverriddenTest < ActionDispatch::IntegrationTest
test 'show error page' do
@app = ShowExceptionsOverriddenController.action(:boom)
get '/', params: {'detailed' => '0'}
get '/', params: { 'detailed' => '0' }
assert_equal "500 error fixture\n", body
end
test 'show diagnostics message' do
@app = ShowExceptionsOverriddenController.action(:boom)
get '/', params: {'detailed' => '1'}
get '/', params: { 'detailed' => '1' }
assert_match(/boom/, body)
end
end
@ -72,7 +72,7 @@ module ShowExceptions
class ShowExceptionsFormatsTest < ActionDispatch::IntegrationTest
def test_render_json_exception
@app = ShowExceptionsOverriddenController.action(:boom)
get "/", headers: {'HTTP_ACCEPT' => 'application/json'}
get "/", headers: { 'HTTP_ACCEPT' => 'application/json' }
assert_response :internal_server_error
assert_equal 'application/json', response.content_type.to_s
assert_equal({ :status => '500', :error => 'Internal Server Error' }.to_json, response.body)
@ -80,7 +80,7 @@ module ShowExceptions
def test_render_xml_exception
@app = ShowExceptionsOverriddenController.action(:boom)
get "/", headers: {'HTTP_ACCEPT' => 'application/xml'}
get "/", headers: { 'HTTP_ACCEPT' => 'application/xml' }
assert_response :internal_server_error
assert_equal 'application/xml', response.content_type.to_s
assert_equal({ :status => '500', :error => 'Internal Server Error' }.to_xml, response.body)
@ -88,7 +88,7 @@ module ShowExceptions
def test_render_fallback_exception
@app = ShowExceptionsOverriddenController.action(:boom)
get "/", headers: {'HTTP_ACCEPT' => 'text/csv'}
get "/", headers: { 'HTTP_ACCEPT' => 'text/csv' }
assert_response :internal_server_error
assert_equal 'text/html', response.content_type.to_s
end
@ -101,7 +101,7 @@ module ShowExceptions
@app.instance_variable_set(:@exceptions_app, nil)
$stderr = StringIO.new
get '/', headers: {'HTTP_ACCEPT' => 'text/json'}
get '/', headers: { 'HTTP_ACCEPT' => 'text/json' }
assert_response :internal_server_error
assert_equal 'text/plain', response.content_type.to_s
ensure

View file

@ -129,7 +129,7 @@ XML
def test_assigns
@foo = "foo"
@foo_hash = {foo: :bar}
@foo_hash = { foo: :bar }
render nothing: true
end
@ -209,7 +209,7 @@ XML
end
def test_raw_post_handling
params = Hash[:page, {name: 'page name'}, 'some key', 123]
params = Hash[:page, { name: 'page name' }, 'some key', 123]
post :render_raw_post, params: params.dup
assert_equal params.to_query, @response.body
@ -381,7 +381,7 @@ XML
end
def test_deprecated_process_with_request_uri_with_params
assert_deprecated { process :test_uri, "GET", id: 7}
assert_deprecated { process :test_uri, "GET", id: 7 }
assert_equal "/test_case_test/test/test_uri/7", @response.body
end
@ -401,7 +401,7 @@ XML
def test_process_with_request_uri_with_params_with_explicit_uri
@request.env['PATH_INFO'] = "/explicit/uri"
process :test_uri, method: "GET", params: {id: 7}
process :test_uri, method: "GET", params: { id: 7 }
assert_equal "/explicit/uri", @response.body
end
@ -466,10 +466,10 @@ XML
def test_assert_generates
assert_generates 'controller/action/5', controller: 'controller', action: 'action', id: '5'
assert_generates 'controller/action/7', {id: "7"}, {controller: "controller", action: "action"}
assert_generates 'controller/action/5', {controller: "controller", action: "action", id: "5", name: "bob"}, {}, {name: "bob"}
assert_generates 'controller/action/7', {id: "7", name: "bob"}, {controller: "controller", action: "action"}, {name: "bob"}
assert_generates 'controller/action/7', {id: "7"}, {controller: "controller", action: "action", name: "bob"}, {}
assert_generates 'controller/action/7', { id: "7" }, { controller: "controller", action: "action" }
assert_generates 'controller/action/5', { controller: "controller", action: "action", id: "5", name: "bob" }, {}, { name: "bob" }
assert_generates 'controller/action/7', { id: "7", name: "bob" }, { controller: "controller", action: "action" }, { name: "bob" }
assert_generates 'controller/action/7', { id: "7" }, { controller: "controller", action: "action", name: "bob" }, {}
end
def test_assert_routing
@ -504,12 +504,14 @@ XML
def test_deprecated_params_passing
assert_deprecated {
get :test_params, page: {name: "Page name", month: '4', year: '2004', day: '6'}
get :test_params, page: { name: "Page name", month: '4', year: '2004', day: '6' }
}
parsed_params = eval(@response.body)
assert_equal(
{'controller' => 'test_case_test/test', 'action' => 'test_params',
'page' => {'name' => "Page name", 'month' => '4', 'year' => '2004', 'day' => '6'}},
{
'controller' => 'test_case_test/test', 'action' => 'test_params',
'page' => { 'name' => "Page name", 'month' => '4', 'year' => '2004', 'day' => '6' }
},
parsed_params
)
end
@ -525,8 +527,10 @@ XML
}
parsed_params = eval(@response.body)
assert_equal(
{'controller' => 'test_case_test/test', 'action' => 'test_params',
'page' => {'name' => "Page name", 'month' => '4', 'year' => '2004', 'day' => '6'}},
{
'controller' => 'test_case_test/test', 'action' => 'test_params',
'page' => { 'name' => "Page name", 'month' => '4', 'year' => '2004', 'day' => '6' }
},
parsed_params
)
end
@ -609,7 +613,7 @@ XML
end
def test_params_passing_doesnt_modify_in_place
page = {name: "Page name", month: 4, year: 2004, day: 6}
page = { name: "Page name", month: 4, year: 2004, day: 6 }
get :test_params, params: { page: page }
assert_equal 2004, page[:year]
end

View file

@ -37,7 +37,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest
with_test_route_set do
post "/",
params: '{"entry":{"summary":"content..."}}',
headers: {'CONTENT_TYPE' => 'application/json'}
headers: { 'CONTENT_TYPE' => 'application/json' }
assert_equal 'entry', @controller.response.body
assert @controller.params.has_key?(:entry)
@ -62,7 +62,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest
with_params_parsers Mime::JSON => Proc.new { |data| ActiveSupport::JSON.decode(data)['request'].with_indifferent_access } do
post "/",
params: '{"request":{"summary":"content...","title":"JSON"}}',
headers: {'CONTENT_TYPE' => 'application/json'}
headers: { 'CONTENT_TYPE' => 'application/json' }
assert_equal 'summary, title', @controller.response.body
assert @controller.params.has_key?(:summary)
@ -75,7 +75,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest
def test_use_json_with_empty_request
with_test_route_set do
assert_nothing_raised { post "/", headers: {'CONTENT_TYPE' => 'application/json'} }
assert_nothing_raised { post "/", headers: { 'CONTENT_TYPE' => 'application/json' } }
assert_equal '', @controller.response.body
end
end
@ -84,7 +84,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest
with_test_route_set do
post "/?full=1",
params: '{"first-key":{"sub-key":"..."}}',
headers: {'CONTENT_TYPE' => 'application/json'}
headers: { 'CONTENT_TYPE' => 'application/json' }
assert_equal 'action, controller, first-key(sub-key), full', @controller.response.body
assert_equal "...", @controller.params['first-key']['sub-key']
end
@ -96,7 +96,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest
assert_raises(Interrupt) do
post "/",
params: '{"title":"JSON"}}',
headers: {'CONTENT_TYPE' => 'application/json'}
headers: { 'CONTENT_TYPE' => 'application/json' }
end
end
end

View file

@ -86,21 +86,21 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
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
@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
@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
@ -108,14 +108,14 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
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
@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
@ -125,7 +125,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
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/
@ -134,27 +134,27 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
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
@ -204,8 +204,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("&quot;foo&quot;=&gt;&quot;[FILTERED]&quot;", body)
end
@ -213,7 +213,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
@ -221,7 +221,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)
@ -267,21 +267,21 @@ 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
@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 'uses backtrace cleaner from env' do
@app = DevelopmentApp
cleaner = stub(:clean => ['passed backtrace cleaner'])
get "/", headers: {'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => cleaner}
get "/", headers: { 'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => cleaner }
assert_match(/passed backtrace cleaner/, body)
end
@ -301,7 +301,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
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
@ -328,7 +328,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
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
@ -344,7 +344,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
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

View file

@ -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

View file

@ -56,7 +56,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/

View file

@ -140,7 +140,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest
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

View file

@ -147,7 +147,7 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest
get ':action', :to => ::QueryStringParsingTest::TestController
end
get "/parse", headers: {"QUERY_STRING" => "foo[]=bar&foo[4]=bar"}
get "/parse", headers: { "QUERY_STRING" => "foo[]=bar&foo[4]=bar" }
assert_response :bad_request
end
end

View file

@ -41,7 +41,7 @@ class RequestIdResponseTest < ActionDispatch::IntegrationTest
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

View file

@ -362,22 +362,22 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get 'admin/passwords' => "queenbee#passwords", :constraints => ::TestRoutingMapper::IpRestrictor
end
get '/admin', headers: {'REMOTE_ADDR' => '192.168.1.100'}
get '/admin', headers: { 'REMOTE_ADDR' => '192.168.1.100' }
assert_equal 'queenbee#index', @response.body
get '/admin', headers: {'REMOTE_ADDR' => '10.0.0.100'}
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'}
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'}
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'}
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'}
get '/admin/passwords', headers: { 'REMOTE_ADDR' => '10.0.0.100' }
assert_equal 'pass', @response.headers['X-Cascade']
end
@ -1683,9 +1683,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get '/products/0001/images/0001'
assert_equal 'images#show', @response.body
get '/dashboard', headers: {'REMOTE_ADDR' => '10.0.0.100'}
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'}
get '/dashboard', headers: { 'REMOTE_ADDR' => '192.168.1.100' }
assert_equal 'dashboards#show', @response.body
end
@ -3573,12 +3573,12 @@ class TestAltApp < ActionDispatch::IntegrationTest
end
def test_alt_request_with_matched_header
get "/", headers: {"HTTP_X_HEADER" => "HEADER"}
get "/", headers: { "HTTP_X_HEADER" => "HEADER" }
assert_equal "XHeader", @response.body
end
def test_alt_request_with_unmatched_header
get "/", headers: {"HTTP_X_HEADER" => "NON_MATCH"}
get "/", headers: { "HTTP_X_HEADER" => "NON_MATCH" }
assert_equal "Alternative App", @response.body
end
end
@ -3773,7 +3773,7 @@ class TestHttpMethods < ActionDispatch::IntegrationTest
(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

View file

@ -125,7 +125,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
def test_does_set_secure_cookies_over_https
with_test_route_set(:secure => true) do
get '/set_session_value', headers: {'HTTPS' => 'on'}
get '/set_session_value', headers: { 'HTTPS' => 'on' }
assert_response :success
assert_equal "_myapp_session=#{response.body}; path=/; secure; HttpOnly",
headers['Set-Cookie']

View file

@ -27,30 +27,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
@ -61,11 +61,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
@ -76,14 +76,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
@ -97,7 +97,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 BRO", body
end
@ -108,7 +108,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

View file

@ -20,7 +20,7 @@ class SSLTest < ActionDispatch::IntegrationTest
end
def test_allows_https_proxy_header_url
get "http://example.org/", headers: {'HTTP_X_FORWARDED_PROTO' => "https"}
get "http://example.org/", headers: { 'HTTP_X_FORWARDED_PROTO' => "https" }
assert_response :success
end

View file

@ -39,7 +39,7 @@ module TestUrlGeneration
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

View file

@ -495,13 +495,13 @@ All the keyword arguments are optional.
Example: Calling the `:show` action, passing an `id` of 12 as the `params` and setting a `user_id` of 5 in the session:
```ruby
get(:show, params: {'id' => "12"}, session: {'user_id' => 5})
get(:show, params: { 'id' => "12" }, session: { 'user_id' => 5 })
```
Another example: Calling the `:view` action, passing an `id` of 12 as the `params`, this time with no session, but with a flash message.
```ruby
get(:view, params: {'id' => '12'}, flash: {'message' => 'booya!'})
get(:view, params: { 'id' => '12' }, flash: { 'message' => 'booya!' })
```
NOTE: If you try running `test_should_create_article` test from `articles_controller_test.rb` it will fail on account of the newly added model level validation and rightly so.
@ -511,7 +511,7 @@ Let us modify `test_should_create_article` test in `articles_controller_test.rb`
```ruby
test "should create article" do
assert_difference('Article.count') do
post :create, params: { article: {title: 'Some title'} }
post :create, params: { article: { title: 'Some title' } }
end
assert_redirected_to article_path(assigns(:article))
@ -645,7 +645,7 @@ Let's start by adding this assertion to our `test_should_create_article` test:
```ruby
test "should create article" do
assert_difference('Article.count') do
post :create, params: { article: {title: 'Some title'} }
post :create, params: { article: { title: 'Some title' } }
end
assert_redirected_to article_path(assigns(:article))
@ -740,7 +740,7 @@ We can also add a test for updating an existing Article.
```ruby
test "should update article" do
article = articles(:one)
patch :update, params: { id: article.id, article: {title: "updated"} }
patch :update, params: { id: article.id, article: { title: "updated" } }
assert_redirected_to article_path(assigns(:article))
end
```
@ -779,7 +779,7 @@ class ArticlesControllerTest < ActionController::TestCase
end
test "should update article" do
patch :update, params: { id: @article.id, article: {title: "updated"} }
patch :update, params: { id: @article.id, article: { title: "updated" } }
assert_redirected_to article_path(assigns(:article))
end
end
@ -1034,7 +1034,7 @@ test "can create an article" do
assert_template "articles/new", partial: "articles/_form"
post "/articles",
params: { article: {title: "can create", body: "article successfully."} }
params: { article: { title: "can create", body: "article successfully." } }
assert_response :redirect
follow_redirect!
assert_response :success
@ -1051,7 +1051,7 @@ After this we make a post request to the `:create` action of our Articles contro
```ruby
post "/articles",
params: { article: {title: "can create", body: "article successfully."} }
params: { article: { title: "can create", body: "article successfully." } }
assert_response :redirect
follow_redirect!
```