Sha256: 4576b9510aa55d9c3229719ba997c173e1a72aed03bc7a0ac4e485073e66dd97

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

module Clearance
  module Testing
    # Provides helpers to your controller specs.
    # These are typically used in tests by requiring `clearance/rspec` or
    # `clearance/test_unit` as appropriate in your `rails_helper.rb` or
    # `test_helper.rb` files.
    module ControllerHelpers
      # @api private
      def setup_controller_request_and_response
        super
        @request.env[:clearance] = Clearance::Session.new(@request.env)
      end

      # Signs in a user that is created using FactoryGirl.
      # The factory name is derrived from your `user_class` Clearance
      # configuration.
      #
      # @raise [RuntimeError] if FactoryGirl is not defined.
      def sign_in
        unless defined?(FactoryGirl)
          raise("Clearance's `sign_in` helper requires factory_girl")
        end

        factory = Clearance.configuration.user_model.to_s.underscore.to_sym
        sign_in_as FactoryGirl.create(factory)
      end

      # Signs in the provided user.
      #
      # @return user
      def sign_in_as(user)
        @controller.sign_in user
        user
      end

      # Signs out a user that may be signed in.
      #
      # @return [void]
      def sign_out
        @controller.sign_out
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clearance-1.12.1 lib/clearance/testing/controller_helpers.rb
clearance-1.12.0 lib/clearance/testing/controller_helpers.rb