Skip to content

Commit

Permalink
Set the correct access permissions order
Browse files Browse the repository at this point in the history
  • Loading branch information
colby-swandale committed Nov 13, 2024
1 parent 067683f commit 555736f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/access.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Access
NONE = 0
MAINTAINER = 50
ADMIN = 90
OWNER = 100
ADMIN = 60
OWNER = 70

DEFAULT_ROLE = "owner".freeze

Expand All @@ -16,7 +17,7 @@ def self.flag_for_role(role)
end

def self.with_minimum_role(role)
Range.new(flag_for_role(role), nil)
Range.new(flag_for_role(role), NONE)
end

def self.role_for_flag(flag)
Expand Down
14 changes: 10 additions & 4 deletions test/lib/access_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require "test_helper"

class AccessTest < ActiveSupport::TestCase
context "roles are correctly sequenced" do
should "be in the correct order" do
assert_operator Access::OWNER, :>, Access::ADMIN
assert_operator Access::ADMIN, :>, Access::MAINTAINER
end
end

context ".role_for_flag" do
should "return the role for a given permission flag" do
assert_equal "owner", Access.role_for_flag(Access::OWNER)
Expand Down Expand Up @@ -31,10 +38,9 @@ class AccessTest < ActiveSupport::TestCase

context ".with_minimum_role" do
should "return the range of roles for a given permission flag" do
assert_equal Range.new(Access::OWNER, nil), Access.with_minimum_role("owner")
refute_includes Access.with_minimum_role("owner"), Access::MAINTAINER
assert_includes Access.with_minimum_role("owner"), Access::OWNER
assert_includes Access.with_minimum_role("owner"), Access::ADMIN
assert_equal (Access::OWNER..Access::NONE), Access.with_minimum_role("owner")
assert_equal (Access::ADMIN..Access::NONE), Access.with_minimum_role("admin")
assert_equal (Access::MAINTAINER..Access::NONE), Access.with_minimum_role("maintainer")
end
end
end

0 comments on commit 555736f

Please sign in to comment.