This project is archived and is in readonly mode.
put :update in json format should return '{}' in real-life and not only in tests
-
Christiaan Van den Poel
- Assigned user cleared.
The bug was rejected by the jquery team http://bugs.jquery.com/ticket/7521
They say the string with whitespaces is not valid json, so it's in the rails code where the whitespaces should be removed from the response, no?
-
Christiaan Van den Poel
In the file 'actionpack/lib/action_controller/metal/responder.rb' on line 167
https://github.com/rails/rails/blob/master/actionpack/lib/action_co...The code is that for a successful update the response is
head :okIn the file 'actionpack/lib/action_controller/metal/head.rb' on line 29
https://github.com/rails/rails/blob/master/actionpack/lib/action_co...There is code that set the response body to a string with one whitespace, which is, according the jQuery team non valid when you return json.
self.response_body = " "I can imagine there is a historic reason to return one whitespace in case of a head response, but I also follow the jQuery team when they state that in case of a JSON response this string/response is invalid.
-
Christiaan Van den Poel
- Assigned user set to Neeraj Singh
Seems during my comment edit I've removed the who's responsible?
-
Christiaan Van den Poel
When I look at the rails code there is a test for returning '{}' when a put request is made in json format.
https://github.com/rails/rails/blob/master/actionpack/test/controll...
But when I use it in my application and browser, I get " " which is invalid json.
The thing is also: the accepts request header is:
Chrome 7: application/json, text/javascript, /; q=0.01
FF3: application/json, text/javascript, /; q=0.01So when I write a new test:
def test_using_resource_for_put_with_json_yields_ok_on_success_2 Customer.any_instance.stubs(:to_json).returns('{"name": "David"}') @request.accept = "application/json,text/javascript,*/*;q=0.01" put :using_resource assert_equal "application/json", @response.content_type assert_equal 200, @response.status assert_equal "{}", @response.body endthis fails (exception):
NoMethodError: undefined method `hash_for_customer_url' for #<Module:0xb6936fb4> /var/projects/github/rails@github/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb:135:in `__send__' /var/projects/github/rails@github/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb:135:in `polymorphic_url' /var/projects/github/rails@github/actionpack/lib/action_dispatch/routing/url_for.rb:138:in `url_for' /var/projects/github/rails@github/actionpack/lib/action_controller/metal/redirecting.rb:93:in `_compute_redirect_to_location' /var/projects/github/rails@github/actionpack/lib/action_controller/metal/redirecting.rb:63:in `redirect_to' ....So then I write the test like this:
def test_using_resource_for_put_with_json_yields_ok_on_success_2 with_test_route_set do Customer.any_instance.stubs(:to_json).returns('{"name": "David"}') @request.accept = "application/json,text/javascript,*/*;q=0.01" put :using_resource assert_equal "application/json", @response.content_type assert_equal 200, @response.status assert_equal "{}", @response.body end endThe test fails (real test fail):
1) Failure: test_using_resource_for_put_with_json_yields_ok_on_success_2(RespondWithControllerTest) [controller/mime_responds_test.rb:742:in `test_using_resource_for_put_with_json_yields_ok_on_success_2' controller/mime_responds_test.rb:932:in `with_test_route_set' /var/projects/github/rails@github/actionpack/lib/action_dispatch/testing/assertions/routing.rb:164:in `with_routing' controller/mime_responds_test.rb:924:in `with_test_route_set' controller/mime_responds_test.rb:738:in `test_using_resource_for_put_with_json_yields_ok_on_success_2' /var/projects/github/rails@github/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in `__send__' /var/projects/github/rails@github/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in `run' /var/projects/github/rails@github/activesupport/lib/active_support/callbacks.rb:428:in `_run_setup_callbacks' /var/projects/github/rails@github/activesupport/lib/active_support/testing/setup_and_teardown.rb:65:in `run']: <"application/json"> expected but was <"text/html">.So I'm testing with a reallife situation and the test fails?
Perhaps I'm not getting all this rails code and am I doing it wrong, perhaps someone can help out here.
-
Christiaan Van den Poel
- Title changed from latest jquery (1.4.4) has a bug in its parseJSON that has an effect on jquery-ujs and its callbacks to put :update in json format should return '{}' in real-life and not only in tests
-
Neeraj Singh
I followed your instruction and I am getting {} as the response.
-
Neeraj Singh
I tested on rails edge.
-
Christiaan Van den Poel
indeed, it look likes it is fixed in edge since 3.0.1.
My mistake...
Thx for checking
-
Neeraj Singh
- State changed from new to resolved
