Class: ControllerActionTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
Goldberg::TestHelper
Defined in:
lib/six-updater-web/vendor/plugins/goldberg/test/unit/controller_action_test.rb

Instance Method Summary collapse

Methods included from Goldberg::TestHelper

#form_login, #form_logout, included, #login_user

Instance Method Details

#setupObject



6
7
8
9
10
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/unit/controller_action_test.rb', line 6

def setup
  # Some associated records (two of each will do)
  (@sc1, @sc2) = Goldberg::SiteController.find :all
  (@p1, @p2) = Goldberg::Permission.find :all
end

#test_all_fieldsObject



31
32
33
34
35
36
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/unit/controller_action_test.rb', line 31

def test_all_fields
  ca = Goldberg::ControllerAction.new(:name => 'test')
  ca.site_controller = @sc1
  ca.permission = @p1
  assert ca.save
end

#test_effective_permissionObject

The effective permission is the permission of the controller action, if specified; otherwise it is the permission of the action’s site controller.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/unit/controller_action_test.rb', line 64

def test_effective_permission
  # Make sure we know the permission on the site controller
  @sc1.permission = @p1
  @sc1.save!
  
  ca = Goldberg::ControllerAction.new(:name => 'test')
  ca.site_controller = @sc1
  ca.save!

  # No explicit permission: effective permission should be the same
  # as site controller
  assert_nil ca.permission
  assert_equal @p1.id, ca.effective_permission.id

  # Explicit permission: should override permission of site
  # controller
  ca.permission = @p2
  ca.save!
  assert_not_nil ca.permission
  assert_equal @p2.id, ca.effective_permission.id
end

#test_minimal_fieldsObject



21
22
23
24
25
26
27
28
29
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/unit/controller_action_test.rb', line 21

def test_minimal_fields
  ca = Goldberg::ControllerAction.new(:name => 'test')
  ca.site_controller = @sc1
  assert ca.save
  
  # All fields
  ca.permission = @p1
  assert ca.save
end

#test_name_unique_within_scope_of_site_controllerObject

The name of the controller action should be unique within the scope of the site controller.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/unit/controller_action_test.rb', line 40

def test_name_unique_within_scope_of_site_controller
  ca1 = Goldberg::ControllerAction.new(:name => 'test')
  ca2 = Goldberg::ControllerAction.new(:name => 'test')
  ca1.site_controller = @sc1
  ca2.site_controller = @sc1
  ca1.save

  # Error: name not unique within scope of controller
  assert !ca2.save
  assert ca2.errors.on(:name)

  # Should work: same name, different controllers
  ca2.site_controller = @sc2
  assert ca2.save

  # Should work: different names, same controller
  ca2.name = 'test2'
  ca2.site_controller = @sc1
  assert ca2.save
end

#test_no_fieldsObject



12
13
14
15
16
17
18
19
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/unit/controller_action_test.rb', line 12

def test_no_fields
  ca = Goldberg::ControllerAction.new
  assert !ca.valid?
  # name, and site_controller_id are compulsory
  [:name, :site_controller_id].each do |attr|
    assert ca.errors.on(attr)
  end
end