-
-
Save scalvert/0666538d84f9284c0d146630bcd8c0a8 to your computer and use it in GitHub Desktop.
EmberLearn - Ember.Object
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 Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
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 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
import { module, test } from 'qunit'; | |
if (require.entries['twiddle/utils/course']) { | |
module('Ember.Object | Modeling Data'); | |
const Course = require('twiddle/utils/course').default; | |
// Replace this with your real tests. | |
test('Correct defaults for data', function(assert) { | |
let course = Course.create(); | |
assert.equal(course.get('title'), 'No Title', 'title defaults to "No Title"'); | |
assert.equal(course.get('description'), '', 'description defaults to empty string'); | |
assert.deepEqual(course.get('tags'), [], 'tags defaults to empty array'); | |
}); | |
test('Adding and removing tags', function(assert) { | |
let course = Course.create(); | |
let otherCourse = Course.create(); | |
course.get('tags').addObject('front end'); | |
assert.equal(otherCourse.get('tags').length, 0, 'Adding tags to a course doesn not result in it being added to all courses'); | |
}); | |
test('Getting a language from a language ID', function(assert) { | |
assert.equal(Course.languageName('js'), 'JavaScript', 'Course.languageName("js") returns "JavaScript"'); | |
assert.equal(Course.languageName(null), 'Unknown', 'Course.languageName() returns "Unknown"'); | |
}); | |
} |
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.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
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'; | |
/** | |
* Requirements | |
* | |
* I want to be able to create an instance of | |
* this new type of object | |
* | |
* let myCourse = Course.create(); | |
* | |
* and then we should be able to get and set | |
* serveral properties (title, description, tags) | |
* on this instance | |
* | |
* myCourse.set('description', 'In this course, we'll learn about cats!') | |
* | |
* Additionally, you need to make a class method | |
* for taking abbreviated programming language | |
* names, and expanding them. | |
* | |
* Course.languageName('js') // returns "JavaScript" | |
* | |
*/ | |
const Course = Ember.Object.extend({ | |
title: 'No Title', | |
description: '', | |
tags: null, | |
init() { | |
this.set('tags', []); | |
} | |
}); | |
Course.reopenClass({ | |
languageName(language) { | |
switch (language) { | |
case 'js': | |
return 'JavaScript'; | |
case 'py': | |
return 'Python'; | |
default: | |
return 'Unknown'; | |
} | |
} | |
}); | |
export default Course; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment