From 31e40a9360be8d8452da5f71a777958009a2c5a1 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 29 May 2014 01:08:29 +0400 Subject: [PATCH] #394: updated BuildListsController, RpmWorkerObserver, added specs --- .../projects/build_lists_controller.rb | 2 +- lib/abf_worker/rpm_worker_observer.rb | 4 +- spec/models/build_list_spec.rb | 46 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index e82e76b29..f0e576b37 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -184,7 +184,7 @@ class Projects::BuildListsController < Projects::BaseController protected def do_and_back(action, prefix, success = 'success', fail = 'fail') - result = @build_list.send(action) + result = @build_list.send("can_#{action}?") && @build_list.send(action) message = result ? success : fail flash[result ? :notice : :error] = t("layout.build_lists.#{prefix}#{message}") redirect_to :back diff --git a/lib/abf_worker/rpm_worker_observer.rb b/lib/abf_worker/rpm_worker_observer.rb index a87ddb9d6..747169af9 100644 --- a/lib/abf_worker/rpm_worker_observer.rb +++ b/lib/abf_worker/rpm_worker_observer.rb @@ -23,9 +23,9 @@ module AbfWorker case status when COMPLETED subject.build_success - if subject.can_auto_publish? + if subject.can_auto_publish? && subject.can_publish? subject.now_publish - elsif subject.auto_publish_into_testing? + elsif subject.auto_publish_into_testing? && subject.can_publish_into_testing? subject.publish_into_testing end when FAILED diff --git a/spec/models/build_list_spec.rb b/spec/models/build_list_spec.rb index fa0426f33..f45535063 100644 --- a/spec/models/build_list_spec.rb +++ b/spec/models/build_list_spec.rb @@ -239,4 +239,50 @@ describe BuildList do end + describe '#can_publish?' do + let(:build_list) { FactoryGirl.create(:build_list) } + + before do + build_list.update_attributes({ status: BuildList::SUCCESS }, without_protection: true) + allow(build_list).to receive(:valid_branch_for_publish?).and_return(true) + end + + it 'returns true for eligible build' do + expect(build_list.can_publish?).to be_true + end + + it 'returns false if branch invalid' do + allow(build_list).to receive(:valid_branch_for_publish?).and_return(false) + expect(build_list.can_publish?).to be_false + end + + it 'returns false if extra builds not published' do + allow(build_list).to receive(:extra_build_lists_published?).and_return(false) + expect(build_list.can_publish?).to be_false + end + + it 'returns false if project does not exist in repository' do + build_list.stub_chain(:save_to_repository, :projects, :exists?).and_return(false) + expect(build_list.can_publish?).to be_false + end + end + + describe '#can_publish_into_testing?' do + let(:build_list) { FactoryGirl.create(:build_list) } + + before do + build_list.update_attributes({ status: BuildList::SUCCESS }, without_protection: true) + end + + it 'returns true for eligible build' do + allow(build_list).to receive(:valid_branch_for_publish?).and_return(true) + expect(build_list.can_publish_into_testing?).to be_true + end + + it 'returns false if branch invalid' do + allow(build_list).to receive(:valid_branch_for_publish?).and_return(false) + expect(build_list.can_publish_into_testing?).to be_false + end + end + end