Created
March 31, 2017 15:19
-
-
Save bmac/3a2db002c1d423d7801708d9aa5000f6 to your computer and use it in GitHub Desktop.
debug 4907
This file contains 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.JSONAPIAdapter.extend({ | |
urlForFindAll(modelName, snapshot) { | |
const options = snapshot.adapterOptions; | |
let query = '?'; | |
if (options) { | |
Object.keys(options).forEach(function (key) { | |
query += `&${key}=${options[key]}`; | |
}); | |
} | |
return `${this._buildURL(modelName)}${query}`; | |
} | |
}); |
This file contains 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 function returnJSON(status, body) { | |
return json(...arguments); | |
}; | |
export function json(status, body) { | |
if (arguments.length === 1) { | |
body = status; | |
status = 200; | |
} | |
return [ | |
status, | |
{ "Content-Type": "application/json" }, | |
JSON.stringify(body) | |
]; | |
}; | |
export const server = new Pretender(); | |
export function initialize() { | |
server.handledRequest = function(verb, path, request) { | |
console.log(`handled request to ${verb} ${path}`); | |
} | |
server.unhandledRequest = function(verb, path, request) { | |
console.log(`undhandled request ${verb} ${path}`); | |
} | |
}; | |
export default { | |
name: 'pretender', | |
initialize | |
}; |
This file contains 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"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
title: DS.attr('string'), | |
author: DS.belongsTo('author', { async: false }) | |
}); |
This file contains 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 { server, json } from '../initializers/pretender'; | |
server.map(function() { | |
this.get('/authors', function() { | |
return json({ | |
data: [ | |
{ | |
id: 1, | |
type: 'author', | |
attributes: { | |
name: "Mark Twain", | |
"books-signed": 456 | |
}, | |
relationships: { | |
books: { | |
data: [{ | |
id: 1, | |
type: 'book' | |
}] | |
} | |
} | |
}, | |
{ | |
id: 2, | |
type: 'author', | |
attributes: { | |
name: "Ernest Hemingway", | |
"books-signed": 3 | |
}, | |
relationships: { | |
books: { | |
data: [{ | |
id: 2, | |
type: 'book' | |
},{ | |
id: 3, | |
type: 'book' | |
}] | |
} | |
} | |
}, | |
{ | |
id: 3, | |
type: 'author', | |
attributes: { | |
name: "Stephen King", | |
"books-signed": 15021 | |
}, | |
relationships: { | |
books: { | |
data: [{ | |
id: 4, | |
type: 'book' | |
},{ | |
id: 5, | |
type: 'book' | |
},{ | |
id: 6, | |
type: 'book' | |
}] | |
} | |
} | |
} | |
], | |
included: [ | |
{ | |
id: 1, | |
type: 'book', | |
attributes: { | |
title: 'Tom Sawyer' | |
} | |
}, | |
{ | |
id: 2, | |
type: 'book', | |
attributes: { | |
title: 'A Farewell To Arms' | |
} | |
}, | |
{ | |
id: 3, | |
type: 'book', | |
attributes: { | |
title: 'The Old Man And the Sea' | |
} | |
}, | |
{ | |
id: 4, | |
type: 'book', | |
attributes: { | |
title: 'The Shining' | |
} | |
}, | |
{ | |
id: 5, | |
type: 'book', | |
attributes: { | |
title: 'The Stand' | |
} | |
}, | |
{ | |
id: 6, | |
type: 'book', | |
attributes: { | |
title: 'The Long Walk' | |
} | |
} | |
] | |
}); | |
}); | |
}); | |
export default Ember.Route.extend({ | |
model: function() { | |
return this.get('store').findAll('author', { adapterOptions: { classics: true }}); | |
} | |
}); |
This file contains 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 Serializer from "ember-data/serializers/json-api"; | |
export default Serializer.extend(); |
This file contains 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 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 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'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
This file contains 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 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.4", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "release", | |
"ember-data": "release", | |
"ember-template-compiler": "release", | |
"route-recognizer": "https://rawgit.com/tildeio/route-recognizer/56f5fcec6ae58d8e86b5dc77609809fb91198142/dist/route-recognizer.js", | |
"FakeXMLHttpRequest": "https://rawgit.com/pretenderjs/FakeXMLHttpRequest/23c3a96b5b24f1bfe595867437e4f128a29c2840/fake_xml_http_request.js", | |
"pretender": "https://rawgit.com/pretenderjs/pretender/c6de9afe18b1472aded2592f5a80ad9a26a0e262/pretender.js" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment