Forked from mike-north/controllers.application.js
Last active
February 13, 2019 20:53
-
-
Save saranya-vatti/1f53c7bfb3cad87a08dd0c263dfa95a9 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' | |
}); | |
let myCourse = Course.create(); | |
myCourse.set('description', 'In this course, we\'ll learn about cats!'); | |
alert(myCourse.languageName('js')); |
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 { run } from '@ember/runloop'; | |
export default function destroyApp(application) { | |
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.autoboot = true; | |
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
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 does not result in it being added to all courses\ncourse1.get("tags").addObject("a");\nshould not additionally add the tag "a" to course2'); | |
}); | |
test('Getting a language from a language ID', function(assert) { | |
let course = Course.create(); | |
assert.ok(typeof course.languageName === 'undefined', 'There should NOT be a function "languageName" on the course instance.\nThe proper place for this function is on the course class (using Ember.Object#reopenClass)'); | |
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": false | |
}, | |
"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" | |
* | |
* Keep in mind that this function needs to be on the | |
* class, not on instances of the class. | |
*/ | |
const Course = Ember.Object.extend({ | |
'title': 'No Title', | |
'description': '', | |
'tags': [], | |
languageName(langAbbr) { | |
switch(langAbbr) { | |
case 'js': | |
return 'JavaScript'; | |
default: | |
'Unknown'; | |
} | |
} | |
}); | |
export default Course; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment