From e7d644b7412749e4f433ca54675afec77303a68a Mon Sep 17 00:00:00 2001 From: Diego Araújo Date: Thu, 19 Nov 2015 14:26:47 -0200 Subject: [PATCH] Implement Repository#notify_push action --- app/controllers/repositories_controller.rb | 9 ++++++++- spec/controllers/repositories_controller_spec.rb | 10 ++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9d0983b..ea03cec 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,7 +1,7 @@ include OwnershipAuthentication class RepositoriesController < ApplicationController - before_action :authenticate_user!, except: [:show, :state, :state_with_date, :index] + before_action :authenticate_user!, except: [:show, :state, :state_with_date, :index, :notify_push] before_action :project_owner?, only: [:new, :create], unless: Proc.new { params[:project_id].nil? } before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository] before_action :set_repository, only: [:show, :edit, :update, :destroy, :state, :state_with_date, :process_repository] @@ -96,6 +96,13 @@ class RepositoriesController < ApplicationController end end + def notify_push + set_repository + @repository.cancel_processing_of_repository if @repository.last_processing_state.end_with? 'ING' + @repository.process + render :nothing => true, :status => :ok + end + private def set_project_id_repository_types_and_configurations @project_id = params[:project_id] diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index bda95f8..bea14c4 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -479,8 +479,7 @@ describe RepositoriesController, :type => :controller do let(:repository) { FactoryGirl.build(:repository) } before :each do - Repository.expects(:find).with(repository.id).raises(KalibroClient::Errors::RecordNotFound) - post :notify_push, id: repository.id, format: :json + Repository.expects(:find).with(repository.id).returns(repository) end context 'when the repository is being processed' do @@ -488,15 +487,17 @@ describe RepositoriesController, :type => :controller do repository.expects(:last_processing_state).returns('INTERPRETING') repository.expects(:cancel_processing_of_repository).once repository.expects(:process).once + post :notify_push, id: repository.id end - it { is_expected.to respond_with(:accepted) } + it { is_expected.to respond_with(:ok) } end context "when the repository's processing resulted in an error" do before do repository.expects(:last_processing_state).returns('ERROR') repository.expects(:process).once + post :notify_push, id: repository.id end it { is_expected.to respond_with(:ok) } @@ -506,6 +507,7 @@ describe RepositoriesController, :type => :controller do before do repository.expects(:last_processing_state).returns('READY') repository.expects(:process).once + post :notify_push, id: repository.id end it { is_expected.to respond_with(:ok) } @@ -517,7 +519,7 @@ describe RepositoriesController, :type => :controller do before :each do Repository.expects(:find).with(repository_id).raises(KalibroClient::Errors::RecordNotFound) - post :notify_push, id: repository_id, format: :json + post :notify_push, id: repository_id end it { is_expected.to respond_with(:not_found) } -- libgit2 0.21.2