*_attribute methods take String or Symbol

This commit is contained in:
Dylan Knutson
2025-07-19 05:13:14 +00:00
parent 42d3ce97d9
commit 6ba5a70bb5
2 changed files with 9 additions and 1 deletions

View File

@@ -241,7 +241,7 @@ module HasAuxTable
method = self.instance_method(method_name)
self.define_method(method_name) do |name, *args, **kwargs, &block|
T.bind(self, ActiveRecord::Base)
if config.aux.column_names.include?(name)
if config.aux.column_names.include?(name.to_s)
target = config.aux_model_for(self)
T.unsafe(target).send(method_name, name, *args, **kwargs, &block)
else

View File

@@ -77,6 +77,14 @@ RSpec.describe HasAuxTable do
)
end
it "reads attributes with read_attribute" do
car = Car.create!(name: "Honda Civic", fuel_type: "gasoline")
expect(car.read_attribute("name")).to eq("Honda Civic")
expect(car.read_attribute(:name)).to eq("Honda Civic")
expect(car.read_attribute("fuel_type")).to eq("gasoline")
expect(car.read_attribute(:fuel_type)).to eq("gasoline")
end
it "can be created as the base class" do
vehicle = Vehicle.create(type: "Vehicle", name: "big tractor")
expect(vehicle.attributes).to match(