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

Expectations first

This commit is contained in:
Akira Matsuda 2014-08-18 15:29:21 +09:00
parent 87228a207c
commit b30b99c615
7 changed files with 34 additions and 34 deletions

View file

@ -159,24 +159,24 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_get_request
assert_raise(RuntimeError) { get :raise_exception_on_get }
get :raise_exception_on_post
assert_equal @response.body, 'request method: GET'
assert_equal 'request method: GET', @response.body
end
def test_post_request
assert_raise(RuntimeError) { post :raise_exception_on_post }
post :raise_exception_on_get
assert_equal @response.body, 'request method: POST'
assert_equal 'request method: POST', @response.body
end
def test_get_post_request_switch
post :raise_exception_on_get
assert_equal @response.body, 'request method: POST'
assert_equal 'request method: POST', @response.body
get :raise_exception_on_post
assert_equal @response.body, 'request method: GET'
assert_equal 'request method: GET', @response.body
post :raise_exception_on_get
assert_equal @response.body, 'request method: POST'
assert_equal 'request method: POST', @response.body
get :raise_exception_on_post
assert_equal @response.body, 'request method: GET'
assert_equal 'request method: GET', @response.body
end
def test_string_constraint
@ -296,7 +296,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_session_exist
process :session_stuffing
assert_equal session['xmas'], 'turkey'
assert_equal 'turkey', session['xmas']
end
def session_does_not_exist

View file

@ -158,7 +158,7 @@ class PerformActionTest < ActionController::TestCase
exception = assert_raise AbstractController::ActionNotFound do
get :non_existent
end
assert_equal exception.message, "The action 'non_existent' could not be found for EmptyController"
assert_equal "The action 'non_existent' could not be found for EmptyController", exception.message
end
def test_get_on_hidden_should_fail

View file

@ -231,8 +231,8 @@ module AbstractController
def test_trailing_slash_with_params
url = W.new.url_for(:trailing_slash => true, :only_path => true, :controller => 'cont', :action => 'act', :p1 => 'cafe', :p2 => 'link')
params = extract_params(url)
assert_equal params[0], { :p1 => 'cafe' }.to_query
assert_equal params[1], { :p2 => 'link' }.to_query
assert_equal({p1: 'cafe'}.to_query, params[0])
assert_equal({p2: 'link'}.to_query, params[1])
end
def test_relative_url_root_is_respected
@ -305,40 +305,40 @@ module AbstractController
def test_two_parameters
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :p1 => 'X1', :p2 => 'Y2')
params = extract_params(url)
assert_equal params[0], { :p1 => 'X1' }.to_query
assert_equal params[1], { :p2 => 'Y2' }.to_query
assert_equal({p1: 'X1'}.to_query, params[0])
assert_equal({p2: 'Y2'}.to_query, params[1])
end
def test_hash_parameter
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:name => 'Bob', :category => 'prof'})
params = extract_params(url)
assert_equal params[0], { 'query[category]' => 'prof' }.to_query
assert_equal params[1], { 'query[name]' => 'Bob' }.to_query
assert_equal({'query[category]' => 'prof'}.to_query, params[0])
assert_equal({'query[name]' => 'Bob'}.to_query, params[1])
end
def test_array_parameter
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => ['Bob', 'prof'])
params = extract_params(url)
assert_equal params[0], { 'query[]' => 'Bob' }.to_query
assert_equal params[1], { 'query[]' => 'prof' }.to_query
assert_equal({'query[]' => 'Bob'}.to_query, params[0])
assert_equal({'query[]' => 'prof'}.to_query, params[1])
end
def test_hash_recursive_parameters
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:person => {:name => 'Bob', :position => 'prof'}, :hobby => 'piercing'})
params = extract_params(url)
assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
assert_equal params[2], { 'query[person][position]' => 'prof' }.to_query
assert_equal({'query[hobby]' => 'piercing'}.to_query, params[0])
assert_equal({'query[person][name]' => 'Bob' }.to_query, params[1])
assert_equal({'query[person][position]' => 'prof' }.to_query, params[2])
end
def test_hash_recursive_and_array_parameters
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => 101, :query => {:person => {:name => 'Bob', :position => ['prof', 'art director']}, :hobby => 'piercing'})
assert_match(%r(^/c/a/101), url)
params = extract_params(url)
assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
assert_equal params[2], { 'query[person][position][]' => 'art director' }.to_query
assert_equal params[3], { 'query[person][position][]' => 'prof' }.to_query
assert_equal({'query[hobby]' => 'piercing' }.to_query, params[0])
assert_equal({'query[person][name]' => 'Bob' }.to_query, params[1])
assert_equal({'query[person][position][]' => 'art director'}.to_query, params[2])
assert_equal({'query[person][position][]' => 'prof' }.to_query, params[3])
end
def test_path_generation_for_symbol_parameter_keys

