Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add travis for ci testing

  • Loading branch information...
commit 2267f54a5c9be5ffcd2c748fe71e3e9a3272314b 1 parent 9162ab1
@brownman authored
Showing with 449 additions and 29 deletions.
  1. +4 −0 .travis.yml
  2. 0  .travis.yml~
  3. +2 −0  Gemfile
  4. +3 −0  Gemfile.lock
  5. +1 −1  Gemfile~
  6. +9 −11 Guardfile
  7. +9 −7 Guardfile~
  8. +4 −0 app/assets/javascripts/application.js
  9. +4 −1 app/assets/javascripts/application.js~
  10. +1 −1  app/assets/javascripts/backbone/models/comment.js.coffee~
  11. +86 −0 app/assets/javascripts/backbone/models/task.js
  12. +86 −0 app/assets/javascripts/backbone/models/task.js~
  13. +1 −1  app/views/layouts/application.html.erb
  14. +1 −1  app/views/layouts/application.html.erb~
  15. +1 −1  spec/javascripts/collections/tasks_spec.js
  16. +1 −1  spec/javascripts/foo_spec.js.coffee
  17. +1 −3 spec/javascripts/foo_spec.js.coffee~
  18. +7 −0 spec/javascripts/models/comment_spec.coffee
  19. +8 −0 spec/javascripts/models/comment_spec.coffee~
  20. +1 −0  spec/javascripts/models/task_spec.js
  21. +2 −1  spec/javascripts/models/task_spec.js~
  22. +1 −0  spec/javascripts/views/form_spec.js
  23. +130 −0 spec/javascripts/views/form_spec.js~
  24. +1 −0  spec/javascripts/views/list_spec.js
  25. +57 −0 spec/javascripts/views/list_spec.js~
  26. +1 −0  spec/javascripts/views/task_spec.js
  27. +27 −0 spec/javascripts/views/task_spec.js~
