2012-09-19 14:55:17 +01:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
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)
|
|
|
|
bl.valid?.should be_true
|
|
|
|
end
|
|
|
|
it 'when repository does not contain project' do
|
|
|
|
bl = FactoryGirl.build(:build_list)
|
|
|
|
bl.project.repositories = []
|
|
|
|
bl.valid?.should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-19 14:55:17 +01:00
|
|
|
context "#notify_users" do
|
|
|
|
let!(:user) { FactoryGirl.create(:user) }
|
2013-07-01 13:20:38 +01:00
|
|
|
let!(:build_list) { FactoryGirl.create(:build_list,
|
2012-09-19 14:55:17 +01:00
|
|
|
:user => user,
|
|
|
|
:auto_publish => false) }
|
|
|
|
let!(:build_list_package) { FactoryGirl.create(:build_list_package,
|
|
|
|
:build_list => build_list,
|
|
|
|
:project => build_list.project) }
|
|
|
|
|
|
|
|
|
|
|
|
before(:all) { ActionMailer::Base.deliveries = [] }
|
2012-09-19 15:30:35 +01:00
|
|
|
before do
|
2012-12-25 13:11:24 +00:00
|
|
|
build_list.update_attributes({:commit_hash => build_list.project.repo.commits('master').last.id,
|
2013-01-24 11:32:00 +00:00
|
|
|
:status => BuildList::BUILD_STARTED}, :without_protection => true)
|
2012-09-19 15:30:35 +01:00
|
|
|
end
|
2012-09-19 14:55:17 +01:00
|
|
|
after { ActionMailer::Base.deliveries = [] }
|
|
|
|
|
|
|
|
shared_examples_for 'build list notifications by email' do
|
|
|
|
it "gets notification by email when status - Build complete" do
|
|
|
|
build_list.build_success
|
|
|
|
should have(1).item
|
|
|
|
end
|
|
|
|
|
2012-09-19 20:52:18 +01:00
|
|
|
it "gets notification by email when status - Build error" do
|
|
|
|
build_list.build_error
|
|
|
|
should have(1).item
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gets notification by email when auto_publish and status - Build error" do
|
|
|
|
build_list.update_attributes(:auto_publish => true)
|
|
|
|
build_list.build_error
|
|
|
|
should have(1).item
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gets notification by email when status - Failed publish" do
|
2012-12-25 13:11:24 +00:00
|
|
|
build_list.update_attributes({:status => BuildList::BUILD_PUBLISH}, :without_protection => true)
|
2012-09-19 20:52:18 +01:00
|
|
|
build_list.fail_publish
|
|
|
|
should have(1).item
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gets notification by email when auto_publish and status - Failed publish" do
|
2012-12-25 13:11:24 +00:00
|
|
|
build_list.update_attributes({:auto_publish => true, :status => BuildList::BUILD_PUBLISH}, :without_protection => true)
|
2012-09-19 20:52:18 +01:00
|
|
|
build_list.fail_publish
|
|
|
|
should have(1).item
|
|
|
|
end
|
|
|
|
|
2012-09-19 14:55:17 +01:00
|
|
|
it "gets notification by email when status - Build published" do
|
2012-12-25 13:11:24 +00:00
|
|
|
build_list.update_attributes({:status => BuildList::BUILD_PUBLISH}, :without_protection => true)
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.published
|
|
|
|
should have(1).item
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gets notification by email when auto_publish and status - Build published" do
|
2012-12-25 13:11:24 +00:00
|
|
|
build_list.update_attributes({:auto_publish => true, :status => BuildList::BUILD_PUBLISH}, :without_protection => true)
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.published
|
|
|
|
should have(1).item
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when auto_publish and status - Build complete" do
|
|
|
|
build_list.update_attributes(:auto_publish => true)
|
|
|
|
build_list.build_success
|
|
|
|
should have(:no).items
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when mass build" do
|
2012-12-25 13:11:24 +00:00
|
|
|
build_list.update_attributes({:mass_build_id => 1, :status => BuildList::BUILD_PUBLISH}, :without_protection => true)
|
2012-09-19 14:55:17 +01:00
|
|
|
build_list.published
|
|
|
|
should have(:no).items
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when notification by email has been disabled" do
|
|
|
|
notifier.update_attributes(:can_notify => false)
|
|
|
|
build_list.build_success
|
|
|
|
should have(:no).items
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { ActionMailer::Base.deliveries }
|
|
|
|
|
|
|
|
context "user created build task" do
|
|
|
|
let!(:notifier) { user.notifier }
|
|
|
|
before do
|
|
|
|
notifier.update_attributes(:new_associated_build => false)
|
|
|
|
build_list.project.owner.notifier.update_attributes(:can_notify => false)
|
|
|
|
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
|
|
|
|
notifier.update_attributes(:new_build => false)
|
|
|
|
build_list.build_success
|
|
|
|
should have(:no).items
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when 'build list' notifications - enabled, email notifications - disabled" do
|
|
|
|
notifier.update_attributes(:can_notify => false, :new_build => true)
|
|
|
|
build_list.build_success
|
|
|
|
should have(:no).items
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "build task has been created and associated user" do
|
|
|
|
let!(:notifier) { build_list.project.owner.notifier }
|
|
|
|
before do
|
|
|
|
notifier.update_attributes(:new_build => false)
|
|
|
|
user.notifier.update_attributes(:can_notify => false)
|
|
|
|
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
|
|
|
|
notifier.update_attributes(:new_associated_build => false)
|
|
|
|
build_list.build_success
|
|
|
|
should have(:no).items
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get notification by email when 'associated build list' notifications - enabled, email notifications - disabled" do
|
|
|
|
notifier.update_attributes(:can_notify => false, :new_associated_build => true)
|
|
|
|
build_list.build_success
|
|
|
|
should have(:no).items
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't get 2 notification by email when user associated to project and created task" do
|
2012-12-26 13:06:17 +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,
|
2012-09-19 14:55:17 +01:00
|
|
|
:user => user,
|
|
|
|
:auto_publish => true,
|
2012-12-26 17:30:27 +00:00
|
|
|
:project => project
|
|
|
|
)
|
2012-09-19 14:55:17 +01:00
|
|
|
FactoryGirl.create(:build_list_package, :build_list => bl, :project => bl.project)
|
2012-12-25 13:11:24 +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
|
|
|
|
should have(1).item
|
|
|
|
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,
|
|
|
|
:status => BuildList::SUCCESS,
|
|
|
|
:auto_publish => true) }
|
|
|
|
let!(:build_list_package) { FactoryGirl.create( :build_list_package,
|
|
|
|
:build_list => build_list,
|
2013-09-10 17:09:48 +01:00
|
|
|
:version => '3.1.12',
|
|
|
|
:release => 6,
|
2013-09-09 21:10:52 +01:00
|
|
|
:platform => build_list.save_to_platform,
|
|
|
|
:project => build_list.project) }
|
|
|
|
let!(:published_build_list) { FactoryGirl.create( :build_list,
|
|
|
|
:project => build_list.project,
|
|
|
|
:status => BuildList::BUILD_PUBLISHED,
|
|
|
|
:save_to_platform => build_list.save_to_platform,
|
|
|
|
:arch => build_list.arch) }
|
|
|
|
let!(:published_build_list_package) { FactoryGirl.create( :build_list_package,
|
|
|
|
:build_list => published_build_list,
|
|
|
|
:platform => published_build_list.save_to_platform,
|
|
|
|
:actual => true,
|
2013-09-10 17:09:48 +01:00
|
|
|
:version => '3.1.12',
|
|
|
|
:release => 6,
|
2013-09-09 21:10:52 +01:00
|
|
|
:project => published_build_list.project) }
|
|
|
|
|
|
|
|
it 'ensures that return false if version of packages are same' do
|
2013-09-10 17:09:48 +01:00
|
|
|
build_list.has_new_packages?.should be_false
|
2013-09-09 21:10:52 +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
|
|
|
|
published_build_list_package.update_attributes(:version => '3.1.13')
|
|
|
|
build_list.has_new_packages?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'published: 3.1.12, new: 3.0.999' do
|
|
|
|
build_list_package.update_attributes(:version => '3.0.999')
|
|
|
|
build_list.has_new_packages?.should be_false
|
|
|
|
end
|
|
|
|
|
2013-09-11 17:44:27 +01:00
|
|
|
it 'published: 3.0.0, new: 3.0.rc1' do
|
|
|
|
published_build_list_package.update_attributes(:version => '3.0.0')
|
|
|
|
build_list_package.update_attributes(:version => '3.0.rc1')
|
2013-09-10 17:09:48 +01:00
|
|
|
build_list.has_new_packages?.should be_false
|
|
|
|
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
|
|
|
|
published_build_list_package.update_attributes(:version => '3.1.11')
|
|
|
|
build_list.has_new_packages?.should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'published: 3.0.999, new: 3.1.12' do
|
|
|
|
published_build_list_package.update_attributes(:version => '3.0.999')
|
|
|
|
build_list.has_new_packages?.should be_true
|
|
|
|
end
|
|
|
|
|
2013-09-11 17:44:27 +01:00
|
|
|
it 'published: 3.0.rc1, new: 3.0.0' do
|
|
|
|
published_build_list_package.update_attributes(:version => '3.0.rc1')
|
|
|
|
build_list_package.update_attributes(:version => '3.0.0')
|
2013-09-10 17:09:48 +01:00
|
|
|
build_list.has_new_packages?.should be_true
|
|
|
|
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
|
|
|
|
published_build_list_package.update_attributes(:release => 5)
|
2013-09-10 17:09:48 +01:00
|
|
|
build_list.has_new_packages?.should be_true
|
2013-09-10 15:26:49 +01:00
|
|
|
end
|
|
|
|
|
2013-09-09 21:10:52 +01:00
|
|
|
end
|
|
|
|
|
2012-09-19 14:55:17 +01:00
|
|
|
end
|