Commit 675dd9a3 by Luke Griffiths

AttachmentOptions now inherits from Hash

parent 5f8140d1
module Paperclip
class AttachmentOptions
class AttachmentOptions < Hash
def initialize(options)
@options = {:validations => []}.merge(options)
end
def [](key)
@options[key]
end
def []=(key, value)
@options[key] = value
end
def to_hash
@options
options = {:validations => []}.merge(options)
options.each do |k, v|
self.[]=(k, v)
end
end
end
end
......@@ -5,6 +5,11 @@ class AttachmentOptionsTest < Test::Unit::TestCase
Paperclip::AttachmentOptions
end
should "be a Hash" do
attachment_options = Paperclip::AttachmentOptions.new({})
assert attachment_options.is_a?(Hash), "attachment_options is not a Hash"
end
should "add a default empty validations" do
options = {:arbi => :trary}
expected = {:validations => []}.merge(options)
......@@ -12,6 +17,12 @@ class AttachmentOptionsTest < Test::Unit::TestCase
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
Paperclip::AttachmentOptions.new({})[:foo]
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