Module: EspAuth::SpecHelper

Defined in:
lib/esp_auth/spec_helper.rb

Instance Method Summary collapse

Instance Method Details

#ability_for(user) ⇒ Object



4
5
6
# File 'lib/esp_auth/spec_helper.rb', line 4

def ability_for(user)
  Ability.new(user)
end

#another_subcontext(context) ⇒ Object



66
67
68
# File 'lib/esp_auth/spec_helper.rb', line 66

def another_subcontext(context)
  @another_subcontext ||= create_subcontext(context)
end

#another_userObject



30
31
32
# File 'lib/esp_auth/spec_helper.rb', line 30

def another_user
  @another_user ||= create_user
end

#child_1Object



46
47
48
# File 'lib/esp_auth/spec_helper.rb', line 46

def child_1
  @child_1 ||= create_context root
end

#child_1_1Object



50
51
52
# File 'lib/esp_auth/spec_helper.rb', line 50

def child_1_1
  @child_1_1 ||= create_context child_1
end

#child_1_2Object



54
55
56
# File 'lib/esp_auth/spec_helper.rb', line 54

def child_1_2
  @child_1_2 ||= create_context child_1
end

#child_2Object



58
59
60
# File 'lib/esp_auth/spec_helper.rb', line 58

def child_2
  @child_2 ||= create_context root
end

#create_context(parent = nil) ⇒ Object



34
35
36
# File 'lib/esp_auth/spec_helper.rb', line 34

def create_context(parent=nil)
  Context.create! :title => 'context', :parent => parent
end

#create_subcontext(context) ⇒ Object



38
39
40
# File 'lib/esp_auth/spec_helper.rb', line 38

def create_subcontext(context)
  Subcontext.create! :title => 'subcontext', :context => context
end

#create_userObject



8
9
10
11
12
# File 'lib/esp_auth/spec_helper.rb', line 8

def create_user
  @sequence ||= 0
  @sequence += 1
  User.create! :uid => @sequence, :name => "user #{@sequence}"
end

#rootObject



42
43
44
# File 'lib/esp_auth/spec_helper.rb', line 42

def root
  @root ||= create_context
end

#subcontext(context) ⇒ Object



62
63
64
# File 'lib/esp_auth/spec_helper.rb', line 62

def subcontext(context)
  @subcontext ||= create_subcontext(context)
end

#userObject



26
27
28
# File 'lib/esp_auth/spec_helper.rb', line 26

def user
  @user ||= create_user
end

#user_with_role(role, context = root, prefix = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/esp_auth/spec_helper.rb', line 14

def user_with_role(role, context=root, prefix=nil)
  @roles ||= {}
  @roles["#{prefix}_#{role}"] ||= {}
  @roles["#{prefix}_#{role}"][context] ||= create_user.tap do |user|
    user.permissions.new do |permission|
      permission.context = context
      permission.role = role
      permission.save!
    end
  end
end