WSO2's API Vision: Unifying Control, Empowering Developers
Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)
1.
2.
3. DAWNING OF THE AGE OF ANGULARJS
• client-side javascript MVC
framework
• makes use of
directives, dependency
injection, and data binding
• “reasonable magic”, like Rails
• http://angularjs.org/
• by Google
4. ANGULAR.JS
Directives
• Domain specific HTML syntax, reusable
Dependency Injection
• Declarative description how app is wired (de-centralized)
Data Binding
• Automatic updating the view whenever model changes
Community
• Documentation, tutorials, testable, ecosystem
13. TESTING WITH JASMINE AND TEASPOON
Gemfile
gem 'teaspoon’
gem 'phantomjs'
spec/javascripts/support/spec_helper.js
//= require angular-mocks
Run
browse to http://localhost:3000/teaspoon or rake teaspoon
15. SPEC EXAMPLE
it 'creates posts model with index request', ->
$httpBackend.expect('GET', '/posts').respond($fixture)
$controller(PostsCtrl, {$scope: $scope }) //instantiate controller
expect($scope.posts).toEqualData []
$httpBackend.flush()// mock the ajax success
expect($scope.posts.length).toBe 2
expect($scope.posts).toEqualData $fixture
Instantiate a PostsCntlThe posts model inside the controller (scope.posts) starts out as empty (null). When we call $httpBackend.flush(), the mock acts like its completed the asynchronous call. When its done, scope.posts will be populated with the fixture data.