#397: added specs for RunBuildListsJob

This commit is contained in:
Vokhmin Alexey V 2014-06-17 00:23:17 +04:00
parent 4940073780
commit 0c841d49f3
3 changed files with 56 additions and 1 deletions

View File

@ -9,7 +9,7 @@ class RunBuildListsJob
return unless ability.can?(:show, build_list)
project = Project.find(project_id) if project_id.present?
return if project && !ability.can?(:show, project)
return if project && !ability.can?(:write, project)
dependent_packages = build_list.packages.pluck(:dependent_packages).flatten.uniq
project_ids = BuildList::Package.

View File

@ -687,6 +687,7 @@ class BuildList < ActiveRecord::Base
end
def prepare_extra_build_lists
return if extra_build_lists.blank?
bls = BuildList.for_extra_build_lists(extra_build_lists, current_ability, save_to_platform)
if save_to_platform
if save_to_platform.distrib_type == 'rhel'

View File

@ -0,0 +1,54 @@
require 'spec_helper'
describe RunBuildListsJob do
let(:build_list) { FactoryGirl.build(:build_list, id: 123) }
let(:user) { build_list.user }
let(:project) { build_list.project }
let(:ability) { double(:ability) }
before do
stub_symlink_methods
allow(BuildList).to receive(:find).with(123).and_return(build_list)
BuildList::Package.stub_chain(:joins, :where, :reorder, :uniq, :pluck).and_return([project.id])
Project.stub_chain(:where, :to_a).and_return([project])
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
it 'ensures that not raises error' do
expect do
RunBuildListsJob.perform build_list.id, user.id
end.to_not raise_exception
end
it 'ensures that creates build_list' do
expect do
RunBuildListsJob.perform build_list.id, user.id
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
RunBuildListsJob.perform build_list.id, user.id
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
RunBuildListsJob.perform build_list.id, user.id
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
RunBuildListsJob.perform build_list.id, user.id
end.to change(BuildList, :count).by(0)
end
end