diff options
Diffstat (limited to 'test')
32 files changed, 326 insertions, 60 deletions
diff --git a/test/fixtures/email_addresses.yml b/test/fixtures/email_addresses.yml new file mode 100644 index 000000000..a83f81e2f --- /dev/null +++ b/test/fixtures/email_addresses.yml @@ -0,0 +1,57 @@ +--- +email_address_001: + id: 1 + user_id: 1 + address: admin@somenet.foo + is_default: true + created_on: 2006-07-19 19:34:07 +02:00 + updated_on: 2006-07-19 19:34:07 +02:00 +email_address_002: + id: 2 + user_id: 2 + address: jsmith@somenet.foo + is_default: true + created_on: 2006-07-19 19:34:07 +02:00 + updated_on: 2006-07-19 19:34:07 +02:00 +email_address_003: + id: 3 + user_id: 3 + address: dlopper@somenet.foo + is_default: true + created_on: 2006-07-19 19:34:07 +02:00 + updated_on: 2006-07-19 19:34:07 +02:00 +email_address_004: + id: 4 + user_id: 4 + address: rhill@somenet.foo + is_default: true + created_on: 2006-07-19 19:34:07 +02:00 + updated_on: 2006-07-19 19:34:07 +02:00 +email_address_005: + id: 5 + user_id: 5 + address: dlopper2@somenet.foo + is_default: true + created_on: 2006-07-19 19:34:07 +02:00 + updated_on: 2006-07-19 19:34:07 +02:00 +email_address_007: + id: 7 + user_id: 7 + address: someone@foo.bar + is_default: true + created_on: 2006-07-19 19:34:07 +02:00 + updated_on: 2006-07-19 19:34:07 +02:00 +email_address_008: + id: 8 + user_id: 8 + address: miscuser8@foo.bar + is_default: true + created_on: 2006-07-19 19:34:07 +02:00 + updated_on: 2006-07-19 19:34:07 +02:00 +email_address_009: + id: 9 + user_id: 9 + address: miscuser9@foo.bar + is_default: true + created_on: 2006-07-19 19:34:07 +02:00 + updated_on: 2006-07-19 19:34:07 +02:00 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 9adab5edd..986ed5d67 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,22 +1,4 @@ --- -users_004: - created_on: 2006-07-19 19:34:07 +02:00 - status: 1 - last_login_on: - language: en - # password = foo - salt: 3126f764c3c5ac61cbfc103f25f934cf - hashed_password: 9e4dd7eeb172c12a0691a6d9d3a269f7e9fe671b - updated_on: 2006-07-19 19:34:07 +02:00 - admin: false - mail: rhill@somenet.foo - lastname: Hill - firstname: Robert - id: 4 - auth_source_id: - mail_notification: all - login: rhill - type: User users_001: created_on: 2006-07-19 19:12:21 +02:00 status: 1 @@ -27,7 +9,6 @@ users_001: hashed_password: b5b6ff9543bf1387374cdfa27a54c96d236a7150 updated_on: 2006-07-19 22:57:52 +02:00 admin: true - mail: admin@somenet.foo lastname: Admin firstname: Redmine id: 1 @@ -45,7 +26,6 @@ users_002: hashed_password: bfbe06043353a677d0215b26a5800d128d5413bc updated_on: 2006-07-19 22:42:15 +02:00 admin: false - mail: jsmith@somenet.foo lastname: Smith firstname: John id: 2 @@ -63,7 +43,6 @@ users_003: hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed updated_on: 2006-07-19 19:33:19 +02:00 admin: false - mail: dlopper@somenet.foo lastname: Lopper firstname: Dave id: 3 @@ -71,6 +50,23 @@ users_003: mail_notification: all login: dlopper type: User +users_004: + created_on: 2006-07-19 19:34:07 +02:00 + status: 1 + last_login_on: + language: en + # password = foo + salt: 3126f764c3c5ac61cbfc103f25f934cf + hashed_password: 9e4dd7eeb172c12a0691a6d9d3a269f7e9fe671b + updated_on: 2006-07-19 19:34:07 +02:00 + admin: false + lastname: Hill + firstname: Robert + id: 4 + auth_source_id: + mail_notification: all + login: rhill + type: User users_005: id: 5 created_on: 2006-07-19 19:33:19 +02:00 @@ -81,7 +77,6 @@ users_005: hashed_password: 1 updated_on: 2006-07-19 19:33:19 +02:00 admin: false - mail: dlopper2@somenet.foo lastname: Lopper2 firstname: Dave2 auth_source_id: @@ -97,7 +92,6 @@ users_006: hashed_password: 1 updated_on: 2006-07-19 19:33:19 +02:00 admin: false - mail: '' lastname: Anonymous firstname: '' auth_source_id: @@ -116,7 +110,6 @@ users_007: hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed updated_on: 2006-07-19 19:33:19 +02:00 admin: false - mail: someone@foo.bar lastname: One firstname: Some auth_source_id: @@ -134,7 +127,6 @@ users_008: hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed updated_on: 2006-07-19 19:33:19 +02:00 admin: false - mail: miscuser8@foo.bar lastname: Misc firstname: User auth_source_id: @@ -150,7 +142,6 @@ users_009: hashed_password: 1 updated_on: 2006-07-19 19:33:19 +02:00 admin: false - mail: miscuser9@foo.bar lastname: Misc firstname: User auth_source_id: diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index 00a503051..bef3e4284 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class AdminControllerTest < ActionController::TestCase - fixtures :projects, :users, :roles + fixtures :projects, :users, :email_addresses, :roles def setup User.current = nil diff --git a/test/functional/documents_controller_test.rb b/test/functional/documents_controller_test.rb index 065922a56..c53142b5b 100644 --- a/test/functional/documents_controller_test.rb +++ b/test/functional/documents_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class DocumentsControllerTest < ActionController::TestCase - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations, :groups_users, :attachments diff --git a/test/functional/email_addresses_controller_test.rb b/test/functional/email_addresses_controller_test.rb new file mode 100644 index 000000000..7c52d9c1d --- /dev/null +++ b/test/functional/email_addresses_controller_test.rb @@ -0,0 +1,144 @@ +# Redmine - project management software +# Copyright (C) 2006-2015 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../test_helper', __FILE__) + +class EmailAddressesControllerTest < ActionController::TestCase + fixtures :users, :email_addresses + + def setup + User.current = nil + end + + def test_index_with_no_additional_emails + @request.session[:user_id] = 2 + get :index, :user_id => 2 + assert_response :success + assert_template 'index' + end + + def test_index_with_additional_emails + @request.session[:user_id] = 2 + EmailAddress.create!(:user_id => 2, :address => 'another@somenet.foo') + + get :index, :user_id => 2 + assert_response :success + assert_template 'index' + assert_select '.email', :text => 'another@somenet.foo' + end + + def test_index_with_additional_emails_as_js + @request.session[:user_id] = 2 + EmailAddress.create!(:user_id => 2, :address => 'another@somenet.foo') + + xhr :get, :index, :user_id => 2 + assert_response :success + assert_template 'index' + assert_include 'another@somenet.foo', response.body + end + + def test_index_by_admin_should_be_allowed + @request.session[:user_id] = 1 + get :index, :user_id => 2 + assert_response :success + assert_template 'index' + end + + def test_index_by_another_user_should_be_denied + @request.session[:user_id] = 3 + get :index, :user_id => 2 + assert_response 403 + end + + def test_create + @request.session[:user_id] = 2 + assert_difference 'EmailAddress.count' do + post :create, :user_id => 2, :email_address => {:address => 'another@somenet.foo'} + assert_response 302 + assert_redirected_to '/users/2/email_addresses' + end + email = EmailAddress.order('id DESC').first + assert_equal 2, email.user_id + assert_equal 'another@somenet.foo', email.address + end + + def test_create_as_js + @request.session[:user_id] = 2 + assert_difference 'EmailAddress.count' do + xhr :post, :create, :user_id => 2, :email_address => {:address => 'another@somenet.foo'} + assert_response 200 + end + end + + def test_create_with_failure + @request.session[:user_id] = 2 + assert_no_difference 'EmailAddress.count' do + post :create, :user_id => 2, :email_address => {:address => 'invalid'} + assert_response 200 + end + end + + def test_update + @request.session[:user_id] = 2 + email = EmailAddress.create!(:user_id => 2, :address => 'another@somenet.foo') + + put :update, :user_id => 2, :id => email.id, :notify => '0' + assert_response 302 + + assert_equal false, email.reload.notify + end + + def test_update_as_js + @request.session[:user_id] = 2 + email = EmailAddress.create!(:user_id => 2, :address => 'another@somenet.foo') + + xhr :put, :update, :user_id => 2, :id => email.id, :notify => '0' + assert_response 200 + + assert_equal false, email.reload.notify + end + + def test_destroy + @request.session[:user_id] = 2 + email = EmailAddress.create!(:user_id => 2, :address => 'another@somenet.foo') + + assert_difference 'EmailAddress.count', -1 do + delete :destroy, :user_id => 2, :id => email.id + assert_response 302 + assert_redirected_to '/users/2/email_addresses' + end + end + + def test_destroy_as_js + @request.session[:user_id] = 2 + email = EmailAddress.create!(:user_id => 2, :address => 'another@somenet.foo') + + assert_difference 'EmailAddress.count', -1 do + xhr :delete, :destroy, :user_id => 2, :id => email.id + assert_response 200 + end + end + + def test_should_not_destroy_default + @request.session[:user_id] = 2 + + assert_no_difference 'EmailAddress.count' do + delete :destroy, :user_id => 2, :id => User.find(2).email_address.id + assert_response 404 + end + end +end diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 04ebec0df..86c5cdb16 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -19,7 +19,7 @@ require File.expand_path('../../test_helper', __FILE__) class IssuesControllerTest < ActionController::TestCase fixtures :projects, - :users, + :users, :email_addresses, :roles, :members, :member_roles, diff --git a/test/functional/issues_custom_fields_visibility_test.rb b/test/functional/issues_custom_fields_visibility_test.rb index 7d8cfa9a4..6e9ec5f11 100644 --- a/test/functional/issues_custom_fields_visibility_test.rb +++ b/test/functional/issues_custom_fields_visibility_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class IssuesCustomFieldsVisibilityTest < ActionController::TestCase tests IssuesController fixtures :projects, - :users, + :users, :email_addresses, :roles, :members, :member_roles, diff --git a/test/functional/mail_handler_controller_test.rb b/test/functional/mail_handler_controller_test.rb index 91ae34122..3487d5eb2 100644 --- a/test/functional/mail_handler_controller_test.rb +++ b/test/functional/mail_handler_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class MailHandlerControllerTest < ActionController::TestCase - fixtures :users, :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :issue_statuses, + fixtures :users, :email_addresses, :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :issue_statuses, :trackers, :projects_trackers, :enumerations FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb index 9669379d9..cc61e5a14 100644 --- a/test/functional/messages_controller_test.rb +++ b/test/functional/messages_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class MessagesControllerTest < ActionController::TestCase - fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules + fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, :boards, :messages, :enabled_modules def setup User.current = nil diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index 32317cd7c..5f14c5791 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class MyControllerTest < ActionController::TestCase - fixtures :users, :user_preferences, :roles, :projects, :members, :member_roles, + fixtures :users, :email_addresses, :user_preferences, :roles, :projects, :members, :member_roles, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources def setup diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb index 554d1b290..b957dde6e 100644 --- a/test/functional/news_controller_test.rb +++ b/test/functional/news_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class NewsControllerTest < ActionController::TestCase - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :news, :comments, :attachments diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 379fe04da..fa86f1a0f 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class ProjectsControllerTest < ActionController::TestCase - fixtures :projects, :versions, :users, :roles, :members, + fixtures :projects, :versions, :users, :email_addresses, :roles, :members, :member_roles, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, diff --git a/test/functional/repositories_bazaar_controller_test.rb b/test/functional/repositories_bazaar_controller_test.rb index 0374559ba..cde2d1cf7 100644 --- a/test/functional/repositories_bazaar_controller_test.rb +++ b/test/functional/repositories_bazaar_controller_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoriesBazaarControllerTest < ActionController::TestCase tests RepositoriesController - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :repositories, :enabled_modules REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 4dedaf0f0..14f6a6355 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoriesControllerTest < ActionController::TestCase - fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb index 094d027e9..ba35e1ea0 100644 --- a/test/functional/repositories_cvs_controller_test.rb +++ b/test/functional/repositories_cvs_controller_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoriesCvsControllerTest < ActionController::TestCase tests RepositoriesController - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :repositories, :enabled_modules REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s diff --git a/test/functional/repositories_darcs_controller_test.rb b/test/functional/repositories_darcs_controller_test.rb index dd41f51ab..9df8b2a24 100644 --- a/test/functional/repositories_darcs_controller_test.rb +++ b/test/functional/repositories_darcs_controller_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoriesDarcsControllerTest < ActionController::TestCase tests RepositoriesController - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :repositories, :enabled_modules REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s diff --git a/test/functional/repositories_filesystem_controller_test.rb b/test/functional/repositories_filesystem_controller_test.rb index 0de6f6c61..34333cf89 100644 --- a/test/functional/repositories_filesystem_controller_test.rb +++ b/test/functional/repositories_filesystem_controller_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoriesFilesystemControllerTest < ActionController::TestCase tests RepositoriesController - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :repositories, :enabled_modules REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb index f085661dd..c6d7ada9b 100644 --- a/test/functional/repositories_git_controller_test.rb +++ b/test/functional/repositories_git_controller_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoriesGitControllerTest < ActionController::TestCase tests RepositoriesController - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :repositories, :enabled_modules REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb index e4485b91c..734fe0e23 100644 --- a/test/functional/repositories_mercurial_controller_test.rb +++ b/test/functional/repositories_mercurial_controller_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoriesMercurialControllerTest < ActionController::TestCase tests RepositoriesController - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :repositories, :enabled_modules REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb index 9afced4e4..664330ff4 100644 --- a/test/functional/repositories_subversion_controller_test.rb +++ b/test/functional/repositories_subversion_controller_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoriesSubversionControllerTest < ActionController::TestCase tests RepositoriesController - fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 2fc48dbcc..b34c80945 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class UsersControllerTest < ActionController::TestCase include Redmine::I18n - fixtures :users, :projects, :members, :member_roles, :roles, + fixtures :users, :email_addresses, :projects, :members, :member_roles, :roles, :custom_fields, :custom_values, :groups_users, :auth_sources, :enabled_modules, diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index fb9537a04..9bffe66c7 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class WikiControllerTest < ActionController::TestCase - fixtures :projects, :users, :roles, :members, :member_roles, + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments, :issues, :issue_statuses diff --git a/test/integration/account_test.rb b/test/integration/account_test.rb index bf458b734..7f2f0e4ff 100644 --- a/test/integration/account_test.rb +++ b/test/integration/account_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class AccountTest < Redmine::IntegrationTest - fixtures :users, :roles + fixtures :users, :email_addresses, :roles def test_login get "/my/page" diff --git a/test/integration/api_test/users_test.rb b/test/integration/api_test/users_test.rb index f1a0e1055..d8d78ad0e 100644 --- a/test/integration/api_test/users_test.rb +++ b/test/integration/api_test/users_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../../test_helper', __FILE__) class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base - fixtures :users, :members, :member_roles, :roles, :projects + fixtures :users, :email_addresses, :members, :member_roles, :roles, :projects test "GET /users.xml should return users" do get '/users.xml', {}, credentials('admin') diff --git a/test/integration/issues_test.rb b/test/integration/issues_test.rb index d26281172..981fdb760 100644 --- a/test/integration/issues_test.rb +++ b/test/integration/issues_test.rb @@ -19,7 +19,7 @@ require File.expand_path('../../test_helper', __FILE__) class IssuesTest < Redmine::IntegrationTest fixtures :projects, - :users, + :users, :email_addresses, :roles, :members, :member_roles, diff --git a/test/integration/users_test.rb b/test/integration/users_test.rb index ea7f06c12..1ae2f27d6 100644 --- a/test/integration/users_test.rb +++ b/test/integration/users_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class UsersTest < Redmine::IntegrationTest - fixtures :users + fixtures :users, :email_addresses def test_destroy_should_not_accept_get_requests assert_no_difference 'User.count' do diff --git a/test/unit/document_test.rb b/test/unit/document_test.rb index 98d15c0e0..50decb7c7 100644 --- a/test/unit/document_test.rb +++ b/test/unit/document_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class DocumentTest < ActiveSupport::TestCase fixtures :projects, :enumerations, :documents, :attachments, :enabled_modules, - :users, :members, :member_roles, :roles, + :users, :email_addresses, :members, :member_roles, :roles, :groups_users def test_create diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 03208d397..0384dfb0e 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class IssueTest < ActiveSupport::TestCase - fixtures :projects, :users, :members, :member_roles, :roles, + fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, :groups_users, :trackers, :projects_trackers, :enabled_modules, diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index a8a7846ba..bc7e0a0d0 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -223,6 +223,17 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal 1, issue.watcher_user_ids.size end + def test_add_issue_from_additional_email_address + user = User.find(2) + user.mail = 'mainaddress@somenet.foo' + user.save! + EmailAddress.create!(:user => user, :address => 'jsmith@somenet.foo') + + issue = submit_email('ticket_on_given_project.eml') + assert issue + assert_equal user, issue.author + end + def test_add_issue_by_unknown_user assert_no_difference 'User.count' do assert_equal false, diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 9728387a4..b020e5303 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../test_helper', __FILE__) class MailerTest < ActiveSupport::TestCase include Redmine::I18n include ActionDispatch::Assertions::SelectorAssertions - fixtures :projects, :enabled_modules, :issues, :users, :members, + fixtures :projects, :enabled_modules, :issues, :users, :email_addresses, :members, :member_roles, :roles, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :projects_trackers, @@ -298,6 +298,14 @@ class MailerTest < ActiveSupport::TestCase assert last_email.bcc.include?('dlopper@somenet.foo') end + def test_issue_add_should_send_mail_to_all_user_email_address + EmailAddress.create!(:user_id => 3, :address => 'otheremail@somenet.foo') + issue = Issue.find(1) + assert Mailer.deliver_issue_add(issue) + assert last_email.bcc.include?('dlopper@somenet.foo') + assert last_email.bcc.include?('otheremail@somenet.foo') + end + test "#issue_add should not notify project members that are not allow to view the issue" do issue = Issue.find(1) Role.find(2).remove_permission!(:view_issues) @@ -771,6 +779,30 @@ class MailerTest < ActiveSupport::TestCase ActionMailer::Base.delivery_method = :test end + def test_email_addresses_should_keep_addresses + assert_equal ["foo@example.net"], + Mailer.email_addresses("foo@example.net") + + assert_equal ["foo@example.net", "bar@example.net"], + Mailer.email_addresses(["foo@example.net", "bar@example.net"]) + end + + def test_email_addresses_should_replace_users_with_their_email_addresses + assert_equal ["admin@somenet.foo"], + Mailer.email_addresses(User.find(1)) + + assert_equal ["admin@somenet.foo", "jsmith@somenet.foo"], + Mailer.email_addresses(User.where(:id => [1,2])).sort + end + + def test_email_addresses_should_include_notified_emails_addresses_only + EmailAddress.create!(:user_id => 2, :address => "another@somenet.foo", :notify => false) + EmailAddress.create!(:user_id => 2, :address => "another2@somenet.foo") + + assert_equal ["another2@somenet.foo", "jsmith@somenet.foo"], + Mailer.email_addresses(User.find(2)).sort + end + private def last_email diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index fbe35f253..429f2908b 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class UserTest < ActiveSupport::TestCase - fixtures :users, :members, :projects, :roles, :member_roles, :auth_sources, + fixtures :users, :email_addresses, :members, :projects, :roles, :member_roles, :auth_sources, :trackers, :issue_statuses, :projects_trackers, :watchers, @@ -57,11 +57,41 @@ class UserTest < ActiveSupport::TestCase assert_equal "foo@bar.com", u.mail end - def test_mail_validation - u = User.new + def test_should_create_email_address + u = User.new(:firstname => "new", :lastname => "user") + u.login = "create_email_address" + u.mail = "defaultemail@somenet.foo" + assert u.save + u.reload + assert u.email_address + assert_equal "defaultemail@somenet.foo", u.email_address.address + assert_equal true, u.email_address.is_default + assert_equal true, u.email_address.notify + end + + def test_should_not_create_user_without_mail + set_language_if_valid 'en' + u = User.new(:firstname => "new", :lastname => "user") + u.login = "user_without_mail" + assert !u.save + assert_equal ["Email #{I18n.translate('activerecord.errors.messages.blank')}"], u.errors.full_messages + end + + def test_should_not_create_user_with_blank_mail + set_language_if_valid 'en' + u = User.new(:firstname => "new", :lastname => "user") + u.login = "user_with_blank_mail" + u.mail = '' + assert !u.save + assert_equal ["Email #{I18n.translate('activerecord.errors.messages.blank')}"], u.errors.full_messages + end + + def test_should_not_update_user_with_blank_mail + set_language_if_valid 'en' + u = User.find(2) u.mail = '' - assert !u.valid? - assert_include I18n.translate('activerecord.errors.messages.blank'), u.errors[:mail] + assert !u.save + assert_equal ["Email #{I18n.translate('activerecord.errors.messages.blank')}"], u.errors.full_messages end def test_login_length_validation @@ -151,6 +181,7 @@ class UserTest < ActiveSupport::TestCase end def test_mail_uniqueness_should_not_be_case_sensitive + set_language_if_valid 'en' u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") u.login = 'newuser1' u.password, u.password_confirmation = "password", "password" @@ -160,7 +191,7 @@ class UserTest < ActiveSupport::TestCase u.login = 'newuser2' u.password, u.password_confirmation = "password", "password" assert !u.save - assert_include I18n.translate('activerecord.errors.messages.taken'), u.errors[:mail] + assert_include "Email #{I18n.translate('activerecord.errors.messages.taken')}", u.errors.full_messages end def test_update @@ -677,7 +708,7 @@ class UserTest < ActiveSupport::TestCase assert_kind_of AnonymousUser, anon1 anon2 = AnonymousUser.create( :lastname => 'Anonymous', :firstname => '', - :mail => '', :login => '', :status => 0) + :login => '', :status => 0) assert_equal 1, anon2.errors.count end diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index f10276ccb..e7417332c 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class WatcherTest < ActiveSupport::TestCase - fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, + fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, :enabled_modules, :issues, :issue_statuses, :enumerations, :trackers, :projects_trackers, :boards, :messages, :wikis, :wiki_pages, |