1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/test/controllers/internal_helpers_test.rb

57 lines
1.7 KiB
Ruby
Raw Normal View History

require 'test_helper'
2010-01-13 12:12:13 -05:00
class MyController < ApplicationController
include Devise::Controllers::InternalHelpers
end
class HelpersTest < ActionController::TestCase
tests MyController
def setup
@mock_warden = OpenStruct.new
@controller.request.env['warden'] = @mock_warden
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
end
test 'get resource name from env' do
2010-01-13 12:12:13 -05:00
assert_equal :user, @controller.resource_name
end
test 'get resource class from env' do
2010-01-13 12:12:13 -05:00
assert_equal User, @controller.resource_class
end
test 'get resource instance variable from env' do
2010-07-16 05:01:36 -04:00
@controller.instance_variable_set(:@user, user = User.new)
assert_equal user, @controller.resource
2010-01-13 12:12:13 -05:00
end
test 'set resource instance variable from env' do
2010-07-16 05:01:36 -04:00
user = @controller.send(:resource_class).new
@controller.send(:resource=, user)
2010-01-13 12:12:13 -05:00
2010-07-16 05:01:36 -04:00
assert_equal user, @controller.send(:resource)
assert_equal user, @controller.instance_variable_get(:@user)
2010-01-13 12:12:13 -05:00
end
test 'resources methods are not controller actions' do
assert @controller.class.action_methods.empty?
end
test 'require no authentication tests current mapping' do
@mock_warden.expects(:authenticated?).with(:user).returns(true)
@mock_warden.expects(:user).with(:user).returns(User.new)
2010-01-13 12:12:13 -05:00
@controller.expects(:redirect_to).with(root_path)
@controller.send :require_no_authentication
end
2010-07-16 05:01:36 -04:00
test 'signed in resource returns signed in resource for current scope' do
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
assert_kind_of User, @controller.signed_in_resource
end
2010-01-13 12:12:13 -05:00
test 'is a devise controller' do
assert @controller.devise_controller?
end
end