Commit e7d644b7412749e4f433ca54675afec77303a68a
1 parent
1b9b03c1
Exists in
colab
and in
4 other branches
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>
Showing
2 changed files
with
14 additions
and
5 deletions
Show diff stats
app/controllers/repositories_controller.rb
1 | include OwnershipAuthentication | 1 | include OwnershipAuthentication |
2 | 2 | ||
3 | class RepositoriesController < ApplicationController | 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 | before_action :project_owner?, only: [:new, :create], unless: Proc.new { params[:project_id].nil? } | 5 | before_action :project_owner?, only: [:new, :create], unless: Proc.new { params[:project_id].nil? } |
6 | before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository] | 6 | before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository] |
7 | before_action :set_repository, only: [:show, :edit, :update, :destroy, :state, :state_with_date, :process_repository] | 7 | before_action :set_repository, only: [:show, :edit, :update, :destroy, :state, :state_with_date, :process_repository] |
@@ -96,6 +96,13 @@ class RepositoriesController < ApplicationController | @@ -96,6 +96,13 @@ class RepositoriesController < ApplicationController | ||
96 | end | 96 | end |
97 | end | 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 | private | 106 | private |
100 | def set_project_id_repository_types_and_configurations | 107 | def set_project_id_repository_types_and_configurations |
101 | @project_id = params[:project_id] | 108 | @project_id = params[:project_id] |
spec/controllers/repositories_controller_spec.rb
@@ -479,8 +479,7 @@ describe RepositoriesController, :type => :controller do | @@ -479,8 +479,7 @@ describe RepositoriesController, :type => :controller do | ||
479 | let(:repository) { FactoryGirl.build(:repository) } | 479 | let(:repository) { FactoryGirl.build(:repository) } |
480 | 480 | ||
481 | before :each do | 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 | end | 483 | end |
485 | 484 | ||
486 | context 'when the repository is being processed' do | 485 | context 'when the repository is being processed' do |
@@ -488,15 +487,17 @@ describe RepositoriesController, :type => :controller do | @@ -488,15 +487,17 @@ describe RepositoriesController, :type => :controller do | ||
488 | repository.expects(:last_processing_state).returns('INTERPRETING') | 487 | repository.expects(:last_processing_state).returns('INTERPRETING') |
489 | repository.expects(:cancel_processing_of_repository).once | 488 | repository.expects(:cancel_processing_of_repository).once |
490 | repository.expects(:process).once | 489 | repository.expects(:process).once |
490 | + post :notify_push, id: repository.id | ||
491 | end | 491 | end |
492 | 492 | ||
493 | - it { is_expected.to respond_with(:accepted) } | 493 | + it { is_expected.to respond_with(:ok) } |
494 | end | 494 | end |
495 | 495 | ||
496 | context "when the repository's processing resulted in an error" do | 496 | context "when the repository's processing resulted in an error" do |
497 | before do | 497 | before do |
498 | repository.expects(:last_processing_state).returns('ERROR') | 498 | repository.expects(:last_processing_state).returns('ERROR') |
499 | repository.expects(:process).once | 499 | repository.expects(:process).once |
500 | + post :notify_push, id: repository.id | ||
500 | end | 501 | end |
501 | 502 | ||
502 | it { is_expected.to respond_with(:ok) } | 503 | it { is_expected.to respond_with(:ok) } |
@@ -506,6 +507,7 @@ describe RepositoriesController, :type => :controller do | @@ -506,6 +507,7 @@ describe RepositoriesController, :type => :controller do | ||
506 | before do | 507 | before do |
507 | repository.expects(:last_processing_state).returns('READY') | 508 | repository.expects(:last_processing_state).returns('READY') |
508 | repository.expects(:process).once | 509 | repository.expects(:process).once |
510 | + post :notify_push, id: repository.id | ||
509 | end | 511 | end |
510 | 512 | ||
511 | it { is_expected.to respond_with(:ok) } | 513 | it { is_expected.to respond_with(:ok) } |
@@ -517,7 +519,7 @@ describe RepositoriesController, :type => :controller do | @@ -517,7 +519,7 @@ describe RepositoriesController, :type => :controller do | ||
517 | 519 | ||
518 | before :each do | 520 | before :each do |
519 | Repository.expects(:find).with(repository_id).raises(KalibroClient::Errors::RecordNotFound) | 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 | end | 523 | end |
522 | 524 | ||
523 | it { is_expected.to respond_with(:not_found) } | 525 | it { is_expected.to respond_with(:not_found) } |