#859: update specs, API for build_list

This commit is contained in:
Vokhmin Alexey V 2013-01-31 00:04:19 +04:00
parent 2a1a15eb03
commit 3fab64813e
6 changed files with 32 additions and 31 deletions

View File

@ -5,7 +5,7 @@ class Api::V1::BuildListsController < Api::V1::BaseController
skip_before_filter :authenticate_user!, :only => [:show, :index] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, :only => [:show, :index] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :project, :only => :index 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 def index
filter = BuildList::Filter.new(@project, current_user, params[:filter] || {}) filter = BuildList::Filter.new(@project, current_user, params[:filter] || {})
@ -42,15 +42,17 @@ class Api::V1::BuildListsController < Api::V1::BaseController
end end
def create_container 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 end
private private
def render_json(action_name) def render_json(action_name)
if !@build_list.send "can_#{action_name}?" if @build_list.try("can_#{action_name}?") && @build_list.send(action_name)
render_validation_error @build_list, "Incorrect action for current build list")
elsif @build_list.send(action_name)
render_json_response @build_list, t("layout.build_lists.#{action_name}_success") render_json_response @build_list, t("layout.build_lists.#{action_name}_success")
else else
render_validation_error @build_list, t("layout.build_lists.#{action_name}_fail") render_validation_error @build_list, t("layout.build_lists.#{action_name}_fail")

View File

@ -90,17 +90,19 @@ class Projects::BuildListsController < Projects::BaseController
end end
def create_container def create_container
@build_list.publish_container if @build_list.publish_container
redirect_to :back, :notice => t('layout.build_lists.container_will_be_created') 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 end
def cancel def cancel
notice = if @build_list.cancel if @build_list.cancel
t('layout.build_lists.will_be_canceled') redirect_to :back, :notice => t('layout.build_lists.will_be_canceled')
else else
t('layout.build_lists.cancel_fail') redirect_to :back, :notice => t('layout.build_lists.cancel_fail')
end end
redirect_to :back, :notice => notice
end end
def log def log

View File

@ -63,16 +63,15 @@ en:
no_items_data: No data no_items_data: No data
show: Show show: Show
cancel: Cancel build cancel: Cancel build
cancel_success: 'Build canceled'
will_be_canceled: 'Build will be canceled...' will_be_canceled: 'Build will be canceled...'
container_will_be_created: 'Container will be created...'
creating: 'creating...' creating: 'creating...'
publish_success: 'Build published' create_container_success: 'Container is queued for creating'
cancel_fail: 'Errors during build cancelation!' create_container_fail: 'Errors during container creating!'
publish_fail: 'Errors during build publishing!'
publish_success: 'Build is queued for publishing' publish_success: 'Build is queued for publishing'
reject_publish_success: 'Publishing rejected'
publish_fail: 'Errors during build publishing!' 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' reject_publish_fail: 'Rejecting publishing failed'
container_published: 'Container published in a repository' container_published: 'Container published in a repository'
action: Action action: Action

View File

@ -63,13 +63,14 @@ ru:
show: Просмотр show: Просмотр
cancel: Отменить сборку cancel: Отменить сборку
will_be_canceled: 'Сборка будет отменена...' will_be_canceled: 'Сборка будет отменена...'
container_will_be_created: 'Контейнер будет создан...'
creating: 'создается...' creating: 'создается...'
create_container_success: 'Контейнер поставлен в очередь на создание'
create_container_fail: 'При создании контейнера произошла ошибка!'
cancel_success: 'Сборка отменена.' cancel_success: 'Сборка отменена.'
cancel_fail: 'При отмене сборки произошла ошибка!' cancel_fail: 'При отмене сборки произошла ошибка!'
publish_success: 'Сборка поставлена в очередь на публикацию.' publish_success: 'Сборка поставлена в очередь на публикацию.'
reject_publish_success: 'Публикация отклонена'
publish_fail: 'При публикации сборки произошла ошибка!' publish_fail: 'При публикации сборки произошла ошибка!'
reject_publish_success: 'Публикация отклонена'
reject_publish_fail: 'Не удалось отклонить публикацию сборки' reject_publish_fail: 'Не удалось отклонить публикацию сборки'
container_published: 'Контейнер размещен в репозитории' container_published: 'Контейнер размещен в репозитории'
action: Действие action: Действие

View File

@ -19,6 +19,7 @@ Rosa::Application.routes.draw do
put :publish put :publish
put :reject_publish put :reject_publish
put :cancel put :cancel
put :create_container
} }
end end
resources :arches, :only => [:index] resources :arches, :only => [:index]

View File

@ -1,10 +1,6 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
require 'spec_helper' require 'spec_helper'
def incorrect_action_message
'Incorrect action for current build list'
end
shared_examples_for 'show build list via api' do shared_examples_for 'show build list via api' do
it 'should be able to perform show action' do it 'should be able to perform show action' do
get :show, @show_params get :show, @show_params
@ -119,7 +115,7 @@ describe Api::V1::BuildListsController do
it "should return correct json message" do it "should return correct json message" do
@build_list.update_column(:status, BuildList::BUILD_PENDING) @build_list.update_column(:status, BuildList::BUILD_PENDING)
do_cancel 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 end
it "should cancel build list" do it "should cancel build list" do
@ -133,7 +129,7 @@ describe Api::V1::BuildListsController do
it "should return correct json error message" do it "should return correct json error message" do
@build_list.update_column(:status, BuildList::PROJECT_VERSION_NOT_FOUND) @build_list.update_column(:status, BuildList::PROJECT_VERSION_NOT_FOUND)
do_cancel 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 end
it "should not cancel build list" do it "should not cancel build list" do
@ -174,7 +170,7 @@ describe Api::V1::BuildListsController do
context "if it has :failed_publish status" do context "if it has :failed_publish status" do
it "should return correct json message" 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 end
it "should cancel build list" do it "should cancel build list" do
@ -189,7 +185,7 @@ describe Api::V1::BuildListsController do
end end
it "should return correct json error message" do 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 end
it "should not cancel build list" do it "should not cancel build list" do
@ -234,7 +230,7 @@ describe Api::V1::BuildListsController do
context "if it has :success status" do context "if it has :success status" do
it "should return correct json message" 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 end
it "should reject publish build list" do it "should reject publish build list" do
@ -249,7 +245,7 @@ describe Api::V1::BuildListsController do
end end
it "should return correct json error message" do 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 end
it "should not cancel build list" do it "should not cancel build list" do