Sha256: 21ffcf4f2ec0b206800faefa4ff954459e2d18bec4862c78ed4500695161d93e

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

if defined?(Devise)
  require 'securerandom'

  module Bbq
    module Devise
      attr_accessor :devise_authentication_key, :email, :password, :scope

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

      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

      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

      def login
        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_#{scope}_session_path")
      end

      def register_and_login
        register
      end

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bbq-0.2.1 lib/bbq/devise.rb
bbq-0.2.0 lib/bbq/devise.rb
bbq-0.1.0 lib/bbq/devise.rb