Skip to content

Commit

Permalink
Expose attribute_aliases as attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Jan 30, 2025
1 parent 7df03e1 commit b9aa202
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.ar_model_associations

def self.expose_class_attributes(subclass)
subclass.class_eval do
model.attribute_names.each do |attr|
(model.attribute_names | model.try(:attribute_aliases)&.keys).each do |attr|
next if model.private_method_defined?(attr)
next if EXPOSED_ATTR_BLACK_LIST.any? { |rexp| attr =~ rexp }
next if subclass.base_class != self && method_defined?(attr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,39 @@
end
end
end

context 'with a StoreObject service model' do
let(:model) { CloudObjectStoreObject }
let(:service_model) { MiqAeMethodService::MiqAeServiceCloudObjectStoreObject }

# NOTE: CloudObjectStoreObject.alias_attribute :name, :key
it "finds attributes aliases (without virtual attribute defined)" do
# if this shows true, find another model/attribute
expect(model.virtual_attribute?("name")).to eq(false)

expect(service_model.method_defined?("key")).to eq(true)
expect(service_model.method_defined?("name")).to eq(true)
end

it "finds regular attributes" do
service_model.method_defined?("etag")
end
end

context 'with a Flavor service model' do
let(:model) { Flavor }
let(:service_model) { MiqAeMethodService::MiqAeServiceFlavor }

# NOTE: Flavor.alias_attribute :cpus, :cpu_total_cores
it "finds attributes aliases" do
expect(service_model.method_defined?("cpus")).to eq(true)
expect(service_model.method_defined?("cpu_total_cores")).to eq(true)
end

it "finds regular attributes" do
service_model.method_defined?("name")
end
end
end

module MiqAeServiceModelSpec
Expand Down

0 comments on commit b9aa202

Please sign in to comment.