ardm 0.0.1 → 0.1.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 +5 -13
- data/Gemfile +1 -2
- data/LICENSE +2 -2
- data/README.md +72 -16
- data/ardm.gemspec +1 -0
- data/lib/ardm.rb +2 -1
- data/lib/ardm/active_record.rb +8 -1
- data/lib/ardm/active_record/associations.rb +33 -4
- data/lib/ardm/active_record/base.rb +2 -0
- data/lib/ardm/active_record/collection.rb +5 -0
- data/lib/ardm/active_record/data_mapper_constant.rb +1 -0
- data/lib/ardm/active_record/data_mapper_constant_proxy.rb +24 -0
- data/lib/ardm/active_record/finalize.rb +18 -0
- data/lib/ardm/active_record/predicate_builder/array_handler.rb +10 -16
- data/lib/ardm/active_record/predicate_builder/rails3.rb +42 -15
- data/lib/ardm/active_record/predicate_builder/rails4.rb +39 -13
- data/lib/ardm/active_record/property.rb +24 -12
- data/lib/ardm/active_record/query.rb +9 -18
- data/lib/ardm/active_record/record.rb +54 -11
- data/lib/ardm/active_record/relation.rb +36 -6
- data/lib/ardm/active_record/repository.rb +6 -2
- data/lib/ardm/data_mapper.rb +2 -0
- data/lib/ardm/data_mapper/record.rb +3 -9
- data/lib/ardm/version.rb +1 -1
- data/spec/ardm/datamapper_constants_spec.rb +31 -0
- data/spec/fixtures/article.rb +2 -0
- data/spec/integration/api_key_spec.rb +3 -3
- data/spec/integration/bcrypt_hash_spec.rb +7 -7
- data/spec/integration/comma_separated_list_spec.rb +11 -11
- data/spec/integration/dirty_minder_spec.rb +23 -39
- data/spec/integration/enum_spec.rb +11 -11
- data/spec/integration/epoch_time_spec.rb +6 -6
- data/spec/integration/file_path_spec.rb +23 -23
- data/spec/integration/flag_spec.rb +11 -13
- data/spec/integration/ip_address_spec.rb +15 -15
- data/spec/integration/json_spec.rb +7 -7
- data/spec/integration/slug_spec.rb +6 -6
- data/spec/integration/uri_spec.rb +11 -11
- data/spec/integration/uuid_spec.rb +16 -16
- data/spec/integration/yaml_spec.rb +8 -8
- data/spec/public/model_spec.rb +193 -0
- data/spec/public/property/binary_spec.rb +4 -4
- data/spec/public/property/boolean_spec.rb +3 -3
- data/spec/public/property/class_spec.rb +2 -2
- data/spec/public/property/date_spec.rb +2 -2
- data/spec/public/property/date_time_spec.rb +2 -2
- data/spec/public/property/decimal_spec.rb +2 -2
- data/spec/public/property/discriminator_spec.rb +21 -20
- data/spec/public/property/float_spec.rb +2 -2
- data/spec/public/property/integer_spec.rb +2 -2
- data/spec/public/property/object_spec.rb +14 -13
- data/spec/public/property/serial_spec.rb +2 -2
- data/spec/public/property/string_spec.rb +2 -2
- data/spec/public/property/text_spec.rb +2 -2
- data/spec/public/property/time_spec.rb +2 -2
- data/spec/public/property_spec.rb +44 -48
- data/spec/public/resource_spec.rb +278 -0
- data/spec/schema.rb +33 -4
- data/spec/semipublic/property/boolean_spec.rb +5 -5
- data/spec/semipublic/property/class_spec.rb +3 -3
- data/spec/semipublic/property/date_spec.rb +8 -8
- data/spec/semipublic/property/date_time_spec.rb +9 -9
- data/spec/semipublic/property/decimal_spec.rb +16 -16
- data/spec/semipublic/property/float_spec.rb +16 -16
- data/spec/semipublic/property/integer_spec.rb +16 -16
- data/spec/semipublic/property/lookup_spec.rb +4 -4
- data/spec/semipublic/property/text_spec.rb +2 -2
- data/spec/semipublic/property/time_spec.rb +10 -10
- data/spec/semipublic/property_spec.rb +4 -4
- data/spec/shared/finder_shared_spec.rb +1151 -0
- data/spec/shared/flags_shared_spec.rb +6 -6
- data/spec/shared/identity_function_group.rb +1 -1
- data/spec/shared/public_property_spec.rb +26 -25
- data/spec/shared/resource_spec.rb +1218 -0
- data/spec/shared/semipublic_property_spec.rb +23 -22
- data/spec/spec_helper.rb +17 -0
- data/spec/unit/bcrypt_hash_spec.rb +15 -15
- data/spec/unit/csv_spec.rb +11 -11
- data/spec/unit/dirty_minder_spec.rb +3 -5
- data/spec/unit/enum_spec.rb +17 -17
- data/spec/unit/epoch_time_spec.rb +8 -8
- data/spec/unit/file_path_spec.rb +9 -9
- data/spec/unit/flag_spec.rb +9 -9
- data/spec/unit/ip_address_spec.rb +9 -9
- data/spec/unit/json_spec.rb +11 -11
- data/spec/unit/paranoid_boolean_spec.rb +19 -17
- data/spec/unit/paranoid_datetime_spec.rb +21 -19
- data/spec/unit/regexp_spec.rb +4 -4
- data/spec/unit/uri_spec.rb +8 -8
- data/spec/unit/yaml_spec.rb +9 -9
- metadata +35 -27
- data/lib/ardm/active_record/not_found.rb +0 -7
- data/lib/ardm/data_mapper/not_found.rb +0 -5
data/spec/schema.rb
CHANGED
@@ -7,12 +7,19 @@
|
|
7
7
|
|
8
8
|
create_table :articles, :force => true do |t|
|
9
9
|
t.string :title
|
10
|
+
t.string :author
|
10
11
|
t.text :body
|
11
12
|
t.timestamps
|
12
13
|
t.datetime :published_at
|
13
14
|
t.boolean :deleted
|
14
15
|
t.datetime :deleted_at
|
15
16
|
t.string :slug
|
17
|
+
t.integer :original_id
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table :article_publications, :force => true do |t|
|
21
|
+
t.integer :article_id
|
22
|
+
t.integer :publication_id
|
16
23
|
end
|
17
24
|
|
18
25
|
create_table :bookmarks, :force => true do |t|
|
@@ -22,9 +29,14 @@
|
|
22
29
|
t.text :tags
|
23
30
|
end
|
24
31
|
|
32
|
+
create_table :comments, :force => true do |t|
|
33
|
+
t.text :body
|
34
|
+
t.integer :user_id
|
35
|
+
t.timestamps
|
36
|
+
end
|
37
|
+
|
25
38
|
create_table :images, :force => true, :id => false do |t|
|
26
39
|
t.string :md5hash, :length => 32
|
27
|
-
t.index :md5hash, :unique => true
|
28
40
|
t.string :title
|
29
41
|
t.text :description, :length => 1024
|
30
42
|
t.integer :width
|
@@ -32,6 +44,7 @@
|
|
32
44
|
t.string :format
|
33
45
|
t.time :taken_at
|
34
46
|
end
|
47
|
+
add_index :images, :md5hash, :unique => true
|
35
48
|
|
36
49
|
create_table :network_nodes, :force => true do |t|
|
37
50
|
t.string :ip_address
|
@@ -39,6 +52,12 @@
|
|
39
52
|
t.string :node_uuid
|
40
53
|
end
|
41
54
|
|
55
|
+
create_table :paragraphs, :force => true do |t|
|
56
|
+
t.string :text
|
57
|
+
t.integer :article_id
|
58
|
+
t.timestamps
|
59
|
+
end
|
60
|
+
|
42
61
|
create_table :people, :force => true do |t|
|
43
62
|
t.string :name
|
44
63
|
t.text :positions
|
@@ -71,10 +90,10 @@
|
|
71
90
|
t.string :name
|
72
91
|
t.string :album
|
73
92
|
t.string :musicbrainz_hash
|
74
|
-
t.index [:artist, :album]
|
75
|
-
t.index :name
|
76
|
-
t.index :musicbrainz_hash, :unique => true
|
77
93
|
end
|
94
|
+
add_index :tracks, [:artist, :album]
|
95
|
+
add_index :tracks, :name
|
96
|
+
add_index :tracks, :musicbrainz_hash, :unique => true
|
78
97
|
|
79
98
|
create_table :tshirts, :force => true do |t|
|
80
99
|
t.string :writing
|
@@ -83,4 +102,14 @@
|
|
83
102
|
t.text :color
|
84
103
|
t.text :size
|
85
104
|
end
|
105
|
+
|
106
|
+
create_table :users, :force => true, :id => false, :primary_key => :name do |t|
|
107
|
+
t.string :name
|
108
|
+
t.integer :age
|
109
|
+
t.text :summary
|
110
|
+
t.text :description
|
111
|
+
t.boolean :admin
|
112
|
+
t.integer :parent_id
|
113
|
+
t.string :referrer_id
|
114
|
+
end
|
86
115
|
end
|
@@ -15,13 +15,13 @@ describe Ardm::Property::Boolean do
|
|
15
15
|
describe '#valid?' do
|
16
16
|
[ true, false ].each do |value|
|
17
17
|
it "returns true when value is #{value.inspect}" do
|
18
|
-
property.valid?(value).
|
18
|
+
expect(property.valid?(value)).to be(true)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
[ 'true', 'TRUE', '1', 1, 't', 'T', 'false', 'FALSE', '0', 0, 'f', 'F' ].each do |value|
|
23
23
|
it "returns false for #{value.inspect}" do
|
24
|
-
property.valid?(value).
|
24
|
+
expect(property.valid?(value)).to be(false)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -29,19 +29,19 @@ describe Ardm::Property::Boolean do
|
|
29
29
|
describe '#typecast' do
|
30
30
|
[ true, 'true', 'TRUE', '1', 1, 't', 'T' ].each do |value|
|
31
31
|
it "returns true when value is #{value.inspect}" do
|
32
|
-
property.typecast(value).
|
32
|
+
expect(property.typecast(value)).to be(true)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
[ false, 'false', 'FALSE', '0', 0, 'f', 'F' ].each do |value|
|
37
37
|
it "returns false when value is #{value.inspect}" do
|
38
|
-
property.typecast(value).
|
38
|
+
expect(property.typecast(value)).to be(false)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
[ 'string', 2, 1.0, BigDecimal('1.0'), DateTime.now, Time.now, Date.today, Class, Object.new, ].each do |value|
|
43
43
|
it "does not typecast value #{value.inspect}" do
|
44
|
-
property.typecast(value).
|
44
|
+
expect(property.typecast(value)).to equal(value)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -22,15 +22,15 @@ describe Ardm::Property::Class do
|
|
22
22
|
|
23
23
|
describe '#typecast' do
|
24
24
|
it 'returns same value if a class' do
|
25
|
-
property.typecast(model).
|
25
|
+
expect(property.typecast(model)).to equal(model)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'returns the class if found' do
|
29
|
-
property.typecast(model.name).
|
29
|
+
expect(property.typecast(model.name)).to eql(model)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'does not typecast non-class values' do
|
33
|
-
property.typecast('NoClass').
|
33
|
+
expect(property.typecast('NoClass')).to eql('NoClass')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -21,24 +21,24 @@ describe Ardm::Property::Date do
|
|
21
21
|
:day => '25'
|
22
22
|
)
|
23
23
|
|
24
|
-
result.
|
25
|
-
result.year.
|
26
|
-
result.month.
|
27
|
-
result.day.
|
24
|
+
expect(result).to be_kind_of(Date)
|
25
|
+
expect(result.year).to eql(2007)
|
26
|
+
expect(result.month).to eql(3)
|
27
|
+
expect(result.day).to eql(25)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe 'and value is a string' do
|
32
32
|
it 'parses the string' do
|
33
33
|
result = property.typecast('Dec 20th, 2006')
|
34
|
-
result.month.
|
35
|
-
result.day.
|
36
|
-
result.year.
|
34
|
+
expect(result.month).to eq(12)
|
35
|
+
expect(result.day).to eq(20)
|
36
|
+
expect(result.year).to eq(2006)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'does not typecast non-date values' do
|
41
|
-
property.typecast('not-date').
|
41
|
+
expect(property.typecast('not-date')).to eql('not-date')
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -24,24 +24,24 @@ describe Ardm::Property::DateTime do
|
|
24
24
|
:sec => '0'
|
25
25
|
)
|
26
26
|
|
27
|
-
result.
|
28
|
-
result.year.
|
29
|
-
result.month.
|
30
|
-
result.day.
|
31
|
-
result.hour.
|
32
|
-
result.min.
|
33
|
-
result.sec.
|
27
|
+
expect(result).to be_kind_of(DateTime)
|
28
|
+
expect(result.year).to eql(2006)
|
29
|
+
expect(result.month).to eql(11)
|
30
|
+
expect(result.day).to eql(23)
|
31
|
+
expect(result.hour).to eql(12)
|
32
|
+
expect(result.min).to eql(0)
|
33
|
+
expect(result.sec).to eql(0)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'and value is a string' do
|
38
38
|
it 'parses the string' do
|
39
|
-
property.typecast('Dec, 2006').month.
|
39
|
+
expect(property.typecast('Dec, 2006').month).to eq(12)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'does not typecast non-datetime values' do
|
44
|
-
property.typecast('not-datetime').
|
44
|
+
expect(property.typecast('not-datetime')).to eql('not-datetime')
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -15,68 +15,68 @@ describe Ardm::Property::Decimal do
|
|
15
15
|
describe '#typecast' do
|
16
16
|
it 'returns same value if a decimal' do
|
17
17
|
@value = BigDecimal('24.0')
|
18
|
-
property.typecast(@value).
|
18
|
+
expect(property.typecast(@value)).to equal(@value)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'returns decimal representation of a zero string integer' do
|
22
|
-
property.typecast('0').
|
22
|
+
expect(property.typecast('0')).to eql(BigDecimal('0.0'))
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'returns decimal representation of a positive string integer' do
|
26
|
-
property.typecast('24').
|
26
|
+
expect(property.typecast('24')).to eql(BigDecimal('24.0'))
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns decimal representation of a negative string integer' do
|
30
|
-
property.typecast('-24').
|
30
|
+
expect(property.typecast('-24')).to eql(BigDecimal('-24.0'))
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'returns decimal representation of a zero string float' do
|
34
|
-
property.typecast('0.0').
|
34
|
+
expect(property.typecast('0.0')).to eql(BigDecimal('0.0'))
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns decimal representation of a positive string float' do
|
38
|
-
property.typecast('24.35').
|
38
|
+
expect(property.typecast('24.35')).to eql(BigDecimal('24.35'))
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'returns decimal representation of a negative string float' do
|
42
|
-
property.typecast('-24.35').
|
42
|
+
expect(property.typecast('-24.35')).to eql(BigDecimal('-24.35'))
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'returns decimal representation of a zero string float, with no leading digits' do
|
46
|
-
property.typecast('.0').
|
46
|
+
expect(property.typecast('.0')).to eql(BigDecimal('0.0'))
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'returns decimal representation of a positive string float, with no leading digits' do
|
50
|
-
property.typecast('.41').
|
50
|
+
expect(property.typecast('.41')).to eql(BigDecimal('0.41'))
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'returns decimal representation of a zero integer' do
|
54
|
-
property.typecast(0).
|
54
|
+
expect(property.typecast(0)).to eql(BigDecimal('0.0'))
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns decimal representation of a positive integer' do
|
58
|
-
property.typecast(24).
|
58
|
+
expect(property.typecast(24)).to eql(BigDecimal('24.0'))
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'returns decimal representation of a negative integer' do
|
62
|
-
property.typecast(-24).
|
62
|
+
expect(property.typecast(-24)).to eql(BigDecimal('-24.0'))
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'returns decimal representation of a zero float' do
|
66
|
-
property.typecast(0.0).
|
66
|
+
expect(property.typecast(0.0)).to eql(BigDecimal('0.0'))
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'returns decimal representation of a positive float' do
|
70
|
-
property.typecast(24.35).
|
70
|
+
expect(property.typecast(24.35)).to eql(BigDecimal('24.35'))
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'returns decimal representation of a negative float' do
|
74
|
-
property.typecast(-24.35).
|
74
|
+
expect(property.typecast(-24.35)).to eql(BigDecimal('-24.35'))
|
75
75
|
end
|
76
76
|
|
77
77
|
[ Object.new, true, '0.', '-.0', 'string' ].each do |value|
|
78
78
|
it "does not typecast non-numeric value #{value.inspect}" do
|
79
|
-
property.typecast(value).
|
79
|
+
expect(property.typecast(value)).to equal(value)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -15,68 +15,68 @@ describe Ardm::Property::Float do
|
|
15
15
|
describe '#typecast' do
|
16
16
|
it 'returns same value if a float' do
|
17
17
|
value = 24.0
|
18
|
-
property.typecast(value).
|
18
|
+
expect(property.typecast(value)).to equal(value)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'returns float representation of a zero string integer' do
|
22
|
-
property.typecast('0').
|
22
|
+
expect(property.typecast('0')).to eql(0.0)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'returns float representation of a positive string integer' do
|
26
|
-
property.typecast('24').
|
26
|
+
expect(property.typecast('24')).to eql(24.0)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns float representation of a negative string integer' do
|
30
|
-
property.typecast('-24').
|
30
|
+
expect(property.typecast('-24')).to eql(-24.0)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'returns float representation of a zero string float' do
|
34
|
-
property.typecast('0.0').
|
34
|
+
expect(property.typecast('0.0')).to eql(0.0)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns float representation of a positive string float' do
|
38
|
-
property.typecast('24.35').
|
38
|
+
expect(property.typecast('24.35')).to eql(24.35)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'returns float representation of a negative string float' do
|
42
|
-
property.typecast('-24.35').
|
42
|
+
expect(property.typecast('-24.35')).to eql(-24.35)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'returns float representation of a zero string float, with no leading digits' do
|
46
|
-
property.typecast('.0').
|
46
|
+
expect(property.typecast('.0')).to eql(0.0)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'returns float representation of a positive string float, with no leading digits' do
|
50
|
-
property.typecast('.41').
|
50
|
+
expect(property.typecast('.41')).to eql(0.41)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'returns float representation of a zero integer' do
|
54
|
-
property.typecast(0).
|
54
|
+
expect(property.typecast(0)).to eql(0.0)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns float representation of a positive integer' do
|
58
|
-
property.typecast(24).
|
58
|
+
expect(property.typecast(24)).to eql(24.0)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'returns float representation of a negative integer' do
|
62
|
-
property.typecast(-24).
|
62
|
+
expect(property.typecast(-24)).to eql(-24.0)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'returns float representation of a zero decimal' do
|
66
|
-
property.typecast(BigDecimal('0.0')).
|
66
|
+
expect(property.typecast(BigDecimal('0.0'))).to eql(0.0)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'returns float representation of a positive decimal' do
|
70
|
-
property.typecast(BigDecimal('24.35')).
|
70
|
+
expect(property.typecast(BigDecimal('24.35'))).to eql(24.35)
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'returns float representation of a negative decimal' do
|
74
|
-
property.typecast(BigDecimal('-24.35')).
|
74
|
+
expect(property.typecast(BigDecimal('-24.35'))).to eql(-24.35)
|
75
75
|
end
|
76
76
|
|
77
77
|
[ Object.new, true, '0.', '-.0', 'string' ].each do |value|
|
78
78
|
it "does not typecast non-numeric value #{value.inspect}" do
|
79
|
-
property.typecast(value).
|
79
|
+
expect(property.typecast(value)).to equal(value)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -15,68 +15,68 @@ describe Ardm::Property::Integer do
|
|
15
15
|
describe '#typecast' do
|
16
16
|
it 'returns same value if an integer' do
|
17
17
|
value = 24
|
18
|
-
property.typecast(value).
|
18
|
+
expect(property.typecast(value)).to equal(value)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'returns integer representation of a zero string integer' do
|
22
|
-
property.typecast('0').
|
22
|
+
expect(property.typecast('0')).to eql(0)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'returns integer representation of a positive string integer' do
|
26
|
-
property.typecast('24').
|
26
|
+
expect(property.typecast('24')).to eql(24)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns integer representation of a negative string integer' do
|
30
|
-
property.typecast('-24').
|
30
|
+
expect(property.typecast('-24')).to eql(-24)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'returns integer representation of a zero string float' do
|
34
|
-
property.typecast('0.0').
|
34
|
+
expect(property.typecast('0.0')).to eql(0)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns integer representation of a positive string float' do
|
38
|
-
property.typecast('24.35').
|
38
|
+
expect(property.typecast('24.35')).to eql(24)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'returns integer representation of a negative string float' do
|
42
|
-
property.typecast('-24.35').
|
42
|
+
expect(property.typecast('-24.35')).to eql(-24)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'returns integer representation of a zero string float, with no leading digits' do
|
46
|
-
property.typecast('.0').
|
46
|
+
expect(property.typecast('.0')).to eql(0)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'returns integer representation of a positive string float, with no leading digits' do
|
50
|
-
property.typecast('.41').
|
50
|
+
expect(property.typecast('.41')).to eql(0)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'returns integer representation of a zero float' do
|
54
|
-
property.typecast(0.0).
|
54
|
+
expect(property.typecast(0.0)).to eql(0)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns integer representation of a positive float' do
|
58
|
-
property.typecast(24.35).
|
58
|
+
expect(property.typecast(24.35)).to eql(24)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'returns integer representation of a negative float' do
|
62
|
-
property.typecast(-24.35).
|
62
|
+
expect(property.typecast(-24.35)).to eql(-24)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'returns integer representation of a zero decimal' do
|
66
|
-
property.typecast(BigDecimal('0.0')).
|
66
|
+
expect(property.typecast(BigDecimal('0.0'))).to eql(0)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'returns integer representation of a positive decimal' do
|
70
|
-
property.typecast(BigDecimal('24.35')).
|
70
|
+
expect(property.typecast(BigDecimal('24.35'))).to eql(24)
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'returns integer representation of a negative decimal' do
|
74
|
-
property.typecast(BigDecimal('-24.35')).
|
74
|
+
expect(property.typecast(BigDecimal('-24.35'))).to eql(-24)
|
75
75
|
end
|
76
76
|
|
77
77
|
[ Object.new, true, '0.', '-.0', 'string' ].each do |value|
|
78
78
|
it "does not typecast non-numeric value #{value.inspect}" do
|
79
|
-
property.typecast(value).
|
79
|
+
expect(property.typecast(value)).to equal(value)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|