Commit 1d621d81 by Agustin Cavilliotti Committed by Jon Yurek

Add the ability to deep_merge! Attachment definitions instead of just merging them

parent a6972db7
......@@ -52,7 +52,7 @@ module Paperclip
def definitions_for(klass)
klass.ancestors.each_with_object({}) do |ancestor, inherited_definitions|
inherited_definitions.merge! @attachments[ancestor]
inherited_definitions.deep_merge! @attachments[ancestor]
end
end
end
......
......@@ -64,11 +64,30 @@ describe 'Attachment Registry' do
it "produces defintions for subclasses" do
expected_definitions = { avatar: { yo: 'greeting' } }
Foo = Class.new
Bar = Class.new(Foo)
Paperclip::AttachmentRegistry.register(Foo, :avatar, expected_definitions[:avatar])
foo = Class.new
bar = Class.new(foo)
Paperclip::AttachmentRegistry.register(foo, :avatar, expected_definitions[:avatar])
definitions = Paperclip::AttachmentRegistry.definitions_for(bar)
assert_equal expected_definitions, definitions
end
it "produces defintions for subclasses but deep merging them" do
foo_definitions = { avatar: { yo: 'greeting' } }
bar_definitions = { avatar: { ciao: 'greeting' } }
expected_definitions = {
avatar: {
yo: 'greeting',
ciao: 'greeting'
}
}
foo = Class.new
bar = Class.new(foo)
Paperclip::AttachmentRegistry.register(foo, :avatar, foo_definitions[:avatar])
Paperclip::AttachmentRegistry.register(bar, :avatar, bar_definitions[:avatar])
definitions = Paperclip::AttachmentRegistry.definitions_for(Bar)
definitions = Paperclip::AttachmentRegistry.definitions_for(bar)
assert_equal expected_definitions, definitions
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