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.map_priorities = {
<%=BuildList::WAITING_FOR_RESPONSE%>: 11,
<%=BuildList::BUILD_PENDING%>: 10,
<%=BuildList::BUILD_CANCELING%>: 9,
<%=BuildList::BUILD_CANCELED%>: 8,
<%=BuildList::BUILD_STARTED%>: 7,
<%=BuildList::WAITING_FOR_RESPONSE%>: 13,
<%=BuildList::BUILD_PENDING%>: 12,
<%=BuildList::RERUN_TESTS%>: 11,
<%=BuildList::BUILD_CANCELING%>: 10,
<%=BuildList::BUILD_CANCELED%>: 9,
<%=BuildList::BUILD_STARTED%>: 8,
<%=BuildList::RERUNNING_TESTS%>: 7,
<%=BuildList::BUILD_PUBLISH%>: 6,
<%=BuildList::BUILD_PUBLISHED%>: 5,
<%=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']
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
authorize!(:show, @project) if @project
@ -43,6 +43,10 @@ class Api::V1::BuildListsController < Api::V1::BaseController
render_json :create_container, :publish_container
end
def rerun_tests
render_json :rerun_tests
end
def publish_into_testing
@build_list.publisher = current_user
render_json :publish_into_testing

View File

@ -14,7 +14,9 @@ class Api::V1::JobsController < Api::V1::BaseController
else
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?
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)
build_lists = build_lists.for_platform(platform_ids) if platform_ids.present?

View File

@ -119,30 +119,29 @@ class Projects::BuildListsController < Projects::BaseController
end
@build_list.publisher = current_user
message = @build_list.publish ? 'success' : 'fail'
redirect_to :back, notice: t("layout.build_lists.publish_#{message}")
do_and_back(:publish, 'publish_')
end
def publish_into_testing
@build_list.publisher = current_user
message = @build_list.publish_into_testing ? 'success' : 'fail'
redirect_to :back, notice: t("layout.build_lists.publish_#{message}")
do_and_back(:publish_into_testing, 'publish_')
end
def rerun_tests
do_and_back(:rerun_tests, 'rerun_tests_')
end
def reject_publish
@build_list.publisher = current_user
message = @build_list.reject_publish ? 'success' : 'fail'
redirect_to :back, notice: t("layout.build_lists.reject_publish_#{message}")
do_and_back(:reject_publish, 'reject_publish_')
end
def create_container
message = @build_list.publish_container ? 'success' : 'fail'
redirect_to :back, notice: t("layout.build_lists.create_container_#{message}")
do_and_back(:publish_container, 'create_container_')
end
def cancel
message = @build_list.cancel ? 'will_be_canceled' : 'cancel_fail'
redirect_to :back, notice: t("layout.build_lists.#{message}")
do_and_back(:cancel, nil, 'will_be_canceled', 'cancel_fail')
end
def log
@ -184,6 +183,13 @@ class Projects::BuildListsController < Projects::BaseController
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
@build_list = BuildList.find(params[:id])
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(: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 &&
can?(:write, build_list.project) &&
(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(WAITING_FOR_RESPONSE 4000),
%w(BUILD_PENDING 2000),
%w(RERUN_TESTS 2500),
%w(RERUNNING_TESTS 2550),
%w(BUILD_PUBLISHED 6000),
%w(BUILD_PUBLISH 7000),
%w(FAILED_PUBLISH 8000),
@ -156,9 +158,10 @@ class BuildList < ActiveRecord::Base
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?
end
after_transition on: :published,
do: [:set_version_and_tag, :actualize_packages]
after_transition on: :publish, do: :set_publisher
@ -177,18 +180,25 @@ class BuildList < ActiveRecord::Base
transition waiting_for_response: :build_pending
end
event :rerun_tests do
transition %i(success tests_failed) => :rerun_tests
end
event :start_build do
transition build_pending: :build_started
transition rerun_tests: :rerunning_tests
end
event :cancel do
transition [:build_pending, :build_started] => :build_canceling
transition [:rerun_tests, :rerunning_tests] => :tests_failed
end
# build_canceling: :build_canceled - canceling from UI
# build_started: :build_canceled - canceling from worker by time-out (time_living has been expired)
event :build_canceled do
transition [:build_canceling, :build_started, :build_pending] => :build_canceled
transition [:rerun_tests, :rerunning_tests] => :tests_failed
end
event :published do
@ -245,12 +255,13 @@ class BuildList < ActiveRecord::Base
# ===== into testing - end
event :build_success do
transition [:build_started, :build_canceling, :build_canceled] => :success
transition [:build_started, :build_canceling, :build_canceled, :rerunning_tests] => :success
end
[:build_error, :tests_failed].each do |kind|
event kind do
transition [:build_started, :build_canceling, :build_canceled] => kind
transition rerunning_tests: :tests_failed
end
end
@ -525,6 +536,10 @@ class BuildList < ActiveRecord::Base
'EXTRA_BUILD_SRC_RPM_OPTIONS' => extra_params['build_src_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?
sha1 = build_for_platform.cached_chroot(arch.name)
cmd_params.merge!('CACHED_CHROOT_SHA1' => sha1) if sha1.present?

View File

@ -181,6 +181,13 @@
data: { confirm: t("layout.publish_again_warning") },
name: 'publish',
'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"),
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}"

View File

@ -81,6 +81,9 @@ en:
cancel: Cancel build
will_be_canceled: 'Build will be canceled...'
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_fail: 'Errors during container creating!'
publish_success: 'Build is queued for publishing'
@ -143,6 +146,8 @@ en:
statuses:
build_lists: All
rerun_tests: Rerun tests
rerunning_tests: Build is being rerun tests
build_error: Build error
build_published: Build has been published
tests_failed: Tests failed

View File

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

View File

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

View File

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

View File

@ -25,10 +25,6 @@ shared_examples_for 'not show build list via api' do
end
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
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
shared_examples_for 'validation error via build list api' do |message|
it 'should return 422 response code' do
response.status.should == 422
end
it "should return correct json error message" do
response.body.should == { build_list: {id: nil, message: message} }.to_json
it 'should return 422 response code and correct json error message' do
expect(response.status).to eq(422)
expect(response.body).to eq({ build_list: {id: nil, message: message} }.to_json)
end
end
describe Api::V1::BuildListsController do
before(:each) { stub_symlink_methods }
before { stub_symlink_methods }
context 'create and update abilities' do
context 'for user' do
before(:each) do
Arch.destroy_all
User.destroy_all
before do
@build_list = FactoryGirl.create(:build_list)
@params = @build_list.attributes.symbolize_keys
@project = @build_list.project
@platform = @build_list.save_to_platform
#@platform = FactoryGirl.create(:platform_with_repos)
stub_symlink_methods
@user = FactoryGirl.create(:user)
@owner_user = @project.owner
@member_user = FactoryGirl.create(:user)
@ -113,65 +102,76 @@ describe Api::V1::BuildListsController do
# Create and show params:
@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)
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)
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
def do_cancel
put :cancel, id: @build_list, format: :json
end
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
before do
@build_list.update_column(:status, BuildList::BUILD_PENDING)
do_cancel
end
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
it 'cancels build' do
expect_any_instance_of(BuildList).to receive(:cancel).and_return(true)
do_cancel
expect(response.body).to eq({ build_list: {id: @build_list.id, message: I18n.t('layout.build_lists.cancel_success')} }.to_json)
expect(response).to be_success
end
context "if it has another status" do
context 'returns an error if the can not cancel' do
before do
@build_list.update_column(:status, BuildList::SUCCESS)
allow_any_instance_of(BuildList).to receive(:cancel).and_return(false)
do_cancel
end
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
context 'if user is not project owner' do
before(:each) do
@build_list.update_column(:status, BuildList::BUILD_PENDING)
do_cancel
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
it 'returns an error if user is not project owner' do
expect_any_instance_of(BuildList).to_not receive(:cancel)
do_cancel
expect(response.body).to eq({"message" => "Access violation to this page!"}.to_json)
end
end
@ -204,7 +204,7 @@ describe Api::V1::BuildListsController do
end
context "if it has another status" do
before(:each) do
before do
@build_list.update_column(:status, BuildList::BUILD_ERROR)
do_create_container
end
@ -218,7 +218,7 @@ describe Api::V1::BuildListsController do
end
context 'if user is not project owner' do
before(:each) do
before do
@build_list.update_column(:status, BuildList::SUCCESS)
do_create_container
end
@ -239,7 +239,7 @@ describe Api::V1::BuildListsController do
end
context 'if user is project && platform owner' do
before(:each) do
before do
http_login(@owner_user)
end
@ -281,7 +281,7 @@ describe Api::V1::BuildListsController do
end
context "if it has another status" do
before(:each) do
before do
@build_list.update_column(:status, BuildList::BUILD_CANCELED)
do_publish_into_testing
end
@ -340,7 +340,7 @@ describe Api::V1::BuildListsController do
end
context 'if user is project && platform owner' do
before(:each) do
before do
http_login(@owner_user)
end
@ -382,7 +382,7 @@ describe Api::V1::BuildListsController do
end
context "if it has another status" do
before(:each) do
before do
@build_list.update_column(:status, BuildList::BUILD_CANCELED)
do_publish
end
@ -450,7 +450,7 @@ describe Api::V1::BuildListsController do
end
context "do reject_publish" do
before(:each) do
before do
any_instance_of(BuildList, current_duration: 100)
@build_list.save_to_repository.update_column(:publish_without_qa, false)
end
@ -460,7 +460,7 @@ describe Api::V1::BuildListsController do
end
context 'if user is project owner' do
before(:each) do
before do
http_login(@owner_user)
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_platform.update_column(:released, true)
@ -482,7 +482,7 @@ describe Api::V1::BuildListsController do
end
context "if it has another status" do
before(:each) do
before do
@build_list.update_column(:status, BuildList::BUILD_CANCELED)
do_reject_publish
end
@ -496,7 +496,7 @@ describe Api::V1::BuildListsController do
end
context 'if user is not project owner' do
before(:each) do
before do
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_platform.update_column(:released, true)
do_reject_publish
@ -513,7 +513,7 @@ describe Api::V1::BuildListsController do
end
context 'if user is project reader' do
before(:each) do
before do
@another_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true)
@ -533,7 +533,7 @@ describe Api::V1::BuildListsController do
end
context 'if user is project writer' do
before(:each) do
before do
@another_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS)
@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'
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'
context 'no ability to read build_for_platform' do
@ -579,36 +579,33 @@ describe Api::V1::BuildListsController do
end
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'
end
end
context 'for hidden project' do
before(:each) do
before do
@project.update_column(:visibility, 'hidden')
end
it_should_behave_like 'not create build list via api'
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'
end
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'
end
end
end
context 'for group' do
before(:each) do
Arch.destroy_all
User.destroy_all
before do
@build_list = FactoryGirl.create(:build_list)
@params = @build_list.attributes.symbolize_keys
@project = @build_list.project
@ -651,30 +648,30 @@ describe Api::V1::BuildListsController do
it_should_behave_like 'not create build list via api'
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'
end
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'
end
end
context 'for hidden project' do
before(:each) do
before do
@build_list.project.update_column(:visibility, 'hidden')
end
it_should_behave_like 'not create build list via api'
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'
end
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'
end
end
@ -683,10 +680,7 @@ describe Api::V1::BuildListsController do
end
context 'read and accessible abilities' do
before(:each) do
Arch.destroy_all
User.destroy_all
before do
@user = FactoryGirl.create(:user)
# Build Lists:
@ -723,7 +717,7 @@ describe Api::V1::BuildListsController do
end
context 'for all build lists' do
before(:each) {
before {
http_login(@user)
}
@ -743,7 +737,7 @@ describe Api::V1::BuildListsController do
end
context 'filter' do
before(:each) do
before do
http_login FactoryGirl.create(:admin)
end
@ -775,7 +769,7 @@ describe Api::V1::BuildListsController do
end
context "for user" do
before(:each) do
before do
@build_list = FactoryGirl.create(:build_list)
@params = @build_list.attributes.symbolize_keys
@project = @build_list.project
@ -792,45 +786,45 @@ describe Api::V1::BuildListsController do
context 'for open project' do
context 'for simple user' do
before(:each) {http_login(@user)}
before {http_login(@user)}
it_should_behave_like 'show build list via api'
end
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'
end
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'
end
end
context 'for hidden project' do
before(:each) do
before do
@project.update_column(:visibility, 'hidden')
end
context 'for simple user' do
before(:each) {http_login(@user)}
before {http_login(@user)}
it_should_behave_like 'not show build list via api'
end
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'
end
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'
end
end
end
context "for group" do
before(:each) do
before do
@platform = FactoryGirl.create(:platform_with_repos)
@build_list = FactoryGirl.create(:build_list, save_to_platform: @platform)
@project = @build_list.project
@ -854,38 +848,38 @@ describe Api::V1::BuildListsController do
context 'for open project' do
context 'for simple user' do
before(:each) {http_login(@user)}
before {http_login(@user)}
it_should_behave_like 'show build list via api'
end
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'
end
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'
end
end
context 'for hidden project' do
before(:each) do
before do
@build_list.project.update_column(:visibility, 'hidden')
end
context 'for simple user' do
before(:each) {http_login(@user)}
before {http_login(@user)}
it_should_behave_like 'not show build list via api'
end
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'
end
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'
end
end

View File

@ -80,7 +80,7 @@ describe Projects::BuildListsController do
before { stub_symlink_methods }
context 'crud' do
before(:each) do
before do
@platform = FactoryGirl.create(:platform_with_repos)
@create_params = {
build_list: {
@ -109,7 +109,7 @@ describe Projects::BuildListsController do
end
context 'for user' do
before(:each) do
before do
any_instance_of(BuildList, current_duration: 100)
@build_list = FactoryGirl.create(:build_list)
@project = @build_list.project
@ -124,15 +124,69 @@ describe Projects::BuildListsController do
@request.env['HTTP_REFERER'] = build_list_path(@build_list)
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
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
put :reject_publish, id: @build_list
end
context 'if user is project owner' do
before(:each) do
before do
set_session_for(@owner_user)
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_platform.update_column(:released, true)
@ -150,7 +204,7 @@ describe Projects::BuildListsController do
end
context "if it has another status" do
before(:each) do
before do
@build_list.update_column(:status, BuildList::BUILD_ERROR)
do_reject_publish
end
@ -162,7 +216,7 @@ describe Projects::BuildListsController do
end
context 'if user is not project owner' do
before(:each) do
before do
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_platform.update_column(:released, true)
do_reject_publish
@ -179,7 +233,7 @@ describe Projects::BuildListsController do
end
context 'if user is project reader' do
before(:each) do
before do
@another_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true)
@ -199,7 +253,7 @@ describe Projects::BuildListsController do
end
context 'if user is project writer' do
before(:each) do
before do
@writer_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true)
@ -219,7 +273,7 @@ describe Projects::BuildListsController do
end
context 'for all build lists' do
before(:each) do
before do
@build_list1 = 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'
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 'create build list'
@ -270,14 +324,14 @@ describe Projects::BuildListsController do
end
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 'not create build list'
end
end
context 'for hidden project' do
before(:each) do
before do
@project.visibility = 'hidden'
@project.save
end
@ -286,13 +340,13 @@ describe Projects::BuildListsController do
it_should_behave_like 'not create build list'
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 'create build list'
end
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 'not create build list'
end
@ -300,7 +354,7 @@ describe Projects::BuildListsController do
end
context 'for group' do
before(:each) do
before do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@ -319,7 +373,7 @@ describe Projects::BuildListsController do
end
context 'for all build lists' do
before(:each) do
before do
@build_list1 = 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'
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 'create build list'
end
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 'not create build list'
end
end
context 'for hidden project' do
before(:each) do
before do
@project.visibility = 'hidden'
@project.save
end
@ -374,13 +428,13 @@ describe Projects::BuildListsController do
it_should_behave_like 'not create build list'
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 'create build list'
end
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 'not create build list'
end
@ -391,7 +445,7 @@ describe Projects::BuildListsController do
context 'filter' do
before(:each) do
before do
set_session_for FactoryGirl.create(:admin)
@build_list1 = FactoryGirl.create(:build_list)

View File

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