Skip to content

Commit

Permalink
Merge pull request thoughtbot#407 from reenhanced/paperclip
Browse files Browse the repository at this point in the history
---

When an attachment has an uppercase extension and a default style, the to_s and url methods do not match when a size is not passed in. This contains the test and fix for this issue.
  • Loading branch information
Jon Yurek committed Feb 16, 2011
2 parents f89ab82 + 0708cd4 commit 6a10b35
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/paperclip/attachment.rb
Expand Up @@ -134,7 +134,7 @@ def path style_name = default_style
end

# Alias to +url+
def to_s style_name = nil
def to_s style_name = default_style
url(style_name)
end

Expand Down
40 changes: 40 additions & 0 deletions test/attachment_test.rb
Expand Up @@ -558,6 +558,46 @@ def do_after_all; end
assert_equal "sheep_say_bæ.png", @dummy.avatar.original_filename
end
end

context "Attachment with uppercase extension and a default style" do
setup do
@old_defaults = Paperclip::Attachment.default_options.dup
Paperclip::Attachment.default_options.merge!({
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
})
FileUtils.rm_rf("tmp")
rebuild_model
@instance = Dummy.new
@instance.stubs(:id).returns 123

@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "uppercase.PNG"), 'rb')

styles = {:styles => { :large => ["400x400", :jpg],
:medium => ["100x100", :jpg],
:small => ["32x32#", :jpg]},
:default_style => :small}
@attachment = Paperclip::Attachment.new(:avatar,
@instance,
styles)
now = Time.now
Time.stubs(:now).returns(now)
@attachment.assign(@file)
@attachment.save
end

teardown do
@file.close
Paperclip::Attachment.default_options.merge!(@old_defaults)
end

should "should have matching to_s and url methods" do
file = @attachment.to_file
assert file
assert_match @attachment.to_s, @attachment.url
assert_match @attachment.to_s(:small), @attachment.url(:small)
file.close
end
end

context "An attachment" do
setup do
Expand Down
Binary file added test/fixtures/uppercase.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6a10b35

Please sign in to comment.