Skip to content

Commit

Permalink
Merge pull request #26 from PRX/feat/stringify_hash_access
Browse files Browse the repository at this point in the history
Automatically stringify index access on ResourceMap and define ScopeList#==
  • Loading branch information
cavis committed Aug 28, 2020
2 parents 63c306c + 86f8d1f commit 035c87f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/prx_auth/resource_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def contains?(resource, namespace=nil, scope=nil)
end
end

def [](key)
super(key.to_s)
end

def []=(key, value)
super(key.to_s, value)
end

def condense
condensed_wildcard = @wildcard.condense
condensed_map = Hash[map do |resource, list|
Expand Down
4 changes: 4 additions & 0 deletions lib/prx_auth/scope_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def &(other_list)
self - (self - other_list)
end

def ==(other)
condense.sort_by(&:to_s) == other.condense.sort_by(&:to_s)
end

private

def symbolize(value)
Expand Down
2 changes: 1 addition & 1 deletion lib/prx_auth/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PrxAuth
VERSION = "1.2.1"
VERSION = "1.3.0"
end
13 changes: 13 additions & 0 deletions test/prx_auth/resource_map_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,17 @@ def new_map(val)
assert map.as_json.has_key?('*')
end
end

describe '#[]' do
it 'automatically stringifies' do
refute_nil map[123]
end
end

describe '#[]=' do
it 'automatically stringifies' do
map[789] = PrxAuth::ScopeList.new("")
refute_nil map["789"]
end
end
end
11 changes: 11 additions & 0 deletions test/prx_auth/scope_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,15 @@ def new_list(val)
assert !sl.contains?(:one)
end
end

describe '==' do

it 'is equal when they are functionally equal' do
assert_equal PrxAuth::ScopeList.new("foo ns:foo bar ns2:baz"), PrxAuth::ScopeList.new("ns2:baz bar foo")
end

it 'is not equal when they are not functionally equal' do
refute_equal PrxAuth::ScopeList.new("foo bar"), PrxAuth::ScopeList.new("foo:bar bar:foo")
end
end
end

0 comments on commit 035c87f

Please sign in to comment.