cirandas.net

ref: master

plugins/social_statistics/test/functional/social_statistics_plugins/application_controller_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# encoding: UTF-8
require_relative "../../../../../test/test_helper"
require_relative '../../../lib/ext/application_controller'

class SocialStatisticsPlugin::ApplicationControllerTest < ActionController::TestCase
  def setup
    @controller = ApplicationController.new
  end

  should 'render not_found if user is blank' do
    @controller.stubs(:user).returns(nil)
    @controller.expects(:social_statistics_plugin_not_found)
    @controller.social_statistics_plugin_verify_access
  end

  should 'render not_found if environment blank' do
    user = mock()
    user.stubs(:environment).returns(nil)
    @controller.stubs(:user).returns(user)
    @controller.expects(:social_statistics_plugin_not_found)
    @controller.social_statistics_plugin_verify_access
  end

  should 'render not_found if plugin is disabled' do
    user = mock()
    environment = mock()
    environment.stubs(:plugin_enabled?).with('SocialStatisticsPlugin').returns(false)
    user.stubs(:environment).returns(environment)
    @controller.stubs(:user).returns(user)
    @controller.expects(:social_statistics_plugin_not_found)
    @controller.social_statistics_plugin_verify_access
  end

  should 'render access_denied if user is not admin' do
    user = mock()
    environment = mock()
    environment.stubs(:plugin_enabled?).with('SocialStatisticsPlugin').returns(true)
    user.stubs(:environment).returns(environment)
    user.stubs(:is_admin?).returns(false)
    @controller.stubs(:user).returns(user)
    @controller.expects(:social_statistics_plugin_not_found).never
    @controller.expects(:social_statistics_plugin_access_denied)
    @controller.social_statistics_plugin_verify_access
  end

  should 'not render anything' do
    user = mock()
    environment = mock()
    environment.stubs(:plugin_enabled?).with('SocialStatisticsPlugin').returns(true)
    user.stubs(:environment).returns(environment)
    user.stubs(:is_admin?).returns(true)
    @controller.stubs(:user).returns(user)
    @controller.expects(:social_statistics_plugin_not_found).never
    @controller.expects(:social_statistics_plugin_access_denied).never
    @controller.social_statistics_plugin_verify_access
  end
end