2012-09-19 14:55:17 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BuildList do
|
2013-09-10 17:09:48 +01:00
|
|
|
before { stub_symlink_methods }
|
2012-09-19 14:55:17 +01:00
|
|
|
|
2012-12-26 13:06:17 +00:00
|
|
|
context 'validates that repository contains project' do
|
|
|
|
it 'when repository contains project' do
|
|
|
|
bl = FactoryGirl.build(:build_list)
|
2015-02-19 01:12:08 +00:00
|
|
|
bl.valid?.should be_truthy
|
2012-12-26 13:06:17 +00:00
|
|
|
end
|
|
|
|
it 'when repository does not contain project' do
|
|
|
|
bl = FactoryGirl.build(:build_list)
|
|
|
|
bl.project.repositories = []
|
2015-02-19 01:12:08 +00:00
|
|
|
bl.valid?.should be_falsy
|
2012-12-26 13:06:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-18 22:25:35 +01:00
|
|
|
context '#next_build' do
|
|
|
|
let!(:build_list) { FactoryGirl.create(:build_list, updated_at: Time.now - 20.seconds) }
|
|
|
|
|
|
|
|
it 'returns build list' do
|
|
|
|
expect_any_instance_of(BuildList).to receive(:delayed_add_job_to_abf_worker_queue)
|
|
|
|
expect(BuildList.next_build([], [])).to eq build_list
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filtering build lists by platform' do
|
|
|
|
it 'returns build list for correct platform' do
|
|
|
|
expect_any_instance_of(BuildList).to receive(:delayed_add_job_to_abf_worker_queue)
|
|
|
|
expect(BuildList.next_build([], [build_list.build_for_platform_id])).to eq build_list
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nothing for wrong platform' do
|
2014-12-10 22:27:12 +00:00
|
|
|
expect_any_instance_of(BuildList).to receive(:restart_job)
|
2014-09-18 22:25:35 +01:00
|
|
|
expect(BuildList.next_build([], [-1])).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filtering build lists by arch' do
|
|
|
|
it 'returns build list for correct arch' do
|
|
|
|
expect_any_instance_of(BuildList).to receive(:delayed_add_job_to_abf_worker_queue)
|
|
|
|
expect(BuildList.next_build([build_list.arch_id], [])).to eq build_list
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nothing for wrong arch' do
|
2014-12-10 22:27:12 +00:00
|
|
|
expect_any_instance_of(BuildList).to receive(:restart_job)
|
2014-09-18 22:25:35 +01:00
|
|
|
expect(BuildList.next_build([-1], [])).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-09-19 14:55:17 +01:00
|
|
|
context "#notify_users" do
|
2014-09-23 18:41:34 +01:00
|
|
|
let(:user) { FactoryGirl.build(:user) }
|
|
|
|
let!(:build_list) {
|
|
|
|
FactoryGirl.create(:build_list,
|
|
|
|
user: user,
|
|
|
|
auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_NONE,
|
|
|
|
status: BuildList::BUILD_STARTED
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
before(:all) { ActionMailer::Base.deliveries = [] }
|
|
|
|
after { ActionMailer::Base.deliveries = [] }
|
2012-09-19 14:55:17 +01:00
|
|
|
|
|
|
|
shared_examples_for 'build list notifications by email' do
|
|
|
|
it "gets notification by email when status - Build complete" do
|
|
|
|
build_list.build_success
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
2012-09-19 20:52:18 +01:00
|
|
|
it "gets notification by email when status - Build error" do
|
|
|
|
build_list.build_error
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2012-09-19 20:52:18 +01:00
|
|
|
end
|
|
|
|
|
2014-09-23 18:41:34 +01:00
|
|
|
it "gets notification by email when status - Unpermitted architecture" do
|
|
|
|
build_list.unpermitted_arch
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2014-09-23 18:41:34 +01:00
|
|
|
end
|
|
|
|
|
2012-09-19 20:52:18 +01:00
|
|
|
it "gets notification by email when auto_publish and status - Build error" do
|
2014-09-23 18:41:34 +01:00
|
|
|
build_list.auto_publish_status = BuildList::AUTO_PUBLISH_STATUS_DEFAULT
|
2012-09-19 20:52:18 +01:00
|
|
|
build_list.build_error
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2012-09-19 20:52:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "gets notification by email when status - Failed publish" do
|
2014-09-23 18:41:34 +01:00
|
|
|
build_list.status = BuildList::BUILD_PUBLISH
|
2012-09-19 20:52:18 +01:00
|
|
|
build_list.fail_publish
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2012-09-19 20:52:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "gets notification by email when auto_publish and status - Failed publish" do
|
2014-09-23 18:41:34 +01:00
|
|
|
build_list.auto_publish_status = BuildList::AUTO_PUBLISH_STATUS_DEFAULT
|
|
|
|
build_list.status = BuildList::BUILD_PUBLISH
|
2012-09-19 20:52:18 +01:00
|
|
|
build_list.fail_publish
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2012-09-19 20:52:18 +01:00
|
|
|
end
|
|
|
|
|
2012-09-19 14:55:17 +01:00
|
|
|
it "gets notification by email when status - Build published" do
|
2014-09-23 18:41:34 +01:00
|
|
|
build_list.status = BuildList::BUILD_PUBLISH
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.published
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "gets notification by email when auto_publish and status - Build published" do
|
2014-09-23 18:41:34 +01:00
|
|
|
build_list.auto_publish_status = BuildList::AUTO_PUBLISH_STATUS_DEFAULT
|
|
|
|
build_list.status = BuildList::BUILD_PUBLISH
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.published
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when auto_publish and status - Build complete" do
|
2014-09-23 18:41:34 +01:00
|
|
|
build_list.auto_publish_status = BuildList::AUTO_PUBLISH_STATUS_DEFAULT
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.build_success
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 0
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
2014-02-19 21:23:38 +00:00
|
|
|
it "doesn't get notification by email when auto_publish_into_testing and status - Build complete" do
|
2014-09-23 19:52:55 +01:00
|
|
|
build_list.auto_publish_status = BuildList::AUTO_PUBLISH_STATUS_TESTING
|
2014-02-19 21:23:38 +00:00
|
|
|
build_list.build_success
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 0
|
2014-02-19 21:23:38 +00:00
|
|
|
end
|
|
|
|
|
2012-09-19 14:55:17 +01:00
|
|
|
it "doesn't get notification by email when mass build" do
|
2014-09-23 19:52:55 +01:00
|
|
|
mb = FactoryGirl.create(:mass_build)
|
|
|
|
build_list.mass_build_id = mb.id
|
2014-09-23 18:41:34 +01:00
|
|
|
build_list.status = BuildList::BUILD_PUBLISH
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.published
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 0
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when notification by email has been disabled" do
|
2014-01-21 04:51:49 +00:00
|
|
|
notifier.update_attributes(can_notify: false)
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.build_success
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 0
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { ActionMailer::Base.deliveries }
|
|
|
|
|
|
|
|
context "user created build task" do
|
|
|
|
let!(:notifier) { user.notifier }
|
|
|
|
before do
|
2014-09-23 18:41:34 +01:00
|
|
|
allow(notifier).to receive(:new_associated_build?).and_return(false)
|
2014-01-21 04:51:49 +00:00
|
|
|
build_list.project.owner.notifier.update_attributes(can_notify: false)
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'build list notifications by email'
|
|
|
|
|
|
|
|
it "doesn't get notification by email when 'build list' notifications has been disabled" do
|
2014-09-23 18:41:34 +01:00
|
|
|
allow(notifier).to receive(:new_build?).and_return(false)
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.build_success
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 0
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when 'build list' notifications - enabled, email notifications - disabled" do
|
2014-09-23 18:41:34 +01:00
|
|
|
allow(notifier).to receive(:can_notify?).and_return(false)
|
|
|
|
allow(notifier).to receive(:new_build?).and_return(true)
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.build_success
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 0
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "build task has been created and associated user" do
|
|
|
|
let!(:notifier) { build_list.project.owner.notifier }
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
notifier.update_attributes(new_build: false)
|
|
|
|
user.notifier.update_attributes(can_notify: false)
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'build list notifications by email'
|
|
|
|
|
|
|
|
it "doesn't get notification by email when 'associated build list' notifications has been disabled" do
|
2014-01-21 04:51:49 +00:00
|
|
|
notifier.update_attributes(new_associated_build: false)
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.build_success
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 0
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when 'associated build list' notifications - enabled, email notifications - disabled" do
|
2014-01-21 04:51:49 +00:00
|
|
|
notifier.update_attributes(can_notify: false, new_associated_build: true)
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.build_success
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 0
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get 2 notification by email when user associated to project and created task" do
|
2014-01-21 04:51:49 +00:00
|
|
|
project = FactoryGirl.create(:project_with_commit, owner: user)
|
2013-07-01 13:20:38 +01:00
|
|
|
bl = FactoryGirl.create(:build_list_with_attaching_project,
|
2014-02-19 21:19:49 +00:00
|
|
|
user: user,
|
|
|
|
auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT,
|
|
|
|
project: project
|
2012-12-26 17:30:27 +00:00
|
|
|
)
|
2014-01-21 04:51:49 +00:00
|
|
|
bl.update_attributes({commit_hash: bl.project.repo.commits('master').last.id,
|
|
|
|
status: BuildList::BUILD_PUBLISH}, without_protection: true)
|
2012-09-19 14:55:17 +01:00
|
|
|
bl.published
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(subject.count).to eq 1
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end # notify_users
|
|
|
|
|
2013-09-10 17:09:48 +01:00
|
|
|
context '#has_new_packages?' do
|
2013-09-09 21:10:52 +01:00
|
|
|
let!(:build_list) { FactoryGirl.create( :build_list,
|
2014-02-19 21:19:49 +00:00
|
|
|
status: BuildList::SUCCESS,
|
|
|
|
auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT) }
|
2013-09-09 21:10:52 +01:00
|
|
|
let!(:build_list_package) { FactoryGirl.create( :build_list_package,
|
2014-01-21 04:51:49 +00:00
|
|
|
build_list: build_list,
|
|
|
|
version: '3.1.12',
|
|
|
|
release: 6,
|
|
|
|
platform: build_list.save_to_platform,
|
|
|
|
project: build_list.project) }
|
2013-09-09 21:10:52 +01:00
|
|
|
let!(:published_build_list) { FactoryGirl.create( :build_list,
|
2014-01-21 04:51:49 +00:00
|
|
|
project: build_list.project,
|
|
|
|
status: BuildList::BUILD_PUBLISHED,
|
|
|
|
save_to_platform: build_list.save_to_platform,
|
|
|
|
arch: build_list.arch) }
|
2013-09-09 21:10:52 +01:00
|
|
|
let!(:published_build_list_package) { FactoryGirl.create( :build_list_package,
|
2014-01-21 04:51:49 +00:00
|
|
|
build_list: published_build_list,
|
|
|
|
platform: published_build_list.save_to_platform,
|
|
|
|
actual: true,
|
|
|
|
version: '3.1.12',
|
|
|
|
release: 6,
|
|
|
|
project: published_build_list.project) }
|
2013-09-09 21:10:52 +01:00
|
|
|
|
2013-09-16 15:14:55 +01:00
|
|
|
it 'ensures that return false if version of packages are same and platform is released' do
|
2014-01-21 04:51:49 +00:00
|
|
|
build_list.save_to_platform.update_attributes(released: true)
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_falsy
|
2013-09-09 21:10:52 +01:00
|
|
|
end
|
|
|
|
|
2014-10-14 19:19:44 +01:00
|
|
|
it 'ensures that return true if version of packages are same and platform RHEL is released' do
|
2014-10-14 20:44:26 +01:00
|
|
|
build_list.save_to_platform.update_attributes(released: true, distrib_type: 'rhel')
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_truthy
|
2014-10-14 19:19:44 +01:00
|
|
|
end
|
|
|
|
|
2013-09-16 15:14:55 +01:00
|
|
|
it 'ensures that return true if version of packages are same and platform is not released' do
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_truthy
|
2013-09-16 15:14:55 +01:00
|
|
|
end
|
|
|
|
|
2013-09-10 17:09:48 +01:00
|
|
|
context 'ensures that return false if version of published package >' do
|
|
|
|
|
|
|
|
it 'published: 3.1.13, new: 3.1.12' do
|
2014-01-21 04:51:49 +00:00
|
|
|
published_build_list_package.update_attributes(version: '3.1.13')
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_falsy
|
2013-09-10 17:09:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'published: 3.1.12, new: 3.0.999' do
|
2014-01-21 04:51:49 +00:00
|
|
|
build_list_package.update_attributes(version: '3.0.999')
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_falsy
|
2013-09-10 17:09:48 +01:00
|
|
|
end
|
|
|
|
|
2013-09-11 17:44:27 +01:00
|
|
|
it 'published: 3.0.0, new: 3.0.rc1' do
|
2014-01-21 04:51:49 +00:00
|
|
|
published_build_list_package.update_attributes(version: '3.0.0')
|
|
|
|
build_list_package.update_attributes(version: '3.0.rc1')
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_falsy
|
2013-09-10 17:09:48 +01:00
|
|
|
end
|
|
|
|
|
2013-09-09 21:10:52 +01:00
|
|
|
end
|
|
|
|
|
2013-09-10 17:09:48 +01:00
|
|
|
context 'ensures that return true if version of published package <' do
|
|
|
|
|
|
|
|
it 'published: 3.1.11, new: 3.1.12' do
|
2014-01-21 04:51:49 +00:00
|
|
|
published_build_list_package.update_attributes(version: '3.1.11')
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_truthy
|
2013-09-10 17:09:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'published: 3.0.999, new: 3.1.12' do
|
2014-01-21 04:51:49 +00:00
|
|
|
published_build_list_package.update_attributes(version: '3.0.999')
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_truthy
|
2013-09-10 17:09:48 +01:00
|
|
|
end
|
|
|
|
|
2013-09-11 17:44:27 +01:00
|
|
|
it 'published: 3.0.rc1, new: 3.0.0' do
|
2014-01-21 04:51:49 +00:00
|
|
|
published_build_list_package.update_attributes(version: '3.0.rc1')
|
|
|
|
build_list_package.update_attributes(version: '3.0.0')
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_truthy
|
2013-09-10 17:09:48 +01:00
|
|
|
end
|
|
|
|
|
2013-09-09 21:10:52 +01:00
|
|
|
end
|
|
|
|
|
2013-09-10 15:26:49 +01:00
|
|
|
it 'ensures that return true if release of published package <' do
|
2014-01-21 04:51:49 +00:00
|
|
|
published_build_list_package.update_attributes(release: 5)
|
2015-02-19 01:12:08 +00:00
|
|
|
build_list.has_new_packages?.should be_truthy
|
2013-09-10 15:26:49 +01:00
|
|
|
end
|
|
|
|
|
2013-09-09 21:10:52 +01:00
|
|
|
end
|
|
|
|
|
2014-10-23 19:29:46 +01:00
|
|
|
context '#can_publish?' do
|
2014-05-28 22:08:29 +01:00
|
|
|
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
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(build_list.can_publish?).to be_truthy
|
2014-05-28 22:08:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if branch invalid' do
|
|
|
|
allow(build_list).to receive(:valid_branch_for_publish?).and_return(false)
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(build_list.can_publish?).to be_falsy
|
2014-05-28 22:08:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if extra builds not published' do
|
|
|
|
allow(build_list).to receive(:extra_build_lists_published?).and_return(false)
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(build_list.can_publish?).to be_falsy
|
2014-05-28 22:08:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if project does not exist in repository' do
|
|
|
|
build_list.stub_chain(:save_to_repository, :projects, :exists?).and_return(false)
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(build_list.can_publish?).to be_falsy
|
2014-05-28 22:08:29 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-23 19:29:46 +01:00
|
|
|
context '#can_publish_into_testing?' do
|
2014-05-28 22:08:29 +01:00
|
|
|
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)
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(build_list.can_publish_into_testing?).to be_truthy
|
2014-05-28 22:08:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if branch invalid' do
|
|
|
|
allow(build_list).to receive(:valid_branch_for_publish?).and_return(false)
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(build_list.can_publish_into_testing?).to be_falsy
|
2014-05-28 22:08:29 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-23 19:29:46 +01:00
|
|
|
context '#prepare_extra_params' do
|
|
|
|
let(:build_list) { FactoryGirl.build(:build_list) }
|
|
|
|
|
|
|
|
it 'removes unsafe symbols' do
|
|
|
|
build_list.extra_params = { 'build_rpm' => '--test \'001\' --define "cross armv7hl"{(@' }
|
|
|
|
build_list.send :prepare_extra_params
|
2014-10-23 19:52:38 +01:00
|
|
|
expect(build_list.extra_params['build_rpm']).to eq '--test 001 --define "cross armv7hl"'
|
2014-10-23 19:29:46 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|