2012-07-06 17:36:44 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
shared_examples_for 'mass_build platform owner' do
|
|
|
|
it 'should be able to perform index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, platform_id: @platform
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to render_template(:index)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
2014-06-26 18:20:26 +01:00
|
|
|
it 'should be able to perform show action' do
|
|
|
|
get :show, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to render_template(:show)
|
2014-06-26 18:20:26 +01:00
|
|
|
end
|
|
|
|
|
2013-06-05 14:48:11 +01:00
|
|
|
it 'should be able to perform new action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :new, platform_id: @platform
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to render_template(:new)
|
2013-06-05 14:48:11 +01:00
|
|
|
end
|
|
|
|
|
2012-07-06 17:36:44 +01:00
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(platform_mass_builds_path(@platform))
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform cancel action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :cancel, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(platform_mass_builds_path(@platform))
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should change stop_build on cancel' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :cancel, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(@mass_build.reload.stop_build).to be_truthy
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
2013-03-21 15:17:30 +00:00
|
|
|
it 'should be able to perform publish action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :publish, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(platform_mass_builds_path(@platform))
|
2013-03-21 15:17:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should change build_publish on publish' do
|
2014-05-28 22:17:15 +01:00
|
|
|
allow_any_instance_of(BuildList).to receive(:valid_branch_for_publish?).and_return(true)
|
2014-01-21 04:51:49 +00:00
|
|
|
post :publish, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(@mass_build.reload.build_publish_count).to eq 1
|
2013-03-21 15:17:30 +00:00
|
|
|
end
|
|
|
|
|
2012-07-06 17:36:44 +01:00
|
|
|
it 'should not be able to perform cancel action if stop_build is true' do
|
2012-08-15 14:52:32 +01:00
|
|
|
@mass_build.stop_build = true; @mass_build.save
|
2014-01-21 04:51:49 +00:00
|
|
|
post :cancel, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should change objects count on create success' do
|
2015-04-02 23:13:26 +01:00
|
|
|
expect do
|
|
|
|
post :create, @create_params
|
|
|
|
end.to change(MassBuild, :count).by(1)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
2013-04-01 12:08:25 +01:00
|
|
|
it 'should be able to perform get_list action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :get_list, platform_id: @platform, id: @mass_build, kind: 'failed_builds_list'
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to be_success
|
2013-04-01 12:08:25 +01:00
|
|
|
end
|
2013-06-05 14:48:11 +01:00
|
|
|
end
|
2013-04-01 12:08:25 +01:00
|
|
|
|
2013-06-05 14:48:11 +01:00
|
|
|
shared_examples_for 'mass_build platform owner of personal platform' do
|
|
|
|
before(:each) do
|
2014-01-21 04:51:49 +00:00
|
|
|
Platform.update_all(platform_type: 'personal')
|
2013-06-05 14:48:11 +01:00
|
|
|
repository = FactoryGirl.create(:repository)
|
|
|
|
@mass_build.build_lists.each do |bl|
|
|
|
|
bl.build_for_platform = repository.platform
|
|
|
|
bl.include_repos = [repository.id]
|
|
|
|
bl.save
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
end
|
2013-06-05 14:48:11 +01:00
|
|
|
it_should_behave_like 'mass_build platform owner'
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'mass_build platform reader' do
|
2013-04-01 12:08:25 +01:00
|
|
|
it 'should be able to perform index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, platform_id: @platform
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to render_template(:index)
|
2013-04-01 12:08:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform get_list action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :get_list, platform_id: @platform, id: @mass_build, kind: 'failed_builds_list'
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to be_success
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
2013-06-05 14:48:11 +01:00
|
|
|
it "should not be able to perform new action" do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :new, platform_id: @platform
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2013-06-05 14:48:11 +01:00
|
|
|
end
|
|
|
|
|
2013-04-01 12:08:25 +01:00
|
|
|
it "should not be able to perform create action" do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :create, platform_id: @platform
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
2013-04-01 12:08:25 +01:00
|
|
|
[:cancel, :publish].each do |action|
|
2012-07-06 17:36:44 +01:00
|
|
|
it "should not be able to perform #{ action } action" do
|
2014-01-21 04:51:49 +00:00
|
|
|
get action, platform_id: @platform, id: @mass_build.id
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not change objects count on create success' do
|
2015-04-02 23:13:26 +01:00
|
|
|
expect do
|
|
|
|
post :create, @create_params
|
|
|
|
end.to_not change(MassBuild, :count)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not change stop_build on cancel' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :cancel, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(@mass_build.reload.stop_build).to be_falsy
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
2013-03-21 15:17:30 +00:00
|
|
|
|
|
|
|
it 'should not change build_publish on publish' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :publish, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(@mass_build.reload.build_publish_count).to eq 0
|
2013-03-21 15:17:30 +00:00
|
|
|
end
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe Platforms::MassBuildsController, type: :controller do
|
2012-07-06 17:36:44 +01:00
|
|
|
before(:each) do
|
|
|
|
stub_symlink_methods
|
|
|
|
|
2012-07-17 09:02:56 +01:00
|
|
|
FactoryGirl.create(:arch)
|
2012-07-06 17:36:44 +01:00
|
|
|
@platform = FactoryGirl.create(:platform)
|
2014-01-21 04:51:49 +00:00
|
|
|
@repository = FactoryGirl.create(:repository, platform: @platform)
|
|
|
|
@personal_platform = FactoryGirl.create(:platform, platform_type: 'personal')
|
2012-07-06 17:36:44 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2014-01-21 04:51:49 +00:00
|
|
|
project = FactoryGirl.create(:project, owner: @user)
|
2012-12-11 15:20:00 +00:00
|
|
|
@repository.projects << project
|
|
|
|
|
2012-07-06 17:36:44 +01:00
|
|
|
@create_params = {
|
2014-01-21 04:51:49 +00:00
|
|
|
mass_build: {
|
2013-06-05 14:48:11 +01:00
|
|
|
:projects_list => @repository.projects.map(&:name).join("\n"),
|
2014-09-02 12:10:56 +01:00
|
|
|
:build_for_platform_id => @platform.id
|
2013-06-05 14:48:11 +01:00
|
|
|
},
|
|
|
|
:platform_id => @platform,
|
|
|
|
:arches => [Arch.first.id],
|
2012-07-06 17:36:44 +01:00
|
|
|
}
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
@mass_build = FactoryGirl.create(:mass_build, save_to_platform: @platform, user: @user, projects_list: project.name)
|
|
|
|
FactoryGirl.create(:build_list, mass_build: @mass_build, status: BuildList::SUCCESS)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for guest' do
|
2013-04-01 12:08:25 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
it 'should be able to perform index action', anonymous_access: true do
|
|
|
|
get :index, platform_id: @platform
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to render_template(:index)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
it 'should not be able to perform index action', anonymous_access: false do
|
|
|
|
get :index, platform_id: @platform
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
it 'should be able to perform get_list action', anonymous_access: true do
|
|
|
|
get :get_list, platform_id: @platform, id: @mass_build, kind: 'failed_builds_list'
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to be_success
|
2013-04-01 12:08:25 +01:00
|
|
|
end
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
it "should not be able to get failed builds list", anonymous_access: false do
|
|
|
|
get :get_list, platform_id: @platform, id: @mass_build, kind: 'failed_builds_list'
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-07-17 09:02:56 +01:00
|
|
|
end
|
|
|
|
|
2013-06-05 14:48:11 +01:00
|
|
|
it "should not be able to perform new action" do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :new, platform_id: @platform
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-07-26 22:15:57 +01:00
|
|
|
end
|
|
|
|
|
2013-06-05 14:48:11 +01:00
|
|
|
[:cancel, :publish, :create].each do |action|
|
2013-03-21 15:17:30 +00:00
|
|
|
it "should not be able to perform #{action} action" do
|
2014-01-21 04:51:49 +00:00
|
|
|
post action, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2013-03-21 15:17:30 +00:00
|
|
|
end
|
2012-07-26 22:15:57 +01:00
|
|
|
end
|
|
|
|
|
2012-07-06 17:36:44 +01:00
|
|
|
it 'should not change objects count on create success' do
|
2015-04-02 23:13:26 +01:00
|
|
|
expect do
|
|
|
|
post :create, @create_params
|
|
|
|
end.to_not change(MassBuild, :count)
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not change stop_build on cancel' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :cancel, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(@mass_build.reload.stop_build).to be_falsy
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
2013-03-21 15:17:30 +00:00
|
|
|
|
|
|
|
it 'should not change build_publish_count on publish' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :publish, platform_id: @platform, id: @mass_build
|
2015-04-02 23:13:26 +01:00
|
|
|
expect(@mass_build.reload.build_publish_count).to eq 0
|
2013-03-21 15:17:30 +00:00
|
|
|
end
|
|
|
|
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for global admin' do
|
|
|
|
before(:each) do
|
|
|
|
@admin = FactoryGirl.create(:admin)
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'mass_build platform owner'
|
2013-06-05 14:48:11 +01:00
|
|
|
it_should_behave_like 'mass_build platform owner of personal platform'
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for owner user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2012-09-06 11:53:03 +01:00
|
|
|
@platform.owner = @user
|
|
|
|
@platform.save
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'mass_build platform owner'
|
2013-06-05 14:48:11 +01:00
|
|
|
it_should_behave_like 'mass_build platform owner of personal platform'
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@platform, @user, 'admin')
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'mass_build platform owner'
|
2013-06-05 14:48:11 +01:00
|
|
|
it_should_behave_like 'mass_build platform owner of personal platform'
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@platform, @user, 'reader')
|
2012-07-06 17:36:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'mass_build platform reader'
|
|
|
|
end
|
|
|
|
end
|