2011-10-08 21:36:38 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Project do
|
2011-10-26 13:46:25 +00:00
|
|
|
describe :authorization do
|
|
|
|
before do
|
2012-11-06 03:31:55 +00:00
|
|
|
@p1 = create(:project)
|
2012-12-05 15:06:15 +00:00
|
|
|
|
2012-11-06 03:31:55 +00:00
|
|
|
@u1 = create(:user)
|
|
|
|
@u2 = create(:user)
|
2012-12-05 15:06:15 +00:00
|
|
|
@u3 = create(:user)
|
2013-01-02 17:00:00 +00:00
|
|
|
@u4 = @p1.owner
|
2012-12-05 15:06:15 +00:00
|
|
|
|
2011-10-08 21:36:38 +00:00
|
|
|
@abilities = Six.new
|
|
|
|
@abilities << Ability
|
|
|
|
end
|
|
|
|
|
2012-12-05 15:06:15 +00:00
|
|
|
let(:guest_actions) { Ability.project_guest_rules }
|
|
|
|
let(:report_actions) { Ability.project_report_rules }
|
|
|
|
let(:dev_actions) { Ability.project_dev_rules }
|
|
|
|
let(:master_actions) { Ability.project_master_rules }
|
|
|
|
let(:admin_actions) { Ability.project_admin_rules }
|
|
|
|
|
|
|
|
describe "Non member rules" do
|
|
|
|
it "should deny for non-project users any actions" do
|
|
|
|
admin_actions.each do |action|
|
|
|
|
@abilities.allowed?(@u1, action, @p1).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Guest Rules" do
|
|
|
|
before do
|
2014-09-14 16:32:51 +00:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, project_access: ProjectMember::GUEST)
|
2012-12-05 15:06:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow for project user any guest actions" do
|
|
|
|
guest_actions.each do |action|
|
|
|
|
@abilities.allowed?(@u2, action, @p1).should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Report Rules" do
|
2011-10-26 13:46:25 +00:00
|
|
|
before do
|
2014-09-14 16:32:51 +00:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, project_access: ProjectMember::REPORTER)
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
|
2012-12-05 15:06:15 +00:00
|
|
|
it "should allow for project user any report actions" do
|
|
|
|
report_actions.each do |action|
|
|
|
|
@abilities.allowed?(@u2, action, @p1).should be_true
|
|
|
|
end
|
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
|
2012-12-05 15:06:15 +00:00
|
|
|
describe "Developer Rules" do
|
|
|
|
before do
|
2014-09-14 16:32:51 +00:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, project_access: ProjectMember::REPORTER)
|
|
|
|
@p1.project_members.create(project: @p1, user: @u3, project_access: ProjectMember::DEVELOPER)
|
2012-12-05 15:06:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should deny for developer master-specific actions" do
|
|
|
|
[dev_actions - report_actions].each do |action|
|
|
|
|
@abilities.allowed?(@u2, action, @p1).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow for project user any dev actions" do
|
|
|
|
dev_actions.each do |action|
|
|
|
|
@abilities.allowed?(@u3, action, @p1).should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Master Rules" do
|
2011-10-26 13:46:25 +00:00
|
|
|
before do
|
2014-09-14 16:32:51 +00:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, project_access: ProjectMember::DEVELOPER)
|
|
|
|
@p1.project_members.create(project: @p1, user: @u3, project_access: ProjectMember::MASTER)
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
|
2012-12-05 15:06:15 +00:00
|
|
|
it "should deny for developer master-specific actions" do
|
|
|
|
[master_actions - dev_actions].each do |action|
|
|
|
|
@abilities.allowed?(@u2, action, @p1).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow for project user any master actions" do
|
|
|
|
master_actions.each do |action|
|
|
|
|
@abilities.allowed?(@u3, action, @p1).should be_true
|
|
|
|
end
|
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
|
2012-12-05 15:06:15 +00:00
|
|
|
describe "Admin Rules" do
|
2011-10-26 13:46:25 +00:00
|
|
|
before do
|
2014-09-14 16:32:51 +00:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, project_access: ProjectMember::DEVELOPER)
|
|
|
|
@p1.project_members.create(project: @p1, user: @u3, project_access: ProjectMember::MASTER)
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
|
2012-12-05 15:06:15 +00:00
|
|
|
it "should deny for masters admin-specific actions" do
|
|
|
|
[admin_actions - master_actions].each do |action|
|
|
|
|
@abilities.allowed?(@u2, action, @p1).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow for project owner any admin actions" do
|
|
|
|
admin_actions.each do |action|
|
|
|
|
@abilities.allowed?(@u4, action, @p1).should be_true
|
|
|
|
end
|
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: projects
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# name :string(255)
|
|
|
|
# path :string(255)
|
|
|
|
# description :text
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# private_flag :boolean default(TRUE), not null
|
|
|
|
# code :string(255)
|
|
|
|
#
|
|
|
|
|