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
|
2014-03-18 09:31:01 +00:00
|
|
|
before(:each) { create_relation(@project, @group, group_role) }
|
2012-06-21 15:19:44 +01:00
|
|
|
|
|
|
|
%w(reader writer admin).each do |role|
|
|
|
|
context "for user with #{role} role in group" do
|
2014-03-18 09:31:01 +00:00
|
|
|
before(:each) { create_actor_relation(@group, @user, role) }
|
2012-06-21 15:19:44 +01:00
|
|
|
|
|
|
|
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-11-07 09:30:34 +00:00
|
|
|
|
2012-09-06 19:48:36 +01:00
|
|
|
@project.owner = @group
|
|
|
|
@project.save
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @project.owner, 'admin')
|
2012-06-20 19:10:27 +01:00
|
|
|
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
|
2014-03-18 09:31:01 +00:00
|
|
|
before(:each) { create_actor_relation(@group, @user, role) }
|
2012-06-21 15:19:44 +01:00
|
|
|
|
|
|
|
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
|
2014-03-18 09:31:01 +00:00
|
|
|
before(:each) { create_relation(@project, @user, role) }
|
2012-06-20 19:10:27 +01:00
|
|
|
|
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
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @user, 'reader')
|
|
|
|
create_relation(@project, @user, 'writer')
|
2012-06-21 15:19:44 +01:00
|
|
|
@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
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @user, 'admin')
|
|
|
|
create_relation(@project, @user, 'reader')
|
2012-06-21 15:19:44 +01:00
|
|
|
@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-11-07 10:20:24 +00:00
|
|
|
it {should_not allow_value("new_user\nHello World!").for(:uname)}
|
2012-06-20 19:10:27 +01:00
|
|
|
end
|