Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrokiefer committed Feb 22, 2015
1 parent 19c055b commit c654fe2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
24 changes: 19 additions & 5 deletions dist/amd/factory-guy.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,21 +651,37 @@ var MockCreateRequest = function(url, store, modelName, options) {

var MockUpdateRequest = function(url, model, mapFind, options) {
var status = options.status || 200;
var succeed = options.succeed || true;
var succeed = true;
var response = null;

this.andReturn = function(returns) {
if ('succeed' in options) {
succeed = options.succeed;
}

if ('response' in options) {
response = options.response;
}

this.andSucceed = function(options) {
succeed = true;
return this;
};

this.andFail = function(options) {
succeed = false;
status = options.status || 500;
if ('response' in options) {
response = options.response;
}
return this;
};

this.handler = function(settings) {
if (!succeed) {
this.status = status;
if (response !== null) {
this.responseText = response;
}
} else {
var json = model.toJSON({includeId: true});
this.responseText = mapFind(model.constructor.typeKey, json);
Expand All @@ -677,7 +693,6 @@ var MockUpdateRequest = function(url, model, mapFind, options) {
url: url,
dataType: 'json',
type: 'PUT',
status: status,
response: this.handler
};

Expand Down Expand Up @@ -1258,8 +1273,7 @@ var FactoryGuyTestMixin = Em.Mixin.create({
Ember.assert("To handleUpdate pass in a model instance or a type and an id",type && id);

var url = this.buildURL(type, id);
var opts = options === undefined ? {} : options;
return new MockUpdateRequest(url, model, this.mapFind, opts);
return new MockUpdateRequest(url, model, this.mapFind, options);
},
/**
Handling ajax DELETE ( delete record ) for a model type. You can mock
Expand Down
24 changes: 19 additions & 5 deletions dist/ember-data-factory-guy.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,21 +646,37 @@ var MockCreateRequest = function(url, store, modelName, options) {

var MockUpdateRequest = function(url, model, mapFind, options) {
var status = options.status || 200;
var succeed = options.succeed || true;
var succeed = true;
var response = null;

this.andReturn = function(returns) {
if ('succeed' in options) {
succeed = options.succeed;
}

if ('response' in options) {
response = options.response;
}

this.andSucceed = function(options) {
succeed = true;
return this;
};

this.andFail = function(options) {
succeed = false;
status = options.status || 500;
if ('response' in options) {
response = options.response;
}
return this;
};

this.handler = function(settings) {
if (!succeed) {
this.status = status;
if (response !== null) {
this.responseText = response;
}
} else {
var json = model.toJSON({includeId: true});
this.responseText = mapFind(model.constructor.typeKey, json);
Expand All @@ -672,7 +688,6 @@ var MockUpdateRequest = function(url, model, mapFind, options) {
url: url,
dataType: 'json',
type: 'PUT',
status: status,
response: this.handler
};

Expand Down Expand Up @@ -1253,8 +1268,7 @@ var FactoryGuyTestMixin = Em.Mixin.create({
Ember.assert("To handleUpdate pass in a model instance or a type and an id",type && id);

var url = this.buildURL(type, id);
var opts = options === undefined ? {} : options;
return new MockUpdateRequest(url, model, this.mapFind, opts);
return new MockUpdateRequest(url, model, this.mapFind, options);
},
/**
Handling ajax DELETE ( delete record ) for a model type. You can mock
Expand Down
Loading

0 comments on commit c654fe2

Please sign in to comment.