class TestCaseTest

Constants

FILES_DIR
READ_BINARY
READ_PLAIN

Public Class Methods

fixture_path() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 9
def self.fixture_path; end

Public Instance Methods

setup() click to toggle source
Calls superclass method
# File actionpack/test/controller/test_case_test.rb, line 170
def setup
  super
  @controller = TestController.new
  @request.delete_header "PATH_INFO"
  @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
    r.draw do
      ActiveSupport::Deprecation.silence do
        get ":controller(/:action(/:id))"
      end
    end
  end
end
test_action_dispatch_uploaded_file_upload() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 871
def test_action_dispatch_uploaded_file_upload
  filename = "ruby_on_quails.jpg"
  path = "#{FILES_DIR}/#{filename}"
  post :test_file_upload, params: {
    file: Rack::Test::UploadedFile.new(path, "image/jpg", true)
  }
  assert_equal "45142", @response.body
end
test_array_path_parameter_handled_properly() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 599
def test_array_path_parameter_handled_properly
  with_routing do |set|
    set.draw do
      get "file/*path", to: "test_case_test/test#test_params"

      ActiveSupport::Deprecation.silence do
        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
  end
end
test_assert_generates() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 393
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" }, {}
end
test_assert_realistic_path_parameters() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 615
def test_assert_realistic_path_parameters
  get :test_params, params: { id: 20, foo: Object.new }

  # All elements of path_parameters should use Symbol keys
  @request.path_parameters.each_key do |key|
    assert_kind_of Symbol, key
  end
end
test_assert_routing() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 401
def test_assert_routing
  assert_routing "content", controller: "content", action: "index"
end
test_assert_routing_in_module() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 412
def test_assert_routing_in_module
  with_routing do |set|
    set.draw do
      namespace :admin do
        get "user" => "user#index"
      end
    end

    assert_routing "admin/user", controller: "admin/user", action: "index"
  end
end
test_assert_routing_with_glob() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 424
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")
  end
end
test_assert_routing_with_method() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 405
def test_assert_routing_with_method
  with_routing do |set|
    set.draw { resources(:content) }
    assert_routing({ method: "post", path: "content" }, { controller: "content", action: "create" })
  end
end
test_assert_select_with_body() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 206
def test_assert_select_with_body
  get :test_with_body

  assert_select "body.foo"
end
test_assert_select_without_body() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 199
def test_assert_select_without_body
  get :test_without_body

  assert_select "body", 0
  assert_select "div.foo"
end
test_body_stream() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 226
def test_body_stream
  params = Hash[:page, { name: "page name" }, "some key", 123]

  post :render_body, params: params.dup

  assert_equal params.to_query, @response.body
end
test_cookies_should_be_escaped_properly() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 749
def test_cookies_should_be_escaped_properly
  cookies["foo"] = "+"
  get :render_cookie
  assert_equal "+", @response.body
end
test_document_body_and_params_with_post() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 234
def test_document_body_and_params_with_post
  post :test_params, params: { id: 1 }
  assert_equal({ "id" => "1", "controller" => "test_case_test/test", "action" => "test_params" }, ::JSON.parse(@response.body))
end
test_document_body_with_post() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 239
def test_document_body_with_post
  post :render_body, body: "document body"
  assert_equal "document body", @response.body
end
test_document_body_with_put() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 244
def test_document_body_with_put
  put :render_body, body: "document body"
  assert_equal "document body", @response.body
end
test_exception_in_action_reaches_test() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 898
def test_exception_in_action_reaches_test
  assert_raise(RuntimeError) do
    process :boom, method: "GET"
  end
end
test_filtered_parameters_reset_between_requests() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 676
def test_filtered_parameters_reset_between_requests
  get :no_op, params: { foo: "bar" }
  assert_equal "bar", @request.filtered_parameters[:foo]

  get :no_op, params: { foo: "baz" }
  assert_equal "baz", @request.filtered_parameters[:foo]
end
test_fixture_file_upload() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 844
def test_fixture_file_upload
  post :test_file_upload,
    params: {
      file: fixture_file_upload(FILES_DIR + "/ruby_on_quails.jpg", "image/jpg")
    }
  assert_equal "45142", @response.body
end
test_fixture_file_upload_ignores_fixture_path_given_full_path() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 859
def test_fixture_file_upload_ignores_fixture_path_given_full_path
  TestCaseTest.stub :fixture_path, __dir__ do
    uploaded_file = fixture_file_upload("#{FILES_DIR}/ruby_on_quails.jpg", "image/jpg")
    assert_equal File.open("#{FILES_DIR}/ruby_on_quails.jpg", READ_PLAIN).read, uploaded_file.read
  end
