Sha256: 41e9c7365c66fa3149a717f5a6dba1ba681a3f267d3b4149cb0eaefefa2e0781

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

module Sorcery
  module TestHelpers
    module Internal
      module Rails
        include ::Sorcery::TestHelpers::Rails

        SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS = [:register_last_activity_time_to_db, :deny_banned_user, :validate_session]

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

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

          # remove all plugin before_filters so they won't fail other tests.
          # I don't like this way, but I didn't find another.
          # hopefully it won't break until Rails 4.
          ApplicationController._process_action_callbacks.delete_if {|c| SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS.include?(c.filter) }

          # configure
          ::Sorcery::Controller::Config.submodules = submodules
          ::Sorcery::Controller::Config.user_class = nil
          ActionController::Base.send(:include,::Sorcery::Controller)

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

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

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

        # This helper is used to fake multiple users signing in in tests.
        # It does so by clearing @current_user, thus allowing a new user to login,
        # all this without calling the :logout action explicitly.
        # A dirty dirty hack.
        def clear_user_without_logout
          subject.instance_variable_set(:@current_user,nil)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sorcery-0.5.1 lib/sorcery/test_helpers/internal/rails.rb
sorcery-0.5.0 lib/sorcery/test_helpers/internal/rails.rb
sorcery-0.4.2 lib/sorcery/test_helpers/internal/rails.rb