huacnlee / rails-settings-cached

Global settings for your Rails application.
Other
1.06k stars 202 forks source link

Consider implementing respond_to? in RailsSettings::Settings #121

Closed artur-intech closed 5 years ago

artur-intech commented 7 years ago
irb(main):001:0> Setting.postal_address_processing
=> true
irb(main):002:0> Setting.respond_to? :postal_address_processing
=> false
irb(main):003:0>

https://github.com/huacnlee/rails-settings-cached/blob/master/lib/rails-settings/settings.rb#L21

I wonder if this is expected behaviour, since it seems quite confusing to me. The downside of this is the inability to mock/stub the settings, which prevents tests from accessing the database.

artur-intech commented 7 years ago

Also, the following code leads to "deadlock; recursive locking" error:

class Setting < RailsSettings::CachedSettings
  class << self
    def respond_to_missing?(method, include_all = false)
      get_all.include?(method.to_s) || super
    end
  end
end

https://gist.github.com/artur-beljajev/1947c0b35509b776f216a5dedff82f51