home_controller_test.rb
4.5 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
require 'home_controller'
class HomeController; def rescue_action(e) raise e end;
end
class HomeControllerTest < ActionController::TestCase
def setup
@controller = HomeController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@person = create_user('person').person
@environment = Environment.default
@environment.enable_plugin('EnvironmentNotificationPlugin')
@environment.save!
end
attr_accessor :person
should 'an active notification be displayed on home page for a logged in user' do
login_as(@person.user.login)
@notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
:environment_id => @environment.id,
:message => "Hello, this is a Notification Message",
:active => true,
:type => "EnvironmentNotificationPlugin::DangerNotification"
)
get :index
assert_match /Hello, this is a Notification Message/, @response.body
end
should 'an active notification not be displayed on home page for unlogged user' do
@notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
:environment_id => @environment.id,
:message => "Hello, this is a Notification Message",
:active => true,
:type => "EnvironmentNotificationPlugin::DangerNotification"
)
get :index
assert_no_match /Hello, this is a Notification Message/, @response.body
end
should 'an active notification be displayed on home page for unlogged user' do
@notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
:environment_id => @environment.id,
:message => "Hello, this is a Notification Message",
:display_to_all_users => true,
:active => true,
:type => "EnvironmentNotificationPlugin::DangerNotification"
)
get :index
assert_match /Hello, this is a Notification Message/, @response.body
end
should 'only display the notification with display_to_all_users option for unlogged user ' do
@notification1 = EnvironmentNotificationPlugin::EnvironmentNotification.create(
:environment_id => @environment.id,
:message => "Hello, this is an old Notification Message",
:active => true,
:type => "EnvironmentNotificationPlugin::DangerNotification"
)
@notification2 = EnvironmentNotificationPlugin::EnvironmentNotification.create(
:environment_id => @environment.id,
:message => "Hello, this is a new Notification Message",
:display_to_all_users => true,
:active => true,
:type => "EnvironmentNotificationPlugin::DangerNotification"
)
get :index
assert_no_match /Hello, this is a Notification Message/, @response.body
assert_match /Hello, this is a new Notification Message/, @response.body
end
should 'an inactive notification not be displayed on home page' do
@notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
:environment_id => @environment.id,
:message => "Hello, this is a Notification Message",
:active => false,
:type => "EnvironmentNotificationPlugin::DangerNotification"
)
get :index
assert_no_match /Hello, this is a Notification Message/, @response.body
end
should 'an active notification not be displayed to a logged in user after been closed by him' do
login_as(@person.user.login)
@notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
:environment_id => @environment.id,
:message => "Hello, this is a Notification Message",
:active => true,
:type => "EnvironmentNotificationPlugin::DangerNotification"
)
@notification.users << @person.user
@notification.save!
assert_equal true, @notification.users.include?(@person.user)
get :index
assert_no_match /Hello, this is a Notification Message/, @response.body
end
end