Defect #33459 » fix-33459.patch
| app/helpers/journals_helper.rb | ||
|---|---|---|
| 22 | 22 |
# Returns the attachments of a journal that are displayed as thumbnails |
| 23 | 23 |
def journal_thumbnail_attachments(journal) |
| 24 | 24 |
ids = journal.details.select {|d| d.property == 'attachment' && d.value.present?}.map(&:prop_key)
|
| 25 |
ids.any? ? Attachment.where(:id => ids).select(&:thumbnailable?) : [] |
|
| 25 |
ids.any? ? Attachment.where(:id => ids).select(&:thumbnailable?).sort_by{ |o| ids.index(o.id.to_s)} : []
|
|
| 26 | 26 |
end |
| 27 | 27 | |
| 28 | 28 |
# Returns the action links for an issue journal |
| test/helpers/journals_helper_test.rb | ||
|---|---|---|
| 49 | 49 |
assert_kind_of Attachment, thumbnails.first |
| 50 | 50 |
assert_equal 'image.png', thumbnails.first.filename |
| 51 | 51 |
end |
| 52 | ||
| 53 |
def test_journal_thumbnail_attachments_should_be_in_the_same_order_as_the_journal_details |
|
| 54 |
skip unless convert_installed? |
|
| 55 |
set_tmp_attachments_directory |
|
| 56 |
issue = Issue.generate! |
|
| 57 | ||
| 58 |
# If the order of Attachment id and journal.details is different, the order will be the same as journal_details. |
|
| 59 |
attachment1 = Attachment.generate!(:file => mock_file_with_options(:original_filename => 'image1.png'), :author => User.find(1)) |
|
| 60 |
attachment2 = Attachment.generate!(:file => mock_file_with_options(:original_filename => 'image2.png'), :author => User.find(1)) |
|
| 61 |
journal = Journal.create!(:journalized => issue, :user_id => 1) |
|
| 62 |
JournalDetail.create!( |
|
| 63 |
:journal => journal, :property => 'attachment', |
|
| 64 |
:prop_key => attachment2.id.to_s, |
|
| 65 |
:value => 'image2.png' |
|
| 66 |
) |
|
| 67 |
JournalDetail.create!( |
|
| 68 |
:journal => journal, :property => 'attachment', |
|
| 69 |
:prop_key => attachment1.id.to_s, |
|
| 70 |
:value => 'image1.png' |
|
| 71 |
) |
|
| 72 |
journal.reload |
|
| 73 |
thumbnails = journal_thumbnail_attachments(journal) |
|
| 74 |
assert_equal 2, thumbnails.count |
|
| 75 |
assert_equal 2, journal.details.count |
|
| 76 |
assert_equal journal.details.map(&:value), thumbnails.map(&:filename) |
|
| 77 |
end |
|
| 52 | 78 |
end |
- « Previous
- 1
- 2
- Next »