end
test_fixture_file_upload_ignores_nil_fixture_path() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 866
def test_fixture_file_upload_ignores_nil_fixture_path
  uploaded_file = fixture_file_upload("#{FILES_DIR}/ruby_on_quails.jpg", "image/jpg")
  assert_equal File.open("#{FILES_DIR}/ruby_on_quails.jpg", READ_PLAIN).read, uploaded_file.read
end
test_fixture_file_upload_relative_to_fixture_path() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 852
def test_fixture_file_upload_relative_to_fixture_path
  TestCaseTest.stub :fixture_path, FILES_DIR do
    uploaded_file = fixture_file_upload("ruby_on_quails.jpg", "image/jpg")
    assert_equal File.open("#{FILES_DIR}/ruby_on_quails.jpg", READ_PLAIN).read, uploaded_file.read
  end
end
test_fixture_file_upload_should_be_able_access_to_tempfile() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 839
def test_fixture_file_upload_should_be_able_access_to_tempfile
  file = fixture_file_upload(FILES_DIR + "/ruby_on_quails.jpg", "image/jpg")
  assert file.respond_to?(:tempfile), "expected tempfile should respond on fixture file object, got nothing"
end
test_fixture_file_upload_with_binary() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 827
def test_fixture_file_upload_with_binary
  filename = "ruby_on_quails.jpg"
  path = "#{FILES_DIR}/#{filename}"
  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

  plain_file_upload = fixture_file_upload(path, content_type)
  assert_equal File.open(path, READ_PLAIN).read, plain_file_upload.read
end
test_fixture_path_is_accessed_from_self_instead_of_active_support_test_case() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 808
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("/ruby_on_quails.jpg", "image/png")
    assert_equal File.open("#{FILES_DIR}/ruby_on_quails.jpg", READ_PLAIN).read, uploaded_file.read
  end
end
test_head() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 249
def test_head
  head :test_params
  assert_equal 200, @response.status
end
test_header_properly_reset_after_remote_http_request() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 647
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"]
end
test_id_converted_to_string() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 592
def test_id_converted_to_string
  get :test_params, params: {
    id: 20, foo: Object.new
  }
  assert_kind_of String, @request.path_parameters[:id]
end
test_kwarg_params_passing_with_session_and_flash() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 462
def test_kwarg_params_passing_with_session_and_flash
  get :test_params, params: {
    page: {
      name: "Page name",
      month: "4",
      year: "2004",
      day: "6"
    }
  }, 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" } },
    parsed_params
  )

  assert_equal "bar", session[:foo]
  assert_equal "created", flash[:notice]
end
test_merged_session_arg_is_retained_across_requests() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 303
def test_merged_session_arg_is_retained_across_requests
  get :no_op, session: { foo: "bar" }
  assert_equal "bar", session[:foo]
  get :no_op
  assert_equal "bar", session[:foo]
end
test_multiple_calls() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 372
def test_multiple_calls
  process :test_only_one_param, method: "GET", params: { left: true }
  assert_equal "OK", @response.body
  process :test_only_one_param, method: "GET", params: { right: true }
  assert_equal "OK", @response.body
end
test_multiple_mixed_method_process_should_scrub_rack_input() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 761
def test_multiple_mixed_method_process_should_scrub_rack_input
  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" }
  assert_equal({ "bar" => "an bar", "controller" => "test_case_test/test", "action" => "test_params" }, ::JSON.parse(@response.body))
end
test_mutating_content_type_headers_for_html_files_sets_the_header() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 576
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" }

  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
test_mutating_content_type_headers_for_non_registered_mime_type_raises_an_error() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 585
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" }
  end
end
test_mutating_content_type_headers_for_plain_text_files_sets_the_header() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 567
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" }

  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
test_params_passing() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 431
def test_params_passing
  get :test_params, 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" }
    },
    parsed_params
  )
end
test_params_passing_doesnt_modify_in_place() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 529
def test_params_passing_doesnt_modify_in_place
  page = { name: "Page name", month: 4, year: 2004, day: 6 }
  get :test_params, params: { page: page }
  assert_equal 2004, page[:year]
end
test_params_passing_path_parameter_is_string_when_not_html_request() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 505
def test_params_passing_path_parameter_is_string_when_not_html_request
  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" },
    parsed_params
  )
end
test_params_passing_with_frozen_values() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 515
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
    }
  end
  parsed_params = ::JSON.parse(@response.body)
  assert_equal(
    { "controller" => "test_case_test/test", "action" => "test_params",
     "frozen" => "icy", "frozens" => ["icy"], "deepfreeze" => { "frozen" => "icy" } },
    parsed_params
  )
end
test_params_passing_with_integer() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 483
def test_params_passing_with_integer
  get :test_params, 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" } },
    parsed_params
  )
