@@ -62,7 +62,19 module Redmine | |||
|
62 | 62 | |
|
63 | 63 | def save_attachments(attachments, author=User.current) |
|
64 | 64 | if attachments.is_a?(Hash) |
|
65 |
attachments = attachments. |
|
|
65 | attachments = attachments.stringify_keys | |
|
66 | attachments = attachments.to_a.sort {|a, b| | |
|
67 | if a.first.to_i > 0 && b.first.to_i > 0 | |
|
68 | a.first.to_i <=> b.first.to_i | |
|
69 | elsif a.first.to_i > 0 | |
|
70 | 1 | |
|
71 | elsif b.first.to_i > 0 | |
|
72 | -1 | |
|
73 | else | |
|
74 | a.first <=> b.first | |
|
75 | end | |
|
76 | } | |
|
77 | attachments = attachments.map(&:last) | |
|
66 | 78 | end |
|
67 | 79 | if attachments.is_a?(Array) |
|
68 | 80 | attachments.each do |attachment| |
@@ -1888,4 +1888,18 class IssueTest < ActiveSupport::TestCase | |||
|
1888 | 1888 | assert_include 'priority-8', classes |
|
1889 | 1889 | assert_include 'priority-highest', classes |
|
1890 | 1890 | end |
|
1891 | ||
|
1892 | def test_save_attachments_with_hash_should_save_attachments_in_keys_order | |
|
1893 | set_tmp_attachments_directory | |
|
1894 | issue = Issue.generate! | |
|
1895 | issue.save_attachments({ | |
|
1896 | 'p0' => {'file' => mock_file_with_options(:original_filename => 'upload')}, | |
|
1897 | '3' => {'file' => mock_file_with_options(:original_filename => 'bar')}, | |
|
1898 | '1' => {'file' => mock_file_with_options(:original_filename => 'foo')} | |
|
1899 | }) | |
|
1900 | issue.attach_saved_attachments | |
|
1901 | ||
|
1902 | assert_equal 3, issue.reload.attachments.count | |
|
1903 | assert_equal %w(upload foo bar), issue.attachments.map(&:filename) | |
|
1904 | end | |
|
1891 | 1905 | end |
General Comments 0
You need to be logged in to leave comments.
Login now