2011-10-08 17:36:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 04:50:51 -05:00
|
|
|
describe Project, models: true do
|
2016-07-11 18:12:31 -04:00
|
|
|
describe 'authorization' do
|
2011-10-26 09:46:25 -04:00
|
|
|
before do
|
2012-11-05 22:31:55 -05:00
|
|
|
@p1 = create(:project)
|
2012-12-05 10:06:15 -05:00
|
|
|
|
2012-11-05 22:31:55 -05:00
|
|
|
@u1 = create(:user)
|
|
|
|
@u2 = create(:user)
|
2012-12-05 10:06:15 -05:00
|
|
|
@u3 = create(:user)
|
2013-01-02 12:00:00 -05:00
|
|
|
@u4 = @p1.owner
|
2012-12-05 10:06:15 -05:00
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
@abilities = Six.new
|
|
|
|
@abilities << Ability
|
|
|
|
end
|
|
|
|
|
2012-12-05 10:06:15 -05: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 }
|
2016-03-20 17:55:08 -04:00
|
|
|
let(:owner_actions) { Ability.project_owner_rules }
|
2012-12-05 10:06:15 -05:00
|
|
|
|
|
|
|
describe "Non member rules" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "denies for non-project users any actions" do
|
2016-03-20 17:55:08 -04:00
|
|
|
owner_actions.each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u1, action, @p1)).to be_falsey
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Guest Rules" do
|
|
|
|
before do
|
2014-09-15 04:36:50 -04:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::GUEST)
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "allows for project user any guest actions" do
|
2012-12-05 10:06:15 -05:00
|
|
|
guest_actions.each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Report Rules" do
|
2011-10-26 09:46:25 -04:00
|
|
|
before do
|
2014-09-15 04:36:50 -04:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER)
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "allows for project user any report actions" do
|
2012-12-05 10:06:15 -05:00
|
|
|
report_actions.each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2012-12-05 10:06:15 -05:00
|
|
|
describe "Developer Rules" do
|
|
|
|
before do
|
2014-09-15 04:36:50 -04:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER)
|
|
|
|
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::DEVELOPER)
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "denies for developer master-specific actions" do
|
2012-12-05 10:06:15 -05:00
|
|
|
[dev_actions - report_actions].each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "allows for project user any dev actions" do
|
2012-12-05 10:06:15 -05:00
|
|
|
dev_actions.each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Master Rules" do
|
2011-10-26 09:46:25 -04:00
|
|
|
before do
|
2014-09-15 04:36:50 -04:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::DEVELOPER)
|
|
|
|
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER)
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "denies for developer master-specific actions" do
|
2012-12-05 10:06:15 -05:00
|
|
|
[master_actions - dev_actions].each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "allows for project user any master actions" do
|
2012-12-05 10:06:15 -05:00
|
|
|
master_actions.each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2016-03-20 17:55:08 -04:00
|
|
|
describe "Owner Rules" do
|
2011-10-26 09:46:25 -04:00
|
|
|
before do
|
2014-09-15 04:36:50 -04:00
|
|
|
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::DEVELOPER)
|
|
|
|
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER)
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "denies for masters admin-specific actions" do
|
2016-03-20 17:55:08 -04:00
|
|
|
[owner_actions - master_actions].each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "allows for project owner any admin actions" do
|
2016-03-20 17:55:08 -04:00
|
|
|
owner_actions.each do |action|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@abilities.allowed?(@u4, action, @p1)).to be_truthy
|
2012-12-05 10:06:15 -05:00
|
|
|
end
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|