#859: update specs, API for build_list
This commit is contained in:
parent
2a1a15eb03
commit
3fab64813e
|
@ -5,7 +5,7 @@ class Api::V1::BuildListsController < Api::V1::BaseController
|
|||
skip_before_filter :authenticate_user!, :only => [:show, :index] if APP_CONFIG['anonymous_access']
|
||||
|
||||
load_and_authorize_resource :project, :only => :index
|
||||
load_and_authorize_resource :build_list, :only => [:show, :create, :cancel, :publish, :reject_publish]
|
||||
load_and_authorize_resource :build_list, :only => [:show, :create, :cancel, :publish, :reject_publish, :create_container]
|
||||
|
||||
def index
|
||||
filter = BuildList::Filter.new(@project, current_user, params[:filter] || {})
|
||||
|
@ -42,15 +42,17 @@ class Api::V1::BuildListsController < Api::V1::BaseController
|
|||
end
|
||||
|
||||
def create_container
|
||||
render_json :create_container
|
||||
if @build_list.publish_container
|
||||
render_json_response @build_list, t('layout.build_lists.create_container_success')
|
||||
else
|
||||
render_validation_error @build_list, t('layout.build_lists.create_container_fail')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_json(action_name)
|
||||
if !@build_list.send "can_#{action_name}?"
|
||||
render_validation_error @build_list, "Incorrect action for current build list")
|
||||
elsif @build_list.send(action_name)
|
||||
if @build_list.try("can_#{action_name}?") && @build_list.send(action_name)
|
||||
render_json_response @build_list, t("layout.build_lists.#{action_name}_success")
|
||||
else
|
||||
render_validation_error @build_list, t("layout.build_lists.#{action_name}_fail")
|
||||
|
|
|
@ -90,17 +90,19 @@ class Projects::BuildListsController < Projects::BaseController
|
|||
end
|
||||
|
||||
def create_container
|
||||
@build_list.publish_container
|
||||
redirect_to :back, :notice => t('layout.build_lists.container_will_be_created')
|
||||
if @build_list.publish_container
|
||||
redirect_to :back, :notice => t('layout.build_lists.create_container_success')
|
||||
else
|
||||
redirect_to :back, :notice => t('layout.build_lists.create_container_fail')
|
||||
end
|
||||
end
|
||||
|
||||
def cancel
|
||||
notice = if @build_list.cancel
|
||||
t('layout.build_lists.will_be_canceled')
|
||||
if @build_list.cancel
|
||||
redirect_to :back, :notice => t('layout.build_lists.will_be_canceled')
|
||||
else
|
||||
t('layout.build_lists.cancel_fail')
|
||||
redirect_to :back, :notice => t('layout.build_lists.cancel_fail')
|
||||
end
|
||||
redirect_to :back, :notice => notice
|
||||
end
|
||||
|
||||
def log
|
||||
|
|
|
@ -63,16 +63,15 @@ en:
|
|||
no_items_data: No data
|
||||
show: Show
|
||||
cancel: Cancel build
|
||||
cancel_success: 'Build canceled'
|
||||
will_be_canceled: 'Build will be canceled...'
|
||||
container_will_be_created: 'Container will be created...'
|
||||
creating: 'creating...'
|
||||
publish_success: 'Build published'
|
||||
cancel_fail: 'Errors during build cancelation!'
|
||||
publish_fail: 'Errors during build publishing!'
|
||||
create_container_success: 'Container is queued for creating'
|
||||
create_container_fail: 'Errors during container creating!'
|
||||
publish_success: 'Build is queued for publishing'
|
||||
reject_publish_success: 'Publishing rejected'
|
||||
publish_fail: 'Errors during build publishing!'
|
||||
cancel_success: 'Build canceled'
|
||||
cancel_fail: 'Errors during build cancelation!'
|
||||
reject_publish_success: 'Publishing rejected'
|
||||
reject_publish_fail: 'Rejecting publishing failed'
|
||||
container_published: 'Container published in a repository'
|
||||
action: Action
|
||||
|
|
|
@ -63,13 +63,14 @@ ru:
|
|||
show: Просмотр
|
||||
cancel: Отменить сборку
|
||||
will_be_canceled: 'Сборка будет отменена...'
|
||||
container_will_be_created: 'Контейнер будет создан...'
|
||||
creating: 'создается...'
|
||||
create_container_success: 'Контейнер поставлен в очередь на создание'
|
||||
create_container_fail: 'При создании контейнера произошла ошибка!'
|
||||
cancel_success: 'Сборка отменена.'
|
||||
cancel_fail: 'При отмене сборки произошла ошибка!'
|
||||
publish_success: 'Сборка поставлена в очередь на публикацию.'
|
||||
reject_publish_success: 'Публикация отклонена'
|
||||
publish_fail: 'При публикации сборки произошла ошибка!'
|
||||
reject_publish_success: 'Публикация отклонена'
|
||||
reject_publish_fail: 'Не удалось отклонить публикацию сборки'
|
||||
container_published: 'Контейнер размещен в репозитории'
|
||||
action: Действие
|
||||
|
|
|
@ -19,6 +19,7 @@ Rosa::Application.routes.draw do
|
|||
put :publish
|
||||
put :reject_publish
|
||||
put :cancel
|
||||
put :create_container
|
||||
}
|
||||
end
|
||||
resources :arches, :only => [:index]
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require 'spec_helper'
|
||||
|
||||
def incorrect_action_message
|
||||
'Incorrect action for current build list'
|
||||
end
|
||||
|
||||
shared_examples_for 'show build list via api' do
|
||||
it 'should be able to perform show action' do
|
||||
get :show, @show_params
|
||||
|
@ -119,7 +115,7 @@ describe Api::V1::BuildListsController do
|
|||
it "should return correct json message" do
|
||||
@build_list.update_column(:status, BuildList::BUILD_PENDING)
|
||||
do_cancel
|
||||
response.body.should == {:is_canceled => true, :url => api_v1_build_list_path(@build_list, :format => :json), :message => I18n.t('layout.build_lists.cancel_success')}.to_json
|
||||
response.body.should == { :build_list => {:id => @build_list.id, :message => I18n.t('layout.build_lists.cancel_success')} }.to_json
|
||||
end
|
||||
|
||||
it "should cancel build list" do
|
||||
|
@ -133,7 +129,7 @@ describe Api::V1::BuildListsController do
|
|||
it "should return correct json error message" do
|
||||
@build_list.update_column(:status, BuildList::PROJECT_VERSION_NOT_FOUND)
|
||||
do_cancel
|
||||
response.body.should == {:is_canceled => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => incorrect_action_message}.to_json
|
||||
response.body.should == { :build_list => {:id => nil, :message => I18n.t('layout.build_lists.cancel_fail')} }.to_json
|
||||
end
|
||||
|
||||
it "should not cancel build list" do
|
||||
|
@ -174,7 +170,7 @@ describe Api::V1::BuildListsController do
|
|||
|
||||
context "if it has :failed_publish status" do
|
||||
it "should return correct json message" do
|
||||
response.body.should == {:is_published => true, :url => api_v1_build_list_path(@build_list, :format => :json), :message => I18n.t('layout.build_lists.publish_success')}.to_json
|
||||
response.body.should == { :build_list => {:id => @build_list.id, :message => I18n.t('layout.build_lists.publish_success')} }.to_json
|
||||
end
|
||||
|
||||
it "should cancel build list" do
|
||||
|
@ -189,7 +185,7 @@ describe Api::V1::BuildListsController do
|
|||
end
|
||||
|
||||
it "should return correct json error message" do
|
||||
response.body.should == {:is_published => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => incorrect_action_message}.to_json
|
||||
response.body.should == { :build_list => {:id => nil, :message => I18n.t('layout.build_lists.publish_fail')} }.to_json
|
||||
end
|
||||
|
||||
it "should not cancel build list" do
|
||||
|
@ -234,7 +230,7 @@ describe Api::V1::BuildListsController do
|
|||
|
||||
context "if it has :success status" do
|
||||
it "should return correct json message" do
|
||||
response.body.should == {:is_reject_published => true, :url => api_v1_build_list_path(@build_list, :format => :json), :message => I18n.t('layout.build_lists.reject_publish_success')}.to_json
|
||||
response.body.should == { :build_list => {:id => @build_list.id, :message => I18n.t('layout.build_lists.reject_publish_success')} }.to_json
|
||||
end
|
||||
|
||||
it "should reject publish build list" do
|
||||
|
@ -249,7 +245,7 @@ describe Api::V1::BuildListsController do
|
|||
end
|
||||
|
||||
it "should return correct json error message" do
|
||||
response.body.should == {:is_reject_published => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => incorrect_action_message}.to_json
|
||||
response.body.should == { :build_list => {:id => nil, :message => I18n.t('layout.build_lists.reject_publish_fail')} }.to_json
|
||||
end
|
||||
|
||||
it "should not cancel build list" do
|
||||
|
|
Loading…
Reference in New Issue