View
4 .travis.yml
@@ -0,0 +1,4 @@
+script: "bundle exec rake db:drop db:create db:migrate db:test:prepare spec"
+
+rvm:
+ - 1.9.3
View
0  .travis.yml~
No changes.
View
2  Gemfile
@@ -1,5 +1,6 @@
source 'https://rubygems.org'
+ruby '1.9.3'
gem 'rails', '3.2.2'
# Bundle edge Rails instead:
@@ -53,6 +54,7 @@ group :development, :test do
gem 'guard-coffeescript'
gem 'guard-livereload'
gem 'sqlite3'
+ gem 'rb-inotify', '~> 0.8.8'
end
View
3  Gemfile.lock
@@ -137,6 +137,8 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
+ rb-inotify (0.8.8)
+ ffi (>= 0.5.0)
rdoc (3.12)
json (~> 1.4)
rspec (2.11.0)
@@ -200,6 +202,7 @@ DEPENDENCIES
pg
rails (= 3.2.2)
rails-backbone (= 0.7.0)
+ rb-inotify (~> 0.8.8)
sass-rails (~> 3.2.3)
sqlite3
thin
View
2  Gemfile~
@@ -48,12 +48,12 @@ gem 'jasmine'
gem 'jasminerice'
group :development, :test do
-
gem 'guard'
gem 'guard-jasmine'
gem 'guard-coffeescript'
gem 'guard-livereload'
gem 'sqlite3'
+ gem 'rb-inotify', '~> 0.8.8'
end
View
20 Guardfile
@@ -1,22 +1,20 @@
+guard :jasmine , :cli => "--drb", :all_on_start => false, :all_after_pass => false do
+ watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
+ watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
+ watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
+end
+
+
guard 'livereload' do
- watch(%r{app/views/.+\.(erb|haml|slim)})
- watch(%r{app/helpers/.+\.rb})
- watch(%r{public/.+\.(css|js|html)})
- watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)/assets/\w+/(.+\.(css|js|html)).*}) { |m| "/assets/#{m[2]}" }
-end
-guard :jasmine do
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
-end
-guard :jasmine do
- watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
- watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
- watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
end
+
+
View
16 Guardfile~
@@ -1,3 +1,10 @@
+guard :jasmine , :cli => "--drb", :all_on_start => false, :all_after_pass => false do
+ watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
+ watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
+ watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
+end
+
+
guard 'livereload' do
@@ -7,16 +14,11 @@ guard 'livereload' do
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)/assets/\w+/(.+\.(css|js|html)).*}) { |m| "/assets/#{m[2]}" }
-end
-guard :jasmine do
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
-end
-guard :jasmine do
- watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
- watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
- watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
end
+
+
View
4 app/assets/javascripts/application.js
@@ -21,3 +21,7 @@
//= require backbone-localstorage
//= require backbone/rails_backbone_relational
//= require_tree .
+
+alert = (msg) ->
+ console.log(this)
+ window.alert(msg)
View
5 app/assets/javascripts/application.js~
@@ -21,4 +21,7 @@
//= require backbone-localstorage
//= require backbone/rails_backbone_relational
//= require_tree .
-alert('app')
+
+alert = (msg) ->
+ console.log(this)
+ alert(msg)
View
2  app/assets/javascripts/backbone/models/comment.js.coffee~
@@ -98,7 +98,7 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
if ( num1 == length_i)
for i in [0...length_i]
this.models[i].array[j..j] = []
- this.models[i].save
+
View
86 app/assets/javascripts/backbone/models/task.js
@@ -0,0 +1,86 @@
+TodoList.Models.Task = Backbone.Model.extend({
+
+ defaults: {
+ name: '',
+ complete: false
+ },
+
+ url: function() {
+ if (this.isNew()) {
+ return "/tasks.json";
+ } else {
+ return "/tasks/" + this.id + ".json";
+ }
+ },
+
+ toJSON: function() {
+ return { task: this.attributes };
+ },
+
+ getId: function() {
+ return this.get('id');
+ },
+
+ getName: function() {
+ return this.get('name');
+ },
+
+ getComplete: function() {
+ return this.get('complete');
+ },
+ replace :function(str, sym) {
+ for (var i = 0; i < sym.length ; i++) {
+ str = this.replace_one(str, sym[i]);
+ //str.replace(sym[i], sym[i].concat('='));
+ }
+
+ //.replace(",", ",=");
+ return str;
+ },
+ replace_one : function(story,sign)
+ {
+ //sign = "."
+ var to_sign = sign + "$"
+ var from="[" + sign + "]"
+ var from_reg = new RegExp(from,"g");
+
+ var str = story.replace(from_reg , to_sign);
+ return str;
+ },
+
+ split : function(){
+var str = this.get('name')
+ var story_enc = str
+
+ story_enc = story_enc.replace(/\n/g, " ");
+
+ var arr_symbols = [',', '!', '.', "?", ":", ";", "=" ]
+ story_enc = this.replace(story_enc, arr_symbols);
+
+
+
+ //split replace
+ var story_arr = story_enc.split('$');
+
+ // console.log(story_arr);
+
+ //each symbol to replace str
+ // this.trace(story_arr);
+ return story_arr
+
+ }
+
+
+
+
+});
+TodoList.Collections.Tasks = Backbone.Collection.extend({
+
+ url: '/tasks.json',
+ model: TodoList.Models.Task,
+
+ parse: function(response) {
+ return response.tasks;
+ }
+
+});
View
86 app/assets/javascripts/backbone/models/task.js~
@@ -0,0 +1,86 @@
+TodoList.Models.Task = Backbone.Model.extend({
+
+ defaults: {
+ name: '',
+ complete: false
+ },
+
+ url: function() {
+ if (this.isNew()) {
+ return "/tasks.json";
+ } else {
+ return "/tasks/" + this.id + ".json";
+ }
+ },
+
+ toJSON: function() {
+ return { task: this.attributes };
+ },
+
+ getId: function() {
+ return this.get('id');
+ },
+
+ getName: function() {
+ return this.get('name');
+ },
+
+ getComplete: function() {
+ return this.get('complete');
+ },
+ replace :function(str, sym) {
+ for (var i = 0; i < sym.length ; i++) {
+ str = this.replace_one(str, sym[i]);
+ //str.replace(sym[i], sym[i].concat('='));
+ }
+
+ //.replace(",", ",=");
+ return str;
+ },
+ replace_one : function(story,sign)
+ {
+ //sign = "."
+ var to_sign = sign + "$"
+ var from="[" + sign + "]"
+ var from_reg = new RegExp(from,"g");
+
+ var str = story.replace(from_reg , to_sign);
+ return str;
+ },
+
+ split : function(){
+var str = this.get('name')
+ var story_enc = str
+
+ story_enc = story_enc.replace(/\n/g, " ");
+
+ var arr_symbols = [',', '!', '.', "?", ":", ";", "=" ]
+ story_enc = this.replace(story_enc, arr_symbols);
+
+
+
+ //split replace
+ var story_arr = story_enc.split('$');
+
+ // console.log(story_arr);
+
+ //each symbol to replace str
+ // this.trace(story_arr);
+ return story_arr
+
+ }
+
+
+
+
+});
+TodoList.Collections.Tasks = Backbone.Collection.extend({
+
+ url: '/tasks.json',
+ model: TodoList.Models.Task,
+
+ parse: function(response) {
+ return response.tasks;
+ }
+
+});
View
2  app/views/layouts/application.html.erb
@@ -6,7 +6,7 @@
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
- <meta name="viewport" content="width=device-width,initial-scale=1" />
+ <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
</head>
View
2  app/views/layouts/application.html.erb~
@@ -6,7 +6,7 @@
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
- <meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1, user-scalable=no" />
+ <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
</head>
View
2  spec/javascripts/collections/tasks_spec.js
@@ -1,3 +1,4 @@
+return;
describe('TodoList.Collections.Tasks', function() {
it('should be defined', function() {
@@ -13,7 +14,6 @@ describe('TodoList.Collections.Tasks', function() {
describe('#fetch', function() {
- alert('collection')
var server = null;
beforeEach(function() {
server = sinon.fakeServer.create();
View
2  spec/javascripts/foo_spec.js.coffee
@@ -1,5 +1,5 @@
# use require to load any .js file available to the asset pipeline
-
+return;
describe "Foo", ->
loadFixtures 'baz' # located at 'spec/javascripts/fixtures/baz.html.haml'
it "it is not bar", ->
View
4 spec/javascripts/foo_spec.js.coffee~
@@ -1,7 +1,5 @@
# use require to load any .js file available to the asset pipeline
-#= require foo
-#= require bar
-return
+
describe "Foo", ->
loadFixtures 'baz' # located at 'spec/javascripts/fixtures/baz.html.haml'
it "it is not bar", ->
View
7 spec/javascripts/models/comment_spec.coffee
@@ -0,0 +1,7 @@
+describe "MyGame", ->
+ beforeEach ->
+ @comment = new RailsBackboneRelational.Models.Comment({content: 'a,b,c'})
+
+ it "should have two players", ->
+ expect(@comment.array).toEqual ['a,','b,','c']
+
View
8 spec/javascripts/models/comment_spec.coffee~
@@ -0,0 +1,8 @@
+describe "MyGame", ->
+ beforeEach ->
+ @comment = new RailsBackboneRelational.Models.Comment({content: 'a,b,c'})
+
+ it "should have two players", ->
+ alert('game1')
+ expect(@comment.array).toEqual ['a,','b,','c']
+
View
1  spec/javascripts/models/task_spec.js
@@ -1,3 +1,4 @@
+return;
describe('TodoList.Models.Task', function() {
it('should be defined', function() {
View
3  spec/javascripts/models/task_spec.js~
@@ -1,7 +1,8 @@
+return;
describe('TodoList.Models.Task', function() {
it('should be defined', function() {
- expect(TodoList.Models.Taskii).toBeDefined();
+ expect(TodoList.Models.Task).toBeDefined();
});
var task;
View
1  spec/javascripts/views/form_spec.js
@@ -1,3 +1,4 @@
+return;
describe('TodoList.Views.Form', function() {
it('should be defined', function() {
View
130 spec/javascripts/views/form_spec.js~
@@ -0,0 +1,130 @@
+describe('TodoList.Views.Form', function() {
+
+ it('should be defined', function() {
+ expect(TodoList.Views.Form).toBeDefined();
+ });
+
+ var view, $fixture, collection;
+
+ beforeEach(function() {
+ loadFixtures('form-fixture.html');
+ $fixture = $('#form-fixture');
+ collection = new TodoList.Collections.Tasks();
+
+ view = new TodoList.Views.Form({ el: $fixture, collection: collection });
+ });
+
+ describe('events', function() {
+ it('should handle click event on submit button', function() {
+ expect(view.events['click button.submit']).toEqual('submit');
+ });
+ });
+
+ describe('#getInputFor', function () {
+ it('should return form input for given name', function () {
+ expect(view.getInputFor('name')).toBe($fixture.find('input'));
+ });
+ });
+
+ describe('#getAttributes', function () {
+ it('should be defined', function() {
+ expect(view.getAttributes).toBeDefined();
+ });
+
+ it('should return valid attributes', function () {
+ $fixture.find('input').val('Do something');
+ var attributes = view.getAttributes();
+
+ expect(attributes).toBeDefined();
+ expect(attributes.name).toBeDefined();
+ expect(attributes.name).toEqual('Do something');
+ });
+ });
+
+ describe('#submit', function() {
+ it('should be defined', function() {
+ expect(view.submit).toBeDefined();
+ });
+
+ var server;
+ beforeEach(function () {
+ server = sinon.fakeServer.create();
+ });
+
+ afterEach(function() {
+ server.restore();
+ });
+
+ it('should prevent default action', function() {
+ var event = { preventDefault: function() {} };
+ var mock = sinon.mock(event).expects('preventDefault').once();
+ view.submit(event);
+ mock.verify();
+ });
+
+ describe('sent request', function () {
+ it('should send valid attributes to the server', function () {
+ $fixture.find('input').val('New task name');
+ view.submit();
+
+ var request = server.requests[0];
+ expect(request).toHaveMethod('POST');
+ expect(request).toHaveUrl('/tasks.json');
+
+ var attributes = JSON.parse(request.requestBody);
+ expect(attributes.task).toBeDefined();
+ expect(attributes.task.name).toBeDefined();
+ expect(attributes.task.name).toEqual('New task name');
+ });
+ });
+
+ describe('on success', function () {
+ beforeEach(function () {
+ var fixtures = {};
+ server.respondWith('POST', '/tasks.json',
+ [
+ 200,
+ { "Content-Type": "application/json" },
+ JSON.stringify(fixtures)
+ ]
+ );
+ });
+
+ it('should clear the form input', function () {
+ var $nameInput = $fixture.find('input');
+ $nameInput.val('New task name');
+
+ view.submit();
+ expect($nameInput).toHaveValue('New task name');
+
+ server.respond();
+ expect($nameInput).toHaveValue('');
+ });
+ });
+
+ describe('on error', function () {
+ beforeEach(function () {
+ server.respondWith('POST', '/tasks.json',
+ [
+ 422,
+ { "Content-Type": "application/json" },
+ JSON.stringify({ errors: { name: "can't be blank" } })
+ ]
+ );
+ });
+
+ it('should display validation messages', function () {
+ var $nameInput = $fixture.find('input');
+ $nameInput.val('');
+
+ var mock = sinon.mock(window).expects('alert').withArgs("Task name can't be blank");
+
+ view.submit();
+ server.respond();
+
+ mock.verify();
+ });
+ });
+ });
+
+});
View
1  spec/javascripts/views/list_spec.js
@@ -1,3 +1,4 @@
+return;
describe('TodoList.Views.List', function () {
it('should be defined', function() {
View
57 spec/javascripts/views/list_spec.js~
@@ -0,0 +1,57 @@
+describe('TodoList.Views.List', function () {
+
+ it('should be defined', function() {
+ expect(TodoList.Views.List).toBeDefined();
+ });
+
+ var collection, view;
+
+ beforeEach(function () {
+ collection = new Backbone.Collection();
+ view = new TodoList.Views.List({ collection: collection });
+ });
+
+ describe('collection', function () {
+ var event = { preventDefault: function() {} };
+
+ describe('on reset event', function () {
+ it('should call render', function() {
+ var spy = sinon.spy(collection, 'on');
+ view.initialize();
+
+ expect(spy.called).toBeTruthy();
+ expect(spy.calledWith(event, view.render, view));
+ });
+ });
+
+ describe('on add event', function () {
+ it('should call render', function() {
+ var spy = sinon.spy(collection, 'on');
+ view.initialize();
+
+ expect(spy.called).toBeTruthy();
+ expect(spy.calledWith(event, view.appendTask, view));
+ });
+ });
+ });
+
+ describe('#render', function() {
+ it('should render tasks', function() {
+ var tasks = [
+ new TodoList.Models.Task({id: 11, name: 'First task', complete: true}),
+ new TodoList.Models.Task({id: 12, name: 'Second task', complete: false})
+ ];
+
+ collection.models = tasks;
+
+ var $el = view.render().$el;
+
+ expect($el).toContain('table.table.table-striped');
+ expect($el.find('tr').length).toEqual(tasks.length);
+
+ expect($el.find('tr:nth(0) td:nth(1)')).toHaveText('First task');
+ expect($el.find('tr:nth(1) td:nth(1)')).toHaveText('Second task');
+ });
+ });
+
+});
View
1  spec/javascripts/views/task_spec.js
@@ -1,3 +1,4 @@
+return;
describe('TodoList.Views.Task', function () {
it('should be defined', function() {
expect(TodoList.Views.Task).toBeDefined();
View
27 spec/javascripts/views/task_spec.js~
@@ -0,0 +1,27 @@
+describe('TodoList.Views.Task', function () {
+ it('should be defined', function() {
+ expect(TodoList.Views.Task).toBeDefined();
+ });
+
+ var task, view;
+
+ beforeEach(function () {
+ task = { id: 11, getName: function() {} };
+ view = new TodoList.Views.Task({ model: task });
+ });
+
+ describe('render', function() {
+ it('should render the task', function() {
+ sinon.mock(task).expects('getName').returns('Some task name');
+
+ var $el = view.render().$el;
+
+ expect($el).toBeDefined();
+ expect($el).toBe('tr');
+
+ expect($el.find('td').length).toEqual(3);
+ expect($el.find('td:nth(0)')).toHaveText('#11');
+ expect($el.find('td:nth(1)')).toHaveText('Some task name');
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.