end
test_params_passing_with_integers_when_not_html_request() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 495
def test_params_passing_with_integers_when_not_html_request
  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" },
    parsed_params
  )
end
test_params_reset_between_post_requests() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 668
def test_params_reset_between_post_requests
  post :no_op, params: { foo: "bar" }
  assert_equal "bar", @request.params[:foo]

  post :no_op
  assert @request.params[:foo].blank?
end
test_path_is_kept_after_the_request() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 684
def test_path_is_kept_after_the_request
  get :test_params, params: { id: "foo" }
  assert_equal "/test_case_test/test/test_params/foo", @request.path
end
test_path_params_reset_between_request() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 689
def test_path_params_reset_between_request
  get :test_params, params: { id: "foo" }
  assert_equal "foo", @request.path_parameters[:id]

  get :test_params
  assert_nil @request.path_parameters[:id]
end
test_process_delete_flash() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 273
def test_process_delete_flash
  process :set_flash
  process :delete_flash
  assert_empty flash
  assert_empty session
end
test_process_merges_session_arg() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 296
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]
end
test_process_overwrites_existing_session_arg() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 310
def test_process_overwrites_existing_session_arg
  session[:foo] = "bar"
  get :no_op, session: { foo: "baz" }
  assert_equal "baz", session[:foo]
end
test_process_with_flash() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 259
def test_process_with_flash
  process :set_flash,
    method: "GET",
    flash: { "test" => "value" }
  assert_equal ">value<", flash["test"]
end
test_process_with_flash_now() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 266
def test_process_with_flash_now
  process :set_flash_now,
    method: "GET",
    flash: { "test_now" => "value_now" }
  assert_equal ">value_now<", flash["test_now"]
end
test_process_with_query_string() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 358
def test_process_with_query_string
  process :test_query_string,
    method: "GET",
    params: { q: "test" }
  assert_equal "q=test", @response.body
end
test_process_with_query_string_with_explicit_uri() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 365
def test_process_with_query_string_with_explicit_uri
  @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
test_process_with_request_uri_with_no_params() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 334
def test_process_with_request_uri_with_no_params
  process :test_uri
  assert_equal "/test_case_test/test/test_uri", @response.body
end
test_process_with_request_uri_with_params() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 344
def test_process_with_request_uri_with_params
  process :test_uri,
    method: "GET",
    params: { id: 7 }

  assert_equal "/test_case_test/test/test_uri/7", @response.body
end
test_process_with_request_uri_with_params_with_explicit_uri() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 352
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 }
  assert_equal "/explicit/uri", @response.body
end
test_process_with_session() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 280
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"
end
test_process_with_session_kwarg() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 288
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]
end
test_process_with_symbol_method() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 339
def test_process_with_symbol_method
  process :test_uri, method: :get
  assert_equal "/test_case_test/test/test_uri", @response.body
end
test_process_without_flash() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 254
def test_process_without_flash
  process :set_flash
  assert_equal "><", flash["test"]
end
test_query_param_named_action() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 450
def test_query_param_named_action
  get :test_query_parameters, params: { action: "foobar" }
  parsed_params = JSON.parse(@response.body)
  assert_equal({ "action" => "foobar" }, parsed_params)
end
test_raw_post_handling() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 219
def test_raw_post_handling
  params = Hash[:page, { name: "page name" }, "some key", 123]
  post :render_raw_post, params: params.dup

  assert_equal params.to_query, @response.body
end
test_redirect_url_only_cares_about_location_header() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 884
def test_redirect_url_only_cares_about_location_header
  get :create
  assert_response :created

  # Redirect url doesn't care that it wasn't a :redirect response.
  assert_equal "/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 "/resource"
  end
end
test_remote_addr() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 638
def test_remote_addr
  get :test_remote_addr
  assert_equal "0.0.0.0", @response.body

  @request.remote_addr = "192.0.0.1"
  get :test_remote_addr
  assert_equal "192.0.0.1", @response.body
end
test_request_format() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 710
def test_request_format
  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: "xml" }
  assert_equal "application/xml", @response.body

  get :test_format
  assert_equal "text/html", @response.body
end
test_request_format_kwarg() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 724
def test_request_format_kwarg
  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: "xml"
  assert_equal "application/xml", @response.body

  get :test_format
  assert_equal "text/html", @response.body
end
test_request_format_kwarg_overrides_params() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 738
def test_request_format_kwarg_overrides_params
  get :test_format, format: "json", params: { format: "html" }
  assert_equal "application/json", @response.body
end
test_request_param_named_action() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 456
def test_request_param_named_action
  post :test_request_parameters, params: { action: "foobar" }
  parsed_params = eval(@response.body)
  assert_equal({ "action" => "foobar" }, parsed_params)
end
test_request_protocol_is_reset_after_request() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 697
def test_request_protocol_is_reset_after_request
  get :test_protocol
  assert_equal "http://", @response.body

  @request.env["HTTPS"] = "on"
  get :test_protocol
  assert_equal "https://", @response.body

  @request.env.delete("HTTPS")
  get :test_protocol
  assert_equal "http://", @response.body
end
test_request_state_is_cleared_after_exception() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 904
def test_request_state_is_cleared_after_exception
  assert_raise(RuntimeError) do
    process :boom,
      method: "GET",
      params: { q: "test1" }
  end

  process :test_query_string,
    method: "GET",
    params: { q: "test2" }

  assert_equal "q=test2", @response.body
end
test_response_and_request_have_nice_accessors() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 328
def test_response_and_request_have_nice_accessors
  process :no_op
  assert_equal @response, response
  assert_equal @request, request
end
test_session_is_cleared_from_controller_after_reset_session() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 316
def test_session_is_cleared_from_controller_after_reset_session
  process :set_session
  process :reset_the_session
  assert_equal Hash.new, @controller.session.to_hash
end
test_session_is_cleared_from_request_after_reset_session() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 322
def test_session_is_cleared_from_request_after_reset_session
  process :set_session
  process :reset_the_session
  assert_equal Hash.new, @request.session.to_hash
end
test_should_impose_childless_html_tags_in_html() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 379
def test_should_impose_childless_html_tags_in_html
  process :test_xml_output, params: { response_as: "text/html" }

  # <area> auto-closes, so the <p> becomes a sibling
  assert_select "root > area + p"
end
test_should_not_impose_childless_html_tags_in_xml() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 386
def test_should_not_impose_childless_html_tags_in_xml
  process :test_xml_output, params: { response_as: "application/xml" }

  # <area> is not special, so the <p> is its child
  assert_select "root > area > p"
end
test_test_uploaded_file() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 790
def test_test_uploaded_file
  filename = "ruby_on_quails.jpg"
  path = "#{FILES_DIR}/#{filename}"
  content_type = "image/png"
  expected = File.read(path)
  expected.force_encoding(Encoding::BINARY)

  file = Rack::Test::UploadedFile.new(path, content_type)
  assert_equal filename, file.original_filename
  assert_equal content_type, file.content_type
  assert_equal file.path, file.local_path
  assert_equal expected, file.read

  new_content_type = "new content_type"
  file.content_type = new_content_type
  assert_equal new_content_type, file.content_type
end
test_test_uploaded_file_exception_when_file_doesnt_exist() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 880
def test_test_uploaded_file_exception_when_file_doesnt_exist
  assert_raise(RuntimeError) { Rack::Test::UploadedFile.new("non_existent_file") }
end
test_test_uploaded_file_with_binary() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 815
def test_test_uploaded_file_with_binary
  filename = "ruby_on_quails.jpg"
  path = "#{FILES_DIR}/#{filename}"
  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

  plain_uploaded_file = Rack::Test::UploadedFile.new(path, content_type)
  assert_equal File.open(path, READ_PLAIN).read, plain_uploaded_file.read
end
test_url_options_reset() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 212
def test_url_options_reset
  @controller = DefaultUrlOptionsCachingController.new
  get :test_url_options_reset
  assert_nil @request.params["dynamic_opt"]
  assert_match(/dynamic_opt=opt/, @response.body)
end
test_using_as_json_sets_format_json() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 562
def test_using_as_json_sets_format_json
  post :render_body, params: { bool_value: true, str_value: "string", num_value: 2 }, as: :json
  assert_equal "json", @request.format
end
test_using_as_json_sets_request_content_type_to_json() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 553
def test_using_as_json_sets_request_content_type_to_json
  post :render_body, params: { bool_value: true, str_value: "string", num_value: 2 }, as: :json

  assert_equal "application/json", @request.headers["CONTENT_TYPE"]
  assert_equal true, @request.request_parameters[:bool_value]
  assert_equal "string", @request.request_parameters[:str_value]
  assert_equal 2, @request.request_parameters[:num_value]
end
test_with_routing_places_routes_back() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 624
def test_with_routing_places_routes_back
  assert @routes
  routes_id = @routes.object_id

  begin
    with_routing { raise "fail" }
    fail "Should not be here."
  rescue RuntimeError
  end

  assert @routes
  assert_equal routes_id, @routes.object_id
end
test_xhr_with_params() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 653
def test_xhr_with_params
  get :test_params, params: { id: 1 }, xhr: true

  assert_equal({ "id" => "1", "controller" => "test_case_test/test", "action" => "test_params" }, ::JSON.parse(@response.body))
end
test_xhr_with_session() click to toggle source
# File actionpack/test/controller/test_case_test.rb, line 659
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"
end