Sha256: 650817e24b08588bc59a0ce1bf4ed9505e7a7f5daea31f9371b65a2d06d01d7f

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

if defined?(Devise)

  require 'bbq/test'

  module Bbq
    module Devise

      attr_accessor :devise_authentication_key, :email, :password, :scope

      def self.included(other)
        other.add_callback(self)
      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
        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
        find(:xpath, "//input[@name='commit']").click
      end

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

      def register_and_login
        register
      end

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

      def self.next_password
        ActiveSupport::SecureRandom.hex(8)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bbq-0.0.2.beta.1 lib/bbq/devise.rb