Skip to content

Commit

Permalink
Deep merge Attachment options into default_options
Browse files Browse the repository at this point in the history
  • Loading branch information
s-andringa committed Aug 29, 2013
1 parent 203415c commit 62f2b28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/paperclip/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def initialize(name, instance, options = {})
@name = name
@instance = instance

options = self.class.default_options.merge(options)
options = self.class.default_options.deep_merge(options)

@options = options
@post_processing = true
Expand Down
20 changes: 20 additions & 0 deletions test/attachment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ class AttachmentTest < Test::Unit::TestCase
assert_file_exists(dummy.avatar.path(:original))
end

context "having a not empty hash as a default option" do
setup do
@old_default_options = Paperclip::Attachment.default_options.dup
@new_default_options = { :convert_options => { :all => "-background white" } }
Paperclip::Attachment.default_options.merge!(@new_default_options)
end

teardown do
Paperclip::Attachment.default_options.merge!(@old_default_options)
end

should "deep merge when it is overridden" do
new_options = { :convert_options => { :thumb => "-thumbnailize" } }
attachment = Paperclip::Attachment.new(:name, :instance, new_options)

assert_equal Paperclip::Attachment.default_options.deep_merge(new_options),
attachment.instance_variable_get("@options")
end
end

should "handle a boolean second argument to #url" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, :instance, :url_generator => mock_url_generator_builder)
Expand Down

0 comments on commit 62f2b28

Please sign in to comment.