Commit e7d644b7412749e4f433ca54675afec77303a68a

Authored by Diego Camarinha
1 parent 1b9b03c1

Implement Repository#notify_push action

  * Includes this action in the list of actions that do not need
    user authentication.

Signed-off-by: Heitor Reis <marcheing@gmail.com>
app/controllers/repositories_controller.rb
1 1 include OwnershipAuthentication
2 2  
3 3 class RepositoriesController < ApplicationController
4   - before_action :authenticate_user!, except: [:show, :state, :state_with_date, :index]
  4 + before_action :authenticate_user!, except: [:show, :state, :state_with_date, :index, :notify_push]
5 5 before_action :project_owner?, only: [:new, :create], unless: Proc.new { params[:project_id].nil? }
6 6 before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository]
7 7 before_action :set_repository, only: [:show, :edit, :update, :destroy, :state, :state_with_date, :process_repository]
... ... @@ -96,6 +96,13 @@ class RepositoriesController &lt; ApplicationController
96 96 end
97 97 end
98 98  
  99 + def notify_push
  100 + set_repository
  101 + @repository.cancel_processing_of_repository if @repository.last_processing_state.end_with? 'ING'
  102 + @repository.process
  103 + render :nothing => true, :status => :ok
  104 + end
  105 +
99 106 private
100 107 def set_project_id_repository_types_and_configurations
101 108 @project_id = params[:project_id]
... ...
spec/controllers/repositories_controller_spec.rb
... ... @@ -479,8 +479,7 @@ describe RepositoriesController, :type =&gt; :controller do
479 479 let(:repository) { FactoryGirl.build(:repository) }
480 480  
481 481 before :each do
482   - Repository.expects(:find).with(repository.id).raises(KalibroClient::Errors::RecordNotFound)
483   - post :notify_push, id: repository.id, format: :json
  482 + Repository.expects(:find).with(repository.id).returns(repository)
484 483 end
485 484  
486 485 context 'when the repository is being processed' do
... ... @@ -488,15 +487,17 @@ describe RepositoriesController, :type =&gt; :controller do
488 487 repository.expects(:last_processing_state).returns('INTERPRETING')
489 488 repository.expects(:cancel_processing_of_repository).once
490 489 repository.expects(:process).once
  490 + post :notify_push, id: repository.id
491 491 end
492 492  
493   - it { is_expected.to respond_with(:accepted) }
  493 + it { is_expected.to respond_with(:ok) }
494 494 end
495 495  
496 496 context "when the repository's processing resulted in an error" do
497 497 before do
498 498 repository.expects(:last_processing_state).returns('ERROR')
499 499 repository.expects(:process).once
  500 + post :notify_push, id: repository.id
500 501 end
501 502  
502 503 it { is_expected.to respond_with(:ok) }
... ... @@ -506,6 +507,7 @@ describe RepositoriesController, :type =&gt; :controller do
506 507 before do
507 508 repository.expects(:last_processing_state).returns('READY')
508 509 repository.expects(:process).once
  510 + post :notify_push, id: repository.id
509 511 end
510 512  
511 513 it { is_expected.to respond_with(:ok) }
... ... @@ -517,7 +519,7 @@ describe RepositoriesController, :type =&gt; :controller do
517 519  
518 520 before :each do
519 521 Repository.expects(:find).with(repository_id).raises(KalibroClient::Errors::RecordNotFound)
520   - post :notify_push, id: repository_id, format: :json
  522 + post :notify_push, id: repository_id
521 523 end
522 524  
523 525 it { is_expected.to respond_with(:not_found) }
... ...