Commit 39ec5d1a97040fdfa952a67917db082ad0d4885d

Authored by Heitor
1 parent 8420f609

Continued implementation of repository branch javascript tests

Also added a new gem for javascript mocks

Signed-off-by: Daniel Miranda <danielkza2@gmail.com>
@@ -113,6 +113,9 @@ group :development, :test do @@ -113,6 +113,9 @@ group :development, :test do
113 gem 'i18n_generators' 113 gem 'i18n_generators'
114 114
115 gem 'sprockets', '~>2.12.3' # spckets 3.0.3 breaks konacha 115 gem 'sprockets', '~>2.12.3' # spckets 3.0.3 breaks konacha
  116 +
  117 + # Mocks and stubs for javascript tests
  118 + gem 'sinon-rails'
116 end 119 end
117 120
118 # Acceptance tests 121 # Acceptance tests
@@ -283,6 +283,8 @@ GEM @@ -283,6 +283,8 @@ GEM
283 json (~> 1.8) 283 json (~> 1.8)
284 simplecov-html (~> 0.10.0) 284 simplecov-html (~> 0.10.0)
285 simplecov-html (0.10.0) 285 simplecov-html (0.10.0)
  286 + sinon-rails (1.10.3)
  287 + railties (>= 3.1)
286 spring (1.3.6) 288 spring (1.3.6)
287 sprockets (2.12.3) 289 sprockets (2.12.3)
288 hike (~> 1.2) 290 hike (~> 1.2)
@@ -367,6 +369,7 @@ DEPENDENCIES @@ -367,6 +369,7 @@ DEPENDENCIES
367 sdoc (~> 0.4.0) 369 sdoc (~> 0.4.0)
368 shoulda-matchers (~> 2.8.0) 370 shoulda-matchers (~> 2.8.0)
369 simplecov 371 simplecov
  372 + sinon-rails
370 spring 373 spring
371 sprockets (~> 2.12.3) 374 sprockets (~> 2.12.3)
372 sqlite3 375 sqlite3
spec/javascripts/repository/branch_spec.js.coffee
1 #= require application 1 #= require application
  2 +#= require 'sinon'
2 3
3 -describe "Repository.Branch", ->  
4 - beforeEach ->  
5 - @repository_branch = new Repository.Branch() 4 +describe "Branch#constructor", ->
  5 + it "should construct a branch", ->
  6 + subject = new Repository.Branch()
  7 + subject.names.should.deep.equal({})
  8 + assert.isNull(subject.request)
6 9
7 - describe "Branch#constructor", ->  
8 - it "should construct a branch", ->  
9 - @repository_branch.names.should.deep.equal({})  
10 - assert.isNull(@repository_branch.request) 10 +describe "toggle", ->
  11 + @subject = new Repository.Branch()
  12 + beforeEach ->
  13 + @combo_box = sinon.stub()
  14 + $ = sinon.stub(window, "$")
  15 + $.withArgs("#branches").returns(@combo_box)
  16 + context "scm_type = SVN", ->
  17 + @combo_box.hide = sinon.spy()
  18 + it "should hide the branches combo box", ->
  19 + $.withArgs("#repository_scm_type").returns({val: -> "SVN"})
  20 + @subject.toggle()
  21 + assert.isTrue(@combo_box.hide.calledOnce)
  22 + context "scm_type != SVN", ->
  23 + @combo_box.show = sinon.spy()
  24 + $.withArgs("#repository_address").returns({val: -> "https://github.com/mezuro/prezento.git"})
  25 + sinon.stub(@subject, "fetch").withArgs("https://github.com/mezuro/prezento.git")
  26 + @subject.stub = sinon.spy()
  27 + it "should show the branches combo box", ->
  28 + $.withArgs("#repository_scm_type").returns({val: -> "GIT"})
  29 + @subject.toggle()
  30 + assert.isTrue(@combo_box.show.calledOnce)