Commit 7f948f82 by Luke Griffiths

Merge pull request #729 from Sporky023/master

replace Paperclip::Attachment#initialize options with an AttachmentOptions instance
parents 5d4ba628 9eda1bbe
......@@ -20,3 +20,4 @@ capybara*.html
*SPIKE*
*emfile.lock
tags
......@@ -37,6 +37,7 @@ require 'paperclip/thumbnail'
require 'paperclip/interpolations'
require 'paperclip/style'
require 'paperclip/attachment'
require 'paperclip/attachment_options'
require 'paperclip/storage'
require 'paperclip/callback_compatibility'
require 'paperclip/missing_attachment_styles'
......@@ -325,7 +326,7 @@ module Paperclip
self.attachment_definitions = self.attachment_definitions.dup
end
attachment_definitions[name] = {:validations => []}.merge(options)
attachment_definitions[name] = Paperclip::AttachmentOptions.new(options)
Paperclip.classes_with_attachments << self.name
Paperclip.check_for_url_clash(name,attachment_definitions[name][:url],self.name)
......
module Paperclip
class AttachmentOptions < Hash
def initialize(options)
options = {:validations => []}.merge(options)
options.each do |k, v|
self.[]=(k, v)
end
end
end
end
require './test/helper'
class AttachmentOptionsTest < Test::Unit::TestCase
should "be a Hash" do
assert_kind_of Hash, Paperclip::AttachmentOptions.new({})
end
should "add a default empty validations" do
options = {:arbi => :trary}
expected = {:validations => []}.merge(options)
actual = Paperclip::AttachmentOptions.new(options).to_hash
assert_equal expected, actual
end
should "not override validations if passed to initializer" do
options = {:validations => "something"}
attachment_options = Paperclip::AttachmentOptions.new(options)
assert_equal "something", attachment_options[:validations]
end
should "respond to []" do
assert Paperclip::AttachmentOptions.new({}).respond_to?(:[])
end
should "deliver the specified options through []" do
intended_options = {:specific_key => "specific value"}
attachment_options = Paperclip::AttachmentOptions.new(intended_options)
assert_equal "specific value", attachment_options[:specific_key]
end
should "respond to []=" do
assert Paperclip::AttachmentOptions.new({}).respond_to?(:[]=)
end
should "remember options set with []=" do
attachment_options = Paperclip::AttachmentOptions.new({})
attachment_options[:foo] = "bar"
assert_equal "bar", attachment_options[:foo]
end
end
......@@ -54,10 +54,14 @@ ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FIL
ActiveRecord::Base.establish_connection(config['test'])
Paperclip.options[:logger] = ActiveRecord::Base.logger
Dir[File.join(File.dirname(__FILE__), 'support','*')].each do |f|
def require_everything_in_directory(directory_name)
Dir[File.join(File.dirname(__FILE__), directory_name, '*')].each do |f|
require f
end
end
require_everything_in_directory('support')
def reset_class class_name
ActiveRecord::Base.send(:include, Paperclip::Glue)
Object.send(:remove_const, class_name) rescue nil
......
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