Skip to content

Instantly share code, notes, and snippets.

@aaronfischer
Forked from samselikoff/mirage.config.js
Last active January 19, 2018 17:39
Show Gist options
  • Save aaronfischer/c82a4fb0394ab9aae996115f1d6197bc to your computer and use it in GitHub Desktop.
Save aaronfischer/c82a4fb0394ab9aae996115f1d6197bc to your computer and use it in GitHub Desktop.
mirage reflexive - include error
import DS from 'ember-data';
import UrlTemplates from 'ember-data-url-templates';
export default DS.JSONAPIAdapter.extend(UrlTemplates, {
host: '',
namespace: 'api',
urlTemplate: '{+host}/{+namespace}/{pathForType}{/id}',
});
import Ember from 'ember';
export default Ember.Controller.extend({
});
import Mirage from 'ember-cli-mirage';
export default function() {
this.namespace = '/api';
//window.server = this;
this.get('users/:id', function () {
return new Mirage.Response(404, {});
});
};
import { Factory, faker } from 'ember-cli-mirage';
export default Factory.extend({
name() {
return faker.name.findName();
},
afterCreate(user, server) {
if (user.thingIds.length === 0) {
let size = faker.random.number({ min: 1, max: 3 });
for (let i = size; i >= 0; i--) {
let userThing = server.create('user_thing', {
user: user,
thingId: i + 1,
});
let thingIds = user.thingIds;
thingIds.push(threadThing.id)
user.update('thingIds', thingIds);
}
}
}
});
export default [
{
id: 1,
createdById: 1,
updatedById: 1,
name: 'Categories',
key: 'categories',
isActive: true,
isNested: false,
count: 5,
updatedAt: '2020-01-01T00:00:00+00:00',
createdAt: '2020-01-01T00:00:00+00:00',
},
{
id: 2,
createdById: 1,
updatedById: 1,
name: 'Series',
key: 'series',
isActive: true,
isNested: false,
count: 10,
updatedAt: '2020-01-01T00:00:00+00:00',
createdAt: '2020-01-01T00:00:00+00:00',
},
{
id: 3,
createdById: 1,
updatedById: 1,
name: 'Authors',
key: 'authors',
isActive: true,
isNested: false,
count: 3,
updatedAt: '2020-01-01T00:00:00+00:00',
createdAt: '2020-01-01T00:00:00+00:00',
},
{
id: 4,
createdById: 1,
updatedById: 1,
childrenIds: ['5', '6'],
name: 'Taxonomy',
key: 'taxonomy',
isActive: true,
isNested: true,
count: 2,
updatedAt: '2020-01-01T00:00:00+00:00',
createdAt: '2020-01-01T00:00:00+00:00',
},
{
id: 5,
createdById: 1,
updatedById: 1,
parentId: 4,
name: 'Nested Taxonomy',
key: 'nested-taxonomy',
isActive: true,
isNested: false,
count: 0,
updatedAt: '2020-01-01T00:00:00+00:00',
createdAt: '2020-01-01T00:00:00+00:00',
},
{
id: 6,
createdById: 1,
updatedById: 1,
parentId: 4,
name: 'Secondary Taxonomy',
key: 'secondary-taxonomy',
isActive: true,
isNested: false,
count: 0,
updatedAt: '2020-01-01T00:00:00+00:00',
createdAt: '2020-01-01T00:00:00+00:00',
},
];
import { Model } from 'ember-cli-mirage';
export default Model.extend({
});
import { Model, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
typeKey: 'user/thing',
user: belongsTo(),
});
export default function(server) {
// added this line because global wasn't created otherwise.
server.create('user');
}
import { JSONAPISerializer } from 'ember-cli-mirage';
export default JSONAPISerializer.extend({
});
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr()
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
user: belongsTo(),
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findRecord('user', 1);
},
actions: {
error(error) {
console.log('error', error);
},
},
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findRecord('user', 1);
}
});
body {
margin: 0;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
h1 {
font-size: 12px;
font-weight: bold;
text-align: center;
text-shadow: none;
background: #2e4068;
color: white;
padding: 20px;
margin: 0;
text-transform: uppercase;
}
p {
font-weight: normal;
}
.pa4 {
padding: 20px;
}
<h1>Mirage boilerplate</h1>
<div class='pa4'>
<p>Welcome <strong>{{model.name}}</strong>!</p>
<p>Hi</p>
</div>
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Users');
test('I can see the users', function(assert) {
server.create('user', { name: 'Link' });
//visit('/');
andThen(function() {
assert.ok(true);
//assert.ok(find(':contains(Welcome Link!)').length);
});
});
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import { module } from 'qunit';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
if (options.beforeEach) {
options.beforeEach.apply(this, arguments);
}
},
afterEach() {
if (options.afterEach) {
options.afterEach.apply(this, arguments);
}
destroyApp(this.application);
}
});
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
export default function startApp(attrs) {
let application;
let attributes = Ember.merge({rootElement: "#test-root"}, config.APP);
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
Ember.run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.10.4",
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"EmberENV": {
"FEATURES": {
"ds-finder-include": true
}
},
"options": {
"use_pods": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
},
"addons": {
"ember-cli-mirage": "0.4.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment