Skip to content

Commit

Permalink
If defined, include jQuery.ajaxSetup data in REST parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ismasan authored and benpickles committed Sep 21, 2010
1 parent 8d13519 commit c15f1cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/model_rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Model.REST = function(resource, methods) {
} else {
params = null;
}
if(jQuery.ajaxSettings.data){
params = jQuery.extend(jQuery.ajaxSettings.data, params || {});
}
return JSON.stringify(params)
},

Expand Down
31 changes: 31 additions & 0 deletions test/tests/model_rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,37 @@ test("create failure", function() {
});
});

test("create with AjaxSetup", function() {

jQuery.ajaxSetup({
data: {
socket_id: '111'
}
})

var Post = Model("post", {
persistence: Model.REST("/posts")
});
var post = new Post({ title: "Foo", body: "..." });

equals(Post.count(), 0);

AjaxSpy.start();

stop();

post.save(function(success) {
ok(success);
same(this, post);
start();
});

equals(AjaxSpy.requests.length, 1, "one request should have been made");

var request = AjaxSpy.requests.shift();
same(JSON.parse(request.data), { socket_id: '111', post: { title: "Foo", body: "..." } });
});

test("update", function() {
var Post = Model("post", {
persistence: Model.REST("/posts")
Expand Down

0 comments on commit c15f1cc

Please sign in to comment.