active-hash / active_hash

A readonly ActiveRecord-esque base class that lets you use a hash, a Yaml file or a custom file as the datasource
MIT License
1.19k stars 178 forks source link

fix: ensure the stored field names are always symbols #312

Closed flavorjones closed 3 weeks ago

flavorjones commented 1 month ago

There is code that assumes that @field_names will contain symbols, like this method in ActiveHash::Base:

def respond_to?(method_name, include_private=false)
  super ||
    begin
      config = configuration_for_custom_finder(method_name)
      config && config[:fields].all? do |field|
        field_names.include?(field.to_sym) || field.to_sym == :id
      end
    end
end

This also introduces an explicit test for #field_names.