Commit 2a9e71a2 by Stefano B Committed by Jon Yurek

allow sublcasses to override definitions

parent 9e97a530
......@@ -51,7 +51,7 @@ module Paperclip
end
def definitions_for(klass)
klass.ancestors.each_with_object({}) do |ancestor, inherited_definitions|
klass.ancestors.reverse.each_with_object({}) do |ancestor, inherited_definitions|
inherited_definitions.deep_merge! @attachments[ancestor]
end
end
......
......@@ -111,6 +111,34 @@ describe 'Attachment Registry' do
assert_equal expected_definitions, definitions
end
it 'allows subclasses to override attachment defitions' do
foo_definitions = { avatar: { yo: "greeting" } }
bar_definitions = { avatar: { yo: "hello" } }
expected_definitions = {
avatar: {
yo: "hello"
}
}
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)
assert_equal expected_definitions, definitions
end
end
context '.clear' do
......
......@@ -7,6 +7,7 @@ require 'active_support/core_ext'
require 'mocha/api'
require 'bourne'
require 'ostruct'
require 'pathname'
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
......
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