Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adopted-ember-addons/ember-data-factory-guy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.1
Choose a base ref
...
head repository: adopted-ember-addons/ember-data-factory-guy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.9.2
Choose a head ref
  • 6 commits
  • 12 files changed
  • 1 contributor

Commits on Dec 16, 2014

  1. doc update

    danielspaniel committed Dec 16, 2014

    Verified

    This commit was signed with the committer’s verified signature.
    thetutlage Harminder Virk
    Copy the full SHA
    20aa143 View commit details
  2. doc update

    danielspaniel committed Dec 16, 2014

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a3649cb View commit details

Commits on Dec 23, 2014

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    be60cb8 View commit details
  2. Added handeFindQuery method to FactoryGuyTestHelperMixin

    Took makeFixture and makeList methods out of DS.Store and into FactoryGuy, and added deprecation warnings for those 2 methods
    Adjusted tests to use FactoryGuy.make and make list 
    Improved documentation
    danielspaniel committed Dec 23, 2014

    Verified

    This commit was signed with the committer’s verified signature.
    thetutlage Harminder Virk
    Copy the full SHA
    b222f3b View commit details
  3. doc upates

    danielspaniel committed Dec 23, 2014

    Verified

    This commit was signed with the committer’s verified signature.
    thetutlage Harminder Virk
    Copy the full SHA
    814e8a6 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2a90c1b View commit details
53 changes: 37 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,14 +10,14 @@ of ember-data-factory-guy.
- 0.6.4 -> ember-data-1.0.0-beta.8 and under
- 0.7.1.1 -> ember-data-1.0.0-beta.10
- 0.8.6 -> ember-data-1.0.0-beta.11
- 0.9.0 -> ember-data-1.0.0-beta.12
- 0.9.1 -> ember-data-1.0.0-beta.12

**Support for fixture adapter is currently kinda broken.**

*Version 0.9.0 expects you to no longer use store.makeFixture explicitly in your tests
but rather use the testHelper.make from FactoryGuyTestHelperMixin instead. If your not doing
this already, add a FactoryGuy.setStore(store) somewhere in your code before you start making fixtures.*

*Version 0.9.0 and up deprecates explicit call to store.makeFixture in your tests, in favor
of using the FactoryGuy.make or testHelper.make function from FactoryGuyTestHelperMixin instead.
If your not currently doing this already ( using FactoryGuyTestHelperMixin ), add a call to
FactoryGuy.setStore(store) somewhere in your code before you start making fixtures.*

## Using with Ember Cli
- https://github.com/igorrKurr/ember-cli-factory-guy-example
@@ -39,7 +39,7 @@ gem 'ember-data-factory-guy', group: test
or for particular version:

```ruby
gem 'ember-data-factory-guy', '0.9.0', group: test
gem 'ember-data-factory-guy', '0.9.1', group: test
```

then:
@@ -74,7 +74,7 @@ or for particular version:
"dependencies": {
"foo-dependency": "latest",
"other-foo-dependency": "latest",
"ember-data-factory-guy": "0.9.0"
"ember-data-factory-guy": "0.9.1"
}
```

@@ -227,8 +227,9 @@ the store is looking up the correct model type name

```javascript
// First set the store on FactoryGuy. You don't have to do this step manually if you use
// FactoryGuyTestHelperMixin since this is done for you in the setup method.
var store = this.get('container').lookup('store:main');
// FactoryGuyTestHelperMixin since this is done for you in the setup method. The following
// store lookup assumes you have a namespace for your Ember app named 'App'.
var store = App.__container__.lookup('store:main');
FactoryGuy.setStore(store);

// returns json
@@ -491,7 +492,7 @@ the reverse user hasMany 'projects' association is being setup for you on the us
user.get('projects.length') // => 2

// or
var projects = store.makeList('project', 2);
var projects = FactoryGuy.makeList('project', 2);
var user = FactoryGuy.make('user', {projects: projects});
user.get('projects.length') // => 2

@@ -510,7 +511,7 @@ the reverse 'user' belongsTo association is being setup for you on the project

- FactoryGuy.buildList
- Builds an array of one or more json objects
- store.makeList
- FactoryGuy.makeList
- Loads one or more instances into store


@@ -527,7 +528,7 @@ the reverse 'user' belongsTo association is being setup for you on the project
##### Building model instances

