@@ -537,7 +537,7 module ApplicationHelper | |||||
537 | # when using an image link, try to use an attachment, if possible |
|
537 | # when using an image link, try to use an attachment, if possible | |
538 | if options[:attachments] || (obj && obj.respond_to?(:attachments)) |
|
538 | if options[:attachments] || (obj && obj.respond_to?(:attachments)) | |
539 | attachments = nil |
|
539 | attachments = nil | |
540 | text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| |
|
540 | text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| | |
541 | filename, ext, alt, alttext = $1.downcase, $2, $3, $4 |
|
541 | filename, ext, alt, alttext = $1.downcase, $2, $3, $4 | |
542 | attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse |
|
542 | attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse | |
543 | # search for the picture in attachments |
|
543 | # search for the picture in attachments |
@@ -123,7 +123,7 class Attachment < ActiveRecord::Base | |||||
123 | end |
|
123 | end | |
124 |
|
124 | |||
125 | def image? |
|
125 | def image? | |
126 |
self.filename =~ /\.(jpe |
|
126 | self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png)$/i | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | def is_text? |
|
129 | def is_text? |
@@ -77,6 +77,17 class ActiveSupport::TestCase | |||||
77 | self.class.mock_file |
|
77 | self.class.mock_file | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
|
80 | def mock_file_with_options(options={}) | |||
|
81 | file = '' | |||
|
82 | file.stubs(:size).returns(32) | |||
|
83 | original_filename = options[:original_filename] || nil | |||
|
84 | file.stubs(:original_filename).returns(original_filename) | |||
|
85 | content_type = options[:content_type] || nil | |||
|
86 | file.stubs(:content_type).returns(content_type) | |||
|
87 | file.stubs(:read).returns(false) | |||
|
88 | file | |||
|
89 | end | |||
|
90 | ||||
80 | # Use a temporary directory for attachment related tests |
|
91 | # Use a temporary directory for attachment related tests | |
81 | def set_tmp_attachments_directory |
|
92 | def set_tmp_attachments_directory | |
82 | Dir.mkdir "#{Rails.root}/tmp/test" unless File.directory?("#{Rails.root}/tmp/test") |
|
93 | Dir.mkdir "#{Rails.root}/tmp/test" unless File.directory?("#{Rails.root}/tmp/test") |
@@ -129,6 +129,59 RAW | |||||
129 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } |
|
129 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
|
132 | def test_attached_images_filename_extension | |||
|
133 | set_tmp_attachments_directory | |||
|
134 | a1 = Attachment.new( | |||
|
135 | :container => Issue.find(1), | |||
|
136 | :file => mock_file_with_options({:original_filename => "testtest.JPG"}), | |||
|
137 | :author => User.find(1)) | |||
|
138 | assert a1.save | |||
|
139 | assert_equal "testtest.JPG", a1.filename | |||
|
140 | assert_equal "image/jpeg", a1.content_type | |||
|
141 | assert a1.image? | |||
|
142 | ||||
|
143 | a2 = Attachment.new( | |||
|
144 | :container => Issue.find(1), | |||
|
145 | :file => mock_file_with_options({:original_filename => "testtest.jpeg"}), | |||
|
146 | :author => User.find(1)) | |||
|
147 | assert a2.save | |||
|
148 | assert_equal "testtest.jpeg", a2.filename | |||
|
149 | assert_equal "image/jpeg", a2.content_type | |||
|
150 | assert a2.image? | |||
|
151 | ||||
|
152 | a3 = Attachment.new( | |||
|
153 | :container => Issue.find(1), | |||
|
154 | :file => mock_file_with_options({:original_filename => "testtest.JPE"}), | |||
|
155 | :author => User.find(1)) | |||
|
156 | assert a3.save | |||
|
157 | assert_equal "testtest.JPE", a3.filename | |||
|
158 | assert_equal "image/jpeg", a3.content_type | |||
|
159 | assert a3.image? | |||
|
160 | ||||
|
161 | a4 = Attachment.new( | |||
|
162 | :container => Issue.find(1), | |||
|
163 | :file => mock_file_with_options({:original_filename => "Testtest.BMP"}), | |||
|
164 | :author => User.find(1)) | |||
|
165 | assert a4.save | |||
|
166 | assert_equal "Testtest.BMP", a4.filename | |||
|
167 | assert_equal "image/x-ms-bmp", a4.content_type | |||
|
168 | assert a4.image? | |||
|
169 | ||||
|
170 | to_test = { | |||
|
171 | 'Inline image: !testtest.jpg!' => | |||
|
172 | 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '" alt="" />', | |||
|
173 | 'Inline image: !testtest.jpeg!' => | |||
|
174 | 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />', | |||
|
175 | 'Inline image: !testtest.jpe!' => | |||
|
176 | 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '" alt="" />', | |||
|
177 | 'Inline image: !testtest.bmp!' => | |||
|
178 | 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '" alt="" />', | |||
|
179 | } | |||
|
180 | ||||
|
181 | attachments = [a1, a2, a3, a4] | |||
|
182 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } | |||
|
183 | end | |||
|
184 | ||||
132 | def test_textile_external_links |
|
185 | def test_textile_external_links | |
133 | to_test = { |
|
186 | to_test = { | |
134 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', |
|
187 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', |
General Comments 0
You need to be logged in to leave comments.
Login now