setting_accessors 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c84a9d183c4d530e76b1c5fa3ef5e361732ac4aa
4
- data.tar.gz: 57c5def39a8c796f5d0ecaeb2474a53ff27e541d
3
+ metadata.gz: 4bfc4d6c136c888e3ab70d330ace8ba0b118c9f6
4
+ data.tar.gz: 01bf15e9041976abd2c2804511daf0aeaadc5df5
5
5
  SHA512:
6
- metadata.gz: aa28c3070e77ce1a3abaf62ca71335cd9118b6846e5327885572fa4bbe09143d8b932e9b5544615e11bf20327223df9507e2740d59a4793eefea540277d7d44c
7
- data.tar.gz: f849a1ef5b62ed6c9658194fdf3399e1670b32ff3154aaee18729fadb08c256eccf228bc611c34078a14025863a4952ea7451c3f596e0b94a6790db4f66ed38e
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
- def as_json(*args)
88
- json = super(*args)
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
@@ -1,3 +1,3 @@
1
1
  module SettingAccessors
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setting_accessors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Exner