2014-06-16 21:23:17 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-06-18 21:40:22 +01:00
|
|
|
describe BuildLists::DependentPackagesJob do
|
2014-06-16 21:23:17 +01:00
|
|
|
let(:build_list) { FactoryGirl.build(:build_list, id: 123) }
|
|
|
|
let(:user) { build_list.user }
|
|
|
|
let(:project) { build_list.project }
|
|
|
|
let(:ability) { double(:ability) }
|
2014-07-23 21:41:34 +01:00
|
|
|
let(:project_ids) { [build_list.project_id] }
|
|
|
|
let(:arch_ids) { [build_list.arch_id] }
|
|
|
|
let(:options) { {
|
2014-07-25 15:47:12 +01:00
|
|
|
'auto_publish_status' => 'none',
|
|
|
|
'auto_create_container' => '0',
|
|
|
|
'include_testing_subrepository' => '0',
|
|
|
|
'use_cached_chroot' => '0',
|
|
|
|
'use_extra_tests' => '0'
|
2014-07-23 21:41:34 +01:00
|
|
|
} }
|
2014-06-16 21:23:17 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_symlink_methods
|
|
|
|
allow(BuildList).to receive(:find).with(123).and_return(build_list)
|
2014-07-23 21:41:34 +01:00
|
|
|
# BuildList::Package.stub_chain(:joins, :where, :reorder, :uniq, :pluck).and_return([project.id])
|
2014-06-16 21:23:17 +01:00
|
|
|
Project.stub_chain(:where, :to_a).and_return([project])
|
2014-07-23 21:41:34 +01:00
|
|
|
Arch.stub_chain(:where, :to_a).and_return([build_list.arch])
|
2014-06-16 21:23:17 +01:00
|
|
|
|
|
|
|
allow(Ability).to receive(:new).and_return(ability)
|
|
|
|
allow(ability).to receive(:can?).with(:show, build_list).and_return(true)
|
|
|
|
allow(ability).to receive(:can?).with(:write, project).and_return(true)
|
|
|
|
allow(ability).to receive(:can?).with(:create, anything).and_return(true)
|
|
|
|
end
|
|
|
|
|
2014-06-18 21:40:22 +01:00
|
|
|
subject { BuildLists::DependentPackagesJob }
|
|
|
|
|
2014-06-16 21:23:17 +01:00
|
|
|
it 'ensures that not raises error' do
|
|
|
|
expect do
|
2014-07-23 21:41:34 +01:00
|
|
|
subject.perform build_list.id, user.id, project_ids, arch_ids, options
|
2014-06-16 21:23:17 +01:00
|
|
|
end.to_not raise_exception
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ensures that creates build_list' do
|
|
|
|
expect do
|
2014-07-23 21:41:34 +01:00
|
|
|
subject.perform build_list.id, user.id, project_ids, arch_ids, options
|
2014-06-16 21:23:17 +01:00
|
|
|
end.to change(BuildList, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ensures that do nothing if user has no access for show of build_list' do
|
|
|
|
allow(ability).to receive(:can?).with(:show, build_list).and_return(false)
|
|
|
|
expect do
|
2014-07-23 21:41:34 +01:00
|
|
|
subject.perform build_list.id, user.id, project_ids, arch_ids, options
|
2014-06-16 21:23:17 +01:00
|
|
|
end.to change(BuildList, :count).by(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ensures that do nothing if user has no access for write of project' do
|
|
|
|
allow(ability).to receive(:can?).with(:write, project).and_return(false)
|
|
|
|
expect do
|
2014-07-23 21:41:34 +01:00
|
|
|
subject.perform build_list.id, user.id, project_ids, arch_ids, options
|
2014-06-16 21:23:17 +01:00
|
|
|
end.to change(BuildList, :count).by(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ensures that do nothing if user has no access for create of build_list' do
|
|
|
|
allow(ability).to receive(:can?).with(:create, anything).and_return(false)
|
|
|
|
expect do
|
2014-07-23 21:41:34 +01:00
|
|
|
subject.perform build_list.id, user.id, project_ids, arch_ids, options
|
2014-06-16 21:23:17 +01:00
|
|
|
end.to change(BuildList, :count).by(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|