aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/test_case_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 18:54:50 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 18:54:50 +0200
commit35b3de8021e68649cac963bd82a74cc75d1f60f0 (patch)
treed37f9096be6ee54a13d3c04cc8e1c5a9ba0d99ec /actionpack/test/controller/test_case_test.rb
parent628e51ff109334223094e30ad1365188bbd7f9c6 (diff)
downloadrails-35b3de8021e68649cac963bd82a74cc75d1f60f0.tar.gz
rails-35b3de8021e68649cac963bd82a74cc75d1f60f0.tar.bz2
rails-35b3de8021e68649cac963bd82a74cc75d1f60f0.zip
applies new string literal convention in actionpack/test
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
Diffstat (limited to 'actionpack/test/controller/test_case_test.rb')
-rw-r--r--actionpack/test/controller/test_case_test.rb428
1 files changed, 214 insertions, 214 deletions
diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb
index e288b51716..d369514119 100644
--- a/actionpack/test/controller/test_case_test.rb
+++ b/actionpack/test/controller/test_case_test.rb
@@ -1,40 +1,40 @@
-require 'abstract_unit'
-require 'controller/fake_controllers'
-require 'active_support/json/decoding'
-require 'rails/engine'
+require "abstract_unit"
+require "controller/fake_controllers"
+require "active_support/json/decoding"
+require "rails/engine"
class TestCaseTest < ActionController::TestCase
def self.fixture_path; end;
class TestController < ActionController::Base
def no_op
- render plain: 'dummy'
+ render plain: "dummy"
end
def set_flash
flash["test"] = ">#{flash["test"]}<"
- render plain: 'ignore me'
+ render plain: "ignore me"
end
def delete_flash
flash.delete("test")
- render plain: 'ignore me'
+ render plain: "ignore me"
end
def set_flash_now
flash.now["test_now"] = ">#{flash["test_now"]}<"
- render plain: 'ignore me'
+ render plain: "ignore me"
end
def set_session
- session['string'] = 'A wonder'
- session[:symbol] = 'it works'
- render plain: 'Success'
+ session["string"] = "A wonder"
+ session[:symbol] = "it works"
+ render plain: "Success"
end
def reset_the_session
reset_session
- render plain: 'ignore me'
+ render plain: "ignore me"
end
def render_raw_post
@@ -126,15 +126,15 @@ XML
end
def redirect_to_same_controller
- redirect_to controller: 'test', action: 'test_uri', id: 5
+ redirect_to controller: "test", action: "test_uri", id: 5
end
def redirect_to_different_controller
- redirect_to controller: 'fail', id: 5
+ redirect_to controller: "fail", id: 5
end
def create
- head :created, location: 'created resource'
+ head :created, location: "created resource"
end
def render_cookie
@@ -143,7 +143,7 @@ XML
def delete_cookie
cookies.delete("foo")
- render plain: 'ok'
+ render plain: "ok"
end
def test_without_body
@@ -155,7 +155,7 @@ XML
end
def boom
- raise 'boom!'
+ raise "boom!"
end
private
@@ -168,18 +168,18 @@ XML
def setup
super
@controller = TestController.new
- @request.delete_header 'PATH_INFO'
+ @request.delete_header "PATH_INFO"
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw do
ActiveSupport::Deprecation.silence do
- get ':controller(/:action(/:id))'
+ get ":controller(/:action(/:id))"
end
end
end
end
class DefaultUrlOptionsCachingController < ActionController::Base
- before_action { @dynamic_opt = 'opt' }
+ before_action { @dynamic_opt = "opt" }
def test_url_options_reset
render plain: url_for
@@ -197,32 +197,32 @@ XML
def test_assert_select_without_body
get :test_without_body
- assert_select 'body', 0
- assert_select 'div.foo'
+ assert_select "body", 0
+ assert_select "div.foo"
end
def test_assert_select_with_body
get :test_with_body
- assert_select 'body.foo'
+ assert_select "body.foo"
end
def test_url_options_reset
@controller = DefaultUrlOptionsCachingController.new
get :test_url_options_reset
- assert_nil @request.params['dynamic_opt']
+ assert_nil @request.params["dynamic_opt"]
assert_match(/dynamic_opt=opt/, @response.body)
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
end
def test_body_stream
- params = Hash[:page, { name: 'page name' }, 'some key', 123]
+ params = Hash[:page, { name: "page name" }, "some key", 123]
post :render_body, params: params.dup
@@ -230,7 +230,7 @@ XML
end
def test_deprecated_body_stream
- params = Hash[:page, { name: 'page name' }, 'some key', 123]
+ params = Hash[:page, { name: "page name" }, "some key", 123]
assert_deprecated { post :render_body, params.dup }
@@ -269,31 +269,31 @@ XML
def test_process_without_flash
process :set_flash
- assert_equal '><', flash['test']
+ assert_equal "><", flash["test"]
end
def test_deprecated_process_with_flash
assert_deprecated { process :set_flash, "GET", nil, nil, { "test" => "value" } }
- assert_equal '>value<', flash['test']
+ assert_equal ">value<", flash["test"]
end
def test_process_with_flash
process :set_flash,
method: "GET",
flash: { "test" => "value" }
- assert_equal '>value<', flash['test']
+ assert_equal ">value<", flash["test"]
end
def test_deprecated_process_with_flash_now
assert_deprecated { process :set_flash_now, "GET", nil, nil, { "test_now" => "value_now" } }
- assert_equal '>value_now<', flash['test_now']
+ assert_equal ">value_now<", flash["test_now"]
end
def test_process_with_flash_now
process :set_flash_now,
method: "GET",
flash: { "test_now" => "value_now" }
- assert_equal '>value_now<', flash['test_now']
+ assert_equal ">value_now<", flash["test_now"]
end
def test_process_delete_flash
@@ -305,64 +305,64 @@ XML
def test_process_with_session
process :set_session
- assert_equal 'A wonder', session['string'], "A value stored in the session should be available by string key"
- assert_equal 'A wonder', session[:string], "Test session hash should allow indifferent access"
- assert_equal 'it works', session['symbol'], "Test session hash should allow indifferent access"
- assert_equal 'it works', session[:symbol], "Test session hash should allow indifferent access"
+ assert_equal "A wonder", session["string"], "A value stored in the session should be available by string key"
+ assert_equal "A wonder", session[:string], "Test session hash should allow indifferent access"
+ assert_equal "it works", session["symbol"], "Test session hash should allow indifferent access"
+ assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access"
end
def test_process_with_session_arg
- assert_deprecated { process :no_op, "GET", nil, { 'string' => 'value1', symbol: 'value2' } }
- assert_equal 'value1', session['string']
- assert_equal 'value1', session[:string]
- assert_equal 'value2', session['symbol']
- assert_equal 'value2', session[:symbol]
+ assert_deprecated { process :no_op, "GET", nil, { "string" => "value1", symbol: "value2" } }
+ assert_equal "value1", session["string"]
+ assert_equal "value1", session[:string]
+ assert_equal "value2", session["symbol"]
+ assert_equal "value2", session[:symbol]
end
def test_process_with_session_kwarg
- process :no_op, method: "GET", session: { 'string' => 'value1', symbol: 'value2' }
- assert_equal 'value1', session['string']
- assert_equal 'value1', session[:string]
- assert_equal 'value2', session['symbol']
- assert_equal 'value2', session[:symbol]
+ process :no_op, method: "GET", session: { "string" => "value1", symbol: "value2" }
+ assert_equal "value1", session["string"]
+ assert_equal "value1", session[:string]
+ assert_equal "value2", session["symbol"]
+ assert_equal "value2", session[:symbol]
end
def test_deprecated_process_merges_session_arg
- session[:foo] = 'bar'
+ session[:foo] = "bar"
assert_deprecated {
- get :no_op, nil, { bar: 'baz' }
+ get :no_op, nil, { bar: "baz" }
}
- assert_equal 'bar', session[:foo]
- assert_equal 'baz', session[:bar]
+ assert_equal "bar", session[:foo]
+ assert_equal "baz", session[:bar]
end
def test_process_merges_session_arg
- session[:foo] = 'bar'
- get :no_op, session: { bar: 'baz' }
- assert_equal 'bar', session[:foo]
- assert_equal 'baz', session[:bar]
+ session[:foo] = "bar"
+ get :no_op, session: { bar: "baz" }
+ assert_equal "bar", session[:foo]
+ assert_equal "baz", session[:bar]
end
def test_deprecated_merged_session_arg_is_retained_across_requests
assert_deprecated {
- get :no_op, nil, { foo: 'bar' }
+ get :no_op, nil, { foo: "bar" }
}
- assert_equal 'bar', session[:foo]
+ assert_equal "bar", session[:foo]
get :no_op
- assert_equal 'bar', session[:foo]
+ assert_equal "bar", session[:foo]
end
def test_merged_session_arg_is_retained_across_requests
- get :no_op, session: { foo: 'bar' }
- assert_equal 'bar', session[:foo]
+ get :no_op, session: { foo: "bar" }
+ assert_equal "bar", session[:foo]
get :no_op
- assert_equal 'bar', session[:foo]
+ assert_equal "bar", session[:foo]
end
def test_process_overwrites_existing_session_arg
- session[:foo] = 'bar'
- get :no_op, session: { foo: 'baz' }
- assert_equal 'baz', session[:foo]
+ session[:foo] = "bar"
+ get :no_op, session: { foo: "baz" }
+ assert_equal "baz", session[:foo]
end
def test_session_is_cleared_from_controller_after_reset_session
@@ -407,13 +407,13 @@ XML
end
def test_deprecated_process_with_request_uri_with_params_with_explicit_uri
- @request.env['PATH_INFO'] = "/explicit/uri"
+ @request.env["PATH_INFO"] = "/explicit/uri"
assert_deprecated { process :test_uri, "GET", id: 7 }
assert_equal "/explicit/uri", @response.body
end
def test_process_with_request_uri_with_params_with_explicit_uri
- @request.env['PATH_INFO'] = "/explicit/uri"
+ @request.env["PATH_INFO"] = "/explicit/uri"
process :test_uri, method: "GET", params: { id: 7 }
assert_equal "/explicit/uri", @response.body
end
@@ -421,13 +421,13 @@ XML
def test_process_with_query_string
process :test_query_string,
method: "GET",
- params: { q: 'test' }
+ params: { q: "test" }
assert_equal "q=test", @response.body
end
def test_process_with_query_string_with_explicit_uri
- @request.env['PATH_INFO'] = '/explicit/uri'
- @request.env['QUERY_STRING'] = 'q=test?extra=question'
+ @request.env["PATH_INFO"] = "/explicit/uri"
+ @request.env["QUERY_STRING"] = "q=test?extra=question"
process :test_query_string
assert_equal "q=test?extra=question", @response.body
end
@@ -444,7 +444,7 @@ XML
begin
$stderr = StringIO.new
- assert_select 'area' #This will cause a warning if content is processed as HTML
+ assert_select "area" #This will cause a warning if content is processed as HTML
$stderr.rewind && err = $stderr.read
ensure
$stderr = STDERR
@@ -454,21 +454,21 @@ XML
end
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/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" }, {}
end
def test_assert_routing
- assert_routing 'content', controller: 'content', action: 'index'
+ assert_routing "content", controller: "content", action: "index"
end
def test_assert_routing_with_method
with_routing do |set|
set.draw { resources(:content) }
- assert_routing({ method: 'post', path: 'content' }, { controller: 'content', action: 'create' })
+ assert_routing({ method: "post", path: "content" }, { controller: "content", action: "create" })
end
end
@@ -476,30 +476,30 @@ XML
with_routing do |set|
set.draw do
namespace :admin do
- get 'user' => 'user#index'
+ get "user" => "user#index"
end
end
- assert_routing 'admin/user', controller: 'admin/user', action: 'index'
+ assert_routing "admin/user", controller: "admin/user", action: "index"
end
end
def test_assert_routing_with_glob
with_routing do |set|
- set.draw { get('*path' => "pages#show") }
- assert_routing('/company/about', { controller: 'pages', action: 'show', path: 'company/about' })
+ set.draw { get("*path" => "pages#show") }
+ assert_routing("/company/about", { controller: "pages", action: "show", path: "company/about" })
end
end
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 = ::JSON.parse(@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
)
@@ -509,52 +509,52 @@ XML
get :test_params, params: {
page: {
name: "Page name",
- month: '4',
- year: '2004',
- day: '6'
+ month: "4",
+ year: "2004",
+ day: "6"
}
}
parsed_params = ::JSON.parse(@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
def test_query_param_named_action
- get :test_query_parameters, params: {action: 'foobar'}
+ get :test_query_parameters, params: {action: "foobar"}
parsed_params = JSON.parse(@response.body)
- assert_equal({'action' => 'foobar'}, parsed_params)
+ assert_equal({"action" => "foobar"}, parsed_params)
end
def test_request_param_named_action
- post :test_request_parameters, params: {action: 'foobar'}
+ post :test_request_parameters, params: {action: "foobar"}
parsed_params = eval(@response.body)
- assert_equal({'action' => 'foobar'}, parsed_params)
+ assert_equal({"action" => "foobar"}, parsed_params)
end
def test_kwarg_params_passing_with_session_and_flash
get :test_params, params: {
page: {
name: "Page name",
- month: '4',
- year: '2004',
- day: '6'
+ month: "4",
+ year: "2004",
+ day: "6"
}
- }, session: { 'foo' => 'bar' }, flash: { notice: 'created' }
+ }, session: { "foo" => "bar" }, flash: { notice: "created" }
parsed_params = ::JSON.parse(@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
)
- assert_equal 'bar', session[:foo]
- assert_equal 'created', flash[:notice]
+ assert_equal "bar", session[:foo]
+ assert_equal "created", flash[:notice]
end
def test_params_passing_with_integer
@@ -563,38 +563,38 @@ XML
}
parsed_params = ::JSON.parse(@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
def test_params_passing_with_integers_when_not_html_request
- get :test_params, params: { format: 'json', count: 999 }
+ get :test_params, params: { format: "json", count: 999 }
parsed_params = ::JSON.parse(@response.body)
assert_equal(
- {'controller' => 'test_case_test/test', 'action' => 'test_params',
- 'format' => 'json', 'count' => '999' },
+ {"controller" => "test_case_test/test", "action" => "test_params",
+ "format" => "json", "count" => "999" },
parsed_params
)
end
def test_params_passing_path_parameter_is_string_when_not_html_request
- get :test_params, params: { format: 'json', id: 1 }
+ get :test_params, params: { format: "json", id: 1 }
parsed_params = ::JSON.parse(@response.body)
assert_equal(
- {'controller' => 'test_case_test/test', 'action' => 'test_params',
- 'format' => 'json', 'id' => '1' },
+ {"controller" => "test_case_test/test", "action" => "test_params",
+ "format" => "json", "id" => "1" },
parsed_params
)
end
def test_deprecated_params_passing_path_parameter_is_string_when_not_html_request
- assert_deprecated { get :test_params, format: 'json', id: 1 }
+ assert_deprecated { get :test_params, format: "json", id: 1 }
parsed_params = ::JSON.parse(@response.body)
assert_equal(
- {'controller' => 'test_case_test/test', 'action' => 'test_params',
- 'format' => 'json', 'id' => '1' },
+ {"controller" => "test_case_test/test", "action" => "test_params",
+ "format" => "json", "id" => "1" },
parsed_params
)
end
@@ -602,13 +602,13 @@ XML
def test_params_passing_with_frozen_values
assert_nothing_raised do
get :test_params, params: {
- frozen: 'icy'.freeze, frozens: ['icy'.freeze].freeze, deepfreeze: { frozen: 'icy'.freeze }.freeze
+ frozen: "icy".freeze, frozens: ["icy".freeze].freeze, deepfreeze: { frozen: "icy".freeze }.freeze
}
end
parsed_params = ::JSON.parse(@response.body)
assert_equal(
- {'controller' => 'test_case_test/test', 'action' => 'test_params',
- 'frozen' => 'icy', 'frozens' => ['icy'], 'deepfreeze' => { 'frozen' => 'icy' }},
+ {"controller" => "test_case_test/test", "action" => "test_params",
+ "frozen" => "icy", "frozens" => ["icy"], "deepfreeze" => { "frozen" => "icy" }},
parsed_params
)
end
@@ -620,8 +620,8 @@ XML
end
test "set additional HTTP headers" do
- @request.headers['Referer'] = "http://nohost.com/home"
- @request.headers['Content-Type'] = "application/rss+xml"
+ @request.headers["Referer"] = "http://nohost.com/home"
+ @request.headers["Content-Type"] = "application/rss+xml"
get :test_headers
parsed_env = ActiveSupport::JSON.decode(@response.body)
assert_equal "http://nohost.com/home", parsed_env["HTTP_REFERER"]
@@ -629,8 +629,8 @@ XML
end
test "set additional env variables" do
- @request.headers['HTTP_REFERER'] = "http://example.com/about"
- @request.headers['CONTENT_TYPE'] = "application/json"
+ @request.headers["HTTP_REFERER"] = "http://example.com/about"
+ @request.headers["CONTENT_TYPE"] = "application/json"
get :test_headers
parsed_env = ActiveSupport::JSON.decode(@response.body)
assert_equal "http://example.com/about", parsed_env["HTTP_REFERER"]
@@ -638,27 +638,27 @@ XML
end
def test_mutating_content_type_headers_for_plain_text_files_sets_the_header
- @request.headers['Content-Type'] = 'text/plain'
- post :render_body, params: { name: 'foo.txt' }
+ @request.headers["Content-Type"] = "text/plain"
+ post :render_body, params: { name: "foo.txt" }
- assert_equal 'text/plain', @request.headers['Content-type']
- assert_equal 'foo.txt', @request.request_parameters[:name]
- assert_equal 'render_body', @request.path_parameters[:action]
+ assert_equal "text/plain", @request.headers["Content-type"]
+ assert_equal "foo.txt", @request.request_parameters[:name]
+ assert_equal "render_body", @request.path_parameters[:action]
end
def test_mutating_content_type_headers_for_html_files_sets_the_header
- @request.headers['Content-Type'] = 'text/html'
- post :render_body, params: { name: 'foo.html' }
+ @request.headers["Content-Type"] = "text/html"
+ post :render_body, params: { name: "foo.html" }
- assert_equal 'text/html', @request.headers['Content-type']
- assert_equal 'foo.html', @request.request_parameters[:name]
- assert_equal 'render_body', @request.path_parameters[:action]
+ assert_equal "text/html", @request.headers["Content-type"]
+ assert_equal "foo.html", @request.request_parameters[:name]
+ assert_equal "render_body", @request.path_parameters[:action]
end
def test_mutating_content_type_headers_for_non_registered_mime_type_raises_an_error
assert_raises(RuntimeError) do
- @request.headers['Content-Type'] = 'type/fake'
- post :render_body, params: { name: 'foo.fake' }
+ @request.headers["Content-Type"] = "type/fake"
+ post :render_body, params: { name: "foo.fake" }
end
end
@@ -677,16 +677,16 @@ XML
def test_array_path_parameter_handled_properly
with_routing do |set|
set.draw do
- get 'file/*path', to: 'test_case_test/test#test_params'
+ get "file/*path", to: "test_case_test/test#test_params"
ActiveSupport::Deprecation.silence do
- get ':controller/:action'
+ get ":controller/:action"
end
end
- get :test_params, params: { path: ['hello', 'world'] }
- assert_equal ['hello', 'world'], @request.path_parameters[:path]
- assert_equal 'hello/world', @request.path_parameters[:path].to_param
+ get :test_params, params: { path: ["hello", "world"] }
+ assert_equal ["hello", "world"], @request.path_parameters[:path]
+ assert_equal "hello/world", @request.path_parameters[:path].to_param
end
end
@@ -704,8 +704,8 @@ XML
routes_id = @routes.object_id
begin
- with_routing { raise 'fail' }
- fail 'Should not be here.'
+ with_routing { raise "fail" }
+ fail "Should not be here."
rescue RuntimeError
end
@@ -724,8 +724,8 @@ XML
def test_header_properly_reset_after_remote_http_request
get :test_params, xhr: true
- assert_nil @request.env['HTTP_X_REQUESTED_WITH']
- assert_nil @request.env['HTTP_ACCEPT']
+ assert_nil @request.env["HTTP_X_REQUESTED_WITH"]
+ assert_nil @request.env["HTTP_ACCEPT"]
end
def test_deprecated_xhr_with_params
@@ -743,19 +743,19 @@ XML
def test_xhr_with_session
get :set_session, xhr: true
- assert_equal 'A wonder', session['string'], "A value stored in the session should be available by string key"
- assert_equal 'A wonder', session[:string], "Test session hash should allow indifferent access"
- assert_equal 'it works', session['symbol'], "Test session hash should allow indifferent access"
- assert_equal 'it works', session[:symbol], "Test session hash should allow indifferent access"
+ assert_equal "A wonder", session["string"], "A value stored in the session should be available by string key"
+ assert_equal "A wonder", session[:string], "Test session hash should allow indifferent access"
+ assert_equal "it works", session["symbol"], "Test session hash should allow indifferent access"
+ assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access"
end
def test_deprecated_xhr_with_session
assert_deprecated { xhr :get, :set_session }
- assert_equal 'A wonder', session['string'], "A value stored in the session should be available by string key"
- assert_equal 'A wonder', session[:string], "Test session hash should allow indifferent access"
- assert_equal 'it works', session['symbol'], "Test session hash should allow indifferent access"
- assert_equal 'it works', session[:symbol], "Test session hash should allow indifferent access"
+ assert_equal "A wonder", session["string"], "A value stored in the session should be available by string key"
+ assert_equal "A wonder", session[:string], "Test session hash should allow indifferent access"
+ assert_equal "it works", session["symbol"], "Test session hash should allow indifferent access"
+ assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access"
end
def test_deprecated_params_reset_between_post_requests
@@ -804,61 +804,61 @@ XML
end
def test_request_format
- get :test_format, params: { format: 'html' }
- assert_equal 'text/html', @response.body
+ get :test_format, params: { format: "html" }
+ assert_equal "text/html", @response.body
- get :test_format, params: { format: 'json' }
- assert_equal 'application/json', @response.body
+ get :test_format, params: { format: "json" }
+ assert_equal "application/json", @response.body
- get :test_format, params: { format: 'xml' }
- assert_equal 'application/xml', @response.body
+ get :test_format, params: { format: "xml" }
+ assert_equal "application/xml", @response.body
get :test_format
- assert_equal 'text/html', @response.body
+ assert_equal "text/html", @response.body
end
def test_request_format_kwarg
- get :test_format, format: 'html'
- assert_equal 'text/html', @response.body
+ get :test_format, format: "html"
+ assert_equal "text/html", @response.body
- get :test_format, format: 'json'
- assert_equal 'application/json', @response.body
+ get :test_format, format: "json"
+ assert_equal "application/json", @response.body
- get :test_format, format: 'xml'
- assert_equal 'application/xml', @response.body
+ get :test_format, format: "xml"
+ assert_equal "application/xml", @response.body
get :test_format
- assert_equal 'text/html', @response.body
+ assert_equal "text/html", @response.body
end
def test_request_format_kwarg_overrides_params
- get :test_format, format: 'json', params: { format: 'html' }
- assert_equal 'application/json', @response.body
+ get :test_format, format: "json", params: { format: "html" }
+ assert_equal "application/json", @response.body
end
def test_should_have_knowledge_of_client_side_cookie_state_even_if_they_are_not_set
- cookies['foo'] = 'bar'
+ cookies["foo"] = "bar"
get :no_op
- assert_equal 'bar', cookies['foo']
+ assert_equal "bar", cookies["foo"]
end
def test_cookies_should_be_escaped_properly
- cookies['foo'] = '+'
+ cookies["foo"] = "+"
get :render_cookie
- assert_equal '+', @response.body
+ assert_equal "+", @response.body
end
def test_should_detect_if_cookie_is_deleted
- cookies['foo'] = 'bar'
+ cookies["foo"] = "bar"
get :delete_cookie
- assert_nil cookies['foo']
+ assert_nil cookies["foo"]
end
def test_multiple_mixed_method_process_should_scrub_rack_input
- post :test_params, params: { id: 1, foo: 'an foo' }
+ post :test_params, params: { id: 1, foo: "an foo" }
assert_equal({"id"=>"1", "foo" => "an foo", "controller"=>"test_case_test/test", "action"=>"test_params"}, ::JSON.parse(@response.body))
- get :test_params, params: { bar: 'an bar' }
+ get :test_params, params: { bar: "an bar" }
assert_equal({"bar"=>"an bar", "controller"=>"test_case_test/test", "action"=>"test_params"}, ::JSON.parse(@response.body))
end
@@ -878,15 +878,15 @@ XML
end
end
- FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
+ FILES_DIR = File.dirname(__FILE__) + "/../fixtures/multipart"
- READ_BINARY = 'rb:binary'
- READ_PLAIN = 'r:binary'
+ READ_BINARY = "rb:binary"
+ READ_PLAIN = "r:binary"
def test_test_uploaded_file
- filename = 'mona_lisa.jpg'
+ filename = "mona_lisa.jpg"
path = "#{FILES_DIR}/#{filename}"
- content_type = 'image/png'
+ content_type = "image/png"
expected = File.read(path)
expected.force_encoding(Encoding::BINARY)
@@ -904,15 +904,15 @@ XML
def test_fixture_path_is_accessed_from_self_instead_of_active_support_test_case
TestCaseTest.stub :fixture_path, FILES_DIR do
- uploaded_file = fixture_file_upload('/mona_lisa.jpg', 'image/png')
+ uploaded_file = fixture_file_upload("/mona_lisa.jpg", "image/png")
assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read
end
end
def test_test_uploaded_file_with_binary
- filename = 'mona_lisa.jpg'
+ filename = "mona_lisa.jpg"
path = "#{FILES_DIR}/#{filename}"
- content_type = 'image/png'
+ content_type = "image/png"
binary_uploaded_file = Rack::Test::UploadedFile.new(path, content_type, :binary)
assert_equal File.open(path, READ_BINARY).read, binary_uploaded_file.read
@@ -922,9 +922,9 @@ XML
end
def test_fixture_file_upload_with_binary
- filename = 'mona_lisa.jpg'
+ filename = "mona_lisa.jpg"
path = "#{FILES_DIR}/#{filename}"
- content_type = 'image/jpg'
+ content_type = "image/jpg"
binary_file_upload = fixture_file_upload(path, content_type, :binary)
assert_equal File.open(path, READ_BINARY).read, binary_file_upload.read
@@ -943,7 +943,7 @@ XML
params: {
file: fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg")
}
- assert_equal '159528', @response.body
+ assert_equal "159528", @response.body
end
def test_fixture_file_upload_relative_to_fixture_path
@@ -959,25 +959,25 @@ XML
end
def test_deprecated_action_dispatch_uploaded_file_upload
- filename = 'mona_lisa.jpg'
+ filename = "mona_lisa.jpg"
path = "#{FILES_DIR}/#{filename}"
assert_deprecated {
post :test_file_upload, file: Rack::Test::UploadedFile.new(path, "image/jpg", true)
}
- assert_equal '159528', @response.body
+ assert_equal "159528", @response.body
end
def test_action_dispatch_uploaded_file_upload
- filename = 'mona_lisa.jpg'
+ filename = "mona_lisa.jpg"
path = "#{FILES_DIR}/#{filename}"
post :test_file_upload, params: {
file: Rack::Test::UploadedFile.new(path, "image/jpg", true)
}
- assert_equal '159528', @response.body
+ assert_equal "159528", @response.body
end
def test_test_uploaded_file_exception_when_file_doesnt_exist
- assert_raise(RuntimeError) { Rack::Test::UploadedFile.new('non_existent_file') }
+ assert_raise(RuntimeError) { Rack::Test::UploadedFile.new("non_existent_file") }
end
def test_redirect_url_only_cares_about_location_header
@@ -985,12 +985,12 @@ XML
assert_response :created
# Redirect url doesn't care that it wasn't a :redirect response.
- assert_equal 'created resource', @response.redirect_url
+ assert_equal "created resource", @response.redirect_url
assert_equal @response.redirect_url, redirect_to_url
# Must be a :redirect response.
assert_raise(ActiveSupport::TestCase::Assertion) do
- assert_redirected_to 'created resource'
+ assert_redirected_to "created resource"
end
end
@@ -1004,12 +1004,12 @@ XML
assert_raise(RuntimeError) do
process :boom,
method: "GET",
- params: { q: 'test1' }
+ params: { q: "test1" }
end
process :test_query_string,
method: "GET",
- params: { q: 'test2' }
+ params: { q: "test2" }
assert_equal "q=test2", @response.body
end
@@ -1019,7 +1019,7 @@ class ResponseDefaultHeadersTest < ActionController::TestCase
class TestController < ActionController::Base
def remove_header
headers.delete params[:header]
- head :ok, 'C' => '3'
+ head :ok, "C" => "3"
end
# Render a head response, but don't touch default headers
@@ -1030,7 +1030,7 @@ class ResponseDefaultHeadersTest < ActionController::TestCase
def before_setup
@original = ActionDispatch::Response.default_headers
- @defaults = { 'A' => '1', 'B' => '2' }
+ @defaults = { "A" => "1", "B" => "2" }
ActionDispatch::Response.default_headers = @defaults
super
end
@@ -1042,11 +1042,11 @@ class ResponseDefaultHeadersTest < ActionController::TestCase
def setup
super
@controller = TestController.new
- @request.env['PATH_INFO'] = nil
+ @request.env["PATH_INFO"] = nil
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw do
ActiveSupport::Deprecation.silence do
- get ':controller(/:action(/:id))'
+ get ":controller(/:action(/:id))"
end
end
end
@@ -1056,18 +1056,18 @@ class ResponseDefaultHeadersTest < ActionController::TestCase
get :leave_alone
# Response headers start out with the defaults
- assert_equal @defaults.merge('Content-Type' => 'text/html'), response.headers
+ assert_equal @defaults.merge("Content-Type" => "text/html"), response.headers
end
test "response deletes a default header" do
- get :remove_header, params: { header: 'A' }
+ get :remove_header, params: { header: "A" }
assert_response :ok
# After a request, the response in the test case doesn't have the
# defaults merged on top again.
- assert_not_includes response.headers, 'A'
- assert_includes response.headers, 'B'
- assert_includes response.headers, 'C'
+ assert_not_includes response.headers, "A"
+ assert_includes response.headers, "B"
+ assert_includes response.headers, "C"
end
end
@@ -1076,13 +1076,13 @@ module EngineControllerTests
isolate_namespace EngineControllerTests
routes.draw do
- get '/' => 'bar#index'
+ get "/" => "bar#index"
end
end
class BarController < ActionController::Base
def index
- render plain: 'bar'
+ render plain: "bar"
end
end
@@ -1091,7 +1091,7 @@ module EngineControllerTests
def test_engine_controller_route
get :index
- assert_equal @response.body, 'bar'
+ assert_equal @response.body, "bar"
end
end
@@ -1104,7 +1104,7 @@ module EngineControllerTests
def test_engine_controller_route
get :index
- assert_equal @response.body, 'bar'
+ assert_equal @response.body, "bar"
end
end
end
@@ -1145,7 +1145,7 @@ class CrazySymbolNameTest < ActionController::TestCase
end
class CrazyStringNameTest < ActionController::TestCase
- tests 'content'
+ tests "content"
def test_set_controller_class_using_string
assert_equal ContentController, self.class.controller_class
@@ -1158,8 +1158,8 @@ class NamedRoutesControllerTest < ActionController::TestCase
def test_should_be_able_to_use_named_routes_before_a_request_is_done
with_routing do |set|
set.draw { resources :contents }
- assert_equal 'http://test.host/contents/new', new_content_url
- assert_equal 'http://test.host/contents/1', content_url(id: 1)
+ assert_equal "http://test.host/contents/new", new_content_url
+ assert_equal "http://test.host/contents/1", content_url(id: 1)
end
end
end
@@ -1175,7 +1175,7 @@ class AnonymousControllerTest < ActionController::TestCase
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw do
ActiveSupport::Deprecation.silence do
- get ':controller(/:action(/:id))'
+ get ":controller(/:action(/:id))"
end
end
end
@@ -1183,7 +1183,7 @@ class AnonymousControllerTest < ActionController::TestCase
def test_controller_name
get :index
- assert_equal 'anonymous', @response.body
+ assert_equal "anonymous", @response.body
end
end
@@ -1201,19 +1201,19 @@ class RoutingDefaultsTest < ActionController::TestCase
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw do
- get '/posts/:id', to: 'anonymous#post', bucket_type: 'post'
- get '/projects/:id', to: 'anonymous#project', defaults: { bucket_type: 'project' }
+ get "/posts/:id", to: "anonymous#post", bucket_type: "post"
+ get "/projects/:id", to: "anonymous#project", defaults: { bucket_type: "project" }
end
end
end
def test_route_option_can_be_passed_via_process
- get :post, params: { id: 1, bucket_type: 'post'}
- assert_equal '/posts/1', @response.body
+ get :post, params: { id: 1, bucket_type: "post"}
+ assert_equal "/posts/1", @response.body
end
def test_route_default_is_not_required_for_building_request_uri
get :project, params: { id: 2 }
- assert_equal '/projects/2', @response.body
+ assert_equal "/projects/2", @response.body
end
end