acfs 0.45.0 → 0.46.0
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/CHANGELOG.md +4 -0
- data/lib/acfs/resource/attributes/base.rb +10 -18
- data/lib/acfs/resource/attributes/boolean.rb +10 -6
- data/lib/acfs/resource/attributes/date_time.rb +7 -8
- data/lib/acfs/resource/attributes/dict.rb +15 -5
- data/lib/acfs/resource/attributes/float.rb +11 -3
- data/lib/acfs/resource/attributes/integer.rb +7 -7
- data/lib/acfs/resource/attributes/list.rb +13 -4
- data/lib/acfs/resource/attributes/string.rb +3 -3
- data/lib/acfs/resource/attributes/uuid.rb +8 -15
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/resource/attributes/boolean_spec.rb +40 -9
- data/spec/acfs/resource/attributes/date_time_spec.rb +29 -35
- data/spec/acfs/resource/attributes/dict_spec.rb +54 -29
- data/spec/acfs/resource/attributes/float_spec.rb +48 -9
- data/spec/acfs/resource/attributes/integer_spec.rb +23 -8
- data/spec/acfs/resource/attributes/list_spec.rb +43 -19
- data/spec/acfs/resource/attributes/uuid_spec.rb +31 -54
- data/spec/acfs/resource/attributes_spec.rb +0 -26
- 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: 2ba49d6dd8c50e454b8f3840420655bb3c4ce682
|
4
|
+
data.tar.gz: 643a02f5bf2bee3a9dc58fc2bd1eacc4bbac4b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72c52711056563f03ab5ccd497ea81470934c899e0c3e0f0bc5c66ad3e05e60194066281f2545afd37365876d7c7910c26bcad2efd6c60d10ff295e7dd9ac0f5
|
7
|
+
data.tar.gz: a72dc58cc2f8934aba2d57d69a1171c316bbbb98b5ae912727833afbb0e66d7b3a981b7b6332ad8ab0fd74f70f1d51e0616dc741a4df5d9d911cb2792c31817a
|
data/CHANGELOG.md
CHANGED
@@ -1,35 +1,27 @@
|
|
1
1
|
module Acfs::Resource::Attributes
|
2
2
|
#
|
3
3
|
class Base
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :default
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
8
|
-
@options.reverse_merge! allow_nil: true
|
6
|
+
def initialize(default: nil)
|
7
|
+
@default = default
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def blank_allowed?
|
16
|
-
options[:allow_blank]
|
10
|
+
def cast(value)
|
11
|
+
cast_value(value) unless value.nil?
|
17
12
|
end
|
18
13
|
|
19
14
|
def default_value
|
20
|
-
if
|
21
|
-
|
15
|
+
if default.respond_to? :call
|
16
|
+
default
|
22
17
|
else
|
23
|
-
cast
|
18
|
+
cast default
|
24
19
|
end
|
25
20
|
end
|
26
21
|
|
27
|
-
|
28
|
-
return nil if obj.nil? && nil_allowed? || (obj == '' && blank_allowed?)
|
29
|
-
cast_type obj
|
30
|
-
end
|
22
|
+
private
|
31
23
|
|
32
|
-
def
|
24
|
+
def cast_value(_value)
|
33
25
|
raise NotImplementedError
|
34
26
|
end
|
35
27
|
end
|
@@ -14,20 +14,24 @@ module Acfs::Resource::Attributes
|
|
14
14
|
# true, on, yes
|
15
15
|
#
|
16
16
|
class Boolean < Base
|
17
|
-
|
17
|
+
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', 'no', 'NO'].to_set
|
18
18
|
|
19
19
|
# @api public
|
20
20
|
#
|
21
21
|
# Cast given object to boolean.
|
22
22
|
#
|
23
|
-
# @param [Object]
|
23
|
+
# @param [Object] value Object to cast.
|
24
24
|
# @return [TrueClass, FalseClass] Casted boolean.
|
25
25
|
#
|
26
|
-
def
|
27
|
-
return true if
|
28
|
-
return false if
|
26
|
+
def cast_value(value)
|
27
|
+
return true if value == true
|
28
|
+
return false if value == false
|
29
29
|
|
30
|
-
|
30
|
+
if value.blank?
|
31
|
+
nil
|
32
|
+
else
|
33
|
+
!FALSE_VALUES.include?(value)
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
@@ -10,22 +10,21 @@ module Acfs::Resource::Attributes
|
|
10
10
|
# end
|
11
11
|
#
|
12
12
|
class DateTime < Base
|
13
|
+
|
13
14
|
# @api public
|
14
15
|
#
|
15
16
|
# Cast given object to DateTime.
|
16
17
|
#
|
17
|
-
# @param [Object]
|
18
|
+
# @param [Object] value Object to cast.
|
18
19
|
# @return [DateTime] Casted object as DateTime.
|
19
20
|
#
|
20
|
-
def
|
21
|
-
if
|
21
|
+
def cast_value(value)
|
22
|
+
if value.blank?
|
22
23
|
nil
|
23
|
-
elsif
|
24
|
-
|
25
|
-
elsif obj.is_a?(Time) || obj.is_a?(Date)
|
26
|
-
::DateTime.iso8601 obj.iso8601
|
24
|
+
elsif value.acts_like?(:time) || value.acts_like?(:date)
|
25
|
+
value.to_datetime
|
27
26
|
else
|
28
|
-
::DateTime.iso8601
|
27
|
+
::DateTime.iso8601 value
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
@@ -14,14 +14,24 @@ module Acfs::Resource::Attributes
|
|
14
14
|
#
|
15
15
|
# Cast given object to a dict/hash.
|
16
16
|
#
|
17
|
-
# @param [Object]
|
17
|
+
# @param [Object] value Object to cast.
|
18
18
|
# @return [Hash] Casted object as hash.
|
19
19
|
# @raise [TypeError] If object cannot be casted to a hash.
|
20
20
|
#
|
21
|
-
def
|
22
|
-
return
|
23
|
-
|
24
|
-
|
21
|
+
def cast_value(value)
|
22
|
+
return nil if value.blank?
|
23
|
+
|
24
|
+
if value.is_a?(Hash)
|
25
|
+
value
|
26
|
+
elsif value.respond_to?(:serializable_hash)
|
27
|
+
value.serializable_hash
|
28
|
+
elsif value.respond_to?(:to_hash)
|
29
|
+
value.to_hash
|
30
|
+
elsif value.respond_to?(:to_h)
|
31
|
+
value.to_h
|
32
|
+
else
|
33
|
+
Hash(value)
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
@@ -13,11 +13,19 @@ module Acfs::Resource::Attributes
|
|
13
13
|
#
|
14
14
|
# Cast given object to float.
|
15
15
|
#
|
16
|
-
# @param [Object]
|
16
|
+
# @param [Object] value Object to cast.
|
17
17
|
# @return [Float] Casted object as float.
|
18
18
|
#
|
19
|
-
def
|
20
|
-
|
19
|
+
def cast_value(value)
|
20
|
+
return 0.0 if value.blank?
|
21
|
+
|
22
|
+
case value
|
23
|
+
when ::Float then value
|
24
|
+
when "Infinity" then ::Float::INFINITY
|
25
|
+
when "-Infinity" then -::Float::INFINITY
|
26
|
+
when "NaN" then ::Float::NAN
|
27
|
+
else Float(value)
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
23
31
|
end
|
@@ -13,15 +13,15 @@ module Acfs::Resource::Attributes
|
|
13
13
|
#
|
14
14
|
# Cast given object to integer.
|
15
15
|
#
|
16
|
-
# @param [Object]
|
16
|
+
# @param [Object] value Object to cast.
|
17
17
|
# @return [Fixnum] Casted object as fixnum.
|
18
18
|
#
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
def cast_value(value)
|
20
|
+
if value.blank?
|
21
|
+
0
|
22
|
+
else
|
23
|
+
Integer(value)
|
24
|
+
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -13,13 +13,22 @@ module Acfs::Resource::Attributes
|
|
13
13
|
#
|
14
14
|
# Cast given object to a list.
|
15
15
|
#
|
16
|
-
# @param [Object]
|
16
|
+
# @param [Object] value Object to cast.
|
17
17
|
# @return [Fixnum] Casted object as list.
|
18
18
|
# @raise [TypeError] If object cannot be casted to a list.
|
19
19
|
#
|
20
|
-
def
|
21
|
-
return
|
22
|
-
|
20
|
+
def cast_value(value)
|
21
|
+
return nil if value.blank?
|
22
|
+
|
23
|
+
if value.is_a?(::Array)
|
24
|
+
value
|
25
|
+
elsif value.respond_to?(:to_ary)
|
26
|
+
value.to_ary
|
27
|
+
elsif value.respond_to?(:to_a)
|
28
|
+
value.to_a
|
29
|
+
else
|
30
|
+
Array(value)
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
25
34
|
end
|
@@ -14,11 +14,11 @@ module Acfs::Resource::Attributes
|
|
14
14
|
#
|
15
15
|
# Cast given object to string.
|
16
16
|
#
|
17
|
-
# @param [Object]
|
17
|
+
# @param [Object] value Object to cast.
|
18
18
|
# @return [String] Casted string.
|
19
19
|
#
|
20
|
-
def
|
21
|
-
|
20
|
+
def cast_value(value)
|
21
|
+
value.to_s
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -10,7 +10,7 @@ module Acfs::Resource::Attributes
|
|
10
10
|
#
|
11
11
|
class UUID < Base
|
12
12
|
#
|
13
|
-
|
13
|
+
UUID_REGEXP = /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/i
|
14
14
|
|
15
15
|
# @api public
|
16
16
|
#
|
@@ -28,23 +28,16 @@ module Acfs::Resource::Attributes
|
|
28
28
|
# | 4 | 4 |
|
29
29
|
# | 5 | 12 |
|
30
30
|
#
|
31
|
-
# @param [Object]
|
31
|
+
# @param [Object] value Object to cast.
|
32
32
|
# @return [String] Casted object as UUID.
|
33
33
|
#
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def cast_string(str)
|
41
|
-
if nil_allowed? && str.blank?
|
42
|
-
return nil
|
43
|
-
elsif str =~ REGEXP
|
44
|
-
str
|
34
|
+
def cast_value(value)
|
35
|
+
if value.blank?
|
36
|
+
nil
|
37
|
+
elsif value.to_s =~ UUID_REGEXP
|
38
|
+
value
|
45
39
|
else
|
46
|
-
raise
|
47
|
-
'does not look like a UUID'
|
40
|
+
raise TypeError.new "Invalid UUID: `#{value.to_s}'"
|
48
41
|
end
|
49
42
|
end
|
50
43
|
end
|
data/lib/acfs/version.rb
CHANGED
@@ -3,23 +3,54 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Resource::Attributes::Boolean do
|
4
4
|
subject { Acfs::Resource::Attributes::Boolean.new }
|
5
5
|
|
6
|
-
describe 'cast' do
|
7
|
-
it '
|
6
|
+
describe '#cast' do
|
7
|
+
it 'casts nil' do
|
8
|
+
expect(subject.cast(nil)).to eq nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'casts empty string to false' do
|
12
|
+
expect(subject.cast('')).to eq nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'casts blank string to false' do
|
16
|
+
expect(subject.cast(" \t")).to eq nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'preserves boolean values' do
|
8
20
|
expect(subject.cast(false)).to eq false
|
9
21
|
expect(subject.cast(true)).to eq true
|
10
22
|
end
|
11
23
|
|
12
|
-
it '
|
24
|
+
it 'casts falsy values to false' do
|
25
|
+
expect(subject.cast(false)).to eq false
|
26
|
+
expect(subject.cast(0)).to eq false
|
27
|
+
expect(subject.cast('0')).to eq false
|
28
|
+
expect(subject.cast('no')).to eq false
|
29
|
+
expect(subject.cast('NO')).to eq false
|
30
|
+
expect(subject.cast('off')).to eq false
|
31
|
+
expect(subject.cast('OFF')).to eq false
|
32
|
+
expect(subject.cast('false')).to eq false
|
33
|
+
expect(subject.cast('FALSE')).to eq false
|
34
|
+
expect(subject.cast('f')).to eq false
|
35
|
+
expect(subject.cast('F')).to eq false
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'casts any other value to true' do
|
39
|
+
expect(subject.cast(true)).to eq true
|
40
|
+
expect(subject.cast(1)).to eq true
|
41
|
+
expect(subject.cast('1')).to eq true
|
13
42
|
expect(subject.cast('yes')).to eq true
|
43
|
+
expect(subject.cast('YES')).to eq true
|
14
44
|
expect(subject.cast('on')).to eq true
|
45
|
+
expect(subject.cast('ON')).to eq true
|
15
46
|
expect(subject.cast('true')).to eq true
|
16
|
-
expect(subject.cast('
|
17
|
-
|
47
|
+
expect(subject.cast('TRUE')).to eq true
|
48
|
+
expect(subject.cast('t')).to eq true
|
49
|
+
expect(subject.cast('T')).to eq true
|
18
50
|
|
19
|
-
|
20
|
-
expect(subject.cast('')).to eq
|
21
|
-
expect(subject.cast('
|
22
|
-
expect(subject.cast('random')).to eq false
|
51
|
+
expect(subject.cast(2)).to eq true
|
52
|
+
expect(subject.cast('wrong')).to eq true
|
53
|
+
expect(subject.cast('random')).to eq true
|
23
54
|
end
|
24
55
|
end
|
25
56
|
end
|
@@ -1,55 +1,49 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::DateTime do
|
4
|
-
let(:
|
5
|
-
let(:params) { {} }
|
6
|
-
subject { Acfs::Resource::Attributes::DateTime.new params }
|
4
|
+
let(:type) { Acfs::Resource::Attributes::DateTime.new }
|
7
5
|
|
8
|
-
describe 'cast' do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
describe '#cast' do
|
7
|
+
subject { -> { type.cast value } }
|
8
|
+
|
9
|
+
context 'with nil' do
|
10
|
+
let(:value) { nil }
|
11
|
+
it { expect(subject.call).to eq nil }
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
expect(retval).to be == DateTime.iso8601(time.iso8601)
|
14
|
+
context 'with empty string' do
|
15
|
+
let(:value) { '' }
|
16
|
+
it { expect(subject.call).to eq nil }
|
19
17
|
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
expect(retval).to be == DateTime.iso8601(date.iso8601)
|
19
|
+
context 'with blank string' do
|
20
|
+
let(:value) { " \t" }
|
21
|
+
it { expect(subject.call).to eq nil }
|
25
22
|
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
expect(retval).to be == DateTime.iso8601(date_time_string)
|
24
|
+
context 'with DateTime' do
|
25
|
+
let(:value) { DateTime.now }
|
26
|
+
it { expect(subject.call).to eq value }
|
31
27
|
end
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
expect
|
36
|
-
subject.cast(malformed_string)
|
37
|
-
end.to raise_error ArgumentError
|
29
|
+
context 'with Time' do
|
30
|
+
let(:value) { Time.now }
|
31
|
+
it { expect(subject.call).to eq value.to_datetime }
|
38
32
|
end
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
expect
|
43
|
-
subject.cast(fixnum)
|
44
|
-
end.to raise_error TypeError
|
34
|
+
context 'with Date' do
|
35
|
+
let(:value) { Date.today }
|
36
|
+
it { expect(subject.call).to eq value.to_datetime }
|
45
37
|
end
|
46
38
|
|
47
|
-
context 'with
|
48
|
-
let(:
|
39
|
+
context 'with ISO8601' do
|
40
|
+
let(:value) { DateTime.now.iso8601 }
|
41
|
+
it { expect(subject.call.iso8601).to eq value }
|
42
|
+
end
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
context 'with invalid string' do
|
45
|
+
let(:value) { 'qwe123' }
|
46
|
+
it { is_expected.to raise_error ArgumentError }
|
53
47
|
end
|
54
48
|
end
|
55
49
|
end
|
@@ -1,50 +1,75 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::Dict do
|
4
|
-
let(:
|
5
|
-
subject { Acfs::Resource::Attributes::Dict.new }
|
4
|
+
let(:type) { Acfs::Resource::Attributes::Dict.new }
|
6
5
|
|
7
|
-
describe '
|
8
|
-
|
9
|
-
let(:sample) { {3 => true, 'asfd' => 4} }
|
6
|
+
describe '#cast' do
|
7
|
+
subject { -> { type.cast value } }
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
context 'with nil' do
|
10
|
+
let(:value) { nil }
|
11
|
+
it { expect(subject.call).to eq nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with blank string (I)' do
|
15
|
+
let(:value) { '' }
|
16
|
+
it { expect(subject.call).to eq nil }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with blank string (II)' do
|
20
|
+
let(:value) { " \t" }
|
21
|
+
it { expect(subject.call).to eq nil }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with hash' do
|
25
|
+
let(:value) { {3 => true, abc: 4} }
|
26
|
+
it { expect(subject.call).to eq value }
|
14
27
|
end
|
15
28
|
|
16
|
-
context 'with
|
17
|
-
let(:
|
29
|
+
context 'with non hashable object' do
|
30
|
+
let(:value) { Object.new }
|
31
|
+
it { is_expected.to raise_error TypeError }
|
32
|
+
end
|
18
33
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
34
|
+
context 'with hashable object (I)' do
|
35
|
+
let(:value) do
|
36
|
+
Class.new do
|
37
|
+
def to_hash
|
38
|
+
{id: object_id}
|
39
|
+
end
|
40
|
+
end.new
|
23
41
|
end
|
42
|
+
|
43
|
+
it { expect(subject.call).to eq id: value.object_id }
|
24
44
|
end
|
25
45
|
|
26
|
-
context 'with hashable object' do
|
27
|
-
let(:
|
28
|
-
|
29
|
-
class << o
|
46
|
+
context 'with hashable object (II)' do
|
47
|
+
let(:value) do
|
48
|
+
Class.new do
|
30
49
|
def to_h
|
31
|
-
{
|
50
|
+
{id: object_id}
|
32
51
|
end
|
33
|
-
end
|
34
|
-
o
|
52
|
+
end.new
|
35
53
|
end
|
36
54
|
|
37
|
-
it
|
38
|
-
expect(subject.cast(sample)).to eq 3 => 4, 'test' => true
|
39
|
-
end
|
55
|
+
it { expect(subject.call).to eq id: value.object_id }
|
40
56
|
end
|
41
57
|
|
42
|
-
context 'with
|
43
|
-
let(:
|
44
|
-
|
45
|
-
|
46
|
-
|
58
|
+
context 'with serializable object' do
|
59
|
+
let(:value) do
|
60
|
+
Class.new do
|
61
|
+
def serializable_hash
|
62
|
+
{id: object_id}
|
63
|
+
end
|
64
|
+
end.new
|
47
65
|
end
|
66
|
+
|
67
|
+
it { expect(subject.call).to eq id: value.object_id }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with hash subclass object' do
|
71
|
+
let(:value) { HashWithIndifferentAccess.new test: :foo }
|
72
|
+
it { expect(subject.call).to be value }
|
48
73
|
end
|
49
74
|
end
|
50
75
|
end
|
@@ -1,20 +1,59 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::Float do
|
4
|
-
let(:
|
5
|
-
subject { described_class.new }
|
4
|
+
let(:type) { Acfs::Resource::Attributes::Float.new }
|
6
5
|
|
7
|
-
describe 'cast' do
|
8
|
-
|
9
|
-
|
6
|
+
describe '#cast' do
|
7
|
+
subject { -> { type.cast value } }
|
8
|
+
|
9
|
+
context 'with nil' do
|
10
|
+
let(:value) { nil }
|
11
|
+
it { expect(subject.call).to eq nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with blank string (I)' do
|
15
|
+
let(:value) { '' }
|
16
|
+
it { expect(subject.call).to eq 0.0 }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with blank string (II)' do
|
20
|
+
let(:value) { " \t" }
|
21
|
+
it { expect(subject.call).to eq 0.0 }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with float' do
|
25
|
+
let(:value) { 1.7 }
|
26
|
+
it { expect(subject.call).to eq 1.7 }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with Infinity' do
|
30
|
+
let(:value) { 'Infinity' }
|
31
|
+
it { expect(subject.call).to eq ::Float::INFINITY }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with -Infinity' do
|
35
|
+
let(:value) { '-Infinity' }
|
36
|
+
it { expect(subject.call).to eq -::Float::INFINITY }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with NaN' do
|
40
|
+
let(:value) { 'NaN' }
|
41
|
+
it { expect(subject.call).to be_nan }
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with fixnum' do
|
45
|
+
let(:value) { 1 }
|
46
|
+
it { expect(subject.call).to eq 1.0 }
|
10
47
|
end
|
11
48
|
|
12
|
-
|
13
|
-
|
49
|
+
context 'with valid string' do
|
50
|
+
let(:value) { '1.7' }
|
51
|
+
it { expect(subject.call).to eq 1.7 }
|
14
52
|
end
|
15
53
|
|
16
|
-
|
17
|
-
|
54
|
+
context 'with invalid string (I)' do
|
55
|
+
let(:value) { '1.7a' }
|
56
|
+
it { is_expected.to raise_error ArgumentError }
|
18
57
|
end
|
19
58
|
end
|
20
59
|
end
|
@@ -1,19 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::Integer do
|
4
|
-
|
4
|
+
let(:type) { Acfs::Resource::Attributes::Integer.new }
|
5
5
|
|
6
|
-
describe 'cast' do
|
7
|
-
|
8
|
-
|
6
|
+
describe '#cast' do
|
7
|
+
subject { -> { type.cast value } }
|
8
|
+
|
9
|
+
context 'with nil' do
|
10
|
+
let(:value) { nil }
|
11
|
+
it { expect(subject.call).to eq nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with empty string' do
|
15
|
+
let(:value) { '' }
|
16
|
+
it { expect(subject.call).to eq 0 }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with blank string' do
|
20
|
+
let(:value) { " \t" }
|
21
|
+
it { expect(subject.call).to eq 0 }
|
9
22
|
end
|
10
23
|
|
11
|
-
|
12
|
-
|
24
|
+
context 'with string' do
|
25
|
+
let(:value) { '123' }
|
26
|
+
it { expect(subject.call).to eq 123 }
|
13
27
|
end
|
14
28
|
|
15
|
-
|
16
|
-
|
29
|
+
context 'with invalid string' do
|
30
|
+
let(:value) { '123a' }
|
31
|
+
it { is_expected.to raise_error ArgumentError }
|
17
32
|
end
|
18
33
|
end
|
19
34
|
end
|
@@ -1,34 +1,58 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::List do
|
4
|
-
let(:
|
5
|
-
subject { described_class.new }
|
4
|
+
let(:type) { Acfs::Resource::Attributes::List.new }
|
6
5
|
|
7
|
-
describe '
|
8
|
-
|
9
|
-
let(:sample) { %w(abc cde efg) }
|
6
|
+
describe '#cast' do
|
7
|
+
subject { -> { type.cast value } }
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
context 'with nil' do
|
10
|
+
let(:value) { nil }
|
11
|
+
it { expect(subject.call).to eq nil }
|
14
12
|
end
|
15
13
|
|
16
|
-
context 'with
|
17
|
-
let(:
|
14
|
+
context 'with blank string (I)' do
|
15
|
+
let(:value) { '' }
|
16
|
+
it { expect(subject.call).to eq nil }
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end.to raise_error TypeError
|
23
|
-
end
|
19
|
+
context 'with blank string (II)' do
|
20
|
+
let(:value) { " \t" }
|
21
|
+
it { expect(subject.call).to eq nil }
|
24
22
|
end
|
25
23
|
|
26
|
-
context 'with
|
27
|
-
let(:
|
24
|
+
context 'with array' do
|
25
|
+
let(:value) { %w(abc cde efg) }
|
26
|
+
it { expect(subject.call).to eq value }
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
context 'with convertable object (I)' do
|
30
|
+
let(:value) do
|
31
|
+
Class.new do
|
32
|
+
def to_ary
|
33
|
+
[1, 2, 3]
|
34
|
+
end
|
35
|
+
end.new
|
31
36
|
end
|
37
|
+
|
38
|
+
it { expect(subject.call).to eq [1, 2, 3] }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with convertable object (II)' do
|
42
|
+
let(:value) do
|
43
|
+
Class.new do
|
44
|
+
def to_a
|
45
|
+
[1, 2, 3]
|
46
|
+
end
|
47
|
+
end.new
|
48
|
+
end
|
49
|
+
|
50
|
+
it { expect(subject.call).to eq [1, 2, 3] }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with non castable object' do
|
54
|
+
let(:value) { Object.new }
|
55
|
+
it { expect(subject.call).to eq [value] }
|
32
56
|
end
|
33
57
|
end
|
34
58
|
end
|
@@ -1,63 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::UUID do
|
4
|
-
let(:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
subject { action }
|
13
|
-
|
14
|
-
context 'with String as param' do
|
15
|
-
context 'with valid UUID' do
|
16
|
-
let(:param) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
|
17
|
-
it { should be_a String }
|
18
|
-
it { should eq param }
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with invalid UUID' do
|
22
|
-
subject { -> { action } }
|
23
|
-
|
24
|
-
context 'with random non-empty string' do
|
25
|
-
let(:param) { 'invalid string' }
|
26
|
-
it { should raise_error ArgumentError }
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with UUID string containing invalid characters' do
|
30
|
-
let(:param) { 'xxxxxxxx-yyyy-11e3-baa8-0800200c9a66' }
|
31
|
-
it { should raise_error ArgumentError }
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'with empty string' do
|
35
|
-
let(:param) { '' }
|
36
|
-
|
37
|
-
context 'with allow_nil option' do
|
38
|
-
let(:params) { {allow_nil: true} }
|
39
|
-
subject { action }
|
40
|
-
it { should eq nil }
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'without allow_nil option' do
|
44
|
-
let(:params) { {allow_nil: false} }
|
45
|
-
it { should raise_error ArgumentError }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
4
|
+
let(:type) { Acfs::Resource::Attributes::UUID.new }
|
5
|
+
|
6
|
+
describe '#cast' do
|
7
|
+
subject { -> { type.cast(value) } }
|
8
|
+
|
9
|
+
context 'with nil' do
|
10
|
+
let(:value) { nil }
|
11
|
+
it { expect(subject.call).to eq nil }
|
49
12
|
end
|
50
13
|
|
51
|
-
context 'with
|
52
|
-
|
14
|
+
context 'with empty string' do
|
15
|
+
let(:value) { '' }
|
16
|
+
it { expect(subject.call).to eq nil }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with blank string' do
|
20
|
+
let(:value) { " \t" }
|
21
|
+
it { expect(subject.call).to eq nil }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with string UUID' do
|
25
|
+
let(:value) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
|
26
|
+
it { expect(subject.call).to be_a String }
|
27
|
+
it { expect(subject.call).to eq value }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with invalid string' do
|
31
|
+
let(:value) { 'invalid string' }
|
32
|
+
it { is_expected.to raise_error TypeError, /invalid UUID/i }
|
33
|
+
end
|
53
34
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
let(:param) { incorrect_param }
|
58
|
-
it { should raise_error ArgumentError }
|
59
|
-
end
|
60
|
-
end
|
35
|
+
context 'with invalid UUID' do
|
36
|
+
let(:value) { 'xxxxxxxx-yyyy-11e3-baa8-0800200c9a66' }
|
37
|
+
it { is_expected.to raise_error TypeError, /invalid UUID/i }
|
61
38
|
end
|
62
39
|
end
|
63
40
|
end
|
@@ -162,32 +162,6 @@ describe Acfs::Resource::Attributes do
|
|
162
162
|
|
163
163
|
expect(model.attributes.symbolize_keys).to eq age: 12
|
164
164
|
end
|
165
|
-
|
166
|
-
context 'allow nil option' do
|
167
|
-
it 'should allow nil as value' do
|
168
|
-
model.send :attribute, :updated_at, :date_time,
|
169
|
-
default: DateTime.new, allow_nil: true
|
170
|
-
|
171
|
-
resource = model.new
|
172
|
-
expect(resource.updated_at).to eq DateTime.new
|
173
|
-
|
174
|
-
resource.updated_at = ''
|
175
|
-
expect(resource.updated_at).to eq nil
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context 'allow blank option' do
|
180
|
-
it 'should allow blank as value' do
|
181
|
-
model.send :attribute, :updated_at, :date_time,
|
182
|
-
default: DateTime.new, allow_blank: true
|
183
|
-
|
184
|
-
resource = model.new
|
185
|
-
expect(resource.updated_at).to eq DateTime.new
|
186
|
-
|
187
|
-
resource.updated_at = ''
|
188
|
-
expect(resource.updated_at).to eq nil
|
189
|
-
end
|
190
|
-
end
|
191
165
|
end
|
192
166
|
end
|
193
167
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.46.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
230
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.
|
231
|
+
rubygems_version: 2.6.4
|
232
232
|
signing_key:
|
233
233
|
specification_version: 4
|
234
234
|
summary: An abstract API base client for service oriented application.
|