setting_accessors 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/setting_accessors/integration.rb +11 -3
- data/lib/setting_accessors/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/test/models/user_test.rb +42 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e10e1f1db74ffd1a88c6cda07070ee743347be2
|
4
|
+
data.tar.gz: bb11685605adb3eb565543d9282b76c133609529
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cf233138c9ea194ce51cf154a136030ef7d835fa089f968d2ba6ffdd47b33b191357496e6627a3f56b3d4d9713e678b922d34e6843249f92f859d5c12c9b1c2
|
7
|
+
data.tar.gz: df955321287251309b6a5f2ef6dd24e0701b3218423eb365dbf5e5156e4cea031526fa6ce3b5478b9b69dda030f9067807331d34888dcce2363cacf34a8c0c90
|
@@ -104,9 +104,17 @@ module SettingAccessors::Integration
|
|
104
104
|
self
|
105
105
|
end
|
106
106
|
|
107
|
-
def as_json(
|
108
|
-
json = super
|
109
|
-
|
107
|
+
def as_json(options = {})
|
108
|
+
json = super options
|
109
|
+
|
110
|
+
setting_names = SettingAccessors::Internal.setting_accessor_names(self.class)
|
111
|
+
if only = options[:only]
|
112
|
+
setting_names &= Array(only).map(&:to_s)
|
113
|
+
elsif except = options[:except]
|
114
|
+
setting_names -= Array(except).map(&:to_s)
|
115
|
+
end
|
116
|
+
|
117
|
+
setting_names.each do |setting_name|
|
110
118
|
json[setting_name.to_s] = send(setting_name)
|
111
119
|
end
|
112
120
|
json
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -17,6 +17,48 @@ class UserTest < ActiveSupport::TestCase
|
|
17
17
|
assert_equal @user.as_json[setting_name.to_s], @user.send(setting_name)
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
context 'when using as_json with option :only' do
|
22
|
+
context 'set to a class attribute name' do
|
23
|
+
should 'not include any setting accessors' do
|
24
|
+
json = @user.as_json :only => [:first_name]
|
25
|
+
SettingAccessors::Internal.setting_accessor_names(User).each do |setting_name|
|
26
|
+
assert_not_includes json.keys, setting_name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'set to a setting accessor name' do
|
32
|
+
should 'not include other setting accessors' do
|
33
|
+
json = @user.as_json :only => [:a_string]
|
34
|
+
assert_includes json.keys, 'a_string'
|
35
|
+
(SettingAccessors::Internal.setting_accessor_names(User) - ['a_string']).each do |setting_name|
|
36
|
+
assert_not_includes json.keys, setting_name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when using as_json with option :except' do
|
43
|
+
context 'set to a class attribute name' do
|
44
|
+
should 'include all setting accessors' do
|
45
|
+
json = @user.as_json :except => [:first_name]
|
46
|
+
SettingAccessors::Internal.setting_accessor_names(User).each do |setting_name|
|
47
|
+
assert_includes json.keys, setting_name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'set to a setting accessor name' do
|
53
|
+
should 'include all other setting accessors' do
|
54
|
+
json = @user.as_json :except => [:a_string]
|
55
|
+
assert_not_includes json.keys, 'a_string'
|
56
|
+
(SettingAccessors::Internal.setting_accessor_names(User) - ['a_string']).each do |setting_name|
|
57
|
+
assert_includes json.keys, setting_name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
20
62
|
end
|
21
63
|
|
22
64
|
context 'Boolean getter methods' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: setting_accessors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Exner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
224
|
version: '0'
|
225
225
|
requirements: []
|
226
226
|
rubyforge_project:
|
227
|
-
rubygems_version: 2.
|
227
|
+
rubygems_version: 2.6.9
|
228
228
|
signing_key:
|
229
229
|
specification_version: 4
|
230
230
|
summary: A global key-value-store and virtual model columns
|