From acb970686cf5593a60a021b35e4de241b2f17d33 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 29 Dec 2011 04:37:34 +0200 Subject: [PATCH] Apply auto_publish for build_lists. Apply publish build_list error status. Remove circle build info. Display auto_publish info. Fix bugs. Refactor. Apply specs for all build_lists core callbacks. Refs #72 --- app/controllers/build_lists_controller.rb | 9 +- app/models/build_list.rb | 2 +- app/views/build_lists/_build_lists.html.haml | 2 - app/views/build_lists/new.html.haml | 4 + app/views/build_lists/show.html.haml | 5 + config/locales/ru.yml | 1 + ...8182425_add_auto_publish_to_build_lists.rb | 9 ++ db/schema.rb | 3 +- .../build_lists_controller_spec.rb | 99 ++++++++++++++++++- 9 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20111228182425_add_auto_publish_to_build_lists.rb diff --git a/app/controllers/build_lists_controller.rb b/app/controllers/build_lists_controller.rb index 44b1773f1..143ddc880 100644 --- a/app/controllers/build_lists_controller.rb +++ b/app/controllers/build_lists_controller.rb @@ -6,7 +6,7 @@ class BuildListsController < ApplicationController before_filter :authenticate_build_service!, :only => CALLBACK_ACTIONS before_filter :find_project, :only => NESTED_ACTIONS before_filter :find_build_list, :only => [:show, :publish, :cancel] - before_filter :find_build_list_by_bs, :only => [:publish_build, :status_build, :pre_build, :post_build] + 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 @@ -113,6 +113,8 @@ class BuildListsController < ApplicationController @build_list.notified_at = Time.current @build_list.save + @build_list.publish if @build_list.auto_publish # && @build_list.can_publish? + render :nothing => true, :status => 200 end @@ -130,10 +132,9 @@ class BuildListsController < ApplicationController @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.notified_at = Time.current - @build_list.is_circle = (params[:is_circular] != "0") + @build_list.is_circle = (params[:is_circular].to_i != 0) @build_list.bs_id = params[:id] - params[:arch] + @build_list.notified_at = Time.current @build_list.save render :nothing => true, :status => 200 diff --git a/app/models/build_list.rb b/app/models/build_list.rb index d28e0d293..91534a5a5 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -110,7 +110,7 @@ class BuildList < ActiveRecord::Base def publish return false unless can_publish? has_published = BuildServer.publish_container bs_id - update_attribute(:status, BUILD_PUBLISH) if has_published == 0 + update_attribute(:status, has_published == 0 ? BUILD_PUBLISH : FAILED_PUBLISH) return has_published == 0 end diff --git a/app/views/build_lists/_build_lists.html.haml b/app/views/build_lists/_build_lists.html.haml index 8bd7ab667..a51c428f3 100644 --- a/app/views/build_lists/_build_lists.html.haml +++ b/app/views/build_lists/_build_lists.html.haml @@ -6,7 +6,6 @@ %th= t("activerecord.attributes.build_list.project") %th= t("activerecord.attributes.build_list.arch") %th= t("activerecord.attributes.build_list.user") - %th= t("activerecord.attributes.build_list.is_circle") - unless @project %th= t("layout.build_lists.cancel_button_header") %th.last= t("activerecord.attributes.build_list.notified_at") @@ -19,7 +18,6 @@ %td= link_to build_list.project.name, project_path(build_list.project) %td= build_list.arch.name %td= build_list.user.try(:fullname) - %td= t("layout.#{build_list.is_circle?}_") - unless @project %td= link_to t("layout.build_lists.cancel_button"), cancel_build_list_path(build_list), :method => "put", :confirm => t("layout.confirm") if build_list.can_cancel? %td.last= build_list.notified_at diff --git a/app/views/build_lists/new.html.haml b/app/views/build_lists/new.html.haml index 622191b78..76187ddb5 100644 --- a/app/views/build_lists/new.html.haml +++ b/app/views/build_lists/new.html.haml @@ -50,6 +50,10 @@ = f.label :include_repos, t("activerecord.attributes.build_list.include_repos"), :class => :label #include_repos + .group + = f.check_box :auto_publish + = f.label :auto_publish, t("activerecord.attributes.build_list.auto_publish") + .group.navform.wat-cf %button.button{:type => "submit"} = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.projects.build_button")) diff --git a/app/views/build_lists/show.html.haml b/app/views/build_lists/show.html.haml index eafd98ddd..9c7e779c5 100644 --- a/app/views/build_lists/show.html.haml +++ b/app/views/build_lists/show.html.haml @@ -49,6 +49,11 @@ = t("activerecord.attributes.build_list.build_requires") \: = @build_list.build_requires + %p + %b + = t("activerecord.attributes.build_list.auto_publish") + \: + = @build_list.auto_publish %p %b = t("activerecord.attributes.build_list.status") diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 892d6ff7c..dbc4294dc 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -637,6 +637,7 @@ ru: bpl_id: Платформа update_type: Критичность обновления build_requires: Пересборка с зависимостями + auto_publish: Автоматическая публикация project_version: Версия user: Пользователь diff --git a/db/migrate/20111228182425_add_auto_publish_to_build_lists.rb b/db/migrate/20111228182425_add_auto_publish_to_build_lists.rb new file mode 100644 index 000000000..a9cb7d3bd --- /dev/null +++ b/db/migrate/20111228182425_add_auto_publish_to_build_lists.rb @@ -0,0 +1,9 @@ +class AddAutoPublishToBuildLists < ActiveRecord::Migration + def self.up + add_column :build_lists, :auto_publish, :boolean, :default => true + end + + def self.down + remove_column :build_lists, :auto_publish + end +end diff --git a/db/schema.rb b/db/schema.rb index 2a5a51d73..4fad3e5fa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111221194422) do +ActiveRecord::Schema.define(:version => 20111228182425) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -71,6 +71,7 @@ ActiveRecord::Schema.define(:version => 20111221194422) do t.integer "pl_id" t.text "include_repos" t.integer "user_id" + t.boolean "auto_publish", :default => true end add_index "build_lists", ["arch_id"], :name => "index_build_lists_on_arch_id" diff --git a/spec/controllers/build_lists_controller_spec.rb b/spec/controllers/build_lists_controller_spec.rb index bfedd23a2..a3e088c63 100644 --- a/spec/controllers/build_lists_controller_spec.rb +++ b/spec/controllers/build_lists_controller_spec.rb @@ -50,10 +50,10 @@ describe BuildListsController do end end + before { stub_rsync_methods } + context 'crud' do before(:each) do - stub_rsync_methods - platform = Factory(:platform_with_repos) @create_params = { :build_list => { @@ -257,7 +257,6 @@ describe BuildListsController do context 'filter' do before(:each) do - stub_rsync_methods set_session_for Factory(:admin) @build_list1 = Factory(:build_list_core) @@ -297,5 +296,99 @@ describe BuildListsController do end context 'callbacks' do + let(:build_list) { Factory(:build_list_core) } + + describe 'publish_build' do + def do_get(status) + get :publish_build, :id => build_list.bs_id, :status => status + build_list.reload + end + + it { do_get(BuildServer::SUCCESS); response.should be_ok } + it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) } + it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildList::FAILED_PUBLISH) } + it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :notified_at) } + end + + describe 'status_build' do + before { @item = build_list.items.create(:name => build_list.project.name, :version => build_list.project_version, :level => 0) } + + def do_get + get :status_build, :id => build_list.bs_id, :package_name => build_list.project.name, :status => BuildServer::SUCCESS, :container_path => '/path/to' + 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, :notified_at) } + end + + describe 'pre_build' do + 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, :notified_at) } + end + + describe 'post_build' do + def do_get(status) + 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, :notified_at) } + + context 'with auto_publish' do + it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISH) } + it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildServer::ERROR) } + end + + context 'without auto_publish' do + before { build_list.update_attribute(:auto_publish, false) } + + it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildServer::SUCCESS) } + it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildServer::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, :notified_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, :notified_at) } + end end end