class WebServiceTest
Public Instance Methods
content_length()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 107 def content_length; get_header("rack.input").length; end
params_parsers()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 103 def params_parsers { json: Proc.new { |data| raise Interrupt } } end
setup()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 32 def setup @controller = TestController.new @integration_session = nil end
test_check_parameters()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 37 def test_check_parameters with_test_route_set do get "/" assert_equal "", @controller.response.body end end
test_dasherized_keys_as_json()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 91 def test_dasherized_keys_as_json with_test_route_set do post "/?full=1", params: '{"first-key":{"sub-key":"..."}}', headers: { "CONTENT_TYPE" => "application/json" } assert_equal "action, controller, first-key(sub-key), full", @controller.response.body assert_equal "...", @controller.params["first-key"]["sub-key"] end end
test_parsing_json_doesnot_rescue_exception()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 101 def test_parsing_json_doesnot_rescue_exception req = Class.new(ActionDispatch::Request) do def params_parsers { json: Proc.new { |data| raise Interrupt } } end def content_length; get_header("rack.input").length; end end.new("rack.input" => StringIO.new('{"title":"JSON"}}'), "CONTENT_TYPE" => "application/json") assert_raises(Interrupt) do req.request_parameters end end
test_post_json()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 44 def test_post_json with_test_route_set do post "/", params: '{"entry":{"summary":"content..."}}', headers: { "CONTENT_TYPE" => "application/json" } assert_equal "entry", @controller.response.body assert @controller.params.has_key?(:entry) assert_equal "content...", @controller.params["entry"]["summary"] end end
test_put_json()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 56 def test_put_json with_test_route_set do put "/", params: '{"entry":{"summary":"content..."}}', headers: { "CONTENT_TYPE" => "application/json" } assert_equal "entry", @controller.response.body assert @controller.params.has_key?(:entry) assert_equal "content...", @controller.params["entry"]["summary"] end end
test_register_and_use_json_simple()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 68 def test_register_and_use_json_simple with_test_route_set do with_params_parsers Mime[:json] => Proc.new { |data| ActiveSupport::JSON.decode(data)["request"].with_indifferent_access } do post "/", params: '{"request":{"summary":"content...","title":"JSON"}}', headers: { "CONTENT_TYPE" => "application/json" } assert_equal "summary, title", @controller.response.body assert @controller.params.has_key?(:summary) assert @controller.params.has_key?(:title) assert_equal "content...", @controller.params["summary"] assert_equal "JSON", @controller.params["title"] end end end
test_use_json_with_empty_request()
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 84 def test_use_json_with_empty_request with_test_route_set do assert_nothing_raised { post "/", headers: { "CONTENT_TYPE" => "application/json" } } assert_equal "", @controller.response.body end end
Private Instance Methods
with_params_parsers(parsers = {}) { || ... }
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 116 def with_params_parsers(parsers = {}) old_session = @integration_session original_parsers = ActionDispatch::Request.parameter_parsers ActionDispatch::Request.parameter_parsers = original_parsers.merge parsers reset! yield ensure ActionDispatch::Request.parameter_parsers = original_parsers @integration_session = old_session end
with_test_route_set() { || ... }
click to toggle source
# File actionpack/test/controller/webservice_test.rb, line 127 def with_test_route_set with_routing do |set| set.draw do match "/", to: "web_service_test/test#assign_parameters", via: :all end yield end end