lib/bbq/devise.rb in bbq-0.0.2.beta.2 vs lib/bbq/devise.rb in bbq-0.0.2.beta.3

- old
+ new

@@ -1,40 +1,40 @@ if defined?(Devise) require 'securerandom' module Bbq module Devise - attr_accessor :devise_authentication_key, :email, :password, :scope - def self.included(other) - other.add_callback(self) + def initialize_devise + unless @devise_initialized + 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 + @devise_initialized = true + end end - def self.init(user) - user.devise_authentication_key = ::Devise.authentication_keys.first - user.email = user.options[user.devise_authentication_key.to_sym] || next_email - user.password = user.options[:password] || next_password - user.scope = ::Devise.mappings.first.second.singular.to_s - end - def register - visit send("new_#{self.scope}_registration_path") - fill_in "#{self.scope}_#{self.devise_authentication_key}", :with => @email - fill_in "#{self.scope}_password", :with => @password - fill_in "#{self.scope}_password_confirmation", :with => @password + 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 def login - visit send("new_#{self.scope}_session_path") - fill_in "#{self.scope}_#{self.devise_authentication_key}", :with => @email - fill_in "#{self.scope}_password", :with => @password + 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 def logout - visit send("destroy_#{self.scope}_session_path") + visit send("destroy_#{scope}_session_path") end def register_and_login register end