BigW Consortium Gitlab

Commit 68154e8f by Dmitriy Zaporozhets

spec fix

parent cb021e58
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment