Class: ActionPolicy::TestHelper::WithScopeTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/action_policy/test_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scopes) ⇒ WithScopeTarget

Returns a new instance of WithScopeTarget.



11
12
13
# File 'lib/action_policy/test_helper.rb', line 11

def initialize(scopes)
  @scopes = scopes
end

Instance Attribute Details

#scopesObject (readonly)

Returns the value of attribute scopes.



9
10
11
# File 'lib/action_policy/test_helper.rb', line 9

def scopes
  @scopes
end

Instance Method Details

#with_target {|scopes.first.target| ... } ⇒ Object

Yields:



15
16
17
18
19
20
21
22
# File 'lib/action_policy/test_helper.rb', line 15

def with_target
  if scopes.size > 1
    raise "Too many matching scopings (#{scopes.size}), " \
          "you can run `.with_target` only when there is the only one match"
  end

  yield scopes.first.target
end