module Sorcery::TestHelpers::Internal

Internal TestHelpers are used to test the gem, internally, and should not be used to test apps using sorcery. This file will be included in the spec_helper file.

Public Class Methods

cost() click to toggle source
# File lib/sorcery/test_helpers/internal.rb, line 10
def cost
  1
end
included(_base) click to toggle source
# File lib/sorcery/test_helpers/internal.rb, line 6
def self.included(_base)
  # reducing default cost for specs speed
  CryptoProviders::BCrypt.class_eval do
    class << self
      def cost
        1
      end
    end
  end
end

Public Instance Methods

build_new_user(attributes_hash = nil) click to toggle source
# File lib/sorcery/test_helpers/internal.rb, line 26
def build_new_user(attributes_hash = nil)
  user_attributes_hash = attributes_hash || { username: 'gizmo', email: 'bla@bla.com', password: 'secret' }
  @user = User.new(user_attributes_hash)
end
create_new_external_user(provider, attributes_hash = nil) click to toggle source
# File lib/sorcery/test_helpers/internal.rb, line 37
def create_new_external_user(provider, attributes_hash = nil)
  user_attributes_hash = attributes_hash || { username: 'gizmo' }
  @user = User.new(user_attributes_hash)
  @user.sorcery_adapter.save(raise_on_failure: true)
  @user.authentications.create!(provider: provider, uid: 123)
  @user
end
create_new_user(attributes_hash = nil) click to toggle source
# File lib/sorcery/test_helpers/internal.rb, line 31
def create_new_user(attributes_hash = nil)
  @user = build_new_user(attributes_hash)
  @user.sorcery_adapter.save(raise_on_failure: true)
  @user
end
custom_create_new_external_user(provider, authentication_class, attributes_hash = nil) click to toggle source
# File lib/sorcery/test_helpers/internal.rb, line 45
def custom_create_new_external_user(provider, authentication_class, attributes_hash = nil)
  authentication_association = authentication_class.name.underscore.pluralize

  user_attributes_hash = attributes_hash || { username: 'gizmo' }
  @user = User.new(user_attributes_hash)
  @user.sorcery_adapter.save(raise_on_failure: true)
  @user.send(authentication_association).create!(provider: provider, uid: 123)
  @user
end
sorcery_model_property_set(property, *values) click to toggle source
# File lib/sorcery/test_helpers/internal.rb, line 55
def sorcery_model_property_set(property, *values)
  User.class_eval do
    sorcery_config.send(:"#{property}=", *values)
  end
end
update_model(&block) click to toggle source
# File lib/sorcery/test_helpers/internal.rb, line 61
def update_model(&block)
  User.class_exec(&block)
end

Private Instance Methods

reload_user_class() click to toggle source

reload user class between specs so it will be possible to test the different submodules in isolation

# File lib/sorcery/test_helpers/internal.rb, line 69
def reload_user_class
  User && Object.send(:remove_const, 'User')
  load 'user.rb'

  return unless User.respond_to?(:reset_column_information)

  User.reset_column_information
end