Permalink
Browse files

Don't log an error when Rails returns a response of " " for a `head :…

…ok` response.
  • Loading branch information...
1 parent 7fd9bb3 commit 1d9d72acd6c1db2f7ddbd1e76e496025593d023f @benpickles committed Apr 1, 2010
Showing with 34 additions and 2 deletions.
  1. +3 −1 CHANGELOG.markdown
  2. +3 −1 src/model_rest_persistence.js
  3. +5 −0 test/app.rb
  4. +23 −0 test/public/tests/model_rest_persistence.js
View
4 CHANGELOG.markdown
@@ -1,8 +1,10 @@
# Changelog
+* Don't log an error when Rails returns a response of " " for a `head :ok` response.
+
## 0.8.1
-* Custom class methods should be available after chaining.
+* Fix that custom class methods should be available after chaining.
## 0.8.0
View
4 src/model_rest_persistence.js
@@ -35,7 +35,9 @@ Model.RestPersistence = function(resource, methods) {
parseResponseData: function(xhr) {
try {
- return jQuery.parseJSON(xhr.responseText);
+ return /\S/.test(xhr.responseText) ?
+ jQuery.parseJSON(xhr.responseText) :
+ null;
} catch(e) {
Model.Log(e);
}
View
5 test/app.rb
@@ -18,6 +18,11 @@
delete '/posts/:id' do
end
+# Blank response (Rails' `head :ok`)
+put '/posts-empty-response/:id' do
+ ' '
+end
+
# Failure.
post '/posts-failure' do
status 500
View
23 test/public/tests/model_rest_persistence.js
@@ -97,6 +97,29 @@ test("update", function() {
same(request.data, { post: { title: "Bar", body: "..." } });
});
+test("update - blank response (Rails' `head :ok`)", function() {
+ var Post = Model("post", {
+ persistence: Model.RestPersistence("/posts-empty-response")
+ });
+ var post = new Post({ id: 1, title: "Foo", body: "..." });
+ post.attr("title", "Bar");
+
+ stop();
+
+ var old_log = Model.Log;
+ var logged = [];
+
+ Model.Log = function() {
+ logged.push(arguments);
+ };
+
+ post.save(function(success) {
+ same(logged, []);
+ start();
+ Model.Log = old_log;
+ });
+});
+
test("update - 422 response (failed validations)", function() {
var Post = Model("post", {
persistence: Model.RestPersistence("/posts-validations")

0 comments on commit 1d9d72a

Please sign in to comment.