Forked from samselikoff/controllers.application.js
Last active
January 26, 2017 21:42
-
-
Save dylankb/13dd2b66a6290bf0f502e37096743391 to your computer and use it in GitHub Desktop.
Mirage 0.3 - Many to Many
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
db: Ember.computed('refreshDb', function() { | |
let dump = window.server.schema.db.dump(); | |
return JSON.stringify(dump, null, 2); | |
}), | |
actions: { | |
toggleIsShowingDatabase() { | |
this.toggleProperty('isShowingDatabase'); | |
}, | |
refreshDb() { | |
this.incrementProperty('refreshDb'); | |
}, | |
deleteModel(model) { | |
model.destroyRecord(); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Mirage from 'ember-cli-mirage'; | |
export default function() { | |
window.server = this; | |
this.get('users/:id'); | |
this.delete('users/:id'); | |
this.delete('apps/:id'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Model, hasMany, belongsTo } from 'ember-cli-mirage'; | |
export default Model.extend({ | |
collaborator: belongsTo( 'user', { inverse: 'sharedApps' }), | |
owner: belongsTo('user', { inverse: 'ownedApps' }) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Model, hasMany } from 'ember-cli-mirage'; | |
export default Model.extend({ | |
sharedApps: hasMany( 'app', { inverse: 'collaborator' }), | |
ownedApps: hasMany('app', { inverse: 'owner' }), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function(server) { | |
let jdoe = server.create('user', { | |
name: 'John Doe' | |
}); | |
let jsnow = server.create('user', { | |
name: 'Jane Snow' | |
}); | |
server.create('app', { | |
collaborator: jdoe, | |
owner: jdoe, | |
name: 'Skylight' | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { JSONAPISerializer } from 'ember-cli-mirage'; | |
export default JSONAPISerializer.extend({ | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
name: DS.attr(), | |
collaborator: DS.belongsTo( 'user', { inverse: 'sharedApps' }), | |
owner: DS.belongsTo('user', { inverse: 'ownedApps' }), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
export default Model.extend({ | |
name: DS.attr(), | |
sharedApps: DS.hasMany( 'app', { inverse: 'collaborator' }), | |
ownedApps: DS.hasMany('app', { inverse: 'owner' }), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.store.findRecord('user', 1, { | |
include: 'apps' | |
}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 0; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
header { | |
background: #2e4068; | |
color: white; | |
padding: 14px 20px; | |
} | |
h1 { | |
font-size: 12px; | |
font-weight: bold; | |
text-shadow: none; | |
margin: 0 0 2px; | |
text-transform: uppercase; | |
opacity: 0.5; | |
} | |
h2 { | |
font-size: 16px; | |
margin: 0; | |
} | |
p { | |
font-weight: normal; | |
} | |
.pa4 { | |
padding: 20px; | |
} | |
.ph4 { | |
padding-left: 20px; | |
padding-right: 20px; | |
} | |
hr { | |
border-top: none; | |
border-bottom: 1px solid #ddd; | |
} | |
.panel { | |
background: whitesmoke; | |
} | |
.panel__toggle { | |
display: block; | |
text-decoration: none; | |
padding: 8px; | |
color: #777; | |
} | |
.panel__body { | |
padding: 8px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.10.7", | |
"ENV": { | |
"ember-cli-mirage": { | |
"enabled": true | |
} | |
}, | |
"EmberENV": { | |
"FEATURES": { | |
"ds-finder-include": true | |
} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.10.0", | |
"ember-data": "2.10.0", | |
"ember-template-compiler": "2.10.0", | |
"ember-testing": "2.10.0" | |
}, | |
"addons": { | |
"ember-cli-mirage": "0.3.0-beta.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment