From 412d2f0a0bcf7f166feeb021d1668bebefdad531 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 29 Jun 2021 21:34:01 -0700 Subject: [PATCH] Fix for edgecase with magic attributes --- lib/dragonfly/model/attachment_class_methods.rb | 4 ++-- spec/dragonfly/model/model_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/dragonfly/model/attachment_class_methods.rb b/lib/dragonfly/model/attachment_class_methods.rb index 662be420a..00efa079a 100644 --- a/lib/dragonfly/model/attachment_class_methods.rb +++ b/lib/dragonfly/model/attachment_class_methods.rb @@ -98,8 +98,8 @@ def magic_attributes @magic_attributes ||= begin prefix = attribute.to_s + '_' model_class.public_instance_methods.inject([]) do |attrs, name| - _, __, suffix = name.to_s.partition(prefix) - if !suffix.empty? && allowed_magic_attributes.include?(suffix.to_sym) + pre_prefix, __, suffix = name.to_s.partition(prefix) + if !suffix.empty? && pre_prefix.empty? && allowed_magic_attributes.include?(suffix.to_sym) attrs << suffix.to_sym end attrs diff --git a/spec/dragonfly/model/model_spec.rb b/spec/dragonfly/model/model_spec.rb index 10a2b647c..9980e1e6e 100644 --- a/spec/dragonfly/model/model_spec.rb +++ b/spec/dragonfly/model/model_spec.rb @@ -399,6 +399,10 @@ ) do dragonfly_accessor :preview_image dragonfly_accessor :other_image + + def method_about_other_image_size + fail "This should not be called" + end end @item = @item_class.new end