Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / actionpack / test / controller / request / json_params_parsing_test.rb
1 require 'abstract_unit'
2
3 class JsonParamsParsingTest < ActionController::IntegrationTest
4 class TestController < ActionController::Base
5 class << self
6 attr_accessor :last_request_parameters
7 end
8
9 def parse
10 self.class.last_request_parameters = request.request_parameters
11 head :ok
12 end
13 end
14
15 def teardown
16 TestController.last_request_parameters = nil
17 end
18
19 test "parses json params for application json" do
20 assert_parses(
21 {"person" => {"name" => "David"}},
22 "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/json' }
23 )
24 end
25
26 test "parses json params for application jsonrequest" do
27 assert_parses(
28 {"person" => {"name" => "David"}},
29 "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/jsonrequest' }
30 )
31 end
32
33 private
34 def assert_parses(expected, actual, headers = {})
35 with_routing do |set|
36 set.draw do |map|
37 map.connect ':action', :controller => "json_params_parsing_test/test"
38 end
39
40 post "/parse", actual, headers
41 assert_response :ok
42 assert_equal(expected, TestController.last_request_parameters)
43 end
44 end
45 end