Last active
April 11, 2016 02:43
-
-
Save pangratz/7db2eed0eabc99de29f4 to your computer and use it in GitHub Desktop.
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({ | |
urlForCreateRecord: function(type, snapshot) { | |
var url = this._super(...arguments); | |
var includes = snapshot.adapterOptions.includes; | |
if (includes) { | |
url += `?includes=${includes}`; | |
} | |
return url; | |
} | |
}); |
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.post('/survey-answers?', function(request) { | |
var result = { | |
data: { | |
type: 'survey-answer', | |
id: 1, | |
relationships: { | |
answer: { | |
links: { | |
related: "/survey-answers/1/answer", | |
self: "/survey-answers/1/relationships/master-answer" | |
} | |
} | |
} | |
} | |
}; | |
if (request.queryParams.includes) { | |
result.data.relationships.answer.data = { | |
id: 1, | |
type: "answer" | |
} | |
} | |
return json(result); | |
}); | |
}); | |
export default Ember.Route.extend({ | |
model: function() { | |
let answer = this.store.push({ | |
data: { | |
type: 'answer', | |
id: 1, | |
attributes: { | |
text: "Le answer" | |
} | |
} | |
}); | |
return this.store.createRecord('survey-answer', { | |
answer | |
}); | |
}, | |
actions: { | |
save: function(surveyAnswer) { | |
surveyAnswer.save({ | |
adapterOptions: { | |
includes: "answer" | |
} | |
}).then((result) => { | |
console.log(result.get("answer.text")); | |
}); | |
} | |
} | |
}); |
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}`); | |
} | |
server.map(function() { | |
this.get('/people', returnJSON({ | |
data: [] | |
})); | |
}); | |
}; | |
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 DS from 'ember-data'; | |
export default DS.Model.extend({ | |
text: DS.attr() | |
}); |
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.Model.extend({ | |
answer: DS.belongsTo() | |
}); |
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.4.17", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.2.0", | |
"ember-data": "2.2.1", | |
"ember-template-compiler": "2.2.0", | |
"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" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment