makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

active_type 1.4.0 introduced a bug when extending a record in level 2 #142

Closed FLeinzi closed 3 years ago

FLeinzi commented 3 years ago

Hi,

this commit in 1.4.0 introduced a bug when extending an already extended record again

Given we have these models:

class Note < ActiveRecord
end

class Note
  class Form < ActiveType::Record[Note]
    attribute :some_attribute
  end
end

class Note
  class SuperSpecialForm < ActiveType::Record[Form]
    attribute :some_special_attribute
  end
end

Then my tests for Note::SuperSpecialForm will break, because Rails cannot resolve the model_name properly

$ Note.model_name.singular_route_key
=> "note"

$ Note::Form.model_name.singular_route_key
=> "note" # level 1 is correct

$ Note::SuperSpecialForm.model_name.singular_route_key
=> "note_form" # this is not correct

I already figured out, that it comes from the deeper hierarchy (extension of a extension of a record) and this piece of code from the commit above:

dup_model_name = ActiveModel::Name.new(self, namespace, extended_record_base_class.name)

but I couldn't solve the problem.

Maybe we have to climb via extended_record_base_class until we reach a "normal" record (no ActiveType::Record!)