2011-10-13 16:55:03 +01:00
|
|
|
require 'spec_helper'
|
2012-03-20 15:40:49 +00:00
|
|
|
require "cancan/matchers"
|
2011-10-13 16:55:03 +01:00
|
|
|
|
|
|
|
describe Group do
|
2012-03-20 15:40:49 +00:00
|
|
|
before(:each) do
|
2012-05-16 16:29:28 +01:00
|
|
|
stub_symlink_methods
|
2012-03-29 21:34:22 +01:00
|
|
|
@group = FactoryGirl.create(:group)
|
2012-03-20 15:40:49 +00:00
|
|
|
@ability = Ability.new(User.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for guest' do
|
2012-10-02 17:54:55 +01:00
|
|
|
[:read, :update, :destroy, :manage_members].each do |action|
|
2012-03-20 15:40:49 +00:00
|
|
|
it "should not be able to #{action} group" do
|
|
|
|
@ability.should_not be_able_to(action, @group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for global admin' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@admin = FactoryGirl.create(:admin)
|
2012-03-20 15:40:49 +00:00
|
|
|
@ability = Ability.new(@admin)
|
|
|
|
end
|
|
|
|
|
2012-10-02 17:54:55 +01:00
|
|
|
[:read, :update, :destroy, :manage_members].each do |action|
|
2012-03-20 15:40:49 +00:00
|
|
|
it "should be able to #{action} group" do
|
|
|
|
@ability.should be_able_to(action, @group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for group admin' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@another_user = FactoryGirl.create(:user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @user, 'admin')
|
2012-03-20 15:40:49 +00:00
|
|
|
@ability = Ability.new(@user)
|
|
|
|
end
|
|
|
|
|
2012-10-02 17:54:55 +01:00
|
|
|
[:read, :update, :manage_members].each do |action|
|
2012-03-20 15:40:49 +00:00
|
|
|
it "should be able to #{action} group" do
|
|
|
|
@ability.should be_able_to(action, @group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be able to destroy group" do
|
|
|
|
@ability.should_not be_able_to(:destroy, @group)
|
|
|
|
end
|
2012-03-21 13:52:35 +00:00
|
|
|
|
|
|
|
context 'with mass assignment' do
|
|
|
|
it 'should not be able to update uname' do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.should_not allow_mass_assignment_of uname: 'new_uname'
|
2012-03-21 13:52:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to update owner' do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.should_not allow_mass_assignment_of owner_type: 'User', owner_id: @another_user.id
|
2012-03-21 13:52:35 +00:00
|
|
|
end
|
|
|
|
end
|
2012-03-20 15:40:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for group owner' do
|
|
|
|
before(:each) do
|
2012-11-07 10:20:24 +00:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
|
2012-09-06 11:53:03 +01:00
|
|
|
@group.owner = @user
|
|
|
|
@group.save
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @user, 'admin')
|
2012-03-20 15:40:49 +00:00
|
|
|
@ability = Ability.new(@user)
|
|
|
|
end
|
|
|
|
|
2012-10-02 17:54:55 +01:00
|
|
|
[:read, :update, :destroy, :manage_members].each do |action|
|
2012-03-20 15:40:49 +00:00
|
|
|
it "should be able to #{action} group" do
|
|
|
|
@ability.should be_able_to(action, @group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for group reader and writer user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @user, 'reader')
|
2012-03-20 15:40:49 +00:00
|
|
|
@ability = Ability.new(@user)
|
|
|
|
end
|
|
|
|
|
2012-10-02 17:54:55 +01:00
|
|
|
[:read].each do |action|
|
2012-03-20 15:40:49 +00:00
|
|
|
it "should be able to #{action} group" do
|
|
|
|
@ability.should be_able_to(action, @group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[:update, :destroy, :manage_members].each do |action|
|
|
|
|
it "should not be able to #{action} group" do
|
|
|
|
@ability.should_not be_able_to(action, @group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
|
|
|
it {should_not allow_value("How do you do...\nmy_group").for(:uname)}
|
2011-10-13 16:55:03 +01:00
|
|
|
end
|