Module: Sorcery::TestHelpers::Internal

Defined in:
lib/sorcery/test_helpers/internal.rb,
lib/sorcery.rb,
lib/sorcery/test_helpers/internal/rails.rb

Overview

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.

Defined Under Namespace

Modules: Rails

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# 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

Instance Method Details

#build_new_user(attributes_hash = nil) ⇒ Object



26
27
28
29
# File 'lib/sorcery/test_helpers/internal.rb', line 26

def build_new_user(attributes_hash = nil)
  user_attributes_hash = attributes_hash || {:username => 'gizmo', :email => "[email protected]", :password => 'secret'}
  @user = User.new(user_attributes_hash)
end

#create_new_external_user(provider, attributes_hash = nil) ⇒ Object



37
38
39
40
41
42
43
# 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) ⇒ Object



31
32
33
34
35
# 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) ⇒ Object



45
46
47
48
49
50
51
52
53
# 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) ⇒ Object



55
56
57
58
59
# 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) ⇒ Object



61
62
63
# File 'lib/sorcery/test_helpers/internal.rb', line 61

def update_model(&block)
  User.class_exec(&block)
end