```javascript
var users = store.makeList('user', 2)
var users = FactoryGuy.makeList('user', 2)
users.get('length') // => 2
users[0].toJSON({includeId: true}) // => {id: 3, name: 'User3', style: 'normal'}
users[1].toJSON({includeId: true}) // => {id: 4, name: 'User4', style: 'normal'}
@@ -592,7 +593,8 @@ test("make a user using your applications default adapter", function() {
- Uses mockjax
- Has helper methods
- handleFindMany
- handleCreate
- handleFindQuery
- handleCreate
- handleUpdate
- handleDelete

@@ -618,14 +620,32 @@ tests run as shown in the previous section (Using FactoryGuyTestMixin)**
- for dealing with finding all records of a particular type

```javascript
// can use traits and extra fixture options here as you would with store#makeList
// can use traits and extra fixture options here as you would with FactoryGuy#makeList
testHelper.handleFindMany('profile', 2);

store.find('profile').then(function (profiles) {
profiles.get('length') //=> 2
});
```


##### handleFindQuery
- for dealing with finding all records for a type of model with query parameters.

```javascript
// First build json for the instances you want 'returned' in your query.
var usersJson = FactoryGuy.buildList('user', 2);

// Pass in the parameters you will search on ( in this case 'name' and 'age' )
// as an array, in the second argument.
testHelper.handleFindQuery('user', ['name', 'age'], usersJson);

store.findQuery('user', {name:'Bob', age: 10}}).then(function(userInstances){
/// userInstances are created from the usersJson that you passed in
})
```


##### handleCreate
- options
- match - attributes that must be in request json
@@ -702,10 +722,11 @@ match and or returns options.
```javascript
var profile = testHelper.make('profile');

// Simplest way is to pass in the model that will be updated ( if you have it available )
// Pass in the model that will be updated ( if you have it available )
testHelper.handleUpdate(profile);

// If the model is not available, pass in the modelType and the id ( if you know it )
// If the model is not available, pass in the modelType and the id of
// the model that will be updated
testHelper.handleUpdate('profile', 1);

