Feature #22771 » 22771-add-option-email-notification.patch
| app/models/import.rb | ||
|---|---|---|
| 66 | 66 |
'separator' => separator, |
| 67 | 67 |
'wrapper' => wrapper, |
| 68 | 68 |
'encoding' => encoding, |
| 69 |
'date_format' => date_format |
|
| 69 |
'date_format' => date_format, |
|
| 70 |
'mail_notification' => '0' |
|
| 70 | 71 |
) |
| 71 | 72 |
end |
| 72 | 73 | |
| app/models/issue_import.rb | ||
|---|---|---|
| 77 | 77 |
def build_object(row, item) |
| 78 | 78 |
issue = Issue.new |
| 79 | 79 |
issue.author = user |
| 80 |
issue.notify = false
|
|
| 80 |
issue.notify = !!ActiveRecord::Type::Boolean.new.cast(settings['mail_notification'])
|
|
| 81 | 81 | |
| 82 | 82 |
tracker_id = nil |
| 83 | 83 |
if tracker |
| app/views/imports/settings.html.erb | ||
|---|---|---|
| 21 | 21 |
<label for="import_settings_date_format"><%= l(:setting_date_format) %></label> |
| 22 | 22 |
<%= select_tag 'import_settings[date_format]', options_for_select(date_format_options, @import.settings['date_format']) %> |
| 23 | 23 |
</p> |
| 24 |
<hr/> |
|
| 25 |
<p> |
|
| 26 |
<label for="import_settings_mail_notification"><%= l(:field_mail_notification) %></label> |
|
| 27 |
<%= hidden_field_tag 'import_settings[mail_notification]', '0', :id => nil %> |
|
| 28 |
<%= check_box_tag 'import_settings[mail_notification]', '1', "#{@import.settings['mail_notification']}" == '1' %>
|
|
| 29 |
</p> |
|
| 24 | 30 |
</fieldset> |
| 25 | 31 |
<p><%= submit_tag l(:label_next).html_safe + " »".html_safe, :name => nil %></p> |
| 26 | 32 |
<% end %> |
| test/functional/imports_controller_test.rb | ||
|---|---|---|
| 172 | 172 |
:mapping => {
|
| 173 | 173 |
:project_id => '1', |
| 174 | 174 |
:tracker_id => '2', |
| 175 |
:subject => '0'}
|
|
| 175 |
:subject => '0'} |
|
| 176 | 176 |
} |
| 177 | 177 |
} |
| 178 | 178 |
assert_redirected_to "/imports/#{import.to_param}/run"
|
| ... | ... | |
| 183 | 183 |
assert_equal '2', mapping['tracker_id'] |
| 184 | 184 |
assert_equal '0', mapping['subject'] |
| 185 | 185 |
end |
| 186 |
|
|
| 186 | ||
| 187 | 187 |
def test_get_run |
| 188 | 188 |
import = generate_import_with_mapping |
| 189 | 189 | |
| ... | ... | |
| 193 | 193 |
assert_response :success |
| 194 | 194 |
assert_select '#import-progress' |
| 195 | 195 |
end |
| 196 |
|
|
| 196 | ||
| 197 | 197 |
def test_post_run_should_import_the_file |
| 198 | 198 |
import = generate_import_with_mapping |
| 199 | 199 | |
| ... | ... | |
| 234 | 234 |
assert_equal ["Child of existing issue", "Child 1", "First"], issues.map(&:subject) |
| 235 | 235 |
end |
| 236 | 236 | |
| 237 |
def test_post_run_with_mail_notification |
|
| 238 |
import = generate_import |
|
| 239 | ||
| 240 |
post :settings, :params => {
|
|
| 241 |
:id => import, |
|
| 242 |
:import_settings => {
|
|
| 243 |
:separator => ';', |
|
| 244 |
:wrapper => '"', |
|
| 245 |
:encoding => 'ISO-8859-1', |
|
| 246 |
:mail_notification => '1', |
|
| 247 |
:mapping => {
|
|
| 248 |
:project_id => '1', |
|
| 249 |
:tracker => '13', |
|
| 250 |
:subject => '1', |
|
| 251 |
:assigned_to => '11', |
|
| 252 |
}, |
|
| 253 |
}, |
|
| 254 |
} |
|
| 255 | ||
| 256 |
ActionMailer::Base.deliveries.clear |
|
| 257 |
assert_difference 'Issue.count', 3 do |
|
| 258 |
post :run, :params => {
|
|
| 259 |
:id => import, |
|
| 260 |
} |
|
| 261 |
assert_response :found |
|
| 262 |
end |
|
| 263 |
actual_countof_mail = ActionMailer::Base.deliveries.size |
|
| 264 |
assert_not_equal 0, actual_countof_mail |
|
| 265 | ||
| 266 |
import.reload |
|
| 267 |
issue_ids = import.items.collect(&:obj_id) |
|
| 268 |
expect_countof_user = |
|
| 269 |
Issue.where(:id => issue_ids).inject(0) do |_, issue| |
|
| 270 |
_ + (issue.notified_users | issue.notified_watchers).size |
|
| 271 |
end |
|
| 272 |
assert_equal expect_countof_user, actual_countof_mail |
|
| 273 |
end |
|
| 274 | ||
| 237 | 275 |
def test_show_without_errors |
| 238 | 276 |
import = generate_import_with_mapping |
| 239 | 277 |
import.run |