environment_notification_test.rb
6.41 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
require_relative '../../../../test/test_helper'
class EnvironmentNotificationTest < ActiveSupport::TestCase
def setup
@env = Environment.default
@env.enable_plugin('EnvironmentNotificationPlugin')
User.destroy_all
EnvironmentNotificationPlugin::EnvironmentNotification.destroy_all
EnvironmentNotificationsUser.destroy_all
@user = User.create!(:environment_id => @env.id, :email => "user@domain.com", :login => "new_user", :password => "test", :password_confirmation => "test")
@danger_notification = EnvironmentNotificationPlugin::DangerNotification.create!(
:environment_id => @env.id,
:message => "Danger Message",
:active => true,
)
@warning_notification = EnvironmentNotificationPlugin::WarningNotification.create!(
:environment_id => @env.id,
:message => "Warning Message",
:active => true,
)
@information_notification = EnvironmentNotificationPlugin::InformationNotification.create!(
:environment_id => @env.id,
:message => "Information Message",
:active => true,
)
end
should 'get all notifications that a user did not closed' do
@information_notification.users << @user
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, nil)
assert notifications.include?(@danger_notification)
assert notifications.include?(@warning_notification)
assert !notifications.include?(@information_notification)
end
should 'get only notifications configured to be displayed to all users' do
@information_notification.display_to_all_users = true
@information_notification.save!
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, nil)
assert !notifications.include?(@danger_notification)
assert !notifications.include?(@warning_notification)
assert notifications.include?(@information_notification)
end
should 'get only notifications configured to be displayed to all users and in all pages' do
@information_notification.display_to_all_users = true
@information_notification.display_only_in_homepage = true
@information_notification.save!
@danger_notification.display_to_all_users = true
@danger_notification.save!
@warning_notification.display_only_in_homepage = true
@warning_notification.save!
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, 'not_home')
assert notifications.include?(@danger_notification)
assert !notifications.include?(@warning_notification)
assert !notifications.include?(@information_notification)
end
should 'get only notifications configured to be displayed in all pages' do
@danger_notification.display_to_all_users = true
@danger_notification.display_only_in_homepage = true
@danger_notification.save!
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, "not_home")
assert !notifications.include?(@danger_notification)
assert notifications.include?(@warning_notification)
assert notifications.include?(@information_notification)
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, "home")
assert notifications.include?(@danger_notification)
assert !notifications.include?(@warning_notification)
assert !notifications.include?(@information_notification)
end
should 'get only notifications configured to be displayed to all users and in all pages and not closed by an user' do
@information_notification.display_to_all_users = true
@information_notification.save!
@danger_notification.display_to_all_users = true
@danger_notification.display_only_in_homepage = true
@danger_notification.save!
@warning_notification.display_to_all_users = true
@warning_notification.save!
@warning_notification.users << @user
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, 'not_home')
assert !notifications.include?(@danger_notification)
assert !notifications.include?(@warning_notification)
assert notifications.include?(@information_notification)
end
should 'get only active notifications' do
@information_notification.active = false
@information_notification.save!
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, 'home')
assert notifications.include?(@danger_notification)
assert notifications.include?(@warning_notification)
assert !notifications.include?(@information_notification)
end
should 'get only notifications with popup' do
@information_notification.display_popup = true
@information_notification.display_to_all_users = true
@information_notification.save!
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, @user, 'home')
assert !notifications.include?(@danger_notification)
assert !notifications.include?(@warning_notification)
assert notifications.include?(@information_notification)
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, nil, nil)
assert !notifications.include?(@danger_notification)
assert !notifications.include?(@warning_notification)
assert notifications.include?(@information_notification)
end
should 'get only notifications with popup not closed by an user' do
@information_notification.display_popup = true
@information_notification.display_to_all_users = true
@information_notification.save!
@danger_notification.display_popup = true
@danger_notification.display_to_all_users = true
@danger_notification.save!
@danger_notification.users << @user
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, @user, 'home')
assert !notifications.include?(@danger_notification)
assert !notifications.include?(@warning_notification)
assert notifications.include?(@information_notification)
notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, nil, nil)
assert notifications.include?(@danger_notification)
assert !notifications.include?(@warning_notification)
assert notifications.include?(@information_notification)
end
end