spec/guard_export_spec.rb in ixtlan-guard-0.8.3 vs spec/guard_export_spec.rb in ixtlan-guard-0.9.0
- old
+ new
@@ -5,20 +5,25 @@
describe Ixtlan::Guard::Guard do
def assert(expected, perms)
map = {}
expected.each do |e|
- map[e[:permission][:resource]] = e
- if e[:permission][:actions]
- e[:permission][:actions].sort!{ |n,m| n[:action][:name] <=> m[:action][:name] }
+ map[(e[:permission] || e)[:resource]] = e
+ if (e[:permission] || e)[:actions]
+ (e[:permission] || e)[:actions].sort!{ |n,m| n[:action][:name] <=> m[:action][:name] }
end
end
perms.each do |perm|
- if perm[:actions]
- perm[:actions].sort!{ |n,m| n.content[:name] <=> m.content[:name] }
+ attr = perm.attributes
+ attr[ :actions ] = perm.actions.collect do |a|
+ aa = a.attributes
+ aa.delete( :associations ) if aa[ :associations ].nil? || aa[ :associations ].empty?
+ {:action => aa}
end
- map[perm[:resource].to_s].should == perm
+ attr[:actions].sort!{ |n,m| n[:action][:name] <=> m[:action][:name] }
+ attr.delete( :associations ) if attr[ :associations ].nil? || attr[ :associations ].empty?
+ map[perm[:resource]][:permission].should == attr
end
end
subject do
logger = Logger.new(STDOUT)
@@ -182,11 +187,11 @@
def group.name
"region"
end
perm = subject.permissions([group])do |resource, groups|
if resource == 'regions'
- [:europe, :asia]
+ ["europe", "asia"]
end
end
expected = [
#allow nothing
{:permission=>{:resource=>"accounts", :actions=>[], :deny=>false}},
@@ -217,11 +222,11 @@
{:permission=>{:resource=>"person", :actions=>[], :deny=>false}},
{:permission=>
{:resource=>"regions",
:actions=>
- [{:action=>{:name=>"show", :associations=>[:europe, :asia]}},
- {:action=>{:name=>"create", :associations=>[:europe, :asia]}}],
+ [{:action=>{:name=>"show", :associations=>["europe", "asia"]}},
+ {:action=>{:name=>"create", :associations=>["europe", "asia"]}}],
:deny=>false}},
#allow nothing
{:permission=>{:resource=>"users", :actions=>[], :deny=>false}}]
assert(expected, perm)