diff --git a/app/models/import.rb b/app/models/import.rb index d2c53baac..01fe72d47 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -66,7 +66,8 @@ class Import < ActiveRecord::Base 'separator' => separator, 'wrapper' => wrapper, 'encoding' => encoding, - 'date_format' => date_format + 'date_format' => date_format, + 'mail_notification' => '0' ) end diff --git a/app/models/issue_import.rb b/app/models/issue_import.rb index ad04c0be5..a2925be32 100644 --- a/app/models/issue_import.rb +++ b/app/models/issue_import.rb @@ -77,7 +77,7 @@ class IssueImport < Import def build_object(row, item) issue = Issue.new issue.author = user - issue.notify = false + issue.notify = !!ActiveRecord::Type::Boolean.new.cast(settings['mail_notification']) tracker_id = nil if tracker diff --git a/app/views/imports/settings.html.erb b/app/views/imports/settings.html.erb index 6edfb10af..be504d30d 100644 --- a/app/views/imports/settings.html.erb +++ b/app/views/imports/settings.html.erb @@ -21,6 +21,12 @@ <%= select_tag 'import_settings[date_format]', options_for_select(date_format_options, @import.settings['date_format']) %>

+
+

+ + <%= hidden_field_tag 'import_settings[mail_notification]', '0', :id => nil %> + <%= check_box_tag 'import_settings[mail_notification]', '1', "#{@import.settings['mail_notification']}" == '1' %> +

<%= submit_tag l(:label_next).html_safe + " »".html_safe, :name => nil %>

<% end %> diff --git a/test/functional/imports_controller_test.rb b/test/functional/imports_controller_test.rb index 2802d1524..52f991dbb 100644 --- a/test/functional/imports_controller_test.rb +++ b/test/functional/imports_controller_test.rb @@ -172,7 +172,7 @@ class ImportsControllerTest < Redmine::ControllerTest :mapping => { :project_id => '1', :tracker_id => '2', - :subject => '0'} + :subject => '0'} } } assert_redirected_to "/imports/#{import.to_param}/run" @@ -183,7 +183,7 @@ class ImportsControllerTest < Redmine::ControllerTest assert_equal '2', mapping['tracker_id'] assert_equal '0', mapping['subject'] end - + def test_get_run import = generate_import_with_mapping @@ -193,7 +193,7 @@ class ImportsControllerTest < Redmine::ControllerTest assert_response :success assert_select '#import-progress' end - + def test_post_run_should_import_the_file import = generate_import_with_mapping @@ -234,6 +234,44 @@ class ImportsControllerTest < Redmine::ControllerTest assert_equal ["Child of existing issue", "Child 1", "First"], issues.map(&:subject) end + def test_post_run_with_mail_notification + import = generate_import + + post :settings, :params => { + :id => import, + :import_settings => { + :separator => ';', + :wrapper => '"', + :encoding => 'ISO-8859-1', + :mail_notification => '1', + :mapping => { + :project_id => '1', + :tracker => '13', + :subject => '1', + :assigned_to => '11', + }, + }, + } + + ActionMailer::Base.deliveries.clear + assert_difference 'Issue.count', 3 do + post :run, :params => { + :id => import, + } + assert_response :found + end + actual_countof_mail = ActionMailer::Base.deliveries.size + assert_not_equal 0, actual_countof_mail + + import.reload + issue_ids = import.items.collect(&:obj_id) + expect_countof_user = + Issue.where(:id => issue_ids).inject(0) do |_, issue| + _ + (issue.notified_users | issue.notified_watchers).size + end + assert_equal expect_countof_user, actual_countof_mail + end + def test_show_without_errors import = generate_import_with_mapping import.run