Module: Monban::Test::ControllerHelpers

Defined in:
lib/monban/test/controller_helpers.rb

Overview

Note:

these have only been tested with rspec controller specs

These are test helpers for controller specs

Since:

  • 0.0.15

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Since:

  • 0.0.15



9
10
11
12
13
# File 'lib/monban/test/controller_helpers.rb', line 9

def self.included(base)
  base.class_eval do
    setup :store_controller_for_warden, :warden if respond_to?(:setup)
  end
end

Instance Method Details

#sign_in(user) ⇒ Object

Signs a user in for tests

Parameters:

  • user (User)

    the user to sign in

Since:

  • 0.0.15



17
18
19
# File 'lib/monban/test/controller_helpers.rb', line 17

def (user)
  @controller.(user)
end

#sign_outObject

Signs the user out in tests

Since:

  • 0.0.15



22
23
24
# File 'lib/monban/test/controller_helpers.rb', line 22

def sign_out
  @controller.sign_out
end

#wardenObject

A mock of warden for tests

Since:

  • 0.0.15



27
28
29
30
31
32
33
34
# File 'lib/monban/test/controller_helpers.rb', line 27

def warden
  @warden ||= begin
    manager = Warden::Manager.new(nil) do |config|
      config.merge! Monban.warden_config
    end
    @request.env['warden'] = Warden::Proxy.new(@request.env, manager)
  end
end