[refs #374] Fix test, small refactoring.

This commit is contained in:
Vladimir Sharshov 2012-09-27 16:13:59 +04:00
parent 0dd103b7f4
commit a20e1552cc
5 changed files with 17 additions and 35 deletions

View File

@ -4,10 +4,16 @@ class Api::V1::BaseController < ApplicationController
before_filter :restrict_paginate, :only => :index
#respond_to :json
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.json { render :json => {:message => t("flash.exception_message")}.to_json, :status => 403 }
end
end
protected
def restrict_paginate
params[:per_page] = 30 if params[:per_page].blank? or params[:per_page].to_i < 1
params[:per_page] = 30 if params[:per_page].to_i < 1
params[:per_page] = 100 if params[:per_page].to_i >100
end

View File

@ -19,17 +19,16 @@ class Api::V1::BuildListsController < Api::V1::BaseController
params[:build_list][:save_to_platform_id] = save_to_repository.platform_id
params[:build_list][:auto_publish] = false unless save_to_repository.publish_without_qa?
build_list = project.build_lists.build(params[:build_list])
build_list.project_version = build_list.commit_hash
@build_list = project.build_lists.build(params[:build_list])
@build_list.project_version = @build_list.commit_hash
build_list.user = current_user
build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
@build_list.user = current_user
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
if build_list.save
@build_list = build_list
if @build_list.save
render :action => 'show'
else
render :json => {:message => "Validation Failed", :errors => build_list.errors.messages}.to_json, :status => 422
render :json => {:message => "Validation Failed", :errors => @build_list.errors.messages}.to_json, :status => 422
end
end

View File

@ -1,5 +1,5 @@
# -*- encoding : utf-8 -*-
class Api::V1::PlatformsController < Platforms::BaseController
class Api::V1::PlatformsController < Api::V1::BaseController
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show] if APP_CONFIG['anonymous_access']

View File

@ -15,10 +15,7 @@ class ApplicationController < ActionController::Base
helper_method :get_owner
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.json { render :json => {:message => t("flash.exception_message")}.to_json, :status => 403 }
format.html { redirect_to forbidden_url, :alert => t("flash.exception_message") }
end
redirect_to forbidden_url, :alert => t("flash.exception_message")
end
if !Rails.env.development?

View File

@ -290,26 +290,6 @@ describe CanCan do
@ability.should be_able_to(:read, @repository)
end
end
end
context 'build list relations' do
before(:each) do
@project = FactoryGirl.create(:project)
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'writer')
@build_list = FactoryGirl.create(:build_list, :project => @project)
end
it 'should be able to publish build list with SUCCESS status' do
@build_list.status = BuildServer::SUCCESS
@ability.should be_able_to(:publish, @build_list)
end
it 'should not be able to publish build list with another status' do
@build_list.status = BuildServer::BUILD_ERROR
@ability.should_not be_able_to(:publish, @build_list)
end
end
end
end # 'repository relations'
end # 'Site user'
end