Skip to content

Commit

Permalink
Rest persistence should send JSON encoded data.
Browse files Browse the repository at this point in the history
  • Loading branch information
benpickles committed Sep 15, 2010
1 parent 0f81b7e commit 6d8d9cf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/model_rest_persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Model.RestPersistence = function(resource, methods) {
} else {
params = null;
}
return params;
return JSON.stringify(params)
},

read: function(callback) {
Expand Down Expand Up @@ -84,6 +84,7 @@ Model.RestPersistence = function(resource, methods) {
return jQuery.ajax({
type: method,
url: url,
contentType: "application/json",
dataType: "json",
data: data,
dataFilter: function(data, type) {
Expand Down
7 changes: 7 additions & 0 deletions test/public/javascripts/json.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/tests/model_rest_persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ test("create", function() {

equals(request.type, "POST");
equals(request.url, "/posts");
same(request.data, { post: { title: "Foo", body: "..." } });
same(JSON.parse(request.data), { post: { title: "Foo", body: "..." } });
});

test("create - 422 response (failed validations)", function() {
Expand Down Expand Up @@ -192,7 +192,7 @@ test("update", function() {

equals(request.type, "PUT");
equals(request.url, "/posts/1");
same(request.data, { post: { title: "Bar", body: "..." } });
same(JSON.parse(request.data), { post: { title: "Bar", body: "..." } });
});

test("update - blank response (Rails' `head :ok`)", function() {
Expand Down
1 change: 1 addition & 0 deletions test/views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<!-- Dependencies -->
<script src="javascripts/jquery-1.4.1.min.js"></script>
<script src="javascripts/json.js"></script>

<!-- js-model -->
<script src="/js-model.js"></script>
Expand Down

0 comments on commit 6d8d9cf

Please sign in to comment.