2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-11-22 19:21:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require "cancan/matchers"
|
|
|
|
|
|
|
|
def admin_create
|
2012-03-29 21:34:22 +01:00
|
|
|
@admin = FactoryGirl.create(:admin)
|
2011-11-22 19:21:09 +00:00
|
|
|
@ability = Ability.new(@admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_create
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2011-11-22 19:21:09 +00:00
|
|
|
@ability = Ability.new(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def guest_create
|
|
|
|
@ability = Ability.new(User.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe CanCan do
|
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
let(:personal_platform) { FactoryGirl.create(:platform, :platform_type => 'personal') }
|
|
|
|
let(:personal_repository) { FactoryGirl.create(:personal_repository) }
|
|
|
|
let(:open_platform) { FactoryGirl.create(:platform, :visibility => 'open') }
|
|
|
|
let(:hidden_platform) { FactoryGirl.create(:platform, :visibility => 'hidden') }
|
|
|
|
let(:register_request) { FactoryGirl.create(:register_request) }
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2011-12-12 07:51:39 +00:00
|
|
|
before(:each) do
|
2012-05-16 16:29:28 +01:00
|
|
|
stub_symlink_methods
|
2011-12-12 07:51:39 +00:00
|
|
|
end
|
|
|
|
|
2011-11-22 19:21:09 +00:00
|
|
|
context 'Site admin' do
|
|
|
|
before(:each) do
|
|
|
|
admin_create
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should manage all' do
|
|
|
|
#(@ability.can? :manage, :all).should be_true
|
|
|
|
@ability.should be_able_to(:manage, :all)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to destroy personal platforms' do
|
|
|
|
@ability.should_not be_able_to(:destroy, personal_platform)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to destroy personal repositories' do
|
|
|
|
@ability.should_not be_able_to(:destroy, personal_repository)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Site guest' do
|
|
|
|
before(:each) do
|
|
|
|
guest_create
|
|
|
|
end
|
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
it 'should not be able to read open platform' do
|
|
|
|
@ability.should_not be_able_to(:read, open_platform)
|
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
it 'should not be able to read hidden platform' do
|
|
|
|
@ability.should_not be_able_to(:read, hidden_platform)
|
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
[:publish_build, :status_build, :pre_build, :post_build, :circle_build, :new_bbdt].each do |action|
|
2011-11-22 19:21:09 +00:00
|
|
|
it "should be able to #{ action } build list" do
|
|
|
|
@ability.should be_able_to(action, BuildList)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-09 17:46:23 +00:00
|
|
|
it 'should not be able to update register request' do
|
|
|
|
@ability.should_not be_able_to(:update, register_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to list register requests' do
|
|
|
|
@ability.should_not be_able_to(:read, register_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to destroy register requests' do
|
|
|
|
@ability.should_not be_able_to(:destroy, register_request)
|
|
|
|
end
|
|
|
|
|
2012-04-04 22:43:06 +01:00
|
|
|
pending 'should be able to register new user' do # while self registration is closed
|
2011-11-22 19:21:09 +00:00
|
|
|
@ability.should be_able_to(:create, User)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-23 18:12:20 +00:00
|
|
|
context 'Site user' do
|
|
|
|
before(:each) do
|
|
|
|
user_create
|
|
|
|
end
|
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
[Platform, Repository].each do |model_name|
|
|
|
|
it "should not be able to read #{model_name}" do
|
2011-11-23 18:12:20 +00:00
|
|
|
@ability.should be_able_to(:read, model_name)
|
|
|
|
end
|
|
|
|
end
|
2011-12-28 02:57:42 +00:00
|
|
|
|
2012-05-05 20:26:34 +01:00
|
|
|
it "shoud be able to show user profile" do
|
|
|
|
@ability.should be_able_to(:show, User)
|
|
|
|
end
|
2011-11-23 18:12:20 +00:00
|
|
|
|
|
|
|
it "shoud be able to read another user object" do
|
|
|
|
admin_create
|
|
|
|
@ability.should be_able_to(:read, @admin)
|
|
|
|
end
|
|
|
|
|
2012-01-24 20:35:16 +00:00
|
|
|
pending "shoud be able to read index AutoBuildList" do
|
2011-11-23 18:12:20 +00:00
|
|
|
@ability.should be_able_to(:index, AutoBuildList)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shoud be able to read open projects" do
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project, :visibility => 'open')
|
2011-11-23 18:12:20 +00:00
|
|
|
@ability.should be_able_to(:read, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shoud be able to create project" do
|
|
|
|
@ability.should be_able_to(:create, Project)
|
|
|
|
end
|
|
|
|
|
2012-02-09 17:46:23 +00:00
|
|
|
it "should not be able to manage register requests" do
|
|
|
|
@ability.should_not be_able_to(:manage, RegisterRequest)
|
|
|
|
end
|
|
|
|
|
2011-11-23 18:12:20 +00:00
|
|
|
context "private users relations" do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@private_user = FactoryGirl.create(:private_user)
|
2011-11-23 18:12:20 +00:00
|
|
|
@private_user.platform.update_attribute(:owner, @user)
|
|
|
|
end
|
|
|
|
|
|
|
|
[:read, :create].each do |action|
|
|
|
|
it "should be able to #{ action } PrivateUser" do
|
|
|
|
@ability.should be_able_to(action, @private_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as project collaborator' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
|
|
|
@issue = FactoryGirl.create(:issue, :project_id => @project.id)
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with read rights' do
|
|
|
|
before(:each) do
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader')
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to read project' do
|
|
|
|
@ability.should be_able_to(:read, @project)
|
|
|
|
end
|
2011-12-23 10:56:46 +00:00
|
|
|
|
|
|
|
it 'should be able to read open platform' do
|
2011-11-23 18:12:20 +00:00
|
|
|
@ability.should be_able_to(:read, open_platform)
|
|
|
|
end
|
2011-12-23 10:56:46 +00:00
|
|
|
|
|
|
|
it 'should be able to read issue' do
|
|
|
|
@ability.should be_able_to(:read, @issue)
|
|
|
|
end
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
2011-12-23 10:56:46 +00:00
|
|
|
|
|
|
|
context 'with writer rights' do
|
2011-11-23 18:12:20 +00:00
|
|
|
before(:each) do
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'writer')
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
2011-12-26 12:51:30 +00:00
|
|
|
[:read, :create, :new].each do |action|
|
2011-11-23 18:12:20 +00:00
|
|
|
it "should be able to #{ action } project" do
|
|
|
|
@ability.should be_able_to(action, @project)
|
|
|
|
end
|
|
|
|
end
|
2011-12-23 02:14:28 +00:00
|
|
|
|
|
|
|
[:new, :create].each do |action|
|
|
|
|
it "should be able to #{action} build_list" do
|
2012-03-29 21:34:22 +01:00
|
|
|
@build_list = FactoryGirl.create(:build_list, :project => @project)
|
2011-12-23 02:14:28 +00:00
|
|
|
@ability.should be_able_to(action, @build_list)
|
|
|
|
end
|
|
|
|
end
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with admin rights' do
|
|
|
|
before(:each) do
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
2011-12-23 02:14:28 +00:00
|
|
|
[:read, :update].each do |action|
|
2011-11-23 18:12:20 +00:00
|
|
|
it "should be able to #{ action } project" do
|
|
|
|
@ability.should be_able_to(action, @project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-23 02:14:28 +00:00
|
|
|
[:new, :create].each do |action|
|
|
|
|
it "should be able to #{action} build_list" do
|
2012-03-29 21:34:22 +01:00
|
|
|
@build_list = FactoryGirl.create(:build_list, :project => @project)
|
2011-12-23 02:14:28 +00:00
|
|
|
@ability.should be_able_to(action, @build_list)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-23 18:12:20 +00:00
|
|
|
it "should be able to manage collaborators of project" do
|
|
|
|
@ability.should be_able_to(:manage_collaborators, @project)
|
|
|
|
end
|
2011-12-23 10:56:46 +00:00
|
|
|
|
|
|
|
[:read, :create, :new, :update, :edit].each do |action|
|
|
|
|
it "should be able to #{ action } issue" do
|
|
|
|
@ability.should be_able_to(action, @issue)
|
|
|
|
end
|
|
|
|
end
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with owner rights' do
|
|
|
|
before(:each) do
|
|
|
|
@project.update_attribute(:owner, @user)
|
2012-06-21 11:35:02 +01:00
|
|
|
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
|
2011-12-23 10:56:46 +00:00
|
|
|
@issue.project.reload
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
2011-12-23 02:14:28 +00:00
|
|
|
[:read, :update, :destroy].each do |action|
|
2011-11-23 18:12:20 +00:00
|
|
|
it "should be able to #{ action } project" do
|
|
|
|
@ability.should be_able_to(action, @project)
|
|
|
|
end
|
|
|
|
end
|
2011-12-23 02:14:28 +00:00
|
|
|
|
|
|
|
[:new, :create].each do |action|
|
|
|
|
it "should be able to #{action} build_list" do
|
2012-03-29 21:34:22 +01:00
|
|
|
@build_list = FactoryGirl.create(:build_list, :project => @project)
|
2011-12-23 02:14:28 +00:00
|
|
|
@ability.should be_able_to(action, @build_list)
|
|
|
|
end
|
|
|
|
end
|
2011-12-26 12:51:30 +00:00
|
|
|
|
2011-12-23 10:56:46 +00:00
|
|
|
[:read, :update, :edit].each do |action|
|
|
|
|
it "should be able to #{ action } issue" do
|
|
|
|
@ability.should be_able_to(action, @issue)
|
|
|
|
end
|
|
|
|
end
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'platform relations' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@platform = FactoryGirl.create(:platform)
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with owner rights' do
|
|
|
|
before(:each) do
|
|
|
|
@platform.update_attribute(:owner, @user)
|
|
|
|
end
|
|
|
|
|
2012-03-23 11:29:25 +00:00
|
|
|
[:read, :update, :destroy].each do |action|
|
2011-12-28 02:57:42 +00:00
|
|
|
it "should be able to #{action} platform" do
|
|
|
|
@ability.should be_able_to(action, @platform)
|
|
|
|
end
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with read rights' do
|
|
|
|
before(:each) do
|
2012-04-26 02:38:33 +01:00
|
|
|
@platform.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader')
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to read platform" do
|
|
|
|
@ability.should be_able_to(:read, @platform)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'repository relations' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@repository = FactoryGirl.create(:repository)
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with owner rights' do
|
|
|
|
before(:each) do
|
2012-02-20 23:13:05 +00:00
|
|
|
@repository.platform.update_attribute(:owner, @user)
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
2012-02-20 23:13:05 +00:00
|
|
|
[:read, :create, :update, :destroy, :add_project, :remove_project, :change_visibility, :settings].each do |action|
|
2011-12-28 02:57:42 +00:00
|
|
|
it "should be able to #{action} repository" do
|
2011-11-23 18:12:20 +00:00
|
|
|
@ability.should be_able_to(action, @repository)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with read rights' do
|
|
|
|
before(:each) do
|
2012-04-26 02:38:33 +01:00
|
|
|
@repository.platform.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader')
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to read repository" do
|
|
|
|
@ability.should be_able_to(:read, @repository)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'build list relations' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'writer')
|
2012-03-29 21:34:22 +01:00
|
|
|
@build_list = FactoryGirl.create(:build_list, :project => @project)
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to publish build list with SUCCESS status' do
|
|
|
|
@build_list.status = BuildServer::SUCCESS
|
|
|
|
@ability.should be_able_to(:publish, @build_list)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to publish build list with another status' do
|
|
|
|
@build_list.status = BuildServer::BUILD_ERROR
|
|
|
|
@ability.should_not be_able_to(:publish, @build_list)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
|
|
|
|
2011-12-12 07:51:39 +00:00
|
|
|
end
|