View file

@ -283,7 +283,7 @@ class CookiesTest < ActionController::TestCase
def test_setting_the_same_value_to_permanent_cookie
request.cookies[:user_name] = 'Jamie'
get :set_permanent_cookie
assert_equal response.cookies, 'user_name' => 'Jamie'
assert_equal({'user_name' => 'Jamie'}, response.cookies)
end
def test_setting_with_escapable_characters

View file

@ -151,37 +151,37 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
assert_response 500
assert_no_match(/<header>/, body)
assert_no_match(/<body>/, body)
assert_equal response.content_type, "text/plain"
assert_equal "text/plain", response.content_type
assert_match(/RuntimeError\npuke/, body)
get "/not_found", {}, xhr_request_env
assert_response 404
assert_no_match(/<body>/, body)
assert_equal response.content_type, "text/plain"
assert_equal "text/plain", response.content_type
assert_match(/#{AbstractController::ActionNotFound.name}/, body)
get "/method_not_allowed", {}, xhr_request_env
assert_response 405
assert_no_match(/<body>/, body)
assert_equal response.content_type, "text/plain"
assert_equal "text/plain", response.content_type
assert_match(/ActionController::MethodNotAllowed/, body)
get "/unknown_http_method", {}, xhr_request_env
assert_response 405
assert_no_match(/<body>/, body)
assert_equal response.content_type, "text/plain"
assert_equal "text/plain", response.content_type
assert_match(/ActionController::UnknownHttpMethod/, body)
get "/bad_request", {}, xhr_request_env
assert_response 400
assert_no_match(/<body>/, body)
assert_equal response.content_type, "text/plain"
assert_equal "text/plain", response.content_type
assert_match(/ActionController::BadRequest/, body)
get "/parameter_missing", {}, xhr_request_env
assert_response 400
assert_no_match(/<body>/, body)
assert_equal response.content_type, "text/plain"
assert_equal "text/plain", response.content_type
assert_match(/ActionController::ParameterMissing/, body)
end

View file

@ -124,7 +124,7 @@ class MimeTypeTest < ActiveSupport::TestCase
end
Mime::Type.register("text/foo", :foo)
assert_equal registered_mimes, [Mime::FOO]
assert_equal [Mime::FOO], registered_mimes
ensure
Mime::Type.unregister(:FOO)
end

View file

@ -86,7 +86,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
cookies[SessionKey] = SignedBar
get '/persistent_session_id'
assert_response :success
assert_equal response.body.size, 32
assert_equal 32, response.body.size
session_id = response.body
get '/get_session_id'
@ -247,7 +247,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
cookies[SessionKey] = SignedBar
get '/persistent_session_id'
assert_response :success
assert_equal response.body.size, 32
assert_equal 32, response.body.size
session_id = response.body
get '/persistent_session_id'
assert_equal session_id, response.body
@ -263,7 +263,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
get "/get_session_id"
sid = response.body
assert_equal sid.size, 36
assert_equal 36, sid.size
get "/change_session_id"
assert_not_equal sid, response.body