Permalink
Browse files

Try another way of setting defaults

  • Loading branch information...
1 parent 0164867 commit 70c71a52f6529b0a21556336c076824f519f8202 @ckdake committed Jun 21, 2012
Showing with 10 additions and 3 deletions.
  1. +7 −0 lib/setler/active_record.rb
  2. +3 −3 test/settings_test.rb
@@ -5,6 +5,13 @@ def has_setler(scopename = 'settings')
define_method scopename do
Setler::ScopedSettings.for_thing(self, scopename)
end
+
+ # This connects Example.Settings.defaults to to example.defaults
+ self.class.instance_eval do
+ define_method(scopename.to_s.camelize) do
+ eval scopename.to_s.camelize
+ end
+ end
end
end
@@ -134,9 +134,9 @@ def test_user_settings_override_defaults
def test_user_preferences_has_defaults
user = User.create name: 'user 1'
- assert_equal ::Preferences.all, user.preferences.all
- ::Preferences.defaults[:foo] = true
- assert_equal ::Preferences.all, user.preferences.all
+ assert_equal User.Preferences.all, user.preferences.all
+ User.Preferences.defaults[:foo] = true
+ assert_equal User.Preferences.all, user.preferences.all
assert user.preferences.foo
end

1 comment on commit 70c71a5

@ckdake
Owner
ckdake commented on 70c71a5 Jun 21, 2012

This was an attempt to get access to the user.preferences instance of the Preferences class in a class sort of scope for setting defaults. Test still passes.

Please sign in to comment.