Commit 06802254 by Strech (Sergey Fedorov) Committed by Jon Yurek

Make id partitioning for string similar to integer

parent 87cebf99
...@@ -172,7 +172,7 @@ module Paperclip ...@@ -172,7 +172,7 @@ module Paperclip
when Integer when Integer
("%09d" % id).scan(/\d{3}/).join("/") ("%09d" % id).scan(/\d{3}/).join("/")
when String when String
id.scan(/.{3}/).first(3).join("/") ('%9.9s' % id).tr(" ", "0").scan(/.{3}/).join("/")
else else
nil nil
end end
......
...@@ -138,7 +138,14 @@ describe Paperclip::Interpolations do ...@@ -138,7 +138,14 @@ describe Paperclip::Interpolations do
assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style) assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style)
end end
it "returns the partitioned id of the attachment when the id is a string" do it "returns the partitioned id of the attachment when the id is a short string" do
attachment = mock
attachment.expects(:id).returns("fnj23")
attachment.expects(:instance).returns(attachment)
assert_equal "000/0fn/j23", Paperclip::Interpolations.id_partition(attachment, :style)
end
it "returns the partitioned id of the attachment when the id is a long string" do
attachment = mock attachment = mock
attachment.expects(:id).returns("32fnj23oio2f") attachment.expects(:id).returns("32fnj23oio2f")
attachment.expects(:instance).returns(attachment) attachment.expects(:instance).returns(attachment)
...@@ -204,7 +211,7 @@ describe Paperclip::Interpolations do ...@@ -204,7 +211,7 @@ describe Paperclip::Interpolations do
attachment.stubs(:original_filename).returns("one") attachment.stubs(:original_filename).returns("one")
assert_equal "one", Paperclip::Interpolations.filename(attachment, :style) assert_equal "one", Paperclip::Interpolations.filename(attachment, :style)
end end
it "returns the basename when the extension contains regexp special characters" do it "returns the basename when the extension contains regexp special characters" do
attachment = mock attachment = mock
attachment.stubs(:styles).returns({}) attachment.stubs(:styles).returns({})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment