#465: Update specs for Platforms::MassBuildsController

This commit is contained in:
Vokhmin Alexey V 2015-04-03 01:13:26 +03:00
parent da2c6ee921
commit d2ea9f03ae
3 changed files with 48 additions and 34 deletions

View File

@ -4,28 +4,30 @@ class Platforms::MassBuildsController < Platforms::BaseController
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:index, :get_list] if APP_CONFIG['anonymous_access']
load_resource :platform
load_and_authorize_resource :through => :platform, :shallow => true
before_action :find_mass_build, only: %i(show publish cancel get_list)
def new
if params[:mass_build_id].present?
@mass_build = @platform.mass_builds.find(params[:mass_build_id]).dup
@mass_build.arches = Arch.where(name: @mass_build.arch_names.split(', ')).pluck(:id)
end
authorize @mass_build ||= @platform.mass_builds.build
@mass_build.arches ||= @platform.platform_arch_settings.by_default.pluck(:arch_id)
@mass_build.repositories ||= []
@mass_build.arches.map!(&:to_s)
end
def show
authorize @platform.mass_builds.find(params[:id])
end
def create
@mass_build = @platform.mass_builds.build(params[:mass_build])
@mass_build.user = current_user
@mass_build.arches = params[:arches] || []
@mass_build.repositories ||= params[:repositories] || []
authorize @mass_build
if @mass_build.save
redirect_to(platform_mass_builds_path(@platform), notice: t("flash.platform.build_all_success"))
else
@ -57,7 +59,6 @@ class Platforms::MassBuildsController < Platforms::BaseController
end
def get_list
text =
case params[:kind]
when 'failed_builds_list', 'tests_failed_builds_list', 'success_builds_list'
@ -67,4 +68,11 @@ class Platforms::MassBuildsController < Platforms::BaseController
end
render text: text
end
private
# Private: before_action hook which loads MassBuild.
def find_mass_build
authorize @mass_build = @platform.mass_builds.find(params[:id])
end
end

View File

@ -1,13 +1,13 @@
class MassBuildPolicy < ApplicationPolicy
def show?
ProjectPolicy.new(user, record.save_to_platform).show?
is_admin? || PlatformPolicy.new(user, record.save_to_platform).show?
end
alias_method :read?, :show?
alias_method :get_list?, :show?
def create?
owner?(record.save_to_platform) || local_admin?(record.save_to_platform)
is_admin? || owner?(record.save_to_platform) || local_admin?(record.save_to_platform)
end
alias_method :publish?, :create?

View File

@ -3,58 +3,60 @@ 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)
expect(response).to render_template(:index)
end
it 'should be able to perform show action' do
get :show, platform_id: @platform, id: @mass_build
response.should render_template(:show)
expect(response).to render_template(:show)
end
it 'should be able to perform new action' do
get :new, platform_id: @platform
response.should render_template(:new)
expect(response).to render_template(:new)
end
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(platform_mass_builds_path(@platform))
expect(response).to 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))
expect(response).to 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
expect(@mass_build.reload.stop_build).to be_truthy
end
it 'should be able to perform publish action' do
post :publish, platform_id: @platform, id: @mass_build
response.should redirect_to(platform_mass_builds_path(@platform))
expect(response).to redirect_to(platform_mass_builds_path(@platform))
end
it 'should change build_publish on publish' do
allow_any_instance_of(BuildList).to receive(:valid_branch_for_publish?).and_return(true)
post :publish, platform_id: @platform, id: @mass_build
@mass_build.reload.build_publish_count.should == 1
expect(@mass_build.reload.build_publish_count).to eq 1
end
it 'should not be able to perform cancel action if stop_build is true' do
@mass_build.stop_build = true; @mass_build.save
post :cancel, platform_id: @platform, id: @mass_build
response.should redirect_to(forbidden_path)
expect(response).to 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)
expect do
post :create, @create_params
end.to change(MassBuild, :count).by(1)
end
it 'should be able to perform get_list action' do
get :get_list, platform_id: @platform, id: @mass_build, kind: 'failed_builds_list'
response.should be_success
expect(response).to be_success
end
end
@ -74,43 +76,45 @@ end
shared_examples_for 'mass_build platform reader' do
it 'should be able to perform index action' do
get :index, platform_id: @platform
response.should render_template(:index)
expect(response).to render_template(:index)
end
it 'should be able to perform get_list action' do
get :get_list, platform_id: @platform, id: @mass_build, kind: 'failed_builds_list'
response.should be_success
expect(response).to be_success
end
it "should not be able to perform new action" do
get :new, platform_id: @platform
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
it "should not be able to perform create action" do
get :create, platform_id: @platform
response.should redirect_to(forbidden_path)
expect(response).to redirect_to(forbidden_path)
end
[:cancel, :publish].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)
expect(response).to 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)
expect do
post :create, @create_params
end.to_not change(MassBuild, :count)
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
expect(@mass_build.reload.stop_build).to be_falsy
end
it 'should not change build_publish on publish' do
post :publish, platform_id: @platform, id: @mass_build
@mass_build.reload.build_publish_count.should == 0
expect(@mass_build.reload.build_publish_count).to eq 0
end
end
@ -144,48 +148,50 @@ describe Platforms::MassBuildsController, type: :controller do
it 'should be able to perform index action', anonymous_access: true do
get :index, platform_id: @platform
response.should render_template(:index)
expect(response).to render_template(:index)
end
it 'should not be able to perform index action', anonymous_access: false do
get :index, platform_id: @platform
response.should redirect_to(new_user_session_path)
expect(response).to redirect_to(new_user_session_path)
end
it 'should be able to perform get_list action', anonymous_access: true do
get :get_list, platform_id: @platform, id: @mass_build, kind: 'failed_builds_list'
response.should be_success
expect(response).to be_success
end
it "should not be able to get failed builds list", anonymous_access: false do
get :get_list, platform_id: @platform, id: @mass_build, kind: 'failed_builds_list'
response.should redirect_to(new_user_session_path)
expect(response).to redirect_to(new_user_session_path)
end
it "should not be able to perform new action" do
get :new, platform_id: @platform
response.should redirect_to(new_user_session_path)
expect(response).to redirect_to(new_user_session_path)
end
[:cancel, :publish, :create].each do |action|
it "should not be able to perform #{action} action" do
post action, platform_id: @platform, id: @mass_build
response.should redirect_to(new_user_session_path)
expect(response).to 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)
expect do
post :create, @create_params
end.to_not change(MassBuild, :count)
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
expect(@mass_build.reload.stop_build).to be_falsy
end
it 'should not change build_publish_count on publish' do
post :publish, platform_id: @platform, id: @mass_build
@mass_build.reload.build_publish_count.should == 0
expect(@mass_build.reload.build_publish_count).to eq 0
end
end