setting_accessors 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/setting_accessors/integration.rb +26 -6
- data/lib/setting_accessors/version.rb +1 -1
- data/test/dummy/test/models/user_test.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bfc4d6c136c888e3ab70d330ace8ba0b118c9f6
|
4
|
+
data.tar.gz: 01bf15e9041976abd2c2804511daf0aeaadc5df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071dd2ed23e8ab80dc529999a341d50c1f2d889e587992cb26fe7dce060d9d6c7138a8e5bfb5edcd345f44bc8f166187dd7d13f58e2eae9013660a0e2ad66da1
|
7
|
+
data.tar.gz: 0b9715953ce927a4d00db6cb15083650f1939c775e62f67ce2ed227982543488c43d97d0f538ba189fdf77d4f51b5487760a9b404c532bd3498d1bde1fa1ba4b
|
@@ -2,9 +2,9 @@ module SettingAccessors::Integration
|
|
2
2
|
def self.included(base)
|
3
3
|
base.validates_with SettingAccessors::IntegrationValidator
|
4
4
|
|
5
|
-
#After the main record was saved, we can save its settings.
|
6
|
-
#This is necessary as the record might have been a new record
|
7
|
-
#without an ID yet
|
5
|
+
# After the main record was saved, we can save its settings.
|
6
|
+
# This is necessary as the record might have been a new record
|
7
|
+
# without an ID yet
|
8
8
|
base.after_save do
|
9
9
|
settings.send(:persist!)
|
10
10
|
end
|
@@ -84,8 +84,28 @@ module SettingAccessors::Integration
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
|
88
|
-
|
87
|
+
#
|
88
|
+
# Previously read setting values have to be refreshed if a record is reloaded.
|
89
|
+
# Without this, #reload'ing a record would not update its setting values to the
|
90
|
+
# latest database version if they were previously read.
|
91
|
+
#
|
92
|
+
# Example to demonstrate the problem with this override:
|
93
|
+
# user = User.create(:a_boolean => true)
|
94
|
+
# user_alias = User.find(user.id)
|
95
|
+
# user.a_boolean = !user_alias.a_boolean
|
96
|
+
# user.save
|
97
|
+
# user_alias.reload
|
98
|
+
# user_alias.a_boolean
|
99
|
+
# #=> true
|
100
|
+
#
|
101
|
+
def reload(*)
|
102
|
+
super
|
103
|
+
@settings_accessor = nil
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
def as_json(*)
|
108
|
+
json = super
|
89
109
|
SettingAccessors::Internal.setting_accessor_names(self.class).each do |setting_name|
|
90
110
|
json[setting_name.to_s] = send(setting_name)
|
91
111
|
end
|
@@ -95,4 +115,4 @@ module SettingAccessors::Integration
|
|
95
115
|
def settings
|
96
116
|
@settings_accessor ||= SettingAccessors::Accessor.new(self)
|
97
117
|
end
|
98
|
-
end
|
118
|
+
end
|
@@ -38,6 +38,22 @@ class UserTest < ActiveSupport::TestCase
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
context 'the read set (@temp_settings)' do
|
42
|
+
setup do
|
43
|
+
@user = User.create
|
44
|
+
@user_alias = User.find(@user.id)
|
45
|
+
|
46
|
+
# Use @user_alias here to ensure that the setting value is saved in the instance's read set
|
47
|
+
@user.a_boolean = !@user_alias.a_boolean
|
48
|
+
assert @user.save
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'be refreshed with the new values on #reload' do
|
52
|
+
assert @user_alias.reload
|
53
|
+
assert_equal @user.a_boolean, @user_alias.a_boolean
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
41
57
|
context 'Polymorphic class-wise settings' do
|
42
58
|
setup do
|
43
59
|
@user = User.create
|