activeadmin_settings_cached 2.2.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +9 -0
- data/Gemfile +1 -0
- data/Makefile +6 -0
- data/README.md +1 -1
- data/activeadmin_settings_cached.gemspec +0 -1
- data/docker-compose.yml +3 -4
- data/gemfiles/rails4.2.gemfile +1 -0
- data/gemfiles/rails5.0.gemfile +1 -0
- data/gemfiles/rails5.1.gemfile +1 -0
- data/lib/activeadmin_settings_cached/coercions.rb +15 -14
- data/lib/activeadmin_settings_cached/version.rb +1 -1
- data/spec/coercions_spec.rb +50 -44
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6a36186f3620c9f433f3ae6623aee9ac7f41aa6eba6f09c1d6258e3c85fff4ff
|
4
|
+
data.tar.gz: 8df7671e910503777e8db5ef684ccbe75188e7ff813f57f8674fcbdbbf7dc67f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62a56fafb8fbc35413d980bcbc4e56c8ed8651adb51f9c5af9431f312d30d9b7b3b0f6594d09e53342c236b3721a846ad0c4eae820fd6553031b51efe380c242
|
7
|
+
data.tar.gz: 18fa494be363505eb265ea9031a4eca53931f2f23e222681d0449caac04fa3d1097fa4f6c27587b51c00c93df5ca272230d44b8ca8fa9048ba16dd5a4fce9871
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Makefile
CHANGED
data/README.md
CHANGED
data/docker-compose.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
version: '
|
1
|
+
version: '3.3'
|
2
2
|
|
3
3
|
services:
|
4
4
|
app:
|
@@ -6,8 +6,7 @@ services:
|
|
6
6
|
command: 'make test'
|
7
7
|
volumes:
|
8
8
|
- '.:/app'
|
9
|
-
-
|
9
|
+
- bundler-data:/usr/local/bundle/:cached
|
10
10
|
|
11
11
|
volumes:
|
12
|
-
|
13
|
-
external: true
|
12
|
+
bundler-data:
|
data/gemfiles/rails4.2.gemfile
CHANGED
data/gemfiles/rails5.0.gemfile
CHANGED
data/gemfiles/rails5.1.gemfile
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'dry-types'
|
4
|
-
|
5
3
|
module ActiveadminSettingsCached
|
6
4
|
# Coerce user input values to defined types
|
7
5
|
#
|
8
6
|
# @api private
|
9
7
|
class Coercions
|
8
|
+
TRUE_VALUES = %w[1 on On ON t true True TRUE T y yes Yes YES Y].freeze
|
9
|
+
FALSE_VALUES = %w[0 off Off OFF f false False FALSE F n no No NO N].freeze
|
10
|
+
BOOLEAN_MAP = ::Hash[
|
11
|
+
TRUE_VALUES.product([true]) + FALSE_VALUES.product([false])
|
12
|
+
].freeze
|
13
|
+
|
10
14
|
attr_reader :defaults, :display
|
11
15
|
|
12
16
|
def initialize(defaults, display)
|
13
17
|
@defaults = defaults
|
14
|
-
@display
|
18
|
+
@display = display
|
15
19
|
end
|
16
20
|
|
17
21
|
def cast_params(params)
|
@@ -28,14 +32,14 @@ module ActiveadminSettingsCached
|
|
28
32
|
|
29
33
|
private
|
30
34
|
|
31
|
-
def cast_value(name, value)
|
35
|
+
def cast_value(name, value) # rubocop:disable Metrics/MethodLength
|
32
36
|
case defaults[name]
|
33
37
|
when TrueClass, FalseClass
|
34
|
-
-> {
|
38
|
+
-> { BOOLEAN_MAP.fetch(value, false) }
|
35
39
|
when Integer
|
36
|
-
-> { value_or_default(
|
40
|
+
-> { value_or_default(0) { Integer(value) } }
|
37
41
|
when Float
|
38
|
-
-> { value_or_default(
|
42
|
+
-> { value_or_default(0.0) { Float(value) } }
|
39
43
|
when Hash, 'ActiveSupport::HashWithIndifferentAccess'
|
40
44
|
nil
|
41
45
|
when Symbol
|
@@ -45,13 +49,10 @@ module ActiveadminSettingsCached
|
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
48
|
-
def value_or_default(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
else
|
53
|
-
default
|
54
|
-
end
|
52
|
+
def value_or_default(default)
|
53
|
+
yield
|
54
|
+
rescue ArgumentError, TypeError
|
55
|
+
default
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
data/spec/coercions_spec.rb
CHANGED
@@ -21,60 +21,66 @@ RSpec.describe ActiveadminSettingsCached::Coercions do
|
|
21
21
|
'base.five_setting' => :aaa,
|
22
22
|
'second.first_setting' => false,
|
23
23
|
'second.second_setting' => 'BBB',
|
24
|
-
'some' =>
|
24
|
+
'some' => {}
|
25
25
|
].with_indifferent_access
|
26
26
|
end
|
27
27
|
|
28
|
-
let(:right_params) do
|
29
|
-
ActionController::Parameters.new(
|
30
|
-
Hash[
|
31
|
-
'base.first_setting' => 'BBB',
|
32
|
-
'base.second_setting' => 'false',
|
33
|
-
'base.third_setting' => '155',
|
34
|
-
'base.four_setting' => '55.5',
|
35
|
-
'base.five_setting' => 'bbb',
|
36
|
-
'second.first_setting' => 'true',
|
37
|
-
'second.second_setting' => 'AAA'
|
38
|
-
]
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
let(:wrong_params) do
|
43
|
-
ActionController::Parameters.new(
|
44
|
-
Hash['base.second_setting' => 'hjgj',
|
45
|
-
'base.third_setting' => 'fhfh',
|
46
|
-
'base.four_setting' => 'gjfhg',
|
47
|
-
'second.first_setting' => 'ggf',
|
48
|
-
'some' => Hash.new
|
49
|
-
])
|
50
|
-
end
|
51
|
-
|
52
|
-
let(:no_params) { ActionController::Parameters.new(Hash[]) }
|
53
|
-
|
54
28
|
subject(:coercions) do
|
55
29
|
ActiveadminSettingsCached::Coercions.new(defaults, display)
|
56
30
|
end
|
57
31
|
|
58
|
-
|
59
|
-
|
60
|
-
.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
32
|
+
context 'when params is valid' do
|
33
|
+
let(:params) do
|
34
|
+
ActionController::Parameters.new(
|
35
|
+
Hash[
|
36
|
+
'base.first_setting' => 'BBB',
|
37
|
+
'base.second_setting' => 'false',
|
38
|
+
'base.third_setting' => '155',
|
39
|
+
'base.four_setting' => '55.5',
|
40
|
+
'base.five_setting' => 'bbb',
|
41
|
+
'second.first_setting' => 'true',
|
42
|
+
'second.second_setting' => 'AAA'
|
43
|
+
]
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'casts params' do
|
48
|
+
expect { |b| coercions.cast_params(params, &b) }
|
49
|
+
.to yield_successive_args(['base.first_setting', 'BBB'],
|
50
|
+
['base.second_setting', false],
|
51
|
+
['base.third_setting', 155],
|
52
|
+
['base.four_setting', 55.5],
|
53
|
+
['base.five_setting', :bbb],
|
54
|
+
['second.first_setting', true],
|
55
|
+
['second.second_setting', 'AAA'])
|
56
|
+
end
|
67
57
|
end
|
68
58
|
|
69
|
-
|
70
|
-
|
71
|
-
.
|
72
|
-
|
73
|
-
|
74
|
-
|
59
|
+
context 'when params is wrong' do
|
60
|
+
let(:params) do
|
61
|
+
ActionController::Parameters.new(
|
62
|
+
Hash[
|
63
|
+
'base.second_setting' => 'hjgj',
|
64
|
+
'base.third_setting' => 'fhfh',
|
65
|
+
'base.four_setting' => 'gjfhg',
|
66
|
+
'second.first_setting' => 'ggf',
|
67
|
+
'some' => {}
|
68
|
+
]
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns default values' do
|
73
|
+
expect { |b| coercions.cast_params(params, &b) }
|
74
|
+
.to yield_successive_args(['base.second_setting', false],
|
75
|
+
['base.third_setting', 0],
|
76
|
+
['base.four_setting', 0.0],
|
77
|
+
['second.first_setting', false])
|
78
|
+
end
|
75
79
|
end
|
76
80
|
|
77
|
-
|
78
|
-
|
81
|
+
context 'when params is empty' do
|
82
|
+
let(:params) { ActionController::Parameters.new(Hash[]) }
|
83
|
+
|
84
|
+
it { expect { |b| coercions.cast_params(params, &b) }.not_to yield_control }
|
79
85
|
end
|
80
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_settings_cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Semyon Pupkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: dry-types
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.8.1
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.8.1
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rails-settings-cached
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
248
|
version: '0'
|
263
249
|
requirements: []
|
264
250
|
rubyforge_project:
|
265
|
-
rubygems_version: 2.6
|
251
|
+
rubygems_version: 2.7.6
|
266
252
|
signing_key:
|
267
253
|
specification_version: 4
|
268
254
|
summary: UI interface for rails-settings-cached in active admin
|