profile.set('description', 'good value');
159 changes: 103 additions & 56 deletions dist/amd/factory-guy.js
Original file line number Diff line number Diff line change
@@ -247,25 +247,13 @@ var FactoryGuy = {
*/
isAttributeRelationship: function(typeName, attribute) {
if (!this.store) {
console.log("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures")
Ember.debug("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures")
// The legacy value was true.
return true;
}
var model = this.store.modelFor(typeName);
return !!model.typeForRelationship(attribute);
},
/**
Make new fixture and save to store. Proxy to store#makeFixture method
@param {String} name fixture name
@param {String} trait optional trait names ( one or more )
@param {Object} opts optional fixture options that will override default fixture values
@returns {Object|DS.Model} json or record depending on the adapter type
*/
make: function() {
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", this.store);
return this.store.makeFixture.apply(this.store,arguments);
},
/**
Used in model definitions to declare use of a sequence. For example:
@@ -333,7 +321,7 @@ var FactoryGuy = {
};
},
association: function (fixtureName, opts) {
console.log('DEPRECATION Warning: use FactoryGuy.belongsTo instead');
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.belongsTo instead');
return this.belongsTo(fixtureName, opts);
},
/**
@@ -460,7 +448,53 @@ var FactoryGuy = {
}
return definition.buildList(name, number, traits, opts);
},
/**
Make new fixture and save to store.
@param {String} name fixture name
@param {String} trait optional trait names ( one or more )
@param {Object} options optional fixture options that will override default fixture values
@returns {Object|DS.Model} json or record depending on the adapter type
*/
make: function() {
var store = this.store;
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", store);

var fixture = this.build.apply(this, arguments);
var name = arguments[0];
var modelName = this.lookupModelForFixtureName(name);
var modelType = store.modelFor(modelName);

if (store.usingFixtureAdapter()) {
store.setAssociationsForFixtureAdapter(modelType, modelName, fixture);
return this.pushFixture(modelType, fixture);
} else {
return store.makeModel(modelType, fixture);
}
},
/**
Make a list of Fixtures
@param {String} name name of fixture
@param {Number} number number to create
@param {String} trait optional trait names ( one or more )
@param {Object} options optional fixture options that will override default fixture values
@returns {Array} list of json fixtures or records depending on the adapter type
*/
makeList: function() {
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", this.store);

var arr = [];
var args = Array.prototype.slice.call(arguments);
Ember.assert("makeList needs at least 2 arguments, a name and a number",args.length >= 2);
var number = args.splice(1,1)[0];
Ember.assert("Second argument to makeList should be a number (of fixtures to make.)",typeof number == 'number');

for (var i = 0; i < number; i++) {
arr.push(this.make.apply(this, args));
}
return arr;
},
/**
Clear model instances from FIXTURES array, and from store cache.
Reset the id sequence for the models back to zero.
@@ -548,30 +582,30 @@ var FactoryGuy = {
return adapter instanceof DS.FixtureAdapter;
},
/**
Make new fixture and save to store. If the store is using FixtureAdapter,
will push to FIXTURE array, otherwise will use push method on adapter to load
the record into the store
@param {String} name fixture name
@param {String} trait optional trait names ( one or more )
@param {Object} opts optional fixture options that will override default fixture values
@returns {Object|DS.Model} json or record depending on the adapter type
Deprecated in favor of FactoryGuy.make
*/
makeFixture: function () {
var store = this;
var fixture = FactoryGuy.build.apply(FactoryGuy, arguments);
var name = arguments[0];
var modelName = FactoryGuy.lookupModelForFixtureName(name);
var modelType = store.modelFor(modelName);
if (this.usingFixtureAdapter()) {
this.setAssociationsForFixtureAdapter(modelType, modelName, fixture);
return FactoryGuy.pushFixture(modelType, fixture);
} else {
return store.makeModel(modelType, fixture);
}
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.make instead');
FactoryGuy.make.call(FactoryGuy, arguments)
},
/**
Deprecated in favor of FactoryGuy.makeList
*/
makeList: function () {
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.makeList instead');
FactoryGuy.makeList.call(FactoryGuy, arguments)
},
/**
* Most of the work of making the model from the json fixture is going on here.
* @param modelType
* @param fixture
* @returns {*}
*/
makeModel: function (modelType, fixture) {
var store = this, modelName = store.modelFor(modelType).typeKey, model;
var store = this,
modelName = store.modelFor(modelType).typeKey,
model;

Em.run(function () {
store.findEmbeddedAssociationsForRESTAdapter(modelType, fixture);
if (fixture.type) {
@@ -585,22 +619,6 @@ var FactoryGuy = {
});
return model;
},
/**
Make a list of Fixtures
@param {String} name name of fixture
@param {Number} number number to create
@param {Object} options fixture options
@returns {Array} list of json fixtures or records depending on the adapter type
*/
makeList: function () {
var arr = [];
var number = arguments[1];
for (var i = 0; i < number; i++) {
arr.push(this.makeFixture.apply(this, arguments));
}
return arr;
},
/**
Set the hasMany and belongsTo associations for FixtureAdapter.
@@ -817,11 +835,10 @@ var FactoryGuyTestMixin = Em.Mixin.create({
return this.getStore().find(type, id);
},
/**
Make new fixture and save to store. Proxy to store#makeFixture method
Make new fixture and save to store. Proxy to FactoryGuy#make method
*/
make: function () {
var store = this.getStore();
return store.makeFixture.apply(store, arguments);
return FactoryGuy.make.apply(FactoryGuy, arguments);
},
getStore: function () {
return this.get('container').lookup('store:main');
@@ -842,6 +859,9 @@ var FactoryGuyTestMixin = Em.Mixin.create({
type: options.type || 'GET',
status: options.status || 200
};
if (options.urlParams) {
request.urlParams = options.urlParams;
}
if (options.data) {
request.data = options.data;
}
@@ -868,17 +888,44 @@ var FactoryGuyTestMixin = Em.Mixin.create({
@param {Object} opts optional fixture options
*/
handleFindMany: function () {
var store = this.getStore();
// make the records and load them in the store
store.makeList.apply(store, arguments);
FactoryGuy.makeList.apply(FactoryGuy, arguments);
var name = arguments[0];
var modelName = FactoryGuy.lookupModelForFixtureName(name);
var responseJson = {};
responseJson[modelName] = [];
var url = this.buildURL(modelName);
// mock the ajax call, but return nothing, since the records will be
// retrieved from the store where they were just loaded above
this.stubEndpointForHttpRequest(url, responseJson, { type: 'GET' });
this.stubEndpointForHttpRequest(url, responseJson);
},
/**
Handling ajax GET for finding all records for a type of model with query parameters.
```js
// First build json for the instances you want 'returned' in your query.
var usersJson = FactoryGuy.buildList('user', 2);
// Pass in the parameters you will search on ( in this case 'name' and 'age' ) as an array,
// in the second argument.
testHelper.handleFindQuery('user', ['name', 'age'], usersJson);
store.findQuery('user', {name:'Bob', age: 10}}).then(function(userInstances){
/// userInstances were created from the usersJson that you passed in
})
```
The model instances will be created from the json you have passed in.
@param {String} modelName name of the mode like 'user' for User model type
@param {String} searchParams the parameters that will be queried
@param {Object} json fixture json used to build the resulting modelType instances
*/
handleFindQuery: function (modelName, searchParams, json) {
var responseJson = {};
responseJson[modelName.pluralize()] = json;
var url = this.buildURL(modelName);
this.stubEndpointForHttpRequest(url, responseJson, {urlParams: searchParams});
},
/**
Handling ajax POST ( create record ) for a model. You can mock
Loading