#394: updated BuildListsController, RpmWorkerObserver, added specs

This commit is contained in:
Vokhmin Alexey V 2014-05-29 01:08:29 +04:00
parent 4a0402b4f4
commit 31e40a9360
3 changed files with 49 additions and 3 deletions

View File

@ -184,7 +184,7 @@ class Projects::BuildListsController < Projects::BaseController
protected protected
def do_and_back(action, prefix, success = 'success', fail = 'fail') 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 message = result ? success : fail
flash[result ? :notice : :error] = t("layout.build_lists.#{prefix}#{message}") flash[result ? :notice : :error] = t("layout.build_lists.#{prefix}#{message}")
redirect_to :back redirect_to :back

View File

@ -23,9 +23,9 @@ module AbfWorker
case status case status
when COMPLETED when COMPLETED
subject.build_success subject.build_success
if subject.can_auto_publish? if subject.can_auto_publish? && subject.can_publish?
subject.now_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 subject.publish_into_testing
end end
when FAILED when FAILED

View File

@ -239,4 +239,50 @@ describe BuildList do
end 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 end