spec fix
This commit is contained in:
parent
cb021e5831
commit
68154e8fe9
3 changed files with 22 additions and 13 deletions
|
@ -114,9 +114,18 @@ class Project < ActiveRecord::Base
|
|||
!!commit
|
||||
end
|
||||
|
||||
# Compatible with all access rights
|
||||
# Should be rewrited for new access rights
|
||||
def add_access(user, *access)
|
||||
access = if access.include?(:admin)
|
||||
{ :project_access => PROJECT_RWA }
|
||||
elsif access.include?(:write)
|
||||
{ :project_access => PROJECT_RW }
|
||||
else
|
||||
{ :project_access => PROJECT_R }
|
||||
end
|
||||
opts = { :user => user }
|
||||
access.each { |name| opts.merge!(name => true) }
|
||||
opts.merge!(access)
|
||||
users_projects.create(opts)
|
||||
end
|
||||
|
||||
|
|
|
@ -10,30 +10,30 @@ describe Project do
|
|||
@abilities << Ability
|
||||
end
|
||||
|
||||
describe :read do
|
||||
describe "read access" do
|
||||
before do
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :read => false)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :read => true)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :project_access => Project::PROJECT_N)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :project_access => Project::PROJECT_R)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :read_project, @p1).should be_false }
|
||||
it { @abilities.allowed?(@u2, :read_project, @p1).should be_true }
|
||||
end
|
||||
|
||||
describe :write do
|
||||
describe "write access" do
|
||||
before do
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :write => false)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :write => true)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :project_access => Project::PROJECT_R)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :project_access => Project::PROJECT_RW)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :write_project, @p1).should be_false }
|
||||
it { @abilities.allowed?(@u2, :write_project, @p1).should be_true }
|
||||
end
|
||||
|
||||
describe :admin do
|
||||
describe "admin access" do
|
||||
before do
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :admin => false)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :admin => true)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :project_access => Project::PROJECT_RW)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :project_access => Project::PROJECT_RWA)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :admin_project, @p1).should be_false }
|
||||
|
|
|
@ -20,11 +20,11 @@ describe "Projects" do
|
|||
@u2 = Factory :user
|
||||
@u3 = Factory :user
|
||||
# full access
|
||||
@project.users_projects.create(:user => @u1, :read => true, :write => true, :admin => true)
|
||||
@project.users_projects.create(:user => @u1, :project_access => Project::PROJECT_RWA)
|
||||
# no access
|
||||
@project.users_projects.create(:user => @u2, :read => false, :write => false, :admin => false)
|
||||
@project.users_projects.create(:user => @u2, :project_access => Project::PROJECT_N)
|
||||
# readonly
|
||||
@project.users_projects.create(:user => @u3, :read => true, :write => false, :admin => false)
|
||||
@project.users_projects.create(:user => @u3, :project_access => Project::PROJECT_R)
|
||||
end
|
||||
|
||||
describe "GET /project_code" do
|
||||
|
|
Loading…
Reference in a new issue