Module: Sorcery::TestHelpers::Internal::Sinatra

Includes:
Sinatra::CookieSessionMethods, Sinatra::InstanceMethods
Defined in:
lib/sorcery/test_helpers/internal/sinatra.rb

Instance Method Summary collapse

Methods included from Sinatra::InstanceMethods

#get_sinatra_app, #login_user, #logout_user

Methods included from Sinatra::CookieSessionMethods

#cookies, #session

Instance Method Details

#assignsObject



33
34
35
# File 'lib/sorcery/test_helpers/internal/sinatra.rb', line 33

def assigns
  ::Sinatra::Application.sorcery_vars
end

#clear_user_without_logoutObject



29
30
31
# File 'lib/sorcery/test_helpers/internal/sinatra.rb', line 29

def clear_user_without_logout
  get_sinatra_app(subject).instance_variable_set(:@current_user, nil)
end

#sorcery_controller_external_property_set(provider, property, value) ⇒ Object



68
69
70
# File 'lib/sorcery/test_helpers/internal/sinatra.rb', line 68

def sorcery_controller_external_property_set(provider, property, value)
  ::Sorcery::Controller::Config.send(provider).send(:"#{property}=", value)
end

#sorcery_controller_property_set(property, value) ⇒ Object



64
65
66
# File 'lib/sorcery/test_helpers/internal/sinatra.rb', line 64

def sorcery_controller_property_set(property, value)
  ::Sorcery::Controller::Config.send(:"#{property}=", value)
end

#sorcery_reload!(submodules = [], options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sorcery/test_helpers/internal/sinatra.rb', line 37

def sorcery_reload!(submodules = [], options = {})
  reload_user_class

  # return to no-module configuration
  ::Sorcery::Controller::Config.init!
  ::Sorcery::Controller::Config.reset!

  # clear all filters
  ::Sinatra::Application.instance_variable_set(:@filters, {:before => [], :after => []})
  load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters.rb')
  ::Sinatra::Application.send(:include, ::Filters)

  # configure
  ::Sorcery::Controller::Config.submodules = submodules
  ::Sorcery::Controller::Config.user_class = nil
  ::Sinatra::Application.send(:include, Sorcery::Controller::Adapters::Sinatra)
  ::Sinatra::Application.send(:include, Sorcery::Controller)
  ::Sorcery::Controller::Config.user_class = "User"

  ::Sorcery::Controller::Config.user_config do |user|
    options.each do |property, value|
      user.send(:"#{property}=", value)
    end
  end
  User.authenticates_with_sorcery!
end