From 3177eee3f70df13c5011ffefc191e1ef0c10a845 Mon Sep 17 00:00:00 2001 From: Marcos Ronaldo Date: Mon, 28 Mar 2016 15:39:31 -0300 Subject: [PATCH] adds functional tests --- plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb | 4 ++-- plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb | 56 ++++++-------------------------------------------------- plugins/environment_notification/test/functional/environment_notification_plugin_myprofile_controller_test.rb | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/environment_notification/test/functional/environment_notification_plugin_public_controller_test.rb | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/environment_notification/test/functional/home_controller_test.rb | 16 ++++++++-------- 5 files changed, 225 insertions(+), 60 deletions(-) create mode 100644 plugins/environment_notification/test/functional/environment_notification_plugin_myprofile_controller_test.rb create mode 100644 plugins/environment_notification/test/functional/environment_notification_plugin_public_controller_test.rb diff --git a/plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb b/plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb index 6607d95..6da5cb4 100644 --- a/plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb +++ b/plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb @@ -16,7 +16,7 @@ class EnvironmentNotificationPluginPublicController < PublicController result = false if logged_in? - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.find(params[:notification_id]) + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(params[:notification_id]) if @notification @notification.users << current_user @@ -31,7 +31,7 @@ class EnvironmentNotificationPluginPublicController < PublicController result = false if logged_in? - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.find(params[:notification_id]) + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(params[:notification_id]) if @notification current_notificaions = [] diff --git a/plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb b/plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb index 1ff4671..424c6e6 100644 --- a/plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb +++ b/plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb @@ -50,7 +50,7 @@ class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestC should 'an admin be able to edit a notification' do @environment.add_admin(@person) @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -69,7 +69,7 @@ class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestC should 'an user not to be able to edit a notification' do @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -88,7 +88,7 @@ class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestC should 'an admin be able to destroy a notification' do @environment.add_admin(@person) @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -99,7 +99,7 @@ class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestC should 'an user not to be able to destroy a notification' do @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -113,7 +113,7 @@ class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestC should 'an admin be able to change Notification status' do @environment.add_admin(@person) @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -127,7 +127,7 @@ class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestC should 'an user not be able to change Notification status' do @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -139,48 +139,4 @@ class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestC assert @notification.active end - should 'a logged in user be able to permanently hide notifications' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - post :close_notification, :notification_id => @notification.id - assert_equal "true", @response.body - assert @notification.users.include?(@person.user) - end - - should 'a logged in user be able to momentarily hide notifications' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - - @another_notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Another Message", - :active => true, - :type => "EnvironmentNotificationPlugin::WarningNotification" - ) - post :hide_notification, :notification_id => @notification.id - assert_equal "true", @response.body - assert @controller.hide_notifications.include?(@notification.id) - assert !@controller.hide_notifications.include?(@another_notification.id) - end - - should 'not momentarily hide any notification if its id is not found' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - - post :hide_notification, :notification_id => nil - assert_equal "false", @response.body - assert !@controller.hide_notifications.include?(@notification.id) - end end diff --git a/plugins/environment_notification/test/functional/environment_notification_plugin_myprofile_controller_test.rb b/plugins/environment_notification/test/functional/environment_notification_plugin_myprofile_controller_test.rb new file mode 100644 index 0000000..f3d6925 --- /dev/null +++ b/plugins/environment_notification/test/functional/environment_notification_plugin_myprofile_controller_test.rb @@ -0,0 +1,142 @@ +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' +require( + File.expand_path(File.dirname(__FILE__)) + + '/../../controllers/environment_notification_plugin_myprofile_controller' +) + +class EnvironmentNotificationPluginMyprofileControllerTest < ActionController::TestCase + def setup + @controller = EnvironmentNotificationPluginMyprofileController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @person = create_user('person').person + @community = fast_create(Community) + + environment = Environment.default + environment.enable_plugin('EnvironmentNotificationPlugin') + environment.save! + + login_as(@person.user.login) + EnvironmentNotificationPluginMyprofileController.any_instance.stubs(:profile).returns(@community) + end + + attr_accessor :person + + should 'profile admin be able to create a notification' do + @community.add_admin(@person) + post :new, :controller => "environment_notification_plugin_myprofile_controller", + :notifications => { + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + } + assert_redirected_to :action => 'index' + notification = EnvironmentNotificationPlugin::EnvironmentNotification.last + assert_equal "Message", notification.message + assert notification.active + assert_equal "EnvironmentNotificationPlugin::DangerNotification", notification.type + end + + should 'a regular user not to be able to create a notification' do + post :new, :notifications => { + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + } + assert_redirected_to :root + assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.last + end + + should 'profile admin be able to edit a notification' do + @community.add_admin(@person) + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + post :edit, :id => @notification.id, :notifications => { + :message => "Edited Message", + :active => false, + :type => "EnvironmentNotificationPlugin::WarningNotification" + } + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.last + assert_redirected_to :action => 'index' + assert_equal "Edited Message", @notification.message + assert !@notification.active + assert_equal "EnvironmentNotificationPlugin::WarningNotification", @notification.type + end + + should 'a regular user not be able to edit a notification' do + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + post :edit, :notifications => { + :message => "Edited Message", + :active => false, + :type => "EnvironmentNotificationPlugin::DangerNotification" + } + @notification.reload + assert_redirected_to :root + assert_equal "Message", @notification.message + assert @notification.active + end + + should 'a profile admin be able to destroy a notification' do + @community.add_admin(@person) + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + delete :destroy, :id => @notification.id + assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id) + end + + should 'a regular user not be able to destroy a notification' do + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + delete :destroy, :id => @notification.id + + assert_redirected_to :root + assert_not_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id) + end + + should 'a profile admin be able to change Notification status' do + @community.add_admin(@person) + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + post :change_status, :id => @notification.id + assert_redirected_to :action => 'index' + + @notification.reload + assert !@notification.active + end + + should 'a regular user not be able to change Notification status' do + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + post :change_status, :id => @notification.id + assert_redirected_to :root + + @notification.reload + assert @notification.active + end + +end diff --git a/plugins/environment_notification/test/functional/environment_notification_plugin_public_controller_test.rb b/plugins/environment_notification/test/functional/environment_notification_plugin_public_controller_test.rb new file mode 100644 index 0000000..3de433d --- /dev/null +++ b/plugins/environment_notification/test/functional/environment_notification_plugin_public_controller_test.rb @@ -0,0 +1,67 @@ +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' +require( + File.expand_path(File.dirname(__FILE__)) + + '/../../controllers/public/environment_notification_plugin_public_controller' +) + +class EnvironmentNotificationPluginPublicControllerTest < ActionController::TestCase + def setup + @controller = EnvironmentNotificationPluginPublicController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @person = create_user('person').person + + @environment = Environment.default + @environment.enable_plugin('EnvironmentNotificationPlugin') + @environment.save! + + login_as(@person.user.login) + end + + # attr_accessor :person + + should 'a logged in user be able to permanently hide notifications' do + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + post :close_notification, :notification_id => @notification.id + assert_equal "true", @response.body + assert @notification.users.include?(@person.user) + end + + should 'a logged in user be able to momentarily hide notifications' do + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + + @another_notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @environment, + :message => "Another Message", + :active => true, + :type => "EnvironmentNotificationPlugin::WarningNotification" + ) + post :hide_notification, :notification_id => @notification.id + assert_equal "true", @response.body + assert @controller.hide_notifications.include?(@notification.id) + assert !@controller.hide_notifications.include?(@another_notification.id) + end + + should 'not momentarily hide any notification if its id is not found' do + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "EnvironmentNotificationPlugin::DangerNotification" + ) + + post :hide_notification, :notification_id => nil + assert_equal "false", @response.body + assert !@controller.hide_notifications.include?(@notification.id) + end +end diff --git a/plugins/environment_notification/test/functional/home_controller_test.rb b/plugins/environment_notification/test/functional/home_controller_test.rb index 73dfd33..671b0c6 100644 --- a/plugins/environment_notification/test/functional/home_controller_test.rb +++ b/plugins/environment_notification/test/functional/home_controller_test.rb @@ -21,7 +21,7 @@ class HomeControllerTest < ActionController::TestCase 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, + :target => @environment, :message => "Hello, this is a Notification Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -33,7 +33,7 @@ class HomeControllerTest < ActionController::TestCase should 'an active notification not be displayed on home page for unlogged user' do @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Hello, this is a Notification Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -44,7 +44,7 @@ class HomeControllerTest < ActionController::TestCase should 'an active notification be displayed on home page for unlogged user' do @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Hello, this is a Notification Message", :display_to_all_users => true, :active => true, @@ -56,14 +56,14 @@ class HomeControllerTest < ActionController::TestCase should 'only display the notification with display_to_all_users option for unlogged user ' do @notification1 = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Hello, this is an old Notification Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" ) @notification2 = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Hello, this is a new Notification Message", :display_to_all_users => true, :active => true, @@ -78,7 +78,7 @@ class HomeControllerTest < ActionController::TestCase should 'an inactive notification not be displayed on home page' do @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Hello, this is a Notification Message", :active => false, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -91,7 +91,7 @@ class HomeControllerTest < ActionController::TestCase 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, + :target => @environment, :message => "Hello, this is a Notification Message", :active => true, :type => "EnvironmentNotificationPlugin::DangerNotification" @@ -106,7 +106,7 @@ class HomeControllerTest < ActionController::TestCase should 'a notification be displayed with a Popup' do login_as(@person.user.login) @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, + :target => @environment, :message => "Message", :display_popup => true, :active => true, -- libgit2 0.21.2