*_attribute methods take String or Symbol
This commit is contained in:
@@ -241,7 +241,7 @@ module HasAuxTable
|
|||||||
method = self.instance_method(method_name)
|
method = self.instance_method(method_name)
|
||||||
self.define_method(method_name) do |name, *args, **kwargs, &block|
|
self.define_method(method_name) do |name, *args, **kwargs, &block|
|
||||||
T.bind(self, ActiveRecord::Base)
|
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)
|
target = config.aux_model_for(self)
|
||||||
T.unsafe(target).send(method_name, name, *args, **kwargs, &block)
|
T.unsafe(target).send(method_name, name, *args, **kwargs, &block)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -77,6 +77,14 @@ RSpec.describe HasAuxTable do
|
|||||||
)
|
)
|
||||||
end
|
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
|
it "can be created as the base class" do
|
||||||
vehicle = Vehicle.create(type: "Vehicle", name: "big tractor")
|
vehicle = Vehicle.create(type: "Vehicle", name: "big tractor")
|
||||||
expect(vehicle.attributes).to match(
|
expect(vehicle.attributes).to match(
|
||||||
|
|||||||
Reference in New Issue
Block a user