Commit e9c593fa21d3aff3057780961d1617004341f934

Authored by Gabriel Silva
1 parent 3177eee3

Functional tests

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb
@@ -9,4 +9,8 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController @@ -9,4 +9,8 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController
9 environment 9 environment
10 end 10 end
11 11
  12 + def admin_required
  13 + redirect_to :root unless current_person.is_admin?
  14 + end
  15 +
12 end 16 end
plugins/environment_notification/controllers/environment_notification_plugin_myprofile_controller.rb
@@ -9,4 +9,8 @@ class EnvironmentNotificationPluginMyprofileController &lt; MyProfileController @@ -9,4 +9,8 @@ class EnvironmentNotificationPluginMyprofileController &lt; MyProfileController
9 profile 9 profile
10 end 10 end
11 11
  12 + def admin_required
  13 + redirect_to :root unless target.is_admin?(current_person)
  14 + end
  15 +
12 end 16 end
plugins/environment_notification/lib/notification_manager.rb
@@ -57,8 +57,4 @@ module NotificationManager @@ -57,8 +57,4 @@ module NotificationManager
57 redirect_to :action => :index 57 redirect_to :action => :index
58 end 58 end
59 59
60 - protected  
61 - def admin_required  
62 - redirect_to :root unless current_user.person.is_admin?  
63 - end  
64 end 60 end
plugins/environment_notification/test/functional/environment_notification_plugin_myprofile_controller_test.rb
@@ -24,65 +24,70 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T @@ -24,65 +24,70 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T
24 24
25 should 'profile admin be able to create a notification' do 25 should 'profile admin be able to create a notification' do
26 @community.add_admin(@person) 26 @community.add_admin(@person)
27 - post :new, :controller => "environment_notification_plugin_myprofile_controller", 27 + post :new, :profile => @community.identifier,
28 :notifications => { 28 :notifications => {
29 :message => "Message", 29 :message => "Message",
30 :active => true, 30 :active => true,
31 :type => "EnvironmentNotificationPlugin::DangerNotification" 31 :type => "EnvironmentNotificationPlugin::DangerNotification"
32 } 32 }
33 - assert_redirected_to :action => 'index'  
34 - notification = EnvironmentNotificationPlugin::EnvironmentNotification.last  
35 - assert_equal "Message", notification.message  
36 - assert notification.active  
37 - assert_equal "EnvironmentNotificationPlugin::DangerNotification", notification.type 33 + assert_redirected_to :action => 'index'
  34 + notification = EnvironmentNotificationPlugin::EnvironmentNotification.last
  35 + assert_equal "Message", notification.message
  36 + assert notification.active
  37 + assert_equal "EnvironmentNotificationPlugin::DangerNotification", notification.type
38 end 38 end
39 39
40 should 'a regular user not to be able to create a notification' do 40 should 'a regular user not to be able to create a notification' do
41 - post :new, :notifications => {  
42 - :message => "Message",  
43 - :active => true,  
44 - :type => "EnvironmentNotificationPlugin::DangerNotification"  
45 - }  
46 - assert_redirected_to :root  
47 - assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.last 41 + post :new, :profile => @community.identifier,
  42 + :notifications => {
  43 + :message => "Message",
  44 + :active => true,
  45 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  46 + }
  47 +
  48 + assert_redirected_to :root
  49 + assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.last
48 end 50 end
49 51
50 - should 'profile admin be able to edit a notification' do 52 + should 'profile admin be able to edit a notification' do
51 @community.add_admin(@person) 53 @community.add_admin(@person)
52 @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( 54 @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
53 - :target => @community,  
54 - :message => "Message",  
55 - :active => true,  
56 - :type => "EnvironmentNotificationPlugin::DangerNotification"  
57 - )  
58 - post :edit, :id => @notification.id, :notifications => {  
59 - :message => "Edited Message",  
60 - :active => false,  
61 - :type => "EnvironmentNotificationPlugin::WarningNotification"  
62 - }  
63 - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.last  
64 - assert_redirected_to :action => 'index'  
65 - assert_equal "Edited Message", @notification.message  
66 - assert !@notification.active  
67 - assert_equal "EnvironmentNotificationPlugin::WarningNotification", @notification.type 55 + :target => @community,
  56 + :message => "Message",
  57 + :active => true,
  58 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  59 + )
  60 +
  61 + post :edit, :profile => @community.identifier, :id => @notification.id,
  62 + :notifications => {
  63 + :message => "Edited Message",
  64 + :active => false,
  65 + :type => "EnvironmentNotificationPlugin::WarningNotification"
  66 + }
  67 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.last
  68 + assert_redirected_to :action => 'index'
  69 + assert_equal "Edited Message", @notification.message
  70 + assert !@notification.active
  71 + assert_equal "EnvironmentNotificationPlugin::WarningNotification", @notification.type
68 end 72 end
69 73
70 should 'a regular user not be able to edit a notification' do 74 should 'a regular user not be able to edit a notification' do
71 @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( 75 @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
72 - :target => @community,  
73 - :message => "Message",  
74 - :active => true,  
75 - :type => "EnvironmentNotificationPlugin::DangerNotification"  
76 - )  
77 - post :edit, :notifications => {  
78 - :message => "Edited Message",  
79 - :active => false,  
80 - :type => "EnvironmentNotificationPlugin::DangerNotification"  
81 - }  
82 - @notification.reload  
83 - assert_redirected_to :root  
84 - assert_equal "Message", @notification.message  
85 - assert @notification.active 76 + :target => @community,
  77 + :message => "Message",
  78 + :active => true,
  79 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  80 + )
  81 + post :edit, :profile => @community.identifier,
  82 + :notifications => {
  83 + :message => "Edited Message",
  84 + :active => false,
  85 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  86 + }
  87 + @notification.reload
  88 + assert_redirected_to :root
  89 + assert_equal "Message", @notification.message
  90 + assert @notification.active
86 end 91 end
87 92
88 should 'a profile admin be able to destroy a notification' do 93 should 'a profile admin be able to destroy a notification' do
@@ -93,7 +98,7 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T @@ -93,7 +98,7 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T
93 :active => true, 98 :active => true,
94 :type => "EnvironmentNotificationPlugin::DangerNotification" 99 :type => "EnvironmentNotificationPlugin::DangerNotification"
95 ) 100 )
96 - delete :destroy, :id => @notification.id 101 + delete :destroy, :profile => @community.identifier, :id => @notification.id
97 assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id) 102 assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id)
98 end 103 end
99 104
@@ -104,10 +109,10 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T @@ -104,10 +109,10 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T
104 :active => true, 109 :active => true,
105 :type => "EnvironmentNotificationPlugin::DangerNotification" 110 :type => "EnvironmentNotificationPlugin::DangerNotification"
106 ) 111 )
107 - delete :destroy, :id => @notification.id 112 + delete :destroy, :profile => @community.identifier, :id => @notification.id
108 113
109 - assert_redirected_to :root  
110 - assert_not_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id) 114 + assert_redirected_to :root
  115 + assert_not_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id)
111 end 116 end
112 117
113 should 'a profile admin be able to change Notification status' do 118 should 'a profile admin be able to change Notification status' do
@@ -118,11 +123,11 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T @@ -118,11 +123,11 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T
118 :active => true, 123 :active => true,
119 :type => "EnvironmentNotificationPlugin::DangerNotification" 124 :type => "EnvironmentNotificationPlugin::DangerNotification"
120 ) 125 )
121 - post :change_status, :id => @notification.id  
122 - assert_redirected_to :action => 'index' 126 + post :change_status, :profile => @community.identifier, :id => @notification.id
  127 + assert_redirected_to :action => 'index'
123 128
124 - @notification.reload  
125 - assert !@notification.active 129 + @notification.reload
  130 + assert !@notification.active
126 end 131 end
127 132
128 should 'a regular user not be able to change Notification status' do 133 should 'a regular user not be able to change Notification status' do
@@ -132,11 +137,11 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T @@ -132,11 +137,11 @@ class EnvironmentNotificationPluginMyprofileControllerTest &lt; ActionController::T
132 :active => true, 137 :active => true,
133 :type => "EnvironmentNotificationPlugin::DangerNotification" 138 :type => "EnvironmentNotificationPlugin::DangerNotification"
134 ) 139 )
135 - post :change_status, :id => @notification.id  
136 - assert_redirected_to :root 140 + post :change_status, :profile => @community.identifier, :id => @notification.id
  141 + assert_redirected_to :root
137 142
138 - @notification.reload  
139 - assert @notification.active 143 + @notification.reload
  144 + assert @notification.active
140 end 145 end
141 146
142 end 147 end