Merge pull request #366 from abf/rosa-build:fix-autostart-projects

Fix: autostart project build_lists
This commit is contained in:
avokhmin 2014-03-13 01:31:58 +04:00
commit 61a7879170
5 changed files with 80 additions and 11 deletions

View File

@ -8,7 +8,11 @@ class PlatformArchSetting < ActiveRecord::Base
belongs_to :platform belongs_to :platform
validates :arch_id, :platform_id, presence: true validates :arch_id, :platform_id, presence: true
validates :platform_id, :uniqueness => {scope: :arch_id} validates :platform_id, :uniqueness => {scope: :arch_id}
validate lambda {
errors.add(:platform, I18n.t('flash.platform_arch_settings.wrong_platform')) unless platform.main?
}
scope :by_arch, lambda {|arch| where(arch_id: arch) if arch.present?} scope :by_arch, lambda {|arch| where(arch_id: arch) if arch.present?}
scope :by_default, where(default: true) scope :by_default, where(default: true)

View File

@ -322,13 +322,18 @@ class Project < ActiveRecord::Base
bl.build_for_platform = platform bl.build_for_platform = platform
bl.update_type = 'newpackage' bl.update_type = 'newpackage'
bl.arch_id = arch_id bl.arch_id = arch_id
bl.project_version = p.project_version_for(platform, platform) bl.project_version = p.project_version_for(repository.platform, platform)
bl.user = user bl.user = user
bl.auto_publish_status = p_to_r.auto_publish? ? BuildList::AUTO_PUBLISH_STATUS_DEFAULT : BuildList::AUTO_PUBLISH_STATUS_NONE bl.auto_publish_status = p_to_r.auto_publish? ? BuildList::AUTO_PUBLISH_STATUS_DEFAULT : BuildList::AUTO_PUBLISH_STATUS_NONE
bl.save_to_repository = repository bl.save_to_repository = repository
bl.include_repos = [repository.id, platform.repositories.main.first.try(:id)].uniq.compact bl.include_repos = [platform.repositories.main.first.try(:id)].compact
if repository.platform.personal?
bl.extra_repositories = [repository.id]
else
bl.include_repos |= [repository.id]
end
end end
build_list.save! build_list.save
end end
end end
end end

View File

@ -5,6 +5,7 @@ en:
flash: flash:
platform_arch_settings: platform_arch_settings:
wrong_platform: should be main
activerecord: activerecord:
attributes: attributes:

View File

@ -5,6 +5,7 @@ ru:
flash: flash:
platform_arch_settings: platform_arch_settings:
wrong_platform: должна быть основной
activerecord: activerecord:
attributes: attributes:

View File

@ -181,7 +181,13 @@ describe Project do
owner.projects.should have(2).items owner.projects.should have(2).items
end end
context '#autostart_build_lists_once_a_*' do shared_examples_for 'autostart build_lists' do |once_a_12_hours, once_a_day, once_a_week|
it { lambda { Project.autostart_build_lists_once_a_12_hours }.should change{ BuildList.count }.by(once_a_12_hours) }
it { lambda { Project.autostart_build_lists_once_a_day }.should change{ BuildList.count }.by(once_a_day) }
it { lambda { Project.autostart_build_lists_once_a_week }.should change{ BuildList.count }.by(once_a_week) }
end
context '#autostart_build_lists_once_a_* for main platform' do
let(:project) { FactoryGirl.create(:project_with_commit) } let(:project) { FactoryGirl.create(:project_with_commit) }
let(:repository) { FactoryGirl.create(:repository) } let(:repository) { FactoryGirl.create(:repository) }
let(:user) { FactoryGirl.create(:user) } let(:user) { FactoryGirl.create(:user) }
@ -201,12 +207,6 @@ describe Project do
it { ProjectToRepository.autostart_enabled.should have(1).item } it { ProjectToRepository.autostart_enabled.should have(1).item }
it { repository.platform.platform_arch_settings.should have(2).item } it { repository.platform.platform_arch_settings.should have(2).item }
shared_examples_for 'autostart build_lists' do |once_a_12_hours, once_a_day, once_a_week|
it { lambda { Project.autostart_build_lists_once_a_12_hours }.should change{ BuildList.count }.by(once_a_12_hours) }
it { lambda { Project.autostart_build_lists_once_a_day }.should change{ BuildList.count }.by(once_a_day) }
it { lambda { Project.autostart_build_lists_once_a_week }.should change{ BuildList.count }.by(once_a_week) }
end
context 'once_a_12_hours' do context 'once_a_12_hours' do
before { project.update_attributes(autostart_status: Modules::Models::Autostart::ONCE_A_12_HOURS) } before { project.update_attributes(autostart_status: Modules::Models::Autostart::ONCE_A_12_HOURS) }
it_should_behave_like 'autostart build_lists', 1, 0, 0 it_should_behave_like 'autostart build_lists', 1, 0, 0
@ -224,4 +224,62 @@ describe Project do
end end
context '#autostart_build_lists_once_a_* for personal platform' do
let(:project) { FactoryGirl.create(:project_with_commit) }
let(:repository) { FactoryGirl.create(:personal_repository) }
let(:main_repository) { FactoryGirl.create(:repository, name: 'main') }
let(:user) { FactoryGirl.create(:user) }
before do
repositories = [repository, main_repository] # 1
# Create 1 main platforms with main repositories
repositories << FactoryGirl.create(:repository, name: 'main') # 2
# Create platform without main repository
repositories << FactoryGirl.create(:repository)
# Hidden platform
r = FactoryGirl.create(:repository, name: 'main')
r.platform.update_attributes(visibility: 'hidden')
repositories << r # 3
# Without access to hidden platform
r = FactoryGirl.create(:repository, name: 'main')
r.platform.update_attributes(visibility: 'hidden')
repositories.each do |r|
r.projects << project
p_to_r = project.project_to_repositories.where(repository_id: r).first
p_to_r.enabled = true
p_to_r.user_id = user.id
p_to_r.save
FactoryGirl.create(:platform_arch_setting, platform: r.platform) if r.platform.main?
end
FactoryGirl.create(:platform_arch_setting, platform: main_repository.platform, default: false)
end
# 1(personal) + 2(main) + 1(hidden) + 1(main, without main repository)
it { ProjectToRepository.autostart_enabled.should have(5).item }
it { main_repository.platform.platform_arch_settings.should have(2).item }
# into main platforms: 2 + 1(hidden)
# into personal platform: 3(main) * 1
context 'once_a_12_hours' do
before { project.update_attributes(autostart_status: Modules::Models::Autostart::ONCE_A_12_HOURS) }
it_should_behave_like 'autostart build_lists', 6, 0, 0
end
context 'once_a_day' do
before { project.update_attributes(autostart_status: Modules::Models::Autostart::ONCE_A_DAY) }
it_should_behave_like 'autostart build_lists', 0, 6, 0
end
context 'once_a_day' do
before { project.update_attributes(autostart_status: Modules::Models::Autostart::ONCE_A_WEEK) }
it_should_behave_like 'autostart build_lists', 0, 0, 6
end
end
end end