has_setting 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/has_setting/ar_extensions.rb +3 -0
- data/lib/has_setting/version.rb +1 -1
- data/test/unit/has_setting_test.rb +23 -29
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c320931c608eaeac7b2134bd75561e57932a6cf8
|
4
|
+
data.tar.gz: 8b7b9a8993158a8b1ef7e584f5b63471c71a7649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e83389a8001fd0906c1c0e53f8a4ed605115a29998d3f6c6d9f21075137f2a733707495c47fde702ce21683e0b0edfbdfa21c7bcf859ae7f12f7493c4da33f36
|
7
|
+
data.tar.gz: 602429b6032d14d649ac29f87f3885c4c678fdc4f7853e2460ec21aaa47344ac593f5963cbec60ea37f8fed8d6dd88a4a080c5b880334bb7530f67f1bef36813
|
@@ -59,6 +59,9 @@ module HasSetting
|
|
59
59
|
setting = self.settings.detect() {|item| item.name == name and item.locale.to_s == locale.to_s }
|
60
60
|
setting = self.settings.build(:name => name, locale: locale) if setting.blank?
|
61
61
|
setting.value = value
|
62
|
+
# mark model as changed to make sure model is saved so that after_save is triggered even if only settings change
|
63
|
+
# maybe there is a better way of doing this.
|
64
|
+
self.updated_at = Time.now if self.respond_to?(:updated_at)
|
62
65
|
end
|
63
66
|
|
64
67
|
def read_setting(name)
|
data/lib/has_setting/version.rb
CHANGED
@@ -6,19 +6,13 @@ class HasSettingTest < Test::Unit::TestCase
|
|
6
6
|
@bar = Bar.create!
|
7
7
|
@baz = Baz.create!
|
8
8
|
end
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
|
11
11
|
def test_setting_has_accessors
|
12
12
|
assert @foo.respond_to?(:setting_1)
|
13
13
|
assert @foo.respond_to?(:setting_1=)
|
14
14
|
end
|
15
|
-
|
16
|
-
|
17
|
-
def test_has_many
|
18
|
-
assert @foo.respond_to?(:settings)
|
19
|
-
assert @foo.settings.is_a?(Array)
|
20
|
-
end
|
21
|
-
|
15
|
+
|
22
16
|
def test_settings_are_destroyed
|
23
17
|
count_before = HasSetting::Setting.count
|
24
18
|
@foo.setting_1 = 10
|
@@ -26,9 +20,9 @@ class HasSettingTest < Test::Unit::TestCase
|
|
26
20
|
assert_equal(count_before + 1, HasSetting::Setting.count)
|
27
21
|
@foo.destroy
|
28
22
|
assert_equal(count_before, HasSetting::Setting.count)
|
29
|
-
|
23
|
+
|
30
24
|
end
|
31
|
-
|
25
|
+
|
32
26
|
def test_write_setting
|
33
27
|
count_before = HasSetting::Setting.count
|
34
28
|
@foo.write_setting('name', 'value1')
|
@@ -37,14 +31,14 @@ class HasSettingTest < Test::Unit::TestCase
|
|
37
31
|
setting = @foo.read_setting('name')
|
38
32
|
assert setting
|
39
33
|
assert_equal('value1', setting.value)
|
40
|
-
|
34
|
+
|
41
35
|
@foo.write_setting('name', 'value2')
|
42
|
-
assert_equal(count_before + 1, HasSetting::Setting.count)
|
36
|
+
assert_equal(count_before + 1, HasSetting::Setting.count)
|
43
37
|
setting = @foo.read_setting('name')
|
44
38
|
assert setting
|
45
39
|
assert_equal('value2', setting.value)
|
46
40
|
end
|
47
|
-
|
41
|
+
|
48
42
|
def test_setting_accessors
|
49
43
|
count_before = HasSetting::Setting.count
|
50
44
|
assert(!@foo.setting_1)
|
@@ -55,7 +49,7 @@ class HasSettingTest < Test::Unit::TestCase
|
|
55
49
|
@foo.setting_1 = 'bla'
|
56
50
|
assert_equal('bla', @foo.setting_1)
|
57
51
|
end
|
58
|
-
|
52
|
+
|
59
53
|
def test_different_classes_do_not_share_setting
|
60
54
|
count_before = HasSetting::Setting.count
|
61
55
|
@foo.setting_1 = 'foo'
|
@@ -63,43 +57,43 @@ class HasSettingTest < Test::Unit::TestCase
|
|
63
57
|
@bar.setting_1 = 'bar'
|
64
58
|
@bar.save!
|
65
59
|
assert_equal(count_before + 2, HasSetting::Setting.count)
|
66
|
-
|
60
|
+
|
67
61
|
assert_equal('foo', @foo.setting_1)
|
68
62
|
assert_equal('bar', @bar.setting_1)
|
69
63
|
end
|
70
64
|
|
71
|
-
|
65
|
+
|
72
66
|
def test_has_nil_setting
|
73
67
|
@foo.setting_1 = nil
|
74
68
|
assert(@foo.read_setting('setting_1'))
|
75
69
|
assert(!@foo.setting_1)
|
76
70
|
end
|
77
|
-
|
71
|
+
|
78
72
|
def test_options_on_getter
|
79
73
|
@foo.setting_1 = '12.3'
|
80
74
|
assert_equal('12.3', @foo.setting_1)
|
81
75
|
assert_equal(12, @foo.setting_1(:type => :int))
|
82
76
|
assert_equal(12.3, @foo.setting_1(:type => :float))
|
83
|
-
|
77
|
+
|
84
78
|
# Foo.setting_2 is a float setting. Override and get as string
|
85
79
|
@foo.setting_2 = 12.3
|
86
80
|
assert_equal('12.3', @foo.setting_2(:type => :string))
|
87
81
|
end
|
88
|
-
|
82
|
+
|
89
83
|
def test_different_classes_do_not_share_options()
|
90
84
|
@foo.setting_2 = 12.3
|
91
85
|
assert_equal(12.3, @foo.setting_2)
|
92
86
|
@bar.setting_2 = 12.3
|
93
87
|
assert_equal(12, @bar.setting_2)
|
94
88
|
end
|
95
|
-
|
89
|
+
|
96
90
|
def test_default_values()
|
97
91
|
assert_equal('def', @foo.with_default)
|
98
92
|
assert_equal('override def', @foo.with_default(:default => 'override def'))
|
99
93
|
@foo.with_default = 'not def'
|
100
94
|
assert_equal('not def', @foo.with_default)
|
101
95
|
end
|
102
|
-
|
96
|
+
|
103
97
|
def test_write_settings_without_saved_parent
|
104
98
|
my_foo = Foo.new
|
105
99
|
count_before = HasSetting::Setting.count
|
@@ -110,19 +104,19 @@ class HasSettingTest < Test::Unit::TestCase
|
|
110
104
|
assert_equal(count_before + 1, HasSetting::Setting.count)
|
111
105
|
assert_equal('radabumm', my_foo.with_default)
|
112
106
|
end
|
113
|
-
|
107
|
+
|
114
108
|
def test_not_everyone_has_settings_association
|
115
109
|
assert_equal(true, @foo.respond_to?(:settings))
|
116
110
|
assert_equal(true, @bar.respond_to?(:settings))
|
117
111
|
assert_equal(false, @baz.respond_to?(:settings))
|
118
112
|
end
|
119
|
-
|
120
|
-
|
113
|
+
|
114
|
+
|
121
115
|
def test_boolean_setting_without_default
|
122
116
|
assert_equal nil, @foo.setting_3
|
123
117
|
@foo.setting_3 = true
|
124
118
|
@foo.save!
|
125
|
-
|
119
|
+
|
126
120
|
@foo = Foo.find @foo.id
|
127
121
|
assert_equal true, @foo.setting_3
|
128
122
|
end
|
@@ -133,7 +127,7 @@ class HasSettingTest < Test::Unit::TestCase
|
|
133
127
|
@foo = Foo.find @foo.id
|
134
128
|
assert_equal true, @foo.setting_4
|
135
129
|
end
|
136
|
-
|
130
|
+
|
137
131
|
def test_boolean_setting_with_default_and_no_saving
|
138
132
|
assert_equal false, @foo.setting_4
|
139
133
|
@foo.setting_4 = true
|
@@ -153,6 +147,6 @@ class HasSettingTest < Test::Unit::TestCase
|
|
153
147
|
I18n.locale = :de
|
154
148
|
assert_equal 'setting de', @bar.setting_1
|
155
149
|
end
|
156
|
-
|
157
|
-
|
150
|
+
|
151
|
+
|
158
152
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_setting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simplificator GmbH
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Stores settings as key/value pairs in a settings table and provides accessors
|
15
15
|
for them on the owning object
|