Commit 01d2fdac by Prem Sichanugrist

Symbolize all the style keys

This will prevent a pitfall as sometime the style's name can be a string.
parent 84a01174
...@@ -90,6 +90,7 @@ module Paperclip ...@@ -90,6 +90,7 @@ module Paperclip
ensure_required_accessors! ensure_required_accessors!
file = Paperclip.io_adapters.for(uploaded_file) file = Paperclip.io_adapters.for(uploaded_file)
@options[:only_process].map!(&:to_sym)
self.clear(*@options[:only_process]) self.clear(*@options[:only_process])
return nil if file.nil? return nil if file.nil?
...@@ -164,7 +165,7 @@ module Paperclip ...@@ -164,7 +165,7 @@ module Paperclip
if styling_option.respond_to?(:call) || !@normalized_styles if styling_option.respond_to?(:call) || !@normalized_styles
@normalized_styles = ActiveSupport::OrderedHash.new @normalized_styles = ActiveSupport::OrderedHash.new
(styling_option.respond_to?(:call) ? styling_option.call(self) : styling_option).each do |name, args| (styling_option.respond_to?(:call) ? styling_option.call(self) : styling_option).each do |name, args|
@normalized_styles[name] = Paperclip::Style.new(name, args.dup, self) @normalized_styles[name.to_sym] = Paperclip::Style.new(name.to_sym, args.dup, self)
end end
end end
@normalized_styles @normalized_styles
...@@ -375,6 +376,7 @@ module Paperclip ...@@ -375,6 +376,7 @@ module Paperclip
def post_process(*style_args) #:nodoc: def post_process(*style_args) #:nodoc:
return if @queued_for_write[:original].nil? return if @queued_for_write[:original].nil?
instance.run_paperclip_callbacks(:post_process) do instance.run_paperclip_callbacks(:post_process) do
instance.run_paperclip_callbacks(:"#{name}_post_process") do instance.run_paperclip_callbacks(:"#{name}_post_process") do
post_process_styles(*style_args) post_process_styles(*style_args)
......
...@@ -439,11 +439,50 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -439,11 +439,50 @@ class IntegrationTest < Test::Unit::TestCase
@dummy.avatar = @file @dummy.avatar = @file
end end
teardown { @file.close }
should "should not error when saving" do should "should not error when saving" do
@dummy.save! @dummy.save!
end end
end end
context "A model with an attachment with hash in file name" do
setup do
@settings = { :styles => { :thumb => "50x50#" },
:path => ":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension",
:url => "/system/:attachment/:id_partition/:style/:hash.:extension",
:hash_secret => "somesecret" }
rebuild_model @settings
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
@dummy = Dummy.create! :avatar => @file
end
teardown do
@file.close
end
should "be accessible" do
assert File.exists?(@dummy.avatar.path(:original))
assert File.exists?(@dummy.avatar.path(:thumb))
end
context "when new style is added" do
setup do
@dummy.avatar.options[:styles][:mini] = "25x25#"
@dummy.avatar.instance_variable_set :@normalized_styles, nil
@dummy.avatar.reprocess! 'mini'
end
should "make all the styles accessible" do
assert File.exists?(@dummy.avatar.path(:original))
assert File.exists?(@dummy.avatar.path(:thumb))
assert File.exists?(@dummy.avatar.path(:mini))
end
end
end
if ENV['S3_TEST_BUCKET'] if ENV['S3_TEST_BUCKET']
def s3_files_for attachment def s3_files_for attachment
[:thumb, :medium, :large, :original].inject({}) do |files, style| [:thumb, :medium, :large, :original].inject({}) do |files, style|
...@@ -604,4 +643,3 @@ class IntegrationTest < Test::Unit::TestCase ...@@ -604,4 +643,3 @@ class IntegrationTest < Test::Unit::TestCase
end end
end end
end end
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