Commit 1b9b03c152a36ef552d6da21d5bc25e682f4c0f6

Authored by Heitor
1 parent 00b198bb

Add tests for repository#notify_push

 * Still needs the action implementation on repository controller

Signed off by: Eduardo Araújo <duduktamg@hotmail.com>
Showing 1 changed file with 63 additions and 14 deletions   Show diff stats
spec/controllers/repositories_controller_spec.rb
... ... @@ -171,7 +171,6 @@ describe RepositoriesController, :type =&gt; :controller do
171 171 end
172 172  
173 173 context 'for an specific module_result' do
174   -
175 174 before :each do
176 175 KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration, :with_id))
177 176 Repository.expects(:find).with(repository.id).returns(repository)
... ... @@ -209,8 +208,8 @@ describe RepositoriesController, :type =&gt; :controller do
209 208 delete :destroy, id: repository.id
210 209 end
211 210  
212   - it { is_expected.to redirect_to(projects_url) }
213   - it { is_expected.to respond_with(:redirect) }
  211 + it { is_expected.to redirect_to(projects_url) }
  212 + it { is_expected.to respond_with(:redirect) }
214 213 end
215 214 end
216 215  
... ... @@ -346,7 +345,7 @@ describe RepositoriesController, :type =&gt; :controller do
346 345 context 'with another state then READY' do
347 346 let(:processing) { FactoryGirl.build(:processing, state: 'ANALYZING') }
348 347  
349   - before :each do
  348 + before :each do
350 349 repository.expects(:last_processing).returns(processing)
351 350 Repository.expects(:find).at_least_once.with(repository.id).returns(repository)
352 351  
... ... @@ -400,16 +399,16 @@ describe RepositoriesController, :type =&gt; :controller do
400 399 end
401 400  
402 401 describe 'process_repository' do
403   - let(:repository) { FactoryGirl.build(:repository) }
404   - before :each do
405   - sign_in FactoryGirl.create(:user)
406   - subject.expects(:repository_owner?).returns true
407   - repository.expects(:process)
408   - Repository.expects(:find).at_least_once.with(repository.id).returns(repository)
409   - KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration, :with_id))
410   - get :process_repository, id: repository.id
411   - end
412   - it { is_expected.to redirect_to(repository_path(repository.id)) }
  402 + let(:repository) { FactoryGirl.build(:repository) }
  403 + before :each do
  404 + sign_in FactoryGirl.create(:user)
  405 + subject.expects(:repository_owner?).returns true
  406 + repository.expects(:process)
  407 + Repository.expects(:find).at_least_once.with(repository.id).returns(repository)
  408 + KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration, :with_id))
  409 + get :process_repository, id: repository.id
  410 + end
  411 + it { is_expected.to redirect_to(repository_path(repository.id)) }
413 412 end
414 413  
415 414 describe 'branches' do
... ... @@ -474,4 +473,54 @@ describe RepositoriesController, :type =&gt; :controller do
474 473 end
475 474 end
476 475 end
  476 +
  477 + describe 'notify_push' do
  478 + context 'with a valid repository' do
  479 + let(:repository) { FactoryGirl.build(:repository) }
  480 +
  481 + before :each do
  482 + Repository.expects(:find).with(repository.id).raises(KalibroClient::Errors::RecordNotFound)
  483 + post :notify_push, id: repository.id, format: :json
  484 + end
  485 +
  486 + context 'when the repository is being processed' do
  487 + before do
  488 + repository.expects(:last_processing_state).returns('INTERPRETING')
  489 + repository.expects(:cancel_processing_of_repository).once
  490 + repository.expects(:process).once
  491 + end
  492 +
  493 + it { is_expected.to respond_with(:accepted) }
  494 + end
  495 +
  496 + context "when the repository's processing resulted in an error" do
  497 + before do
  498 + repository.expects(:last_processing_state).returns('ERROR')
  499 + repository.expects(:process).once
  500 + end
  501 +
  502 + it { is_expected.to respond_with(:ok) }
  503 + end
  504 +
  505 + context 'when the repository is not being processed' do
  506 + before do
  507 + repository.expects(:last_processing_state).returns('READY')
  508 + repository.expects(:process).once
  509 + end
  510 +
  511 + it { is_expected.to respond_with(:ok) }
  512 + end
  513 + end
  514 +
  515 + context 'with an invalid repository' do
  516 + let(:repository_id) { 1 }
  517 +
  518 + before :each do
  519 + Repository.expects(:find).with(repository_id).raises(KalibroClient::Errors::RecordNotFound)
  520 + post :notify_push, id: repository_id, format: :json
  521 + end
  522 +
  523 + it { is_expected.to respond_with(:not_found) }
  524 + end
  525 + end
477 526 end
... ...