virtus 0.0.2 → 0.0.3
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.
- data/.gitignore +3 -0
- data/.rvmrc +1 -1
- data/Gemfile +20 -1
- data/History.txt +21 -0
- data/README.markdown +2 -2
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/roodi.yml +18 -0
- data/config/site.reek +91 -0
- data/config/yardstick.yml +2 -0
- data/lib/virtus.rb +51 -45
- data/lib/virtus/attribute.rb +301 -0
- data/lib/virtus/attribute/array.rb +17 -0
- data/lib/virtus/attribute/boolean.rb +60 -0
- data/lib/virtus/attribute/date.rb +35 -0
- data/lib/virtus/attribute/date_time.rb +34 -0
- data/lib/virtus/attribute/decimal.rb +24 -0
- data/lib/virtus/attribute/float.rb +33 -0
- data/lib/virtus/attribute/hash.rb +18 -0
- data/lib/virtus/attribute/integer.rb +30 -0
- data/lib/virtus/{attributes → attribute}/numeric.rb +2 -3
- data/lib/virtus/{attributes → attribute}/object.rb +2 -1
- data/lib/virtus/attribute/string.rb +31 -0
- data/lib/virtus/attribute/time.rb +34 -0
- data/lib/virtus/class_methods.rb +25 -8
- data/lib/virtus/instance_methods.rb +48 -9
- data/lib/virtus/support/chainable.rb +4 -6
- data/lib/virtus/typecast/boolean.rb +27 -0
- data/lib/virtus/typecast/numeric.rb +82 -0
- data/lib/virtus/typecast/time.rb +162 -0
- data/spec/integration/virtus/attributes/attribute/typecast_spec.rb +4 -4
- data/spec/integration/virtus/class_methods/attribute_spec.rb +1 -1
- data/spec/integration/virtus/class_methods/attributes_spec.rb +3 -2
- data/spec/integration/virtus/class_methods/const_missing_spec.rb +2 -2
- data/spec/rcov.opts +6 -0
- data/spec/spec_helper.rb +0 -9
- data/spec/unit/shared/attribute.rb +8 -8
- data/spec/unit/virtus/{attributes → attribute}/array_spec.rb +1 -1
- data/spec/unit/virtus/attribute/attribute_spec.rb +12 -0
- data/spec/unit/virtus/{attributes → attribute}/boolean_spec.rb +4 -4
- data/spec/unit/virtus/{attributes → attribute}/date_spec.rb +13 -7
- data/spec/unit/virtus/{attributes → attribute}/date_time_spec.rb +31 -10
- data/spec/unit/virtus/{attributes → attribute}/decimal_spec.rb +18 -18
- data/spec/unit/virtus/{attributes → attribute}/float_spec.rb +18 -18
- data/spec/unit/virtus/{attributes → attribute}/hash_spec.rb +1 -1
- data/spec/unit/virtus/{attributes → attribute}/integer_spec.rb +18 -18
- data/spec/unit/virtus/attribute/numeric/class_methods/descendants_spec.rb +15 -0
- data/spec/unit/virtus/attribute/object/class_methods/descendants_spec.rb +16 -0
- data/spec/unit/virtus/{attributes → attribute}/string_spec.rb +2 -2
- data/spec/unit/virtus/{attributes → attribute}/time_spec.rb +19 -9
- data/spec/unit/virtus/class_methods/new_spec.rb +7 -7
- data/spec/unit/virtus/determine_type_spec.rb +4 -4
- data/spec/unit/virtus/instance_methods/attribute_get_spec.rb +1 -1
- data/spec/unit/virtus/instance_methods/attribute_set_spec.rb +2 -2
- data/spec/unit/virtus/instance_methods/attributes_spec.rb +2 -2
- data/tasks/metrics/ci.rake +7 -0
- data/tasks/metrics/flay.rake +41 -0
- data/tasks/metrics/flog.rake +43 -0
- data/tasks/metrics/heckle.rake +261 -0
- data/tasks/metrics/metric_fu.rake +29 -0
- data/tasks/metrics/reek.rake +9 -0
- data/tasks/metrics/roodi.rake +15 -0
- data/tasks/metrics/yardstick.rake +23 -0
- data/tasks/spec.rake +26 -0
- data/tasks/yard.rake +9 -0
- data/virtus.gemspec +48 -33
- metadata +51 -41
- data/lib/virtus/attributes/array.rb +0 -8
- data/lib/virtus/attributes/attribute.rb +0 -214
- data/lib/virtus/attributes/boolean.rb +0 -39
- data/lib/virtus/attributes/date.rb +0 -44
- data/lib/virtus/attributes/date_time.rb +0 -43
- data/lib/virtus/attributes/decimal.rb +0 -24
- data/lib/virtus/attributes/float.rb +0 -20
- data/lib/virtus/attributes/hash.rb +0 -8
- data/lib/virtus/attributes/integer.rb +0 -20
- data/lib/virtus/attributes/string.rb +0 -11
- data/lib/virtus/attributes/time.rb +0 -45
- data/lib/virtus/attributes/typecast/numeric.rb +0 -32
- data/lib/virtus/attributes/typecast/time.rb +0 -27
- data/spec/unit/virtus/attributes/attribute_spec.rb +0 -13
- data/spec/unit/virtus/attributes/numeric/class_methods/descendants_spec.rb +0 -15
- data/spec/unit/virtus/attributes/object/class_methods/descendants_spec.rb +0 -16
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Virtus::Attribute do
|
4
|
+
describe '#typecast_to_primitive' do
|
5
|
+
let(:attribute) { Virtus::Attribute.new(:name) }
|
6
|
+
let(:value) { 'value' }
|
7
|
+
|
8
|
+
it "returns original value" do
|
9
|
+
attribute.typecast_to_primitive(value).should eql(value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Virtus::
|
3
|
+
describe Virtus::Attribute::Boolean do
|
4
4
|
it_should_behave_like 'Attribute' do
|
5
5
|
let(:attribute_name) { :is_admin }
|
6
6
|
let(:attribute_value) { true }
|
@@ -12,7 +12,7 @@ describe Virtus::Attributes::Boolean do
|
|
12
12
|
Class.new do
|
13
13
|
include Virtus
|
14
14
|
|
15
|
-
attribute :is_admin, Virtus::
|
15
|
+
attribute :is_admin, Virtus::Attribute::Boolean
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -25,7 +25,7 @@ describe Virtus::Attributes::Boolean do
|
|
25
25
|
|
26
26
|
describe '#typecast' do
|
27
27
|
let(:model) { Class.new { include Virtus } }
|
28
|
-
let(:attribute) { model.attribute(:is_admin, Virtus::
|
28
|
+
let(:attribute) { model.attribute(:is_admin, Virtus::Attribute::Boolean) }
|
29
29
|
|
30
30
|
subject { attribute.typecast(value) }
|
31
31
|
|
@@ -91,7 +91,7 @@ describe Virtus::Attributes::Boolean do
|
|
91
91
|
|
92
92
|
context "with 'Foo'" do
|
93
93
|
let(:value) { 'Foo' }
|
94
|
-
it { should
|
94
|
+
it { should equal(value) }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Virtus::
|
3
|
+
describe Virtus::Attribute::Date do
|
4
4
|
it_should_behave_like 'Attribute' do
|
5
5
|
let(:attribute_name) { :created_on }
|
6
6
|
let(:attribute_value) { Date.today }
|
@@ -9,7 +9,7 @@ describe Virtus::Attributes::Date do
|
|
9
9
|
|
10
10
|
describe '#typecast' do
|
11
11
|
let(:model) { Class.new { include Virtus } }
|
12
|
-
let(:attribute) { model.attribute(:bday, Virtus::
|
12
|
+
let(:attribute) { model.attribute(:bday, Virtus::Attribute::Date) }
|
13
13
|
|
14
14
|
let(:year) { 2011 }
|
15
15
|
let(:month) { 4 }
|
@@ -19,9 +19,9 @@ describe Virtus::Attributes::Date do
|
|
19
19
|
|
20
20
|
shared_examples_for "a correct date" do
|
21
21
|
it { should be_kind_of(Date) }
|
22
|
-
its(:year) { should
|
23
|
-
its(:month) { should
|
24
|
-
its(:day) { should
|
22
|
+
its(:year) { should eql(year) }
|
23
|
+
its(:month) { should eql(month) }
|
24
|
+
its(:day) { should eql(day) }
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'with a time' do
|
@@ -30,6 +30,12 @@ describe Virtus::Attributes::Date do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
context 'with a date time' do
|
34
|
+
it_should_behave_like "a correct date" do
|
35
|
+
let(:value) { DateTime.new(year, month, day) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
33
39
|
context 'with a hash' do
|
34
40
|
it_should_behave_like "a correct date" do
|
35
41
|
let(:value) do
|
@@ -44,9 +50,9 @@ describe Virtus::Attributes::Date do
|
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
47
|
-
context 'with a
|
53
|
+
context 'with a non-date value' do
|
48
54
|
let(:value) { 'non-date' }
|
49
|
-
it { should
|
55
|
+
it { should equal(value) }
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Virtus::
|
3
|
+
describe Virtus::Attribute::DateTime do
|
4
4
|
it_should_behave_like 'Attribute' do
|
5
5
|
let(:attribute_name) { :created_at }
|
6
6
|
let(:attribute_value) { DateTime.now }
|
@@ -9,7 +9,7 @@ describe Virtus::Attributes::DateTime do
|
|
9
9
|
|
10
10
|
describe '#typecast' do
|
11
11
|
let(:model) { Class.new { include Virtus } }
|
12
|
-
let(:attribute) { model.attribute(:bday, Virtus::
|
12
|
+
let(:attribute) { model.attribute(:bday, Virtus::Attribute::DateTime) }
|
13
13
|
|
14
14
|
let(:year) { 2011 }
|
15
15
|
let(:month) { 4 }
|
@@ -21,13 +21,34 @@ describe Virtus::Attributes::DateTime do
|
|
21
21
|
subject { attribute.typecast(value) }
|
22
22
|
|
23
23
|
shared_examples_for "a correct date time" do
|
24
|
-
it
|
25
|
-
|
26
|
-
its(:
|
27
|
-
its(:
|
28
|
-
its(:
|
29
|
-
its(:
|
30
|
-
its(:
|
24
|
+
it { should be_kind_of(DateTime) }
|
25
|
+
|
26
|
+
its(:year) { should eql(year) }
|
27
|
+
its(:month) { should eql(month) }
|
28
|
+
its(:day) { should eql(day) }
|
29
|
+
its(:hour) { should eql(hour) }
|
30
|
+
its(:min) { should eql(min) }
|
31
|
+
its(:sec) { should eql(sec) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with a date' do
|
35
|
+
it_should_behave_like "a correct date time" do
|
36
|
+
let(:hour) { 0 }
|
37
|
+
let(:min) { 0 }
|
38
|
+
let(:sec) { 0 }
|
39
|
+
|
40
|
+
let(:value) do
|
41
|
+
Date.new(year, month, day)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with a time' do
|
47
|
+
it_should_behave_like "a correct date time" do
|
48
|
+
let(:value) do
|
49
|
+
Time.local(year, month, day, hour, min, sec)
|
50
|
+
end
|
51
|
+
end
|
31
52
|
end
|
32
53
|
|
33
54
|
context 'with a hash' do
|
@@ -59,7 +80,7 @@ describe Virtus::Attributes::DateTime do
|
|
59
80
|
|
60
81
|
context 'with a on-date value' do
|
61
82
|
let(:value) { 'non-date' }
|
62
|
-
it { should
|
83
|
+
it { should equal(value) }
|
63
84
|
end
|
64
85
|
end
|
65
86
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Virtus::
|
3
|
+
describe Virtus::Attribute::Decimal do
|
4
4
|
it_should_behave_like 'Attribute' do
|
5
5
|
let(:attribute_name) { :price }
|
6
6
|
let(:attribute_value) { BigDecimal("12.3456789") }
|
@@ -9,89 +9,89 @@ describe Virtus::Attributes::Decimal do
|
|
9
9
|
|
10
10
|
describe '#typecast' do
|
11
11
|
let(:model) { Class.new { include Virtus } }
|
12
|
-
let(:attribute) { model.attribute(:price, Virtus::
|
12
|
+
let(:attribute) { model.attribute(:price, Virtus::Attribute::Decimal) }
|
13
13
|
|
14
14
|
subject { attribute.typecast(value) }
|
15
15
|
|
16
16
|
context "with 24.0 big decimal" do
|
17
17
|
let(:value) { BigDecimal('24.0') }
|
18
|
-
it { should
|
18
|
+
it { should eql(value) }
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'with a zero string integer' do
|
22
22
|
let(:value) { '0' }
|
23
|
-
it { should
|
23
|
+
it { should eql(BigDecimal('0.0')) }
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'with a positive string integer' do
|
27
27
|
let(:value) { '24' }
|
28
|
-
it { should
|
28
|
+
it { should eql(BigDecimal('24.0')) }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'with a negative string integer' do
|
32
32
|
let(:value) { '-24' }
|
33
|
-
it { should
|
33
|
+
it { should eql(BigDecimal('-24.0')) }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'with a zero string float' do
|
37
37
|
let(:value) { '0.0' }
|
38
|
-
it { should
|
38
|
+
it { should eql(BigDecimal('0.0')) }
|
39
39
|
end
|
40
40
|
|
41
41
|
context 'with a positive string float' do
|
42
42
|
let(:value) { '24.35' }
|
43
|
-
it { should
|
43
|
+
it { should eql(BigDecimal('24.35')) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'with a negative string float' do
|
47
47
|
let(:value) { '-24.35' }
|
48
|
-
it { should
|
48
|
+
it { should eql(BigDecimal('-24.35')) }
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'with a zero string float, with no leading digits' do
|
52
52
|
let(:value) { '.0' }
|
53
|
-
it { should
|
53
|
+
it { should eql(BigDecimal('0.0')) }
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'with a positive string float, with no leading digits' do
|
57
57
|
let(:value) { '0.41' }
|
58
|
-
it { should
|
58
|
+
it { should eql(BigDecimal('0.41')) }
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'with a zero integer' do
|
62
62
|
let(:value) { 0 }
|
63
|
-
it { should
|
63
|
+
it { should eql(BigDecimal('0.0')) }
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'with a positive integer' do
|
67
67
|
let(:value) { 24 }
|
68
|
-
it { should
|
68
|
+
it { should eql(BigDecimal('24.0')) }
|
69
69
|
end
|
70
70
|
|
71
71
|
context 'with a negative integer' do
|
72
72
|
let(:value) { -24 }
|
73
|
-
it { should
|
73
|
+
it { should eql(BigDecimal('-24.0')) }
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'with a zero float' do
|
77
77
|
let(:value) { 0.0 }
|
78
|
-
it { should
|
78
|
+
it { should eql(BigDecimal('0.0')) }
|
79
79
|
end
|
80
80
|
|
81
81
|
context 'with a positive float' do
|
82
82
|
let(:value) { 24.35 }
|
83
|
-
it { should
|
83
|
+
it { should eql(BigDecimal('24.35')) }
|
84
84
|
end
|
85
85
|
|
86
86
|
context 'with a negative float' do
|
87
87
|
let(:value) { -24.35 }
|
88
|
-
it { should
|
88
|
+
it { should eql(BigDecimal('-24.35')) }
|
89
89
|
end
|
90
90
|
|
91
91
|
[ Object.new, true, '00.0', '0.', '-.0', 'string' ].each do |non_num_value|
|
92
92
|
context "with a non-numeric value = #{non_num_value.inspect}" do
|
93
93
|
let(:value) { non_num_value }
|
94
|
-
it { should
|
94
|
+
it { should equal(non_num_value) }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Virtus::
|
3
|
+
describe Virtus::Attribute::Float do
|
4
4
|
it_should_behave_like 'Attribute' do
|
5
5
|
let(:attribute_name) { :score }
|
6
6
|
let(:attribute_value) { 12.34 }
|
@@ -9,89 +9,89 @@ describe Virtus::Attributes::Float do
|
|
9
9
|
|
10
10
|
describe '#typecast' do
|
11
11
|
let(:model) { Class.new { include Virtus } }
|
12
|
-
let(:attribute) { model.attribute(:score, Virtus::
|
12
|
+
let(:attribute) { model.attribute(:score, Virtus::Attribute::Float) }
|
13
13
|
|
14
14
|
subject { attribute.typecast(value) }
|
15
15
|
|
16
16
|
context "with a float" do
|
17
17
|
let(:value) { 24.0 }
|
18
|
-
it { should
|
18
|
+
it { should eql(value) }
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'with a zero string integer' do
|
22
22
|
let(:value) { '0' }
|
23
|
-
it { should
|
23
|
+
it { should eql(0.0) }
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'with a positive string integer' do
|
27
27
|
let(:value) { '24' }
|
28
|
-
it { should
|
28
|
+
it { should eql(24.0) }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'with a negative string integer' do
|
32
32
|
let(:value) { '-24' }
|
33
|
-
it { should
|
33
|
+
it { should eql(-24.0) }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'with a zero string float' do
|
37
37
|
let(:value) { '0.0' }
|
38
|
-
it { should
|
38
|
+
it { should eql(0.0) }
|
39
39
|
end
|
40
40
|
|
41
41
|
context 'with a positive string float' do
|
42
42
|
let(:value) { '24.35' }
|
43
|
-
it { should
|
43
|
+
it { should eql(24.35) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'with a negative string float' do
|
47
47
|
let(:value) { '-24.35' }
|
48
|
-
it { should
|
48
|
+
it { should eql(-24.35) }
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'with a zero string float, with no leading digits' do
|
52
52
|
let(:value) { '.0' }
|
53
|
-
it { should
|
53
|
+
it { should eql(0.0) }
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'with a positive string float, with no leading digits' do
|
57
57
|
let(:value) { '.41' }
|
58
|
-
it { should
|
58
|
+
it { should eql(0.41) }
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'with a zero integer' do
|
62
62
|
let(:value) { 0 }
|
63
|
-
it { should
|
63
|
+
it { should eql(0.0) }
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'with a positive integer' do
|
67
67
|
let(:value) { 24 }
|
68
|
-
it { should
|
68
|
+
it { should eql(24.0) }
|
69
69
|
end
|
70
70
|
|
71
71
|
context 'with a negative integer' do
|
72
72
|
let(:value) { -24 }
|
73
|
-
it { should
|
73
|
+
it { should eql(-24.0) }
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'with a zero decimal' do
|
77
77
|
let(:value) { BigDecimal('0.0') }
|
78
|
-
it { should
|
78
|
+
it { should eql(0.0) }
|
79
79
|
end
|
80
80
|
|
81
81
|
context 'with a positive decimal' do
|
82
82
|
let(:value) { BigDecimal('24.35') }
|
83
|
-
it { should
|
83
|
+
it { should eql(24.35) }
|
84
84
|
end
|
85
85
|
|
86
86
|
context 'with a negative decimal' do
|
87
87
|
let(:value) { BigDecimal('-24.35') }
|
88
|
-
it { should
|
88
|
+
it { should eql(-24.35) }
|
89
89
|
end
|
90
90
|
|
91
91
|
[ Object.new, true, '00.0', '0.', '-.0', 'string' ].each do |non_num_value|
|
92
92
|
context "does not typecast non-numeric value #{non_num_value.inspect}" do
|
93
93
|
let(:value) { non_num_value }
|
94
|
-
it { should
|
94
|
+
it { should equal(non_num_value) }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Virtus::
|
3
|
+
describe Virtus::Attribute::Integer do
|
4
4
|
it_should_behave_like 'Attribute' do
|
5
5
|
let(:attribute_name) { :age }
|
6
6
|
let(:attribute_value) { 28 }
|
@@ -9,89 +9,89 @@ describe Virtus::Attributes::Integer do
|
|
9
9
|
|
10
10
|
describe '#typecast' do
|
11
11
|
let(:model) { Class.new { include Virtus } }
|
12
|
-
let(:attribute) { model.attribute(:age, Virtus::
|
12
|
+
let(:attribute) { model.attribute(:age, Virtus::Attribute::Integer) }
|
13
13
|
|
14
14
|
subject { attribute.typecast(value) }
|
15
15
|
|
16
16
|
context "with an integer" do
|
17
17
|
let(:value) { 24 }
|
18
|
-
it { should
|
18
|
+
it { should eql(value) }
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'with a zero string integer' do
|
22
22
|
let(:value) { 24 }
|
23
|
-
it { should
|
23
|
+
it { should eql(value) }
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'with a positive string integer' do
|
27
27
|
let(:value) { '24' }
|
28
|
-
it { should
|
28
|
+
it { should eql(24) }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'with a negative string integer' do
|
32
32
|
let(:value) { '-24' }
|
33
|
-
it { should
|
33
|
+
it { should eql(-24) }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'with a zero string float' do
|
37
37
|
let(:value) { 0.0 }
|
38
|
-
it { should
|
38
|
+
it { should eql(0) }
|
39
39
|
end
|
40
40
|
|
41
41
|
context 'with a positive string float' do
|
42
42
|
let(:value) { '24.35' }
|
43
|
-
it { should
|
43
|
+
it { should eql(24) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'with a negative string float' do
|
47
47
|
let(:value) { '-24.35' }
|
48
|
-
it { should
|
48
|
+
it { should eql(-24) }
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'with a zero string float, with no leading digits' do
|
52
52
|
let(:value) { '.0' }
|
53
|
-
it { should
|
53
|
+
it { should eql(0) }
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'with a positive string float, with no leading digits' do
|
57
57
|
let(:value) { '.41' }
|
58
|
-
it { should
|
58
|
+
it { should eql(0) }
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'with a zero float' do
|
62
62
|
let(:value) { 0.0 }
|
63
|
-
it { should
|
63
|
+
it { should eql(0) }
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'with a positive float' do
|
67
67
|
let(:value) { 24.35 }
|
68
|
-
it { should
|
68
|
+
it { should eql(24) }
|
69
69
|
end
|
70
70
|
|
71
71
|
context 'with a negative float' do
|
72
72
|
let(:value) { -24.35 }
|
73
|
-
it { should
|
73
|
+
it { should eql(-24) }
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'with a zero decimal' do
|
77
77
|
let(:value) { BigDecimal('0.0') }
|
78
|
-
it { should
|
78
|
+
it { should eql(0) }
|
79
79
|
end
|
80
80
|
|
81
81
|
context 'with a positive decimal' do
|
82
82
|
let(:value) { BigDecimal('24.35') }
|
83
|
-
it { should
|
83
|
+
it { should eql(24) }
|
84
84
|
end
|
85
85
|
|
86
86
|
context 'with a negative decimal' do
|
87
87
|
let(:value) { BigDecimal('-24.35') }
|
88
|
-
it { should
|
88
|
+
it { should eql(-24) }
|
89
89
|
end
|
90
90
|
|
91
91
|
[ Object.new, true, '00.0', '0.', '-.0', 'string' ].each do |non_num_value|
|
92
92
|
context "does not typecast non-numeric value #{non_num_value.inspect}" do
|
93
93
|
let(:value) { non_num_value }
|
94
|
-
it { should
|
94
|
+
it { should equal(non_num_value) }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|