From 3fab64813ed17104ba11cc39208a87ffe1d10c6f Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 31 Jan 2013 00:04:19 +0400 Subject: [PATCH] #859: update specs, API for build_list --- .../api/v1/build_lists_controller.rb | 12 +++++++----- .../projects/build_lists_controller.rb | 18 ++++++++++-------- config/locales/models/build_list.en.yml | 11 +++++------ config/locales/models/build_list.ru.yml | 5 +++-- config/routes.rb | 1 + .../api/v1/build_lists_controller_spec.rb | 16 ++++++---------- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index 452324f28..c3e8810a6 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -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") diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index fedc56d3d..3cc8338f8 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -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') - else - t('layout.build_lists.cancel_fail') - end - redirect_to :back, :notice => notice + if @build_list.cancel + redirect_to :back, :notice => t('layout.build_lists.will_be_canceled') + else + redirect_to :back, :notice => t('layout.build_lists.cancel_fail') + end end def log diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index dee17ed66..24bb0f914 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -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 diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 8986c473f..2c83bae9d 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -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: Действие diff --git a/config/routes.rb b/config/routes.rb index 28252dee4..1406ac24a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,7 @@ Rosa::Application.routes.draw do put :publish put :reject_publish put :cancel + put :create_container } end resources :arches, :only => [:index] diff --git a/spec/controllers/api/v1/build_lists_controller_spec.rb b/spec/controllers/api/v1/build_lists_controller_spec.rb index ebfcf29b6..68d32abea 100644 --- a/spec/controllers/api/v1/build_lists_controller_spec.rb +++ b/spec/controllers/api/v1/build_lists_controller_spec.rb @@ -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