Commit 2d1179b098c503a81589d645a34f6bd2ad4a38a9
1 parent
99acd32f
Exists in
colab
and in
4 other branches
Completed konacha test cases for Repository.Branch class.
Signed off by: Daniel Miranda <danielkza2@gmail.com>
Showing
1 changed file
with
36 additions
and
16 deletions
Show diff stats
spec/javascripts/repository/branch_spec.js.coffee
... | ... | @@ -77,31 +77,51 @@ describe "Repository.Branch", -> |
77 | 77 | |
78 | 78 | describe '#fetch', -> |
79 | 79 | beforeEach -> |
80 | + @subject.names = {} | |
81 | + @address = 'https://github.com/mezuro/kalibro_processor.git' | |
80 | 82 | @subject.cancel_request = sinon.stub() |
83 | + sinon.stub(@subject, "fill_options") | |
81 | 84 | |
82 | - context 'with valid address', -> | |
83 | - beforeEach -> | |
84 | - sinon.stub(@subject, "fill_options") | |
85 | + @select = {empty: sinon.stub()} | |
86 | + # $ is a global jQuery variable. That is why we don't need to declare it as @$ | |
87 | + $ = sinon.stub(window, "$") | |
88 | + $.withArgs("#repository_branch").returns(@select) | |
89 | + $.withArgs("#repository_scm_type").returns({val: -> "GIT"}) | |
85 | 90 | |
86 | - afterEach -> | |
87 | - @subject.fill_options.restore() | |
91 | + afterEach -> | |
92 | + @subject.fill_options.restore() | |
93 | + $.restore() | |
88 | 94 | |
89 | - context 'with new address', -> | |
95 | + context 'with valid address', -> | |
96 | + context 'with an address that is not cached', -> | |
90 | 97 | beforeEach -> |
91 | - @subject.names = {} | |
92 | - @address = 'https://github.com/mezuro/kalibro_processor.git' | |
93 | - | |
94 | - @select = {empty: sinon.stub()} | |
95 | - $ = sinon.stub(window, "$") | |
96 | - $.withArgs("#repository_branch").returns(@select) | |
97 | - $.withArgs("#repository_scm_type").returns({val: -> "GIT"}) | |
98 | 98 | $.get = sinon.stub().withArgs('/repository_branches', {'url': @address, 'scm_type': 'GIT'}).returns().yields({ |
99 | 99 | 'branches': ['stable', 'dev', 'master'] |
100 | 100 | }) |
101 | 101 | |
102 | - afterEach -> | |
103 | - $.restore() | |
104 | - | |
105 | 102 | it 'should fetch the branches and fill the options', -> |
106 | 103 | @subject.fetch(@address) |
104 | + sinon.assert.calledWith(@select.empty) | |
105 | + sinon.assert.calledWith(@subject.fill_options, ['stable', 'dev', 'master'], @select) | |
106 | + | |
107 | + context 'with an address that is cached', -> | |
108 | + beforeEach -> | |
109 | + @subject.names[@address] = ['stable', 'dev', 'master'] | |
110 | + $.get = sinon.stub() | |
111 | + | |
112 | + it 'should not request the branches but fill the select with the cached values', -> | |
113 | + @subject.fetch(@address) | |
114 | + sinon.assert.calledWith(@select.empty) | |
107 | 115 | sinon.assert.calledWith(@subject.fill_options, ['stable', 'dev', 'master'], @select) |
116 | + sinon.assert.notCalled($.get) | |
117 | + | |
118 | + context 'with an invalid address', -> | |
119 | + beforeEach -> | |
120 | + $.get = sinon.stub().withArgs('/repository_branches', {'url': @address, 'scm_type': 'GIT'}).returns().yields({ | |
121 | + 'errors': ['InvalidUrl'] | |
122 | + }) | |
123 | + | |
124 | + it 'should not fill the options', -> | |
125 | + @subject.fetch(@address) | |
126 | + sinon.assert.calledWith(@select.empty) | |
127 | + sinon.assert.notCalled(@subject.fill_options) | ... | ... |