Skip to content

Commit

Permalink
Fixed extension interpolation bug when relying on default_style
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed May 11, 2009
1 parent 93073d5 commit 65fb926
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/paperclip/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def url style = default_style, include_updated_timestamp = true
# file is stored in the filesystem the path refers to the path of the file
# on disk. If the file is stored in S3, the path is the "key" part of the
# URL, and the :bucket option refers to the S3 bucket.
def path style = nil #:nodoc:
def path style = default_style
original_filename.nil? ? nil : interpolate(@path, style)
end

Expand Down
14 changes: 14 additions & 0 deletions test/attachment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ class AttachmentTest < Test::Unit::TestCase
end
end

context "An attachment with a default style and an extension interpolation" do
setup do
@attachment = attachment :path => ":basename.:extension",
:styles => { :default => ["100x100", :png] },
:default_style => :default
@file = StringIO.new("...")
@file.expects(:original_filename).returns("file.jpg")
end
should "return the right extension for the path" do
@attachment.assign(@file)
assert_equal "file.png", @attachment.path
end
end

context "An attachment with :convert_options" do
setup do
rebuild_model :styles => {
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def errors
@errors ||= []
end

def run_callbacks
def run_callbacks name, *args
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/interpolations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InterpolationsTest < Test::Unit::TestCase
assert_equal "jpg", Paperclip::Interpolations.extension(attachment, :style)
end

should "return the extension of the file as the format is defined in the style" do
should "return the extension of the file as the format if defined in the style" do
attachment = mock
attachment.expects(:original_filename).never
attachment.expects(:styles).returns({:style => {:format => "png"}})
Expand Down

0 comments on commit 65fb926

Please sign in to comment.