Skip to content
Browse files

AttachmentOptions now inherits from Hash

  • Loading branch information...
1 parent 5f8140d commit 675dd9a374376ed273695b2e621d3df5366e3b3c @Sporky023 committed Feb 3, 2012
Showing with 16 additions and 14 deletions.
  1. +5 −14 lib/paperclip/attachment_options.rb
  2. +11 −0 test/attachment_options_test.rb
View
19 lib/paperclip/attachment_options.rb
@@ -1,19 +1,10 @@
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
View
11 test/attachment_options_test.rb
@@ -5,13 +5,24 @@ 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)
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
Paperclip::AttachmentOptions.new({})[:foo]
end

0 comments on commit 675dd9a

Please sign in to comment.
Something went wrong with that request. Please try again.