Skip to content

Commit

Permalink
Fixed tests: deep cloning of engine
Browse files Browse the repository at this point in the history
  • Loading branch information
stffn committed Oct 31, 2011
1 parent fb37826 commit 2b26106
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/declarative_authorization/authorization.rb
Expand Up @@ -82,7 +82,7 @@ def initialize (reader = nil)
end

def initialize_copy (from) # :nodoc:
[ :reader ].each {|attr| instance_variable_set(:"@#{attr}", from.send(attr).clone) }
@reader = from.reader.clone
end

# {[priv, ctx] => [priv, ...]}
Expand Down Expand Up @@ -349,9 +349,12 @@ def initialize (rules = [])
@rules = rules.clone
reset!
end
def initialize_copy source
initialize @rules.collect {|rule| rule.clone}

def initialize_copy (source)
@rules = @rules.collect {|rule| rule.clone}
reset!
end

def matching(roles, privileges, context)
roles = [roles] unless roles.is_a?(Array)
rules = cached_auth_rules[context] || []
Expand Down
17 changes: 17 additions & 0 deletions lib/declarative_authorization/reader.rb
Expand Up @@ -59,6 +59,11 @@ def initialize ()
@auth_rules_reader = AuthorizationRulesReader.new
end

def initialize_copy (from) # :nodoc:
@privileges_reader = from.privileges_reader.clone
@auth_rules_reader = from.auth_rules_reader.clone
end

# ensures you get back a DSLReader
# if you provide a:
# DSLReader - you will get it back.
Expand Down Expand Up @@ -141,6 +146,11 @@ def initialize # :nodoc:
@privilege_hierarchy = {}
end

def initialize_copy (from) # :nodoc:
@privileges = from.privileges.clone
@privilege_hierarchy = from.privilege_hierarchy.clone
end

def append_privilege (priv) # :nodoc:
@privileges << priv unless @privileges.include?(priv)
end
Expand Down Expand Up @@ -193,6 +203,13 @@ def initialize # :nodoc:
@auth_rules = AuthorizationRuleSet.new
end

def initialize_copy (from) # :nodoc:
[:roles, :role_hierarchy, :auth_rules,
:role_descriptions, :role_titles, :omnipotent_roles].each do |attribute|
instance_variable_set(:"@#{attribute}", from.send(attribute).clone)
end
end

def append_role (role, options = {}) # :nodoc:
@roles << role unless @roles.include? role
@role_titles[role] = options[:title] if options[:title]
Expand Down

0 comments on commit 2b26106

Please sign in to comment.