Module: Bbq::Devise

Defined in:
lib/bbq/devise.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#devise_authentication_keyObject

Returns the value of attribute devise_authentication_key.



6
7
8
# File 'lib/bbq/devise.rb', line 6

def devise_authentication_key
  @devise_authentication_key
end

#emailObject

Returns the value of attribute email.



6
7
8
# File 'lib/bbq/devise.rb', line 6

def email
  @email
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/bbq/devise.rb', line 6

def password
  @password
end

#scopeObject

Returns the value of attribute scope.



6
7
8
# File 'lib/bbq/devise.rb', line 6

def scope
  @scope
end

Class Method Details

.included(klass) ⇒ Object



8
9
10
11
# File 'lib/bbq/devise.rb', line 8

def self.included(klass)
  require 'bbq/rails/routes'
  klass.send(:include, Bbq::Rails::Routes)
end

.next_emailObject



48
49
50
# File 'lib/bbq/devise.rb', line 48

def self.next_email
  "#{SecureRandom.hex(3)}@example.com"
end

.next_passwordObject



52
53
54
# File 'lib/bbq/devise.rb', line 52

def self.next_password
  SecureRandom.hex(8)
end

Instance Method Details

#initialize_deviseObject



13
14
15
16
17
18
19
20
21
# File 'lib/bbq/devise.rb', line 13

def initialize_devise
  @devise_initialized ||= begin
    self.devise_authentication_key = ::Devise.authentication_keys.first
    self.email = options[devise_authentication_key.to_sym] || Bbq::Devise.next_email
    self.password = options[:password] || Bbq::Devise.next_password
    self.scope = ::Devise.mappings.first.second.singular.to_s
    true
  end
end

#loginObject



32
33
34
35
36
37
38
# File 'lib/bbq/devise.rb', line 32

def 
  initialize_devise
  visit send("new_#{scope}_session_path")
  fill_in "#{scope}_#{devise_authentication_key}", :with => @email
  fill_in "#{scope}_password", :with => @password
  find(:xpath, "//input[@name='commit']").click
end

#logoutObject



40
41
42
# File 'lib/bbq/devise.rb', line 40

def logout
  visit send("destroy_#{scope}_session_path")
end

#registerObject



23
24
25
26
27
28
29
30
# File 'lib/bbq/devise.rb', line 23

def register
  initialize_devise
  visit send("new_#{scope}_registration_path")
  fill_in "#{scope}_#{devise_authentication_key}", :with => @email
  fill_in "#{scope}_password", :with => @password
  fill_in "#{scope}_password_confirmation", :with => @password
  find(:xpath, "//input[@name='commit']").click
end

#register_and_loginObject



44
45
46
# File 'lib/bbq/devise.rb', line 44

def 
  register
end