[refs #847] remove core callbacks

This commit is contained in:
Alexander Machehin 2013-01-24 15:33:22 +06:00
parent b15dac590f
commit 1873f9cd49
3 changed files with 3 additions and 254 deletions

View File

@ -1,18 +1,15 @@
# -*- encoding : utf-8 -*-
class Projects::BuildListsController < Projects::BaseController
CALLBACK_ACTIONS = [:publish_build, :status_build, :pre_build, :post_build, :circle_build, :new_bbdt]
NESTED_ACTIONS = [:search, :index, :new, :create]
before_filter :authenticate_user!, :except => CALLBACK_ACTIONS
before_filter :authenticate_build_service!, :only => CALLBACK_ACTIONS
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index, :search, :log] if APP_CONFIG['anonymous_access']
before_filter :find_build_list, :only => [:show, :publish, :cancel, :update, :log]
before_filter :find_build_list_by_bs, :only => [:publish_build, :status_build, :pre_build, :post_build, :circle_build]
load_and_authorize_resource :project, :only => NESTED_ACTIONS
load_and_authorize_resource :build_list, :through => :project, :only => NESTED_ACTIONS, :shallow => true
load_and_authorize_resource :except => CALLBACK_ACTIONS.concat(NESTED_ACTIONS)
load_and_authorize_resource :except => NESTED_ACTIONS
def search
new_params = {:filter => {}}
@ -108,88 +105,19 @@ class Projects::BuildListsController < Projects::BaseController
}
end
def publish_build
if params[:status].to_i == 0 # ok
@build_list.published
else
@build_list.fail_publish
end
render :nothing => true, :status => 200
end
def status_build
@item = @build_list.items.find_by_name!(params[:package_name])
@item.status = params[:status]
@item.save
@build_list.container_path = params[:container_path]
@build_list.save
@build_list.set_packages(ActiveSupport::JSON.decode(params[:pkg_info]), params[:package_name]) if params[:status].to_i == BuildServer::SUCCESS and params[:pkg_info].present?
render :nothing => true, :status => 200
end
def pre_build
@build_list.start_build
render :nothing => true, :status => 200
end
def post_build
params[:status].to_i == BuildServer::SUCCESS ? @build_list.build_success : @build_list.build_error
@build_list.container_path = params[:container_path]
@build_list.save
render :nothing => true, :status => 200
@build_list.publish if @build_list.auto_publish # && @build_list.can_publish? # later with resque
end
def circle_build
@build_list.is_circle = true
@build_list.container_path = params[:container_path]
@build_list.save
render :nothing => true, :status => 200
end
def new_bbdt
@build_list = BuildList.find_by_id!(params[:web_id])
@build_list.name = params[:name]
@build_list.additional_repos = ActiveSupport::JSON.decode(params[:additional_repos])
@build_list.set_items(ActiveSupport::JSON.decode(params[:items]))
@build_list.is_circle = (params[:is_circular].to_i != 0)
@build_list.bs_id = params[:id]
@build_list.save
render :nothing => true, :status => 200
end
protected
def find_build_list
@build_list = BuildList.find(params[:id])
end
def find_build_list_by_bs
@build_list = BuildList.find_by_bs_id!(params[:id])
end
# What is it?
#def authenticate_build_service!
# if request.remote_ip != APP_CONFIG['build_server_ip']
# render :nothing => true, :status => 403
# end
#end
def publish
@build_list.update_type = params[:build_list][:update_type] if params[:build_list][:update_type].present?
if params[:attach_advisory].present? and params[:attach_advisory] != 'no' and !@build_list.advisory
unless @build_list.update_type.in? BuildList::RELEASE_UPDATE_TYPES
redirect_to :back, :notice => t('lyout.build_lists.publish_fail') and return
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return
end
if params[:attach_advisory] == 'new'

View File

@ -207,14 +207,6 @@ Rosa::Application.routes.draw do
end
scope :module => 'projects' do
# Core callbacks
match 'build_lists/publish_build', :to => "build_lists#publish_build"
match 'build_lists/status_build', :to => "build_lists#status_build"
match 'build_lists/post_build', :to => "build_lists#post_build"
match 'build_lists/pre_build', :to => "build_lists#pre_build"
match 'build_lists/circle_build', :to => "build_lists#circle_build"
match 'build_lists/new_bbdt', :to => "build_lists#new_bbdt"
resources :build_lists, :only => [:index, :show, :update] do
member do
put :cancel

View File

@ -321,176 +321,5 @@ describe Projects::BuildListsController do
end
end
context 'callbacks' do
let(:build_list) { FactoryGirl.create(:build_list_core) }
let(:build_list_package) { FactoryGirl.create(:build_list_package, :build_list_id => build_list.id, :platform_id => build_list.save_to_platform_id, :project_id => build_list.project_id, :version => "4.7.5.3", :release => 1) }
before(:each) do
mock(controller).authenticate_build_service! {true}
end
describe 'publish_build' do
before {
build_list.update_column(:commit_hash, build_list.project.repo.commits('master').last.id)
build_list.update_column(:status, BuildList::BUILD_PUBLISH)
build_list_package
}
def do_get(status)
get :publish_build, :id => build_list.bs_id, :status => status, :version => '4.7.5.3', :release => '1'
build_list.reload
end
it(:passes) {
build_list.update_column(:status, BuildServer::BUILD_STARTED)
do_get(BuildServer::SUCCESS)
response.should be_ok
}
it 'should create correct git tag for correct commit' do
do_get(BuildServer::SUCCESS)
build_list.project.repo.tags.last.name.should == build_list.package_version
build_list.project.repo.commits(build_list.package_version).last.id.should == build_list.commit_hash
end
it(:passes) { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) }
it(:passes) { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :package_version).to("#{ build_list_package.platform.name }-4.7.5.3-1") }
it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildList::FAILED_PUBLISH) }
it { lambda{ do_get(BuildServer::ERROR) }.should_not change(build_list, :package_version) }
it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :updated_at) }
end
describe 'status_build' do
before do
@item = build_list.items.create(:name => build_list.project.name, :version => build_list.project_version, :level => 0)
repo = build_list.save_to_platform.repositories.first
@project2 = FactoryGirl.create(:project)
repo.projects << @project2
end
def do_get
get :status_build, :id => build_list.bs_id, :package_name => build_list.project.name, :status => BuildServer::SUCCESS, :container_path => '/path/to',
:pkg_info => ActiveSupport::JSON.encode({'srpm' => {'fullname' => 'srpm_filename.srpm',
'name' => build_list.project.name,
'version' => 'version1',
'release' => 'release1'},
'rpm' => [{'fullname' => 'filename1.rpm',
'name' => build_list.project.name,
'version' => 'version2',
'release' => 'release2'},
{'fullname' => 'filename2.rpm',
'name' => @project2.name,
'version' => 'version2',
'release' => 'release2'}]})
build_list.reload
@item.reload
end
it { do_get; response.should be_ok }
it { lambda{ do_get }.should change(@item, :status) }
it { lambda{ do_get }.should change(build_list, :container_path) }
it { lambda{ do_get }.should change(build_list, :updated_at) }
it('should create packages for build list') { lambda{ do_get }.should change(build_list.packages, :count).to(3) }
it 'should create correct packages for build list' do
do_get
package = build_list.packages.order('created_at ASC').first
package.fullname.should == 'srpm_filename.srpm'
package.name.should == build_list.project.name
package.version.should == 'version1'
package.release.should == 'release1'
package.package_type == 'source'
package.build_list.should == build_list
package.platform.should == build_list.save_to_platform
package.project.should == build_list.project
end
end
describe 'pre_build' do
before do
build_list.update_column :status, BuildList::BUILD_PENDING
end
def do_get
get :pre_build, :id => build_list.bs_id
build_list.reload
end
it { do_get; response.should be_ok }
it { lambda{ do_get }.should change(build_list, :status).to(BuildServer::BUILD_STARTED) }
it { lambda{ do_get }.should change(build_list, :updated_at) }
end
describe 'post_build' do
def do_get(status)
build_list.started_at = Time.now
build_list.save
get :post_build, :id => build_list.bs_id, :status => status, :container_path => '/path/to'
build_list.reload
end
it { do_get(BuildServer::SUCCESS); response.should be_ok }
it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :container_path) }
it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :updated_at) }
context 'with auto_publish' do
it(:passes) {
build_list.update_column(:started_at, (Time.now - 1.day))
build_list.update_column(:status, BuildServer::BUILD_STARTED)
build_list.reload
lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISH)
}
it(:passes) {
build_list.update_column(:started_at, (Time.now - 1.day))
build_list.update_column(:status, BuildServer::BUILD_STARTED)
lambda{ do_get(BuildServer::BUILD_ERROR) }.should change(build_list, :status).to(BuildServer::BUILD_ERROR)
}
end
context 'without auto_publish' do
before { build_list.update_column(:auto_publish, false) }
it(:passes) {
build_list.update_column(:started_at, (Time.now - 1.day))
build_list.update_column(:status, BuildServer::BUILD_STARTED)
lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildServer::SUCCESS)
}
it(:passes) {
build_list.update_column(:started_at, (Time.now - 1.day))
build_list.update_column(:status, BuildServer::BUILD_STARTED)
lambda{ do_get(BuildServer::BUILD_ERROR) }.should change(build_list, :status).to(BuildServer::BUILD_ERROR)
}
end
end
describe 'circle_build' do
def do_get
get :circle_build, :id => build_list.bs_id, :container_path => '/path/to'
build_list.reload
end
it { do_get; response.should be_ok }
it { lambda{ do_get }.should change(build_list, :is_circle).to(true) }
it { lambda{ do_get }.should change(build_list, :container_path) }
it { lambda{ do_get }.should change(build_list, :updated_at) }
end
describe 'new_bbdt' do
before { @items = build_list.items }
def do_get
get :new_bbdt, :id => 123, :web_id => build_list.id, :name => build_list.project.name, :is_circular => 1,
:additional_repos => ActiveSupport::JSON.encode([{:name => 'build_repos'}, {:name => 'main'}]),
:items => ActiveSupport::JSON.encode(0 => [{:name => build_list.project.name, :version => build_list.project_version}])
build_list.reload
@items.reload
end
it { do_get; response.should be_ok }
it { lambda{ do_get }.should change(build_list, :name).to(build_list.project.name) }
it { lambda{ do_get }.should change(build_list, :additional_repos) }
it { lambda{ do_get }.should change(@items, :first) }
it { lambda{ do_get }.should change(build_list, :is_circle).to(true) }
it { lambda{ do_get }.should change(build_list, :bs_id).to(123) }
it { lambda{ do_get }.should change(build_list, :updated_at) }
end
end
after(:all) {clean_projects_dir}
end