Skip to content

Commit 2a08132

Browse files
committed
Test for custom REST code + example of single resource
1 parent 3343a6c commit 2a08132

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/tests/model_rest_test.js

+31
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,37 @@ test("update with custom unique_key field", function() {
123123
server.respond()
124124
});
125125

126+
test("update single resource", 3, function() {
127+
var User = Model("user", function() {
128+
this.use(Model.REST, "/user", {
129+
update_path: function () {
130+
return this.read_path()
131+
}
132+
})
133+
});
134+
var user = new User({ 'id': 1, email: "bob@example.com" });
135+
136+
this.spy(jQuery, "ajax")
137+
138+
var server = this.sandbox.useFakeServer()
139+
server.respondWith("PUT", "/user", [200, {
140+
"Content-Type": "application/json"
141+
}, JSON.stringify({
142+
id: 1, email: "bob@example.com"
143+
})])
144+
145+
user.save(function(success) {
146+
ok(success, "save() wasn't successful");
147+
});
148+
149+
ok(jQuery.ajax.calledOnce)
150+
deepEqual(JSON.parse(jQuery.ajax.getCall(0).args[0].data), {
151+
user: { email: "bob@example.com" }
152+
})
153+
154+
server.respond()
155+
})
156+
126157
test("destroy with named params in resource path", function() {
127158
var Post = Model("post", function() {
128159
this.use(Model.REST, "/root/:root_id/nested/:nested_id/posts")

0 commit comments

Comments
 (0)