Commit 3586d72eb09aa840c7440e5b3fb23840619f0838
1 parent
cf09b187
Exists in
colab
and in
4 other branches
RepositoriesController covered with unit tests
Showing
1 changed file
with
18 additions
and
39 deletions
Show diff stats
spec/controllers/repositories_controller_spec.rb
... | ... | @@ -179,60 +179,38 @@ describe RepositoriesController do |
179 | 179 | end |
180 | 180 | end |
181 | 181 | |
182 | - pending "Work in progress" do | |
183 | 182 | describe 'update' do |
184 | - before do | |
185 | - @subject = FactoryGirl.build(:repository) | |
186 | - @subject_params = Hash[FactoryGirl.attributes_for(:repository).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers | |
187 | - end | |
188 | - | |
183 | + let(:repository) { FactoryGirl.build(:repository) } | |
184 | + let(:repository_params) { Hash[FactoryGirl.attributes_for(:repository).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers | |
185 | + | |
189 | 186 | context 'when the user is logged in' do |
190 | 187 | before do |
191 | 188 | sign_in FactoryGirl.create(:user) |
192 | 189 | end |
193 | 190 | |
194 | 191 | context 'when user owns the repository' do |
195 | - before do | |
196 | - @ownership = FactoryGirl.build(:repository_ownership) | |
197 | - @ownerships = [] | |
198 | - | |
199 | - @ownerships.expects(:find_by_repository_id).with("#{@subject.id}").returns(@ownership) | |
200 | - User.any_instance.expects(:repository_ownerships).at_least_once.returns(@ownerships) | |
192 | + before :each do | |
193 | + subject.expects(:check_repository_ownership).returns true | |
201 | 194 | end |
202 | 195 | |
203 | 196 | context 'with valid fields' do |
204 | 197 | before :each do |
205 | - Repository.expects(:find).with(@subject.id.to_s).returns(@subject) | |
206 | - Repository.any_instance.expects(:update).with(@subject_params).returns(true) | |
207 | - end | |
208 | - | |
209 | - context 'rendering the show' do | |
210 | - before :each do | |
211 | - Repository.expects(:exists?).returns(true) | |
198 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) | |
199 | + Repository.any_instance.expects(:update).with(repository_params).returns(true) | |
212 | 200 | |
213 | - post :update, :id => @subject.id, :repository => @subject_params | |
214 | - end | |
215 | - | |
216 | - it 'should redirect to the show view' do | |
217 | - response.should redirect_to repository_path(@subject) | |
218 | - end | |
201 | + post :update, project_id: project.id.to_s, :id => repository.id, :repository => repository_params | |
219 | 202 | end |
220 | 203 | |
221 | - context 'without rendering the show view' do | |
222 | - before :each do | |
223 | - post :update, :id => @subject.id, :repository => @subject_params | |
224 | - end | |
225 | - | |
226 | - it { should respond_with(:redirect) } | |
227 | - end | |
204 | + it { should redirect_to(project_repository_path(repository.project_id, repository.id)) } | |
205 | + it { should respond_with(:redirect) } | |
228 | 206 | end |
229 | 207 | |
230 | 208 | context 'with an invalid field' do |
231 | 209 | before :each do |
232 | - Repository.expects(:find).with(@subject.id.to_s).returns(@subject) | |
233 | - Repository.any_instance.expects(:update).with(@subject_params).returns(false) | |
210 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) | |
211 | + Repository.any_instance.expects(:update).with(repository_params).returns(false) | |
234 | 212 | |
235 | - post :update, :id => @subject.id, :repository => @subject_params | |
213 | + post :update, project_id: project.id.to_s, :id => repository.id, :repository => repository_params | |
236 | 214 | end |
237 | 215 | |
238 | 216 | it { should render_template(:edit) } |
... | ... | @@ -241,20 +219,21 @@ describe RepositoriesController do |
241 | 219 | |
242 | 220 | context 'when the user does not own the repository' do |
243 | 221 | before :each do |
244 | - post :update, :id => @subject.id, :repository => @subject_params | |
222 | + Repository.expects(:find).at_least_once.with(repository.id).returns(repository) | |
223 | + | |
224 | + post :update, project_id: project.id.to_s, :id => repository.id, :repository => repository_params | |
245 | 225 | end |
246 | 226 | |
247 | - it { should redirect_to repositories_path } | |
227 | + it { should redirect_to projects_path } | |
248 | 228 | end |
249 | 229 | end |
250 | 230 | |
251 | 231 | context 'with no user logged in' do |
252 | 232 | before :each do |
253 | - post :update, :id => @subject.id, :repository => @subject_params | |
233 | + post :update, project_id: project.id.to_s, :id => repository.id, :repository => repository_params | |
254 | 234 | end |
255 | 235 | |
256 | 236 | it { should redirect_to new_user_session_path } |
257 | 237 | end |
258 | 238 | end |
259 | - end | |
260 | 239 | end | ... | ... |