Created
January 25, 2013 15:50
-
-
Save anonymous/4635437 to your computer and use it in GitHub Desktop.
angular and coffeescript in rails
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
// app/assets/javascripts/ng_app/controllers.js | |
function PostListCtrl($scope) { | |
$scope.posts = [ | |
{ "title": "My First Post", "intro": "Subtitle of my post" }, | |
{ "title": "Another Post", "intro": "Something interesting about this post" }, | |
{ "title": "One More Thng", "intro": "There's always something more" } | |
] | |
} | |
// this runs correctly in the browser |
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
# app/assets/javascripts/ng_app/controllers.js.coffee (replaces the js version) | |
app = angular.module 'myapp', [] | |
$ -> | |
angular.bootstrap $("#myapp"), ["myapp"] | |
app.controller "PostListCtrl", ($scope) -> | |
$scope.posts = [ | |
{ "title": "My First Post", "intro": "Subtitle of my post" }, | |
{ "title": "Another Post", "intro": "Something interesting about this post" }, | |
{ "title": "One More Thng", "intro": "There's always something more" } | |
] | |
# note, I had to manually bootstrap it to get it to work | |
# on the page, replaced <div ng-app> with <div id="myapp"> | |
# it runs correctly in the browser | |
# but the test reports | |
# ReferenceError: PostListCtrl is not defined in http://localhost:3000/assets/controllers_spec.js?body=1 (line 7) | |
# how do i get the tests to find it? |
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
# spec/javascripts/controllers_spec.coffee | |
describe 'myapp controllers', -> | |
describe 'PostListCtrl', -> | |
it 'creates "posts" model with 3 posts', -> | |
scope = {} | |
ctrl = new PostListCtrl(scope) | |
expect(scope.posts.length).toBe(3) | |
# this passes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment