Skip to content

Instantly share code, notes, and snippets.

@danielspaniel
Last active February 22, 2018 01:09
Show Gist options
  • Save danielspaniel/b6f438deb2435a70f7c8a7dfc86b27ba to your computer and use it in GitHub Desktop.
Save danielspaniel/b6f438deb2435a70f7c8a7dfc86b27ba to your computer and use it in GitHub Desktop.
FactoryGuy build/mockFindRecord
import Ember from 'ember';
export default Ember.Controller.extend({
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr('string'),
email: attr('string')
});
import Ember from 'ember';
import {build, mockFindRecord} from 'ember-data-factory-guy';
export default Ember.Route.extend({
model() {
let user = build('user');
mockFindRecord('user').returns({json: user});
return this.store.findRecord('user', user.get('id'));
}
});
<h1>Welcome to Factory Guy build / mockFindRecord </h1>
<br>
User:
<br>
name: {{model.name}}
<br>
email: {{model.email}}
<br>
<br>
import FactoryGuy from 'ember-data-factory-guy';
FactoryGuy.define('user', {
default: {
name: (f) => `name-${f.id}`,
email: (f) => `user-${f.id}@test.com`,
}
});
{
"version": "0.13.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3",
"ember-data-factory-guy": "2.13.27"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment