Merge pull request #391 from abf/rosa-build:390-rerun-tests-for-the-build

#390: Add possibility to rerun tests for the build
This commit is contained in:
avokhmin 2014-05-23 22:19:00 +04:00
commit 5cafc7514b
14 changed files with 247 additions and 149 deletions

View File

@ -9,11 +9,13 @@ RosaABF.controller('BuildListsController', ['$scope', '$http', '$location', '$ti
$scope.opened = {}; $scope.opened = {};
$scope.map_priorities = { $scope.map_priorities = {
<%=BuildList::WAITING_FOR_RESPONSE%>: 11, <%=BuildList::WAITING_FOR_RESPONSE%>: 13,
<%=BuildList::BUILD_PENDING%>: 10, <%=BuildList::BUILD_PENDING%>: 12,
<%=BuildList::BUILD_CANCELING%>: 9, <%=BuildList::RERUN_TESTS%>: 11,
<%=BuildList::BUILD_CANCELED%>: 8, <%=BuildList::BUILD_CANCELING%>: 10,
<%=BuildList::BUILD_STARTED%>: 7, <%=BuildList::BUILD_CANCELED%>: 9,
<%=BuildList::BUILD_STARTED%>: 8,
<%=BuildList::RERUNNING_TESTS%>: 7,
<%=BuildList::BUILD_PUBLISH%>: 6, <%=BuildList::BUILD_PUBLISH%>: 6,
<%=BuildList::BUILD_PUBLISHED%>: 5, <%=BuildList::BUILD_PUBLISHED%>: 5,
<%=BuildList::BUILD_ERROR%>: 4, <%=BuildList::BUILD_ERROR%>: 4,

View File

@ -4,7 +4,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_resource :project, only: :index, parent: false load_resource :project, only: :index, parent: false
load_and_authorize_resource :build_list, only: [:show, :create, :cancel, :publish, :reject_publish, :create_container, :publish_into_testing] load_and_authorize_resource :build_list, only: [:show, :create, :cancel, :publish, :reject_publish, :create_container, :publish_into_testing, :rerun_tests]
def index def index
authorize!(:show, @project) if @project authorize!(:show, @project) if @project
@ -43,6 +43,10 @@ class Api::V1::BuildListsController < Api::V1::BaseController
render_json :create_container, :publish_container render_json :create_container, :publish_container
end end
def rerun_tests
render_json :rerun_tests
end
def publish_into_testing def publish_into_testing
@build_list.publisher = current_user @build_list.publisher = current_user
render_json :publish_into_testing render_json :publish_into_testing

View File

@ -14,7 +14,9 @@ class Api::V1::JobsController < Api::V1::BaseController
else else
platform_ids = Platform.where(name: params[:platforms].split(',')).pluck(:id) if params[:platforms].present? platform_ids = Platform.where(name: params[:platforms].split(',')).pluck(:id) if params[:platforms].present?
arch_ids = Arch.where(name: params[:arches].split(',')).pluck(:id) if params[:arches].present? arch_ids = Arch.where(name: params[:arches].split(',')).pluck(:id) if params[:arches].present?
build_lists = BuildList.for_status(BuildList::BUILD_PENDING).scoped_to_arch(arch_ids). build_lists = BuildList.scoped_to_arch(arch_ids).
for_status([BuildList::BUILD_PENDING, BuildList::RERUN_TESTS]).
scoped_to_arch(arch_ids).
oldest.order(:created_at) oldest.order(:created_at)
build_lists = build_lists.for_platform(platform_ids) if platform_ids.present? build_lists = build_lists.for_platform(platform_ids) if platform_ids.present?

View File

@ -119,30 +119,29 @@ class Projects::BuildListsController < Projects::BaseController
end end
@build_list.publisher = current_user @build_list.publisher = current_user
message = @build_list.publish ? 'success' : 'fail' do_and_back(:publish, 'publish_')
redirect_to :back, notice: t("layout.build_lists.publish_#{message}")
end end
def publish_into_testing def publish_into_testing
@build_list.publisher = current_user @build_list.publisher = current_user
message = @build_list.publish_into_testing ? 'success' : 'fail' do_and_back(:publish_into_testing, 'publish_')
redirect_to :back, notice: t("layout.build_lists.publish_#{message}") end
def rerun_tests
do_and_back(:rerun_tests, 'rerun_tests_')
end end
def reject_publish def reject_publish
@build_list.publisher = current_user @build_list.publisher = current_user
message = @build_list.reject_publish ? 'success' : 'fail' do_and_back(:reject_publish, 'reject_publish_')
redirect_to :back, notice: t("layout.build_lists.reject_publish_#{message}")
end end
def create_container def create_container
message = @build_list.publish_container ? 'success' : 'fail' do_and_back(:publish_container, 'create_container_')
redirect_to :back, notice: t("layout.build_lists.create_container_#{message}")
end end
def cancel def cancel
message = @build_list.cancel ? 'will_be_canceled' : 'cancel_fail' do_and_back(:cancel, nil, 'will_be_canceled', 'cancel_fail')
redirect_to :back, notice: t("layout.build_lists.#{message}")
end end
def log def log
@ -184,6 +183,13 @@ class Projects::BuildListsController < Projects::BaseController
protected protected
def do_and_back(action, prefix, success = 'success', fail = 'fail')
result = @build_list.send(action)
message = result ? success : fail
flash[result ? :notice : :error] = t("layout.build_lists.#{prefix}#{message}")
redirect_to :back
end
def find_build_list def find_build_list
@build_list = BuildList.find(params[:id]) @build_list = BuildList.find(params[:id])
end end

View File

@ -87,7 +87,7 @@ class Ability
can([:read, :log, :everything, :list], BuildList, read_relations_with_projects('build_lists')) {|build_list| can? :read, build_list.project} can([:read, :log, :everything, :list], BuildList, read_relations_with_projects('build_lists')) {|build_list| can? :read, build_list.project}
can(:publish_into_testing, BuildList) { |build_list| can?(:create, build_list) && build_list.save_to_platform.main? } can(:publish_into_testing, BuildList) { |build_list| can?(:create, build_list) && build_list.save_to_platform.main? }
can(:create, BuildList) {|build_list| can([:create, :rerun_tests], BuildList) {|build_list|
build_list.project.is_package && build_list.project.is_package &&
can?(:write, build_list.project) && can?(:write, build_list.project) &&
(build_list.build_for_platform.blank? || can?(:show, build_list.build_for_platform)) (build_list.build_for_platform.blank? || can?(:show, build_list.build_for_platform))

View File

@ -86,6 +86,8 @@ class BuildList < ActiveRecord::Base
%w(BUILD_CANCELED 5000), %w(BUILD_CANCELED 5000),
%w(WAITING_FOR_RESPONSE 4000), %w(WAITING_FOR_RESPONSE 4000),
%w(BUILD_PENDING 2000), %w(BUILD_PENDING 2000),
%w(RERUN_TESTS 2500),
%w(RERUNNING_TESTS 2550),
%w(BUILD_PUBLISHED 6000), %w(BUILD_PUBLISHED 6000),
%w(BUILD_PUBLISH 7000), %w(BUILD_PUBLISH 7000),
%w(FAILED_PUBLISH 8000), %w(FAILED_PUBLISH 8000),
@ -156,9 +158,10 @@ class BuildList < ActiveRecord::Base
state_machine :status, initial: :waiting_for_response do state_machine :status, initial: :waiting_for_response do
after_transition(on: :place_build) do |build_list, transition| after_transition(on: [:place_build, :rerun_tests]) do |build_list, transition|
build_list.add_job_to_abf_worker_queue if build_list.external_nodes.blank? build_list.add_job_to_abf_worker_queue if build_list.external_nodes.blank?
end end
after_transition on: :published, after_transition on: :published,
do: [:set_version_and_tag, :actualize_packages] do: [:set_version_and_tag, :actualize_packages]
after_transition on: :publish, do: :set_publisher after_transition on: :publish, do: :set_publisher
@ -177,18 +180,25 @@ class BuildList < ActiveRecord::Base
transition waiting_for_response: :build_pending transition waiting_for_response: :build_pending
end end
event :rerun_tests do
transition %i(success tests_failed) => :rerun_tests
end
event :start_build do event :start_build do
transition build_pending: :build_started transition build_pending: :build_started
transition rerun_tests: :rerunning_tests
end end
event :cancel do event :cancel do
transition [:build_pending, :build_started] => :build_canceling transition [:build_pending, :build_started] => :build_canceling
transition [:rerun_tests, :rerunning_tests] => :tests_failed
end end
# build_canceling: :build_canceled - canceling from UI # build_canceling: :build_canceled - canceling from UI
# build_started: :build_canceled - canceling from worker by time-out (time_living has been expired) # build_started: :build_canceled - canceling from worker by time-out (time_living has been expired)
event :build_canceled do event :build_canceled do
transition [:build_canceling, :build_started, :build_pending] => :build_canceled transition [:build_canceling, :build_started, :build_pending] => :build_canceled
transition [:rerun_tests, :rerunning_tests] => :tests_failed
end end
event :published do event :published do
@ -245,12 +255,13 @@ class BuildList < ActiveRecord::Base
# ===== into testing - end # ===== into testing - end
event :build_success do event :build_success do
transition [:build_started, :build_canceling, :build_canceled] => :success transition [:build_started, :build_canceling, :build_canceled, :rerunning_tests] => :success
end end
[:build_error, :tests_failed].each do |kind| [:build_error, :tests_failed].each do |kind|
event kind do event kind do
transition [:build_started, :build_canceling, :build_canceled] => kind transition [:build_started, :build_canceling, :build_canceled] => kind
transition rerunning_tests: :tests_failed
end end
end end
@ -525,6 +536,10 @@ class BuildList < ActiveRecord::Base
'EXTRA_BUILD_SRC_RPM_OPTIONS' => extra_params['build_src_rpm'], 'EXTRA_BUILD_SRC_RPM_OPTIONS' => extra_params['build_src_rpm'],
'EXTRA_BUILD_RPM_OPTIONS' => extra_params['build_rpm'] 'EXTRA_BUILD_RPM_OPTIONS' => extra_params['build_rpm']
} }
cmd_params.merge!(
'RERUN_TESTS' => true,
'PACKAGES' => packages.pluck(:sha1).compact * ' '
) if rerun_tests?
if use_cached_chroot? if use_cached_chroot?
sha1 = build_for_platform.cached_chroot(arch.name) sha1 = build_for_platform.cached_chroot(arch.name)
cmd_params.merge!('CACHED_CHROOT_SHA1' => sha1) if sha1.present? cmd_params.merge!('CACHED_CHROOT_SHA1' => sha1) if sha1.present?

View File

@ -181,6 +181,13 @@
data: { confirm: t("layout.publish_again_warning") }, data: { confirm: t("layout.publish_again_warning") },
name: 'publish', name: 'publish',
'ng-show' => "build_list.can_publish && build_list.status == #{BuildList::BUILD_PUBLISHED}" 'ng-show' => "build_list.can_publish && build_list.status == #{BuildList::BUILD_PUBLISHED}"
- if (current_user.tester? || current_user.admin?) && can?(:rerun_tests, @build_list)
= link_to t('layout.build_lists.rerun_tests'),
rerun_tests_build_list_path(@build_list),
method: :put,
data: { confirm: t("layout.confirm") },
class: 'button',
'ng-show' => "build_list.status == #{BuildList::TESTS_FAILED} || build_list.status == #{BuildList::SUCCESS}"
= submit_tag t("layout.publish"), = submit_tag t("layout.publish"),
data: { confirm: t('layout.build_lists.tests_failed') }, name: 'publish', data: { confirm: t('layout.build_lists.tests_failed') }, name: 'publish',
'ng-show' => "build_list.can_publish && build_list.can_publish_in_future && build_list.extra_build_lists_published && build_list.status == #{BuildList::TESTS_FAILED}" 'ng-show' => "build_list.can_publish && build_list.can_publish_in_future && build_list.extra_build_lists_published && build_list.status == #{BuildList::TESTS_FAILED}"

View File

@ -81,6 +81,9 @@ en:
cancel: Cancel build cancel: Cancel build
will_be_canceled: 'Build will be canceled...' will_be_canceled: 'Build will be canceled...'
creating: 'creating...' creating: 'creating...'
rerun_tests: Rerun tests
rerun_tests_success: 'Build is queued for rerun tests'
rerun_tests_fail: 'Errors during rerun tests!'
create_container_success: 'Container is queued for creating' create_container_success: 'Container is queued for creating'
create_container_fail: 'Errors during container creating!' create_container_fail: 'Errors during container creating!'
publish_success: 'Build is queued for publishing' publish_success: 'Build is queued for publishing'
@ -143,6 +146,8 @@ en:
statuses: statuses:
build_lists: All build_lists: All
rerun_tests: Rerun tests
rerunning_tests: Build is being rerun tests
build_error: Build error build_error: Build error
build_published: Build has been published build_published: Build has been published
tests_failed: Tests failed tests_failed: Tests failed

View File

@ -80,6 +80,9 @@ ru:
cancel: Отменить сборку cancel: Отменить сборку
will_be_canceled: 'Сборка будет отменена...' will_be_canceled: 'Сборка будет отменена...'
creating: 'создается...' creating: 'создается...'
rerun_tests: Перезапустить тесты
rerun_tests_success: 'Сборка поставлена в очередь на перезапуск тестов'
rerun_tests_fail: 'При перезапуске тестов произошла ошибка!'
create_container_success: 'Контейнер поставлен в очередь на создание' create_container_success: 'Контейнер поставлен в очередь на создание'
create_container_fail: 'При создании контейнера произошла ошибка!' create_container_fail: 'При создании контейнера произошла ошибка!'
cancel_success: 'Сборка отменена.' cancel_success: 'Сборка отменена.'
@ -142,6 +145,8 @@ ru:
statuses: statuses:
build_lists: Всего build_lists: Всего
rerun_tests: перезапуск тестов
rerunning_tests: тесты перезапускаются
build_error: ошибка сборки build_error: ошибка сборки
build_published: опубликован build_published: опубликован
tests_failed: тесты не прошли tests_failed: тесты не прошли

View File

@ -37,6 +37,7 @@ Rosa::Application.routes.draw do
member { member {
put :publish put :publish
put :reject_publish put :reject_publish
put :rerun_tests
put :cancel put :cancel
put :create_container put :create_container
put :publish_into_testing put :publish_into_testing
@ -276,6 +277,7 @@ Rosa::Application.routes.draw do
member do member do
put :cancel put :cancel
put :create_container put :create_container
put :rerun_tests
get :log get :log
patch :publish patch :publish
put :reject_publish put :reject_publish

View File

@ -18,6 +18,8 @@ module AbfWorker
item = find_or_create_item item = find_or_create_item
fill_container_data if status != STARTED fill_container_data if status != STARTED
rerunning_tests = subject.rerunning_tests?
case status case status
when COMPLETED when COMPLETED
subject.build_success subject.build_success
@ -28,17 +30,17 @@ module AbfWorker
end end
when FAILED when FAILED
subject.build_error subject.build_error
item.update_attributes({status: BuildList::BUILD_ERROR}) item.update_attributes({status: BuildList::BUILD_ERROR}) unless rerunning_tests
when STARTED when STARTED
subject.start_build subject.start_build
when CANCELED when CANCELED
item.update_attributes({status: BuildList::BUILD_CANCELED}) unless rerunning_tests || subject.tests_failed?
subject.build_canceled subject.build_canceled
item.update_attributes({status: BuildList::BUILD_CANCELED})
when TESTS_FAILED when TESTS_FAILED
subject.tests_failed subject.tests_failed
end end
if [TESTS_FAILED, COMPLETED].include?(status) if !rerunning_tests && [TESTS_FAILED, COMPLETED].include?(status)
item.update_attributes({status: BuildList::SUCCESS}) item.update_attributes({status: BuildList::SUCCESS})
subject.publish_container if subject.auto_create_container? subject.publish_container if subject.auto_create_container?
end end

View File

@ -25,10 +25,6 @@ shared_examples_for 'not show build list via api' do
end end
shared_examples_for 'create build list via api' do shared_examples_for 'create build list via api' do
before {
#@project.update_attributes({repositories: @platform.repositories})
#test_git_commit(@project)
}
it 'should create one more build list' do it 'should create one more build list' do
lambda { post :create, @create_params }.should change{ BuildList.count }.by(1) lambda { post :create, @create_params }.should change{ BuildList.count }.by(1)
@ -79,31 +75,24 @@ shared_examples_for 'not create build list via api' do
end end
shared_examples_for 'validation error via build list api' do |message| shared_examples_for 'validation error via build list api' do |message|
it 'should return 422 response code' do it 'should return 422 response code and correct json error message' do
response.status.should == 422 expect(response.status).to eq(422)
end expect(response.body).to eq({ build_list: {id: nil, message: message} }.to_json)
it "should return correct json error message" do
response.body.should == { build_list: {id: nil, message: message} }.to_json
end end
end end
describe Api::V1::BuildListsController do describe Api::V1::BuildListsController do
before(:each) { stub_symlink_methods } before { stub_symlink_methods }
context 'create and update abilities' do context 'create and update abilities' do
context 'for user' do context 'for user' do
before(:each) do before do
Arch.destroy_all
User.destroy_all
@build_list = FactoryGirl.create(:build_list) @build_list = FactoryGirl.create(:build_list)
@params = @build_list.attributes.symbolize_keys @params = @build_list.attributes.symbolize_keys
@project = @build_list.project @project = @build_list.project
@platform = @build_list.save_to_platform @platform = @build_list.save_to_platform
#@platform = FactoryGirl.create(:platform_with_repos) #@platform = FactoryGirl.create(:platform_with_repos)
stub_symlink_methods
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
@owner_user = @project.owner @owner_user = @project.owner
@member_user = FactoryGirl.create(:user) @member_user = FactoryGirl.create(:user)
@ -113,65 +102,76 @@ describe Api::V1::BuildListsController do
# Create and show params: # Create and show params:
@create_params = {build_list: @build_list.attributes.symbolize_keys.merge(:qwerty=>'!')} # wrong parameter @create_params = {build_list: @build_list.attributes.symbolize_keys.merge(:qwerty=>'!')} # wrong parameter
@create_params = @create_params.merge(arches: [@params[:arch_id]], build_for_platform_id: @platform.id, format: :json) @create_params = @create_params.merge(arches: [@params[:arch_id]], build_for_platform_id: @platform.id, format: :json)
any_instance_of(Project, versions: ['v1.0', 'v2.0']) allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
http_login(@user) http_login(@user)
end end
context 'do rerun_tests' do
def do_rerun_tests
put :rerun_tests, id: @build_list, format: :json
end
before do
allow_any_instance_of(BuildList).to receive(:can_rerun_tests?).and_return(true)
end
context 'if user is project owner' do
before { http_login(@owner_user) }
it 'reruns tests' do
expect_any_instance_of(BuildList).to receive(:rerun_tests).and_return(true)
do_rerun_tests
expect(response.body).to eq({ build_list: {id: @build_list.id, message: I18n.t('layout.build_lists.rerun_tests_success')} }.to_json)
expect(response).to be_success
end
context 'returns an error if the can not rerun_tests' do
before do
allow_any_instance_of(BuildList).to receive(:rerun_tests).and_return(false)
do_rerun_tests
end
it_should_behave_like 'validation error via build list api', I18n.t('layout.build_lists.rerun_tests_fail')
end
end
it 'returns an error if user is not project owner' do
expect_any_instance_of(BuildList).to_not receive(:rerun_tests)
do_rerun_tests
expect(response.body).to eq({"message" => "Access violation to this page!"}.to_json)
end
end
context "do cancel" do context "do cancel" do
def do_cancel def do_cancel
put :cancel, id: @build_list, format: :json put :cancel, id: @build_list, format: :json
end end
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {http_login(@owner_user)} before {http_login(@owner_user)}
context "if it has :build_pending status" do it 'cancels build' do
before do expect_any_instance_of(BuildList).to receive(:cancel).and_return(true)
@build_list.update_column(:status, BuildList::BUILD_PENDING) do_cancel
do_cancel expect(response.body).to eq({ build_list: {id: @build_list.id, message: I18n.t('layout.build_lists.cancel_success')} }.to_json)
end expect(response).to be_success
it "should return correct json message" do
response.body.should == { build_list: {id: @build_list.id, message: I18n.t('layout.build_lists.cancel_success')} }.to_json
end
it 'should return 200 response code' do
response.should be_success
end
it "should cancel build list" do
@build_list.reload.status.should == BuildList::BUILD_CANCELING
end
end end
context "if it has another status" do context 'returns an error if the can not cancel' do
before do before do
@build_list.update_column(:status, BuildList::SUCCESS) allow_any_instance_of(BuildList).to receive(:cancel).and_return(false)
do_cancel do_cancel
end end
it_should_behave_like 'validation error via build list api', I18n.t('layout.build_lists.cancel_fail') it_should_behave_like 'validation error via build list api', I18n.t('layout.build_lists.cancel_fail')
it "should not change status of build list" do
@build_list.reload.status.should == BuildList::SUCCESS
end
end end
end end
context 'if user is not project owner' do it 'returns an error if user is not project owner' do
before(:each) do expect_any_instance_of(BuildList).to_not receive(:cancel)
@build_list.update_column(:status, BuildList::BUILD_PENDING) do_cancel
do_cancel expect(response.body).to eq({"message" => "Access violation to this page!"}.to_json)
end
it "should return access violation message" do
response.body.should == {"message" => "Access violation to this page!"}.to_json
end
it "should not change status of build list" do
@build_list.reload.status.should == BuildList::BUILD_PENDING
end
end end
end end
@ -204,7 +204,7 @@ describe Api::V1::BuildListsController do
end end
context "if it has another status" do context "if it has another status" do
before(:each) do before do
@build_list.update_column(:status, BuildList::BUILD_ERROR) @build_list.update_column(:status, BuildList::BUILD_ERROR)
do_create_container do_create_container
end end
@ -218,7 +218,7 @@ describe Api::V1::BuildListsController do
end end
context 'if user is not project owner' do context 'if user is not project owner' do
before(:each) do before do
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
do_create_container do_create_container
end end
@ -239,7 +239,7 @@ describe Api::V1::BuildListsController do
end end
context 'if user is project && platform owner' do context 'if user is project && platform owner' do
before(:each) do before do
http_login(@owner_user) http_login(@owner_user)
end end
@ -281,7 +281,7 @@ describe Api::V1::BuildListsController do
end end
context "if it has another status" do context "if it has another status" do
before(:each) do before do
@build_list.update_column(:status, BuildList::BUILD_CANCELED) @build_list.update_column(:status, BuildList::BUILD_CANCELED)
do_publish_into_testing do_publish_into_testing
end end
@ -340,7 +340,7 @@ describe Api::V1::BuildListsController do
end end
context 'if user is project && platform owner' do context 'if user is project && platform owner' do
before(:each) do before do
http_login(@owner_user) http_login(@owner_user)
end end
@ -382,7 +382,7 @@ describe Api::V1::BuildListsController do
end end
context "if it has another status" do context "if it has another status" do
before(:each) do before do
@build_list.update_column(:status, BuildList::BUILD_CANCELED) @build_list.update_column(:status, BuildList::BUILD_CANCELED)
do_publish do_publish
end end
@ -450,7 +450,7 @@ describe Api::V1::BuildListsController do
end end
context "do reject_publish" do context "do reject_publish" do
before(:each) do before do
any_instance_of(BuildList, current_duration: 100) any_instance_of(BuildList, current_duration: 100)
@build_list.save_to_repository.update_column(:publish_without_qa, false) @build_list.save_to_repository.update_column(:publish_without_qa, false)
end end
@ -460,7 +460,7 @@ describe Api::V1::BuildListsController do
end end
context 'if user is project owner' do context 'if user is project owner' do
before(:each) do before do
http_login(@owner_user) http_login(@owner_user)
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_platform.update_column(:released, true) @build_list.save_to_platform.update_column(:released, true)
@ -482,7 +482,7 @@ describe Api::V1::BuildListsController do
end end
context "if it has another status" do context "if it has another status" do
before(:each) do before do
@build_list.update_column(:status, BuildList::BUILD_CANCELED) @build_list.update_column(:status, BuildList::BUILD_CANCELED)
do_reject_publish do_reject_publish
end end
@ -496,7 +496,7 @@ describe Api::V1::BuildListsController do
end end
context 'if user is not project owner' do context 'if user is not project owner' do
before(:each) do before do
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_platform.update_column(:released, true) @build_list.save_to_platform.update_column(:released, true)
do_reject_publish do_reject_publish
@ -513,7 +513,7 @@ describe Api::V1::BuildListsController do
end end
context 'if user is project reader' do context 'if user is project reader' do
before(:each) do before do
@another_user = FactoryGirl.create(:user) @another_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true) @build_list.save_to_repository.update_column(:publish_without_qa, true)
@ -533,7 +533,7 @@ describe Api::V1::BuildListsController do
end end
context 'if user is project writer' do context 'if user is project writer' do
before(:each) do before do
@another_user = FactoryGirl.create(:user) @another_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true) @build_list.save_to_repository.update_column(:publish_without_qa, true)
@ -560,7 +560,7 @@ describe Api::V1::BuildListsController do
it_should_behave_like 'not create build list via api' it_should_behave_like 'not create build list via api'
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {http_login(@owner_user)} before {http_login(@owner_user)}
it_should_behave_like 'create build list via api' it_should_behave_like 'create build list via api'
context 'no ability to read build_for_platform' do context 'no ability to read build_for_platform' do
@ -579,36 +579,33 @@ describe Api::V1::BuildListsController do
end end
context 'if user is project read member' do context 'if user is project read member' do
before(:each) {http_login(@member_user)} before {http_login(@member_user)}
it_should_behave_like 'not create build list via api' it_should_behave_like 'not create build list via api'
end end
end end
context 'for hidden project' do context 'for hidden project' do
before(:each) do before do
@project.update_column(:visibility, 'hidden') @project.update_column(:visibility, 'hidden')
end end
it_should_behave_like 'not create build list via api' it_should_behave_like 'not create build list via api'
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {http_login(@owner_user)} before {http_login(@owner_user)}
it_should_behave_like 'create build list via api' it_should_behave_like 'create build list via api'
end end
context 'if user is project read member' do context 'if user is project read member' do
before(:each) {http_login(@member_user)} before {http_login(@member_user)}
it_should_behave_like 'not create build list via api' it_should_behave_like 'not create build list via api'
end end
end end
end end
context 'for group' do context 'for group' do
before(:each) do before do
Arch.destroy_all
User.destroy_all
@build_list = FactoryGirl.create(:build_list) @build_list = FactoryGirl.create(:build_list)
@params = @build_list.attributes.symbolize_keys @params = @build_list.attributes.symbolize_keys
@project = @build_list.project @project = @build_list.project
@ -651,30 +648,30 @@ describe Api::V1::BuildListsController do
it_should_behave_like 'not create build list via api' it_should_behave_like 'not create build list via api'
context 'if user is group owner' do context 'if user is group owner' do
before(:each) {http_login(@owner_user)} before {http_login(@owner_user)}
it_should_behave_like 'create build list via api' it_should_behave_like 'create build list via api'
end end
context 'if user is group read member' do context 'if user is group read member' do
before(:each) {http_login(@member_user)} before {http_login(@member_user)}
it_should_behave_like 'not create build list via api' it_should_behave_like 'not create build list via api'
end end
end end
context 'for hidden project' do context 'for hidden project' do
before(:each) do before do
@build_list.project.update_column(:visibility, 'hidden') @build_list.project.update_column(:visibility, 'hidden')
end end
it_should_behave_like 'not create build list via api' it_should_behave_like 'not create build list via api'
context 'if user is group owner' do context 'if user is group owner' do
before(:each) {http_login(@owner_user)} before {http_login(@owner_user)}
it_should_behave_like 'create build list via api' it_should_behave_like 'create build list via api'
end end
context 'if user is group read member' do context 'if user is group read member' do
before(:each) {http_login(@member_user)} before {http_login(@member_user)}
it_should_behave_like 'not create build list via api' it_should_behave_like 'not create build list via api'
end end
end end
@ -683,10 +680,7 @@ describe Api::V1::BuildListsController do
end end
context 'read and accessible abilities' do context 'read and accessible abilities' do
before(:each) do before do
Arch.destroy_all
User.destroy_all
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
# Build Lists: # Build Lists:
@ -723,7 +717,7 @@ describe Api::V1::BuildListsController do
end end
context 'for all build lists' do context 'for all build lists' do
before(:each) { before {
http_login(@user) http_login(@user)
} }
@ -743,7 +737,7 @@ describe Api::V1::BuildListsController do
end end
context 'filter' do context 'filter' do
before(:each) do before do
http_login FactoryGirl.create(:admin) http_login FactoryGirl.create(:admin)
end end
@ -775,7 +769,7 @@ describe Api::V1::BuildListsController do
end end
context "for user" do context "for user" do
before(:each) do before do
@build_list = FactoryGirl.create(:build_list) @build_list = FactoryGirl.create(:build_list)
@params = @build_list.attributes.symbolize_keys @params = @build_list.attributes.symbolize_keys
@project = @build_list.project @project = @build_list.project
@ -792,45 +786,45 @@ describe Api::V1::BuildListsController do
context 'for open project' do context 'for open project' do
context 'for simple user' do context 'for simple user' do
before(:each) {http_login(@user)} before {http_login(@user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {http_login(@owner_user)} before {http_login(@owner_user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
context 'if user is project read member' do context 'if user is project read member' do
before(:each) {http_login(@member_user)} before {http_login(@member_user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
end end
context 'for hidden project' do context 'for hidden project' do
before(:each) do before do
@project.update_column(:visibility, 'hidden') @project.update_column(:visibility, 'hidden')
end end
context 'for simple user' do context 'for simple user' do
before(:each) {http_login(@user)} before {http_login(@user)}
it_should_behave_like 'not show build list via api' it_should_behave_like 'not show build list via api'
end end
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {http_login(@owner_user)} before {http_login(@owner_user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
context 'if user is project read member' do context 'if user is project read member' do
before(:each) {http_login(@member_user)} before {http_login(@member_user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
end end
end end
context "for group" do context "for group" do
before(:each) do before do
@platform = FactoryGirl.create(:platform_with_repos) @platform = FactoryGirl.create(:platform_with_repos)
@build_list = FactoryGirl.create(:build_list, save_to_platform: @platform) @build_list = FactoryGirl.create(:build_list, save_to_platform: @platform)
@project = @build_list.project @project = @build_list.project
@ -854,38 +848,38 @@ describe Api::V1::BuildListsController do
context 'for open project' do context 'for open project' do
context 'for simple user' do context 'for simple user' do
before(:each) {http_login(@user)} before {http_login(@user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
context 'if user is group owner' do context 'if user is group owner' do
before(:each) {http_login(@owner_user)} before {http_login(@owner_user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
context 'if user is group read member' do context 'if user is group read member' do
before(:each) {http_login(@member_user)} before {http_login(@member_user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
end end
context 'for hidden project' do context 'for hidden project' do
before(:each) do before do
@build_list.project.update_column(:visibility, 'hidden') @build_list.project.update_column(:visibility, 'hidden')
end end
context 'for simple user' do context 'for simple user' do
before(:each) {http_login(@user)} before {http_login(@user)}
it_should_behave_like 'not show build list via api' it_should_behave_like 'not show build list via api'
end end
context 'if user is group owner' do context 'if user is group owner' do
before(:each) { http_login(@owner_user) } before { http_login(@owner_user) }
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
context 'if user is group read member' do context 'if user is group read member' do
before(:each) {http_login(@member_user)} before {http_login(@member_user)}
it_should_behave_like 'show build list via api' it_should_behave_like 'show build list via api'
end end
end end

View File

@ -80,7 +80,7 @@ describe Projects::BuildListsController do
before { stub_symlink_methods } before { stub_symlink_methods }
context 'crud' do context 'crud' do
before(:each) do before do
@platform = FactoryGirl.create(:platform_with_repos) @platform = FactoryGirl.create(:platform_with_repos)
@create_params = { @create_params = {
build_list: { build_list: {
@ -109,7 +109,7 @@ describe Projects::BuildListsController do
end end
context 'for user' do context 'for user' do
before(:each) do before do
any_instance_of(BuildList, current_duration: 100) any_instance_of(BuildList, current_duration: 100)
@build_list = FactoryGirl.create(:build_list) @build_list = FactoryGirl.create(:build_list)
@project = @build_list.project @project = @build_list.project
@ -124,15 +124,69 @@ describe Projects::BuildListsController do
@request.env['HTTP_REFERER'] = build_list_path(@build_list) @request.env['HTTP_REFERER'] = build_list_path(@build_list)
end end
context 'do rerun_tests' do
def do_rerun_tests
put :rerun_tests, id: @build_list
end
context 'if user is project owner' do
before { set_session_for(@owner_user) }
it 'reruns tests' do
expect_any_instance_of(BuildList).to receive(:rerun_tests).and_return(true)
do_rerun_tests
expect(response).to redirect_to(build_list_path(@build_list))
expect(flash[:notice]).to match I18n.t('layout.build_lists.rerun_tests_success')
end
it 'returns an error if the can not rerun_tests' do
allow_any_instance_of(BuildList).to receive(:rerun_tests).and_return(false)
do_rerun_tests
expect(response).to redirect_to(build_list_path(@build_list))
expect(flash[:error]).to match I18n.t('layout.build_lists.rerun_tests_fail')
end
end
it 'returns an error if user is not project owner' do
expect_any_instance_of(BuildList).to_not receive(:rerun_tests)
do_rerun_tests
expect(response).to redirect_to(forbidden_url)
end
it 'returns an error if user is project reader' do
@another_user = FactoryGirl.create(:user)
@build_list.project.collaborators.create(actor_type: 'User', actor_id: @another_user.id, role: 'reader')
set_session_for(@another_user)
expect_any_instance_of(BuildList).to_not receive(:rerun_tests)
do_rerun_tests
expect(response).to redirect_to(forbidden_url)
end
it 'reruns tests if user is project writer' do
@writer_user = FactoryGirl.create(:user)
create_relation(@build_list.project, @writer_user, 'writer')
set_session_for(@writer_user)
expect_any_instance_of(BuildList).to receive(:rerun_tests).and_return(true)
do_rerun_tests
expect(response).to redirect_to(build_list_path(@build_list))
expect(flash[:notice]).to match I18n.t('layout.build_lists.rerun_tests_success')
end
end
context "do reject_publish" do context "do reject_publish" do
before(:each) {@build_list.save_to_repository.update_column(:publish_without_qa, true)} before {@build_list.save_to_repository.update_column(:publish_without_qa, true)}
def do_reject_publish def do_reject_publish
put :reject_publish, id: @build_list put :reject_publish, id: @build_list
end end
context 'if user is project owner' do context 'if user is project owner' do
before(:each) do before do
set_session_for(@owner_user) set_session_for(@owner_user)
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_platform.update_column(:released, true) @build_list.save_to_platform.update_column(:released, true)
@ -150,7 +204,7 @@ describe Projects::BuildListsController do
end end
context "if it has another status" do context "if it has another status" do
before(:each) do before do
@build_list.update_column(:status, BuildList::BUILD_ERROR) @build_list.update_column(:status, BuildList::BUILD_ERROR)
do_reject_publish do_reject_publish
end end
@ -162,7 +216,7 @@ describe Projects::BuildListsController do
end end
context 'if user is not project owner' do context 'if user is not project owner' do
before(:each) do before do
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_platform.update_column(:released, true) @build_list.save_to_platform.update_column(:released, true)
do_reject_publish do_reject_publish
@ -179,7 +233,7 @@ describe Projects::BuildListsController do
end end
context 'if user is project reader' do context 'if user is project reader' do
before(:each) do before do
@another_user = FactoryGirl.create(:user) @another_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true) @build_list.save_to_repository.update_column(:publish_without_qa, true)
@ -199,7 +253,7 @@ describe Projects::BuildListsController do
end end
context 'if user is project writer' do context 'if user is project writer' do
before(:each) do before do
@writer_user = FactoryGirl.create(:user) @writer_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS) @build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true) @build_list.save_to_repository.update_column(:publish_without_qa, true)
@ -219,7 +273,7 @@ describe Projects::BuildListsController do
end end
context 'for all build lists' do context 'for all build lists' do
before(:each) do before do
@build_list1 = FactoryGirl.create(:build_list) @build_list1 = FactoryGirl.create(:build_list)
@build_list2 = FactoryGirl.create(:build_list) @build_list2 = FactoryGirl.create(:build_list)
@ -252,7 +306,7 @@ describe Projects::BuildListsController do
it_should_behave_like 'not create build list' it_should_behave_like 'not create build list'
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {set_session_for(@owner_user)} before {set_session_for(@owner_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'create build list' it_should_behave_like 'create build list'
@ -270,14 +324,14 @@ describe Projects::BuildListsController do
end end
context 'if user is project read member' do context 'if user is project read member' do
before(:each) {set_session_for(@member_user)} before {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list' it_should_behave_like 'not create build list'
end end
end end
context 'for hidden project' do context 'for hidden project' do
before(:each) do before do
@project.visibility = 'hidden' @project.visibility = 'hidden'
@project.save @project.save
end end
@ -286,13 +340,13 @@ describe Projects::BuildListsController do
it_should_behave_like 'not create build list' it_should_behave_like 'not create build list'
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {set_session_for(@owner_user)} before {set_session_for(@owner_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'create build list' it_should_behave_like 'create build list'
end end
context 'if user is project read member' do context 'if user is project read member' do
before(:each) {set_session_for(@member_user)} before {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list' it_should_behave_like 'not create build list'
end end
@ -300,7 +354,7 @@ describe Projects::BuildListsController do
end end
context 'for group' do context 'for group' do
before(:each) do before do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
set_session_for(@user) set_session_for(@user)
@ -319,7 +373,7 @@ describe Projects::BuildListsController do
end end
context 'for all build lists' do context 'for all build lists' do
before(:each) do before do
@build_list1 = FactoryGirl.create(:build_list) @build_list1 = FactoryGirl.create(:build_list)
@build_list2 = FactoryGirl.create(:build_list) @build_list2 = FactoryGirl.create(:build_list)
@ -352,20 +406,20 @@ describe Projects::BuildListsController do
it_should_behave_like 'not create build list' it_should_behave_like 'not create build list'
context 'if user is group owner' do context 'if user is group owner' do
before(:each) {set_session_for(@owner_user)} before {set_session_for(@owner_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'create build list' it_should_behave_like 'create build list'
end end
context 'if user is group read member' do context 'if user is group read member' do
before(:each) {set_session_for(@member_user)} before {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list' it_should_behave_like 'not create build list'
end end
end end
context 'for hidden project' do context 'for hidden project' do
before(:each) do before do
@project.visibility = 'hidden' @project.visibility = 'hidden'
@project.save @project.save
end end
@ -374,13 +428,13 @@ describe Projects::BuildListsController do
it_should_behave_like 'not create build list' it_should_behave_like 'not create build list'
context 'if user is group owner' do context 'if user is group owner' do
before(:each) {set_session_for(@owner_user)} before {set_session_for(@owner_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'create build list' it_should_behave_like 'create build list'
end end
context 'if user is group read member' do context 'if user is group read member' do
before(:each) {set_session_for(@member_user)} before {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list' it_should_behave_like 'not create build list'
end end
@ -391,7 +445,7 @@ describe Projects::BuildListsController do
context 'filter' do context 'filter' do
before(:each) do before do
set_session_for FactoryGirl.create(:admin) set_session_for FactoryGirl.create(:admin)
@build_list1 = FactoryGirl.create(:build_list) @build_list1 = FactoryGirl.create(:build_list)

View File

@ -45,8 +45,8 @@ def http_login(user=nil, password = '123456')
end end
def stub_symlink_methods def stub_symlink_methods
any_instance_of(Platform, symlink_directory: true) allow_any_instance_of(Platform).to receive(:symlink_directory).and_return(true)
any_instance_of(Platform, remove_symlink_directory: true) allow_any_instance_of(Platform).to receive(:remove_symlink_directory).and_return(true)
end end
Resque.inline = true Resque.inline = true