Commit 675dd9a3 by Luke Griffiths

AttachmentOptions now inherits from Hash

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