Merge pull request #560 from warpc/442-mass_build
[refs #442] Add tests for mass builds and attr_accessible. Fix ability.
This commit is contained in:
commit
c45e599eb0
|
@ -10,13 +10,10 @@ class Platforms::MassBuildsController < Platforms::BaseController
|
|||
skip_authorize_resource :platform, :only => [:create, :index]
|
||||
|
||||
def create
|
||||
mass_build = MassBuild.new(
|
||||
:platform => @platform,
|
||||
:user => current_user,
|
||||
:repositories => params[:repositories],
|
||||
mass_build = @platform.mass_builds.new(:repositories => params[:repositories],
|
||||
:arches => params[:arches],
|
||||
:auto_publish => params[:auto_publish] || false
|
||||
)
|
||||
:auto_publish => params[:auto_publish] || false)
|
||||
mass_build.user = current_user
|
||||
authorize! :create, mass_build
|
||||
|
||||
if mass_build.save
|
||||
|
|
|
@ -86,19 +86,22 @@ class Ability
|
|||
can([:destroy, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
|
||||
can [:autocomplete_user_uname, :read_advisories, :advisories], Platform
|
||||
|
||||
can([:failed_builds_list, :create], MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && mass_build.platform.main? }
|
||||
can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && !mass_build.stop_build && mass_build.platform.main?}
|
||||
|
||||
can [:read, :projects_list], Repository, :platform => {:visibility => 'open'}
|
||||
can [:read, :projects_list], Repository, :platform => {:owner_type => 'User', :owner_id => user.id}
|
||||
can [:read, :projects_list], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids}
|
||||
can([:read, :projects_list], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform}
|
||||
can([:create, :update, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform}
|
||||
can(:clear, Platform) {|platform| local_admin?(platform) && platform.platform_type == 'personal'}
|
||||
can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?}
|
||||
can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform}
|
||||
|
||||
can :read, Product, :platform => {:visibility => 'open'}
|
||||
can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id, :platform_type => 'main'}
|
||||
can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids, :platform_type => 'main'}
|
||||
can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.platform_type == 'main'}
|
||||
can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.platform_type == 'main'}
|
||||
can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.main?}
|
||||
can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.main?}
|
||||
|
||||
can(:create, ProductBuildList) {|pbl| can?(:update, pbl.product)}
|
||||
can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)}
|
||||
|
@ -128,8 +131,9 @@ class Ability
|
|||
|
||||
cannot [:create, :update, :destroy, :clone], Product, :platform => {:platform_type => 'personal'}
|
||||
cannot [:clone], Platform, :platform_type => 'personal'
|
||||
can([:failed_builds_list, :create], MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && (mass_build.platform.platform_type == 'main') }
|
||||
can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && !mass_build.stop_build && (mass_build.platform.platform_type == 'main')}
|
||||
|
||||
cannot([:failed_builds_list, :create], MassBuild) {|mass_build| mass_build.platform.personal?}
|
||||
cannot(:cancel, MassBuild) {|mass_build| mass_build.platform.personal? || mass_build.stop_build}
|
||||
|
||||
can :create, Subscribe do |subscribe|
|
||||
!subscribe.subscribeable.subscribes.exists?(:user_id => user.id)
|
||||
|
|
|
@ -6,11 +6,13 @@ class MassBuild < ActiveRecord::Base
|
|||
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
|
||||
|
||||
attr_accessor :repositories, :arches
|
||||
attr_accessible :repositories, :arches, :auto_publish
|
||||
|
||||
validates :platform_id, :arch_names, :name, :user_id, :repositories, :rep_names, :presence => true
|
||||
validates_inclusion_of :auto_publish, :in => [true, false]
|
||||
|
||||
after_create :build_all
|
||||
before_validation :set_data
|
||||
|
||||
COUNT_STATUSES = [
|
||||
:build_lists,
|
||||
|
@ -21,16 +23,6 @@ class MassBuild < ActiveRecord::Base
|
|||
:build_error
|
||||
]
|
||||
|
||||
def initialize(args = nil)
|
||||
super
|
||||
|
||||
if new_record?
|
||||
self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ")
|
||||
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}"
|
||||
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
|
||||
end
|
||||
end
|
||||
|
||||
# ATTENTION: repositories and arches must be set before calling this method!
|
||||
def build_all
|
||||
platform.build_all(
|
||||
|
@ -58,4 +50,15 @@ class MassBuild < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
later :cancel_all, :queue => :clone_build
|
||||
|
||||
private
|
||||
|
||||
def set_data
|
||||
if new_record?
|
||||
self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ")
|
||||
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}"
|
||||
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -107,6 +107,10 @@ class Platform < ActiveRecord::Base
|
|||
platform_type == 'personal'
|
||||
end
|
||||
|
||||
def main?
|
||||
platform_type == 'main'
|
||||
end
|
||||
|
||||
def base_clone(attrs = {}) # :description, :name, :owner
|
||||
dup.tap do |c|
|
||||
attrs.each {|k,v| c.send("#{k}=", v)} # c.attributes = attrs
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require 'spec_helper'
|
||||
|
||||
shared_examples_for 'mass_build platform owner' do
|
||||
it 'should be able to perform index action' do
|
||||
get :index, :platform_id => @platform
|
||||
response.should render_template(:index)
|
||||
end
|
||||
|
||||
it 'should be able to perform create action' do
|
||||
post :create, @create_params
|
||||
response.should redirect_to(platform_mass_builds_path(@platform))
|
||||
end
|
||||
|
||||
it 'should be able to perform cancel action' do
|
||||
post :cancel, :platform_id => @platform, :id => @mass_build
|
||||
response.should redirect_to(platform_mass_builds_path(@platform))
|
||||
end
|
||||
|
||||
it 'should change stop_build on cancel' do
|
||||
post :cancel, :platform_id => @platform, :id => @mass_build
|
||||
@mass_build.reload.stop_build.should == true
|
||||
end
|
||||
|
||||
it 'should not be able to perform cancel action if stop_build is true' do
|
||||
@mass_build.update_attribute(:stop_build, true)
|
||||
post :cancel, :platform_id => @platform, :id => @mass_build
|
||||
response.should redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should change objects count on create success' do
|
||||
lambda { post :create, @create_params }.should change{ MassBuild.count }.by(1)
|
||||
end
|
||||
|
||||
context 'for personal platform' do
|
||||
before(:each) do
|
||||
Platform.update_all("platform_type = 'personal'")
|
||||
end
|
||||
|
||||
[:cancel, :failed_builds_list, :create].each do |action|
|
||||
it "should not be able to perform #{ action } action" do
|
||||
get action, :platform_id => @platform, :id => @mass_build.id
|
||||
response.should redirect_to(forbidden_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'mass_build platform reader' do
|
||||
[:index, :create].each do |action|
|
||||
it "should not be able to perform #{ action } action" do
|
||||
get action, :platform_id => @platform
|
||||
response.should redirect_to(forbidden_path)
|
||||
end
|
||||
end
|
||||
|
||||
[:cancel, :failed_builds_list].each do |action|
|
||||
it "should not be able to perform #{ action } action" do
|
||||
get action, :platform_id => @platform, :id => @mass_build.id
|
||||
response.should redirect_to(forbidden_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not change objects count on create success' do
|
||||
lambda { post :create, @create_params }.should change{ MassBuild.count }.by(0)
|
||||
end
|
||||
|
||||
it 'should not change stop_build on cancel' do
|
||||
post :cancel, :platform_id => @platform, :id => @mass_build
|
||||
@mass_build.reload.stop_build.should == false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe Platforms::MassBuildsController do
|
||||
before(:each) do
|
||||
stub_symlink_methods
|
||||
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
@repository = FactoryGirl.create(:repository, :platform => @platform)
|
||||
@personal_platform = FactoryGirl.create(:platform, :platform_type => 'personal')
|
||||
@user = FactoryGirl.create(:user)
|
||||
@create_params = {
|
||||
:platform_id => @platform,
|
||||
:repositories => [@platform.repositories.first.id],
|
||||
:arches => [Arch.first.id],
|
||||
:auto_publish => true
|
||||
}
|
||||
|
||||
@mass_build = FactoryGirl.create(:mass_build, :platform => @platform, :user => @user)
|
||||
end
|
||||
|
||||
context 'for guest' do
|
||||
[:index, :create, :cancel, :failed_builds_list].each do |action|
|
||||
it "should not be able to perform #{ action } action" do
|
||||
get action, :platform_id => @platform
|
||||
response.should redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not change objects count on create success' do
|
||||
lambda { post :create, @create_params }.should change{ MassBuild.count }.by(0)
|
||||
end
|
||||
|
||||
it 'should not change stop_build on cancel' do
|
||||
post :cancel, :platform_id => @platform, :id => @mass_build
|
||||
@mass_build.reload.stop_build.should == false
|
||||
end
|
||||
end
|
||||
|
||||
context 'for global admin' do
|
||||
before(:each) do
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
it_should_behave_like 'mass_build platform owner'
|
||||
end
|
||||
|
||||
context 'for owner user' do
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@platform.update_attribute(:owner, @user)
|
||||
end
|
||||
|
||||
it_should_behave_like 'mass_build platform owner'
|
||||
end
|
||||
|
||||
context 'for admin user' do
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
||||
end
|
||||
|
||||
it_should_behave_like 'mass_build platform owner'
|
||||
end
|
||||
|
||||
context 'for reader user' do
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
|
||||
end
|
||||
|
||||
it_should_behave_like 'mass_build platform reader'
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
FactoryGirl.define do
|
||||
factory :mass_build do
|
||||
association :platform
|
||||
#name FactoryGirl.generate(:name)
|
||||
association :user
|
||||
repositories { |mb| [ mb.platform.repositories.first.id ] }
|
||||
arches { [ Arch.first.id ] }
|
||||
auto_publish true
|
||||
stop_build false
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue