diff --git a/app/models/mixins/deprecation_mixin.rb b/app/models/mixins/deprecation_mixin.rb index 3d450f568d4..cc4540e52f3 100644 --- a/app/models/mixins/deprecation_mixin.rb +++ b/app/models/mixins/deprecation_mixin.rb @@ -21,7 +21,9 @@ def deprecate_attribute(old_attribute, new_attribute, type:) end def deprecate_attribute_methods(old_attribute, new_attribute) - alias_attribute old_attribute, new_attribute + define_method(old_attribute) { self.send(new_attribute) } + define_method("#{old_attribute}=") { |object| self.send("#{new_attribute}=", object) } + define_method("#{old_attribute}?") { self.send("#{new_attribute}?") } ["", "=", "?"].each { |suffix| Vmdb::Deprecation.deprecate_methods(self, "#{old_attribute}#{suffix}" => "#{new_attribute}#{suffix}") } end end diff --git a/spec/models/mixins/deprecation_mixin_spec.rb b/spec/models/mixins/deprecation_mixin_spec.rb index 814f6e2194c..31c5f074fb9 100644 --- a/spec/models/mixins/deprecation_mixin_spec.rb +++ b/spec/models/mixins/deprecation_mixin_spec.rb @@ -1,16 +1,4 @@ RSpec.describe DeprecationMixin do - # Host.deprecate_attribute :address, :hostname - context ".arel_table" do - # this is defining an alias - # it is not typical for aliases to work through arel_table - # may need to get rid of this in the future - it "works for deprecate_attribute columns" do - expect(Host.attribute_supported_by_sql?(:address)).to eq(true) - expect(Host.arel_table[:address]).to_not be_nil - expect(Host.arel_table[:address].name).to eq("hostname") # typically this is a symbol. not perfect but it works - end - end - # Host.deprecate_attribute :address, :hostname context ".visible_attribute_names" do it "hides deprecate_attribute columns" do