Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor request json params parsing tests
- Loading branch information
Showing
2 changed files
with
45 additions
and
22 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
actionpack/test/controller/request/json_params_parsing_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters