Permalink
Browse files

Symbolize all the style keys

This will prevent a pitfall as sometime the style's name can be a string.
  • Loading branch information...
1 parent 84a0117 commit 01d2fdacfdf5103805e064ebd297fd9f3f394285 @sikachu sikachu committed May 4, 2012
Showing with 42 additions and 2 deletions.
  1. +3 −1 lib/paperclip/attachment.rb
  2. +39 −1 test/integration_test.rb
@@ -90,6 +90,7 @@ def assign uploaded_file
ensure_required_accessors!
file = Paperclip.io_adapters.for(uploaded_file)
+ @options[:only_process].map!(&:to_sym)
self.clear(*@options[:only_process])
return nil if file.nil?
@@ -164,7 +165,7 @@ def styles
if styling_option.respond_to?(:call) || !@normalized_styles
@normalized_styles = ActiveSupport::OrderedHash.new
(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
@normalized_styles
@@ -375,6 +376,7 @@ def extra_source_file_options_for(style) #:nodoc:
def post_process(*style_args) #:nodoc:
return if @queued_for_write[:original].nil?
+
instance.run_paperclip_callbacks(:post_process) do
instance.run_paperclip_callbacks(:"#{name}_post_process") do
post_process_styles(*style_args)
View
@@ -439,11 +439,50 @@ class IntegrationTest < Test::Unit::TestCase
@dummy.avatar = @file
end
+ teardown { @file.close }
+
should "should not error when saving" do
@dummy.save!
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']
def s3_files_for attachment
[:thumb, :medium, :large, :original].inject({}) do |files, style|
@@ -604,4 +643,3 @@ def s3_headers_for attachment, style
end
end
end
-

0 comments on commit 01d2fda

Please sign in to comment.