Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ember on Rails

Tom Kruijsen
February 04, 2014

Ember on Rails

A quick overview of some useful tools for getting Ember running nice and smooth within a Rails app. Topics included are: setting up Ember, creating an API, and testing.

Tom Kruijsen

February 04, 2014
Tweet

More Decks by Tom Kruijsen

Other Decks in Programming

Transcript

  1. API

  2. {! "cats": [! {! "id": 1,! "name": "Mimi",! "picture_ids": [!

    2, 3! ]! },! {! "id": 2,! "name": "Sammie",! "picture_ids": [! 2, 3! ]! }! ],! "pictures": [! {! "id": 2,! "url": "http://s3-eu-west-1.amazonaws.com/catstagram-pics/2.png"! },! {! "id": 3,! "url": "http://s3-eu-west-1.amazonaws.com/catstagram-pics/3.png"! }! ]! }
  3. #= require 'sinon'! #= require 'application'! ! mocha.ui('bdd')! mocha.globals(['Ember', 'DS',

    'Catstagram', 'MD5'])! mocha.timeout(5)! chai.Assertion.includeStack = true! ! ENV = {! TESTING: true! }! ! window.server = sinon.fakeServer.create()! ! window.testHelper =! lookup: (object, object_name) ->! name = object_name || "main"! Catstagram.__container__.lookup(object + ":" + name)! ! Catstagram.Router.reopen! location: 'none'! ! Konacha.reset = Ember.K! ! Catstagram.setupForTesting()! Catstagram.injectTestHelpers()! ! beforeEach ->! Ember.run ->! Catstagram.reset()! ! Ember.Test.adapter = Ember.Test.Adapter.create()
  4. #= require 'spec_helper'! ! describe 'Cats page', ->! beforeEach ->!

    cat = Ember.Object.create! id: 1! name: 'Mimi'! ! stubStore = sinon.stub(testHelper.lookup('store'), 'find')! stubStore.withArgs('cat').returns([cat])! ! ! visit '/'! ! it 'shows the names of the cats', ->! expect($('li').text()).to.equal('Mimi')! ! it 'links to a cat page', ->! mock = sinon.mock(testHelper.lookup('route', 'cats_cat'))! mock.expects('setupController').once()! $('a').click()! mock.verify()