2011-11-22 19:21:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require "cancan/matchers"
|
|
|
|
|
|
|
|
def admin_create
|
2013-04-09 11:15:39 +01:00
|
|
|
@admin = FactoryGirl.create(:admin)
|
2011-11-22 19:21:09 +00:00
|
|
|
@ability = Ability.new(@admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_create
|
2013-04-09 11:15:39 +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
|
2014-01-21 04:51:49 +00:00
|
|
|
let(:open_platform) { FactoryGirl.create(:platform, visibility: 'open') }
|
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
|
|
|
|
|
2013-04-09 11:15:39 +01:00
|
|
|
context 'Site admin' do
|
2014-01-21 04:51:49 +00:00
|
|
|
let(:personal_platform) { FactoryGirl.create(:platform, platform_type: 'personal') }
|
|
|
|
let(:personal_repository_main) { FactoryGirl.create(:personal_repository, name: 'main') }
|
2013-04-09 11:15:39 +01:00
|
|
|
let(:personal_repository) { FactoryGirl.create(:personal_repository) }
|
|
|
|
before(:each) do
|
|
|
|
admin_create
|
|
|
|
end
|
2012-12-18 17:53:00 +00:00
|
|
|
|
2013-04-09 11:15:39 +01:00
|
|
|
it 'should manage all' do
|
|
|
|
#(@ability.can? :manage, :all).should be_true
|
|
|
|
@ability.should be_able_to(:manage, :all)
|
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2013-04-09 11:15:39 +01:00
|
|
|
it 'should not be able to destroy personal platforms' do
|
|
|
|
@ability.should_not be_able_to(:destroy, personal_platform)
|
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2013-04-09 11:15:39 +01:00
|
|
|
it 'should not be able to destroy personal repositories with name "main"' do
|
|
|
|
@ability.should_not be_able_to(:destroy, personal_repository_main)
|
|
|
|
end
|
|
|
|
it 'should be able to destroy personal repositories with name not "main"' do
|
|
|
|
@ability.should be_able_to(:destroy, personal_repository)
|
|
|
|
end
|
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2013-04-09 11:15:39 +01:00
|
|
|
context 'Site guest' do
|
|
|
|
let(:register_request) { FactoryGirl.create(:register_request) }
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2013-04-09 11:15:39 +01:00
|
|
|
before(:each) do
|
|
|
|
guest_create
|
2011-12-28 02:57:42 +00:00
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
it 'should not be able to read open platform' do
|
2013-04-09 11:15:39 +01:00
|
|
|
@ability.should_not be_able_to(:read, open_platform)
|
2011-12-28 02:57:42 +00:00
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
2013-02-01 17:25:42 +00:00
|
|
|
[:publish, :cancel, :reject_publish, :create_container].each do |action|
|
|
|
|
it "should not be able to #{ action } build list" do
|
|
|
|
@ability.should_not be_able_to(action, BuildList)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-15 19:36:37 +00:00
|
|
|
[:mass_import, :run_mass_import].each do |action|
|
|
|
|
it "should not be able to #{ action } project" do
|
|
|
|
@ability.should_not be_able_to(action, Project)
|
|
|
|
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
|
|
|
|
|
2013-04-09 11:15:39 +01:00
|
|
|
pending 'should be able to register new user' do # while self registration is closed
|
|
|
|
@ability.should be_able_to(:create, User)
|
|
|
|
end
|
|
|
|
end
|
2011-11-22 19:21:09 +00:00
|
|
|
|
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|
|
2013-07-17 04:14:11 +01:00
|
|
|
it "should 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
|
2012-12-18 17:53:00 +00:00
|
|
|
|
2013-11-15 19:36:37 +00:00
|
|
|
[:mass_import, :run_mass_import].each do |action|
|
|
|
|
it "should not be able to #{ action } project" do
|
|
|
|
@ability.should_not be_able_to(action, Project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it "shoud be able to read open projects" do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project = FactoryGirl.create(:project, visibility: 'open')
|
2011-11-23 18:12:20 +00:00
|
|
|
@ability.should be_able_to(:read, @project)
|
|
|
|
end
|
|
|
|
|
2012-09-07 10:41:49 +01:00
|
|
|
it 'should be able to see open platform' do
|
|
|
|
@ability.should be_able_to(:show, open_platform)
|
|
|
|
end
|
|
|
|
|
2011-11-23 18:12:20 +00:00
|
|
|
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)
|
2012-12-18 17:53:00 +00:00
|
|
|
|
2012-09-06 11:53:03 +01:00
|
|
|
@private_user.platform.owner = @user
|
|
|
|
@private_user.platform.save
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
[:read, :create].each do |action|
|
|
|
|
it "should be able to #{ action } PrivateUser" do
|
2012-12-18 17:53:00 +00:00
|
|
|
@ability.should be_able_to(action, @private_user)
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as project collaborator' do
|
|
|
|
before(:each) do
|
2012-12-18 17:53:00 +00:00
|
|
|
@project = FactoryGirl.create(:project_with_commit)
|
2014-01-21 04:51:49 +00:00
|
|
|
@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
|
2014-01-21 04:51:49 +00: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 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
|
2014-01-21 04:51:49 +00: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
|
2014-01-21 04:51:49 +00:00
|
|
|
@build_list = FactoryGirl.create(:build_list_with_attaching_project, 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
|
2014-01-21 04:51:49 +00: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
|
2014-01-21 04:51:49 +00:00
|
|
|
@build_list = FactoryGirl.create(:build_list_with_attaching_project, 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
|
2014-01-21 04:51:49 +00:00
|
|
|
@project = FactoryGirl.create(:project_with_commit, owner: @user)
|
|
|
|
@issue = FactoryGirl.create(:issue, project_id: @project.id)
|
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
|
2014-01-21 04:51:49 +00:00
|
|
|
@build_list = FactoryGirl.create(:build_list_with_attaching_project, 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
|
|
|
|
|
2013-07-17 04:12:43 +01:00
|
|
|
context 'through group-member' do
|
|
|
|
before(:each) do
|
|
|
|
@group_member = FactoryGirl.create(:group)
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.relations.create!(actor_id: @group_member.id, actor_type: 'Group', role: 'reader')
|
2013-07-17 04:12:43 +01:00
|
|
|
@group_member_ability = Ability.new(@group_member.owner)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to read open project' do
|
|
|
|
@group_member_ability.should be_able_to(:read, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to read closed project' do
|
|
|
|
@project.update_attribute :visibility, 'hidden'
|
|
|
|
@group_member_ability.should be_able_to(:read, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should include hidden project in list' do
|
|
|
|
@project.update_attribute :visibility, 'hidden'
|
2014-01-21 04:51:49 +00:00
|
|
|
Project.accessible_by(@group_member_ability, :show).where(projects: {id: @project.id}).count.should == 1
|
2013-07-17 04:12:43 +01:00
|
|
|
end
|
|
|
|
end
|
2011-11-23 18:12:20 +00:00
|
|
|
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
|
2012-09-06 11:53:03 +01:00
|
|
|
@platform.owner = @user
|
|
|
|
@platform.save
|
2013-11-15 19:36:37 +00:00
|
|
|
@ability = Ability.new(@user)
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
2013-11-15 19:36:37 +00:00
|
|
|
[:mass_import, :run_mass_import].each do |action|
|
|
|
|
it "should be able to #{ action } project" do
|
|
|
|
@ability.should be_able_to(action, Project)
|
|
|
|
end
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
2013-06-26 10:53:37 +01:00
|
|
|
[:read, :update, :destroy, :change_visibility].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
|
2014-01-21 04:51:49 +00:00
|
|
|
@platform.relations.create!(actor_id: @user.id, actor_type: 'User', role: 'reader')
|
2013-11-15 19:36:37 +00:00
|
|
|
@ability = Ability.new(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
[:mass_import, :run_mass_import].each do |action|
|
|
|
|
it "should not be able to #{ action } project" do
|
|
|
|
@ability.should_not be_able_to(action, Project)
|
|
|
|
end
|
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-09-06 19:48:36 +01:00
|
|
|
@repository.platform.owner = @user
|
|
|
|
@repository.platform.save
|
2011-11-23 18:12:20 +00:00
|
|
|
end
|
|
|
|
|
2013-06-26 10:53:37 +01:00
|
|
|
[:read, :create, :update, :destroy, :add_project, :remove_project, :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
|
2014-01-21 04:51:49 +00: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
|
2012-09-27 13:13:59 +01:00
|
|
|
end # 'repository relations'
|
|
|
|
end # 'Site user'
|
2011-12-12 07:51:39 +00:00
|
|
|
end
|