Sha256: 08072a87e342b79c4ac1020006f09727ccf45c354f600fd0ee807c75bd0c4fc6

Contents?: true

Size: 1.17 KB

Versions: 15

Compression:

Stored size: 1.17 KB

Contents

require 'abstract_unit'

class JsonParamsParsingTest < ActionController::IntegrationTest
  class TestController < ActionController::Base
    class << self
      attr_accessor :last_request_parameters
    end

    def parse
      self.class.last_request_parameters = request.request_parameters
      head :ok
    end
  end

  def teardown
    TestController.last_request_parameters = nil
  end

  test "parses json params for application json" do
    assert_parses(
      {"person" => {"name" => "David"}},
      "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/json' }
    )
  end

  test "parses json params for application jsonrequest" do
    assert_parses(
      {"person" => {"name" => "David"}},
      "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/jsonrequest' }
    )
  end

  private
    def assert_parses(expected, actual, headers = {})
      with_routing do |set|
        set.draw do |map|
          map.connect ':action', :controller => "json_params_parsing_test/test"
        end

        post "/parse", actual, headers
        assert_response :ok
        assert_equal(expected, TestController.last_request_parameters)
      end
    end
end

Version data entries

15 entries across 14 versions & 8 rubygems

Version Path
elkinsware-erubis_rails_helper-0.6.0 test/controller/request/json_params_parsing_test.rb
elkinsware-erubis_rails_helper-0.6.1 test/controller/request/json_params_parsing_test.rb
elkinsware-erubis_rails_helper-0.9.0 test/controller/request/json_params_parsing_test.rb
elkinsware-erubis_rails_helper-0.9.1 test/controller/request/json_params_parsing_test.rb
elkinsware-erubis_rails_helper-0.9.5 test/controller/request/json_params_parsing_test.rb
ghazel-erubis_rails_helper-0.9.5 test/controller/request/json_params_parsing_test.rb
mitio-erubis_rails_helper-1.0.1 test/controller/request/json_params_parsing_test.rb
erubis_rails_helper-1.0.0 test/controller/request/json_params_parsing_test.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/actionpack/pkg/actionpack-2.3.3/test/controller/request/json_params_parsing_test.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/actionpack/test/controller/request/json_params_parsing_test.rb
ghazel-erubis_rails_helper-0.9.5.1 test/controller/request/json_params_parsing_test.rb
webroar-0.2.2 src/admin_panel/vendor/rails/actionpack/test/controller/request/json_params_parsing_test.rb
actionpack-2.3.3 test/controller/request/json_params_parsing_test.rb
actionpack-2.3.2 test/controller/request/json_params_parsing_test.rb
radiant-0.8.0 vendor/rails/actionpack/test/controller/request/json_params_parsing_test.rb