2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-09 16:16:48 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-06-20 19:10:27 +01:00
|
|
|
describe User do
|
|
|
|
before { stub_symlink_methods }
|
|
|
|
before(:each) do
|
|
|
|
@project = FactoryGirl.create(:project)
|
|
|
|
@group = FactoryGirl.create(:group)
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for own project' do
|
|
|
|
it 'should have admin role' do
|
|
|
|
@project.owner.best_role(@project).should == 'admin'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'other user' do
|
|
|
|
it 'should have not right to project' do
|
|
|
|
other_user = FactoryGirl.create(:user)
|
|
|
|
other_user.best_role(@project).should == nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-21 15:19:44 +01:00
|
|
|
%w(reader writer admin).each do |group_role|
|
|
|
|
context "for group with #{group_role} role in project" do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create :actor_id => @group.id, :actor_type => @group.class.to_s, :role => group_role
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(reader writer admin).each do |role|
|
|
|
|
context "for user with #{role} role in group" do
|
|
|
|
before(:each) do
|
|
|
|
@group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => role)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have #{group_role} role to project" do
|
|
|
|
@user.best_role(@project).should == group_role
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-20 19:10:27 +01:00
|
|
|
context 'for group project' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.destroy_all
|
2012-08-15 14:52:32 +01:00
|
|
|
@project.owner = @group; @project.save
|
2012-06-20 19:10:27 +01:00
|
|
|
@project.relations.create :actor_id => @project.owner.id, :actor_type => @project.owner.class.to_s, :role => 'admin'
|
|
|
|
end
|
|
|
|
|
2012-06-21 15:19:44 +01:00
|
|
|
%w(reader writer admin).each do |role|
|
|
|
|
context "for user with #{role} role in group" do
|
|
|
|
before(:each) do
|
|
|
|
@group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => role)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have #{role} role to project" do
|
|
|
|
@user.best_role(@project).should == role
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(reader writer admin).each do |role|
|
|
|
|
context "for user with #{role} role in project" do
|
2012-06-20 19:10:27 +01:00
|
|
|
before(:each) do
|
2012-06-21 15:19:44 +01:00
|
|
|
@project.relations.create(:actor_id => @user.id, :actor_type => 'User', :role => role)
|
2012-06-20 19:10:27 +01:00
|
|
|
end
|
|
|
|
|
2012-06-21 15:19:44 +01:00
|
|
|
it "should have #{role} role to project" do
|
|
|
|
@user.best_role(@project).should == role
|
2012-06-20 19:10:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-21 15:19:44 +01:00
|
|
|
|
|
|
|
context "for user with reader role in group and writer role in project" do
|
|
|
|
it "should have writer best role to project" do
|
|
|
|
@group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => 'reader')
|
|
|
|
@project.relations.create(:actor_id => @user.id, :actor_type => 'User', :role => 'writer')
|
|
|
|
@user.best_role(@project).should == 'writer'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for user with admin role in group and reader role in project" do
|
|
|
|
it "should have admin best role to project" do
|
|
|
|
@group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
|
|
|
|
@project.relations.create(:actor_id => @user.id, :actor_type => 'User', :role => 'reader')
|
|
|
|
@user.best_role(@project).should == 'admin'
|
|
|
|
end
|
|
|
|
end
|
2012-06-20 19:10:27 +01:00
|
|
|
end
|
2012-06-21 15:19:44 +01:00
|
|
|
|
2012-06-20 19:10:27 +01:00
|
|
|
end
|