Skip to content

Commit

Permalink
Fixed bug so that request data is always passed as an already parsed …
Browse files Browse the repository at this point in the history
…object.
  • Loading branch information
blakewest committed Jan 19, 2015
1 parent 1345726 commit fc2fcf3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facade",
"version": "0.4.1",
"version": "0.4.2",
"authors": [
"Blake West <[email protected]>"
],
Expand Down
6 changes: 3 additions & 3 deletions dist/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ var Y=s();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(G.
throwIfRegex(opts.route);
var fullUrl = opts.resource.url + '/' + opts.item.id + opts.route;
Facade.backend.when(opts.method, fullUrl).respond(function(method, url, requestData, headers) {
requestData = requestData || {};
requestData = JSON.parse(requestData || "{}");
var route = Facade.findRoute(method, url);
var item = getTable(opts.resource).find(opts.item.id);

Expand All @@ -310,7 +310,7 @@ var Y=s();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(G.
function createCustomRouteForCollection(opts) {
var fullUrl = _.isRegExp(opts.route) ? opts.route : opts.resource.url + opts.route
Facade.backend.when(opts.method, fullUrl).respond(function(method, url, requestData, headers) {
requestData = requestData || {};
requestData = JSON.parse(requestData || "{}");
var collection = getTable(opts.resource).getAll();
var route = Facade.findRoute(method, url);

Expand All @@ -327,7 +327,7 @@ var Y=s();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(G.
var fullUrl = opts.resource.url + opts.route;
Facade.backend.expect(opts.method, fullUrl, withJSON(opts.expected))
.respond(function(method, url, requestData, headers) {
requestData = requestData || {};
requestData = JSON.parse(requestData || "{}");
var collection = getTable(opts.resource).getAll();
var route = Facade.findRoute(method, url);

Expand Down
4 changes: 2 additions & 2 deletions dist/facade.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
throwIfRegex(opts.route);
var fullUrl = opts.resource.url + '/' + opts.item.id + opts.route;
Facade.backend.when(opts.method, fullUrl).respond(function(method, url, requestData, headers) {
requestData = requestData || {};
requestData = JSON.parse(requestData || "{}");
var route = Facade.findRoute(method, url);
var item = getTable(opts.resource).find(opts.item.id);

Expand All @@ -254,7 +254,7 @@
function createCustomRouteForCollection(opts) {
var fullUrl = _.isRegExp(opts.route) ? opts.route : opts.resource.url + opts.route
Facade.backend.when(opts.method, fullUrl).respond(function(method, url, requestData, headers) {
requestData = requestData || {};
requestData = JSON.parse(requestData || "{}");
var collection = getTable(opts.resource).getAll();
var route = Facade.findRoute(method, url);

Expand All @@ -271,7 +271,7 @@
var fullUrl = opts.resource.url + opts.route;
Facade.backend.expect(opts.method, fullUrl, withJSON(opts.expected))
.respond(function(method, url, requestData, headers) {
requestData = requestData || {};
requestData = JSON.parse(requestData || "{}");
var collection = getTable(opts.resource).getAll();
var route = Facade.findRoute(method, url);

Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,17 @@
});
describe("the Resource object", function() {
describe("#addItem", function() {
var patientResource;
var patientResource, patient1;
beforeEach(function() {
patientResource = Facade.resource({
name: "patient",
url: "/api/provider/patients"
});
createController();
Facade.initialize({backend: $httpBackend});
patient1 = patientResource.addItem({id: 1, name: "Joe Bob"});
});
it("should take an object and add it to the database for that resource", function() {
patientResource.addItem({id: 1, name: "Joe Bob"});
Facade.db.patient.find(1).should.eql({id: 1, name: "Joe Bob"});
});
it("should auto add rest routes for that patient", function() {
Expand Down

0 comments on commit fc2fcf3

Please sign in to comment.