rcap 0.4 → 1.0.0.rc.1
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 +7 -0
- data/CHANGELOG.rdoc +6 -0
- data/Gemfile +4 -0
- data/README.rdoc +104 -85
- data/Rakefile +35 -0
- data/lib/rcap.rb +21 -14
- data/lib/rcap/alert.rb +26 -325
- data/lib/rcap/cap_1_1/alert.rb +363 -0
- data/lib/rcap/cap_1_1/area.rb +180 -0
- data/lib/rcap/cap_1_1/circle.rb +81 -0
- data/lib/rcap/cap_1_1/event_code.rb +22 -0
- data/lib/rcap/cap_1_1/geocode.rb +22 -0
- data/lib/rcap/cap_1_1/info.rb +470 -0
- data/lib/rcap/cap_1_1/parameter.rb +68 -0
- data/lib/rcap/cap_1_1/point.rb +55 -0
- data/lib/rcap/cap_1_1/polygon.rb +89 -0
- data/lib/rcap/cap_1_1/resource.rb +145 -0
- data/lib/rcap/cap_1_2/alert.rb +363 -0
- data/lib/rcap/cap_1_2/area.rb +180 -0
- data/lib/rcap/cap_1_2/circle.rb +81 -0
- data/lib/rcap/cap_1_2/event_code.rb +22 -0
- data/lib/rcap/cap_1_2/geocode.rb +22 -0
- data/lib/rcap/cap_1_2/info.rb +472 -0
- data/lib/rcap/cap_1_2/parameter.rb +68 -0
- data/lib/rcap/cap_1_2/point.rb +55 -0
- data/lib/rcap/cap_1_2/polygon.rb +90 -0
- data/lib/rcap/cap_1_2/resource.rb +147 -0
- data/lib/rcap/utilities.rb +14 -9
- data/lib/rcap/validations.rb +39 -7
- data/lib/rcap/version.rb +3 -0
- data/rcap.gemspec +30 -0
- data/spec/alert_spec.rb +109 -172
- data/spec/cap_1_1/alert_spec.rb +222 -0
- data/spec/cap_1_1/area_spec.rb +247 -0
- data/spec/cap_1_1/circle_spec.rb +88 -0
- data/spec/{geocode_spec.rb → cap_1_1/geocode_spec.rb} +8 -8
- data/spec/{info_spec.rb → cap_1_1/info_spec.rb} +143 -75
- data/spec/{point_spec.rb → cap_1_1/point_spec.rb} +8 -8
- data/spec/cap_1_1/polygon_spec.rb +97 -0
- data/spec/{resource_spec.rb → cap_1_1/resource_spec.rb} +24 -24
- data/spec/cap_1_2/alert_spec.rb +233 -0
- data/spec/cap_1_2/area_spec.rb +248 -0
- data/spec/cap_1_2/circle_spec.rb +95 -0
- data/spec/cap_1_2/geocode_spec.rb +38 -0
- data/spec/cap_1_2/info_spec.rb +338 -0
- data/spec/cap_1_2/point_spec.rb +46 -0
- data/spec/cap_1_2/polygon_spec.rb +102 -0
- data/spec/cap_1_2/resource_spec.rb +161 -0
- data/spec/spec.opts +2 -0
- data/spec/validations_spec.rb +80 -7
- metadata +122 -37
- data/lib/rcap/area.rb +0 -156
- data/lib/rcap/circle.rb +0 -78
- data/lib/rcap/event_code.rb +0 -20
- data/lib/rcap/geocode.rb +0 -20
- data/lib/rcap/info.rb +0 -437
- data/lib/rcap/parameter.rb +0 -66
- data/lib/rcap/point.rb +0 -53
- data/lib/rcap/polygon.rb +0 -77
- data/lib/rcap/resource.rb +0 -143
- data/spec/area_spec.rb +0 -179
- data/spec/circle_spec.rb +0 -88
- data/spec/polygon_spec.rb +0 -68
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_2::Point ) do
|
4
|
+
describe( 'is not valid if' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@point = RCAP::CAP_1_2::Point.new( :lattitude => 0, :longitude => 0 )
|
7
|
+
@point.should( be_valid )
|
8
|
+
end
|
9
|
+
|
10
|
+
it( 'does not have a longitude defined' ) do
|
11
|
+
@point.longitude = nil
|
12
|
+
@point.should_not( be_valid )
|
13
|
+
end
|
14
|
+
|
15
|
+
it( 'does not have a valid longitude' ) do
|
16
|
+
@point.longitude = RCAP::CAP_1_2::Point::MAX_LONGITUDE + 1
|
17
|
+
@point.should_not( be_valid )
|
18
|
+
@point.longitude = RCAP::CAP_1_2::Point::MIN_LONGITUDE - 1
|
19
|
+
@point.should_not( be_valid )
|
20
|
+
end
|
21
|
+
|
22
|
+
it( 'does not have a lattitude defined' ) do
|
23
|
+
@point.lattitude = nil
|
24
|
+
@point.should_not( be_valid )
|
25
|
+
end
|
26
|
+
|
27
|
+
it( 'does not have a valid lattitude' ) do
|
28
|
+
@point.lattitude = RCAP::CAP_1_2::Point::MAX_LATTITUDE + 1
|
29
|
+
@point.should_not( be_valid )
|
30
|
+
@point.lattitude = RCAP::CAP_1_2::Point::MIN_LATTITUDE - 1
|
31
|
+
@point.should_not( be_valid )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context( 'when exported' ) do
|
36
|
+
before( :each ) do
|
37
|
+
@point = RCAP::CAP_1_2::Point.new( :lattitude => 1, :longitude => 1 )
|
38
|
+
end
|
39
|
+
|
40
|
+
context( 'to hash' ) do
|
41
|
+
it( 'should export correctly' ) do
|
42
|
+
@point.to_h.should == { RCAP::CAP_1_2::Point::LATTITUDE_KEY => 1, RCAP::CAP_1_2::Point::LONGITUDE_KEY => 1 }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_2::Polygon ) do
|
4
|
+
describe( 'is not valid if it' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@polygon = RCAP::CAP_1_2::Polygon.new
|
7
|
+
4.times do
|
8
|
+
@polygon.points << RCAP::CAP_1_2::Point.new( :lattitude => 0, :longitude => 0 )
|
9
|
+
end
|
10
|
+
@polygon.should( be_valid )
|
11
|
+
end
|
12
|
+
|
13
|
+
it( 'hass less than 4 points' ) do
|
14
|
+
@polygon.points.pop
|
15
|
+
@polygon.should_not( be_valid )
|
16
|
+
end
|
17
|
+
|
18
|
+
it( 'does not have the first and last points equal' ) do
|
19
|
+
@polygon.points.last.lattitude = 1
|
20
|
+
@polygon.should_not( be_valid )
|
21
|
+
end
|
22
|
+
|
23
|
+
it( 'does not have a valid collection of points' ) do
|
24
|
+
@polygon.points.first.lattitude = nil
|
25
|
+
@polygon.should_not( be_valid )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context( 'on initialization' ) do
|
30
|
+
context( 'from XML' ) do
|
31
|
+
before( :each ) do
|
32
|
+
@original_polygon = RCAP::CAP_1_2::Polygon.new( :points => Array.new(4){|i| RCAP::CAP_1_2::Point.new( :lattitude => i, :longitude => i )})
|
33
|
+
@empty_original_polygon = RCAP::CAP_1_2::Polygon.new()
|
34
|
+
@alert = RCAP::CAP_1_2::Alert.new( :infos => RCAP::CAP_1_2::Info.new( :areas => RCAP::CAP_1_2::Area.new( :polygons => [@original_polygon, @empty_original_polygon] )))
|
35
|
+
@xml_string = @alert.to_xml
|
36
|
+
@xml_document = REXML::Document.new( @xml_string )
|
37
|
+
@info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_2::Info::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
|
38
|
+
@area_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_2::Area::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
|
39
|
+
@polygon_element = RCAP.xpath_first( @area_element, RCAP::CAP_1_2::Polygon::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
|
40
|
+
@polygon = RCAP::CAP_1_2::Polygon.from_xml_element( @polygon_element )
|
41
|
+
end
|
42
|
+
|
43
|
+
it( 'should parse all the points' ) do
|
44
|
+
@polygon.points.zip( @original_polygon.points ).each do |point, original_point|
|
45
|
+
point.lattitude.should == original_point.lattitude
|
46
|
+
point.longitude.should == original_point.longitude
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should allow empty polygon xml elements' do
|
51
|
+
empty_polygon_element = RCAP.xpath_match( @area_element, RCAP::CAP_1_2::Polygon::XPATH, RCAP::CAP_1_2::Alert::XMLNS )[1]
|
52
|
+
empty_polygon = RCAP::CAP_1_2::Polygon.from_xml_element( empty_polygon_element )
|
53
|
+
empty_polygon.should == @empty_original_polygon
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context( 'from a hash' ) do
|
58
|
+
before( :each ) do
|
59
|
+
@polygon = RCAP::CAP_1_2::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_2::Point.new( :lattitude => i, :longitude => i )})
|
60
|
+
end
|
61
|
+
|
62
|
+
it( 'should load all the points' ) do
|
63
|
+
@new_polygon = RCAP::CAP_1_2::Polygon.from_h( @polygon.to_h )
|
64
|
+
@new_polygon.points.should == @polygon.points
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context( 'when exported' ) do
|
70
|
+
before( :each ) do
|
71
|
+
@polygon = RCAP::CAP_1_2::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_2::Point.new( :lattitude => i, :longitude => i )})
|
72
|
+
end
|
73
|
+
|
74
|
+
context( 'to a hash' ) do
|
75
|
+
it( 'should export correctly' ) do
|
76
|
+
@polygon.to_h.should == { RCAP::CAP_1_2::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_h }}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe( 'instance methods' ) do
|
82
|
+
before( :each ) do
|
83
|
+
@polygon = RCAP::CAP_1_2::Polygon.new
|
84
|
+
end
|
85
|
+
|
86
|
+
describe( '#add_point' ) do
|
87
|
+
before( :each ) do
|
88
|
+
@point = @polygon.add_point( lattitude: 1, longitude: 1 )
|
89
|
+
end
|
90
|
+
|
91
|
+
it( 'should return a 1.2 Point' ) do
|
92
|
+
@point.class.should == RCAP::CAP_1_2::Point
|
93
|
+
@point.lattitude.should == 1
|
94
|
+
@point.longitude.should == 1
|
95
|
+
end
|
96
|
+
|
97
|
+
it( 'should add a Point to the points attribute' ) do
|
98
|
+
@polygon.points.size.should == 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_2::Resource ) do
|
4
|
+
context( 'on initialisation' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@resource = RCAP::CAP_1_2::Resource.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it( 'should have no mime_type' ){ @resource.mime_type.should( be_nil )}
|
10
|
+
it( 'should have no size' ){ @resource.size.should( be_nil )}
|
11
|
+
it( 'should have no uri' ){ @resource.uri.should( be_nil )}
|
12
|
+
it( 'should have no deref_uri' ){ @resource.deref_uri.should( be_nil )}
|
13
|
+
it( 'should have no digest' ){ @resource.digest.should( be_nil )}
|
14
|
+
it( 'should have no resource_desc' ){ @resource.resource_desc.should( be_nil )}
|
15
|
+
|
16
|
+
context( 'from XML' ) do
|
17
|
+
before( :each ) do
|
18
|
+
@original_resource = RCAP::CAP_1_2::Resource.new
|
19
|
+
@original_resource.resource_desc = "Image of incident"
|
20
|
+
@original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
21
|
+
@original_resource.mime_type = 'image/png'
|
22
|
+
@original_resource.deref_uri = "IMAGE DATA"
|
23
|
+
@original_resource.size = "20480"
|
24
|
+
@original_resource.digest = "2048"
|
25
|
+
|
26
|
+
@alert = RCAP::CAP_1_2::Alert.new( :infos => RCAP::CAP_1_2::Info.new( :resources => @original_resource ))
|
27
|
+
@xml_string = @alert.to_xml
|
28
|
+
@xml_document = REXML::Document.new( @xml_string )
|
29
|
+
@info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_2::Info::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
|
30
|
+
@resource_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_2::Resource::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
|
31
|
+
@resource_element.should_not( be_nil )
|
32
|
+
@resource = RCAP::CAP_1_2::Resource.from_xml_element( @resource_element )
|
33
|
+
end
|
34
|
+
|
35
|
+
it( 'should parse resource_desc correctly' ) do
|
36
|
+
@resource.resource_desc.should == @original_resource.resource_desc
|
37
|
+
end
|
38
|
+
|
39
|
+
it( 'should parse uri correctly' ) do
|
40
|
+
@resource.uri.should == @original_resource.uri
|
41
|
+
end
|
42
|
+
|
43
|
+
it( 'should parse mime_type correctly' ) do
|
44
|
+
@resource.mime_type.should == @original_resource.mime_type
|
45
|
+
end
|
46
|
+
|
47
|
+
it( 'should parse deref_uri correctly' ) do
|
48
|
+
@resource.deref_uri.should == @original_resource.deref_uri
|
49
|
+
end
|
50
|
+
|
51
|
+
it( 'should parse size correctly' ) do
|
52
|
+
@resource.size.should == @original_resource.size
|
53
|
+
end
|
54
|
+
|
55
|
+
it( 'should parse digest correctly' ) do
|
56
|
+
@resource.digest.should == @original_resource.digest
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
context( 'from a hash' ) do
|
62
|
+
before( :each ) do
|
63
|
+
@original_resource = RCAP::CAP_1_2::Resource.new
|
64
|
+
@original_resource.resource_desc = "Image of incident"
|
65
|
+
@original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
66
|
+
@original_resource.mime_type = 'image/png'
|
67
|
+
@original_resource.deref_uri = "IMAGE DATA"
|
68
|
+
@original_resource.size = "20480"
|
69
|
+
@original_resource.digest = "2048"
|
70
|
+
|
71
|
+
@resource = RCAP::CAP_1_2::Resource.from_h( @original_resource.to_h )
|
72
|
+
end
|
73
|
+
|
74
|
+
it( 'should parse resource_desc correctly' ) do
|
75
|
+
@resource.resource_desc.should == @original_resource.resource_desc
|
76
|
+
end
|
77
|
+
|
78
|
+
it( 'should parse uri correctly' ) do
|
79
|
+
@resource.uri.should == @original_resource.uri
|
80
|
+
end
|
81
|
+
|
82
|
+
it( 'should parse mime_type correctly' ) do
|
83
|
+
@resource.mime_type.should == @original_resource.mime_type
|
84
|
+
end
|
85
|
+
|
86
|
+
it( 'should parse deref_uri correctly' ) do
|
87
|
+
@resource.deref_uri.should == @original_resource.deref_uri
|
88
|
+
end
|
89
|
+
|
90
|
+
it( 'should parse size correctly' ) do
|
91
|
+
@resource.size.should == @original_resource.size
|
92
|
+
end
|
93
|
+
|
94
|
+
it( 'should parse digest correctly' ) do
|
95
|
+
@resource.digest.should == @original_resource.digest
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
context( 'when exported' ) do
|
102
|
+
before( :each ) do
|
103
|
+
@resource = RCAP::CAP_1_2::Resource.new
|
104
|
+
@resource.resource_desc = "Image of incident"
|
105
|
+
@resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
106
|
+
@resource.mime_type = 'image/png'
|
107
|
+
@resource.deref_uri = "IMAGE DATA"
|
108
|
+
@resource.size = "20480"
|
109
|
+
@resource.digest = "2048"
|
110
|
+
end
|
111
|
+
|
112
|
+
context( 'to a hash' ) do
|
113
|
+
before( :each ) do
|
114
|
+
@resource_hash = @resource.to_h
|
115
|
+
end
|
116
|
+
|
117
|
+
it( 'should set the resource description' ) do
|
118
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::RESOURCE_DESC_KEY ].should == @resource.resource_desc
|
119
|
+
end
|
120
|
+
|
121
|
+
it( 'should set the mime type' ) do
|
122
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::MIME_TYPE_KEY ].should == @resource.mime_type
|
123
|
+
end
|
124
|
+
|
125
|
+
it( 'should set the size' ) do
|
126
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::SIZE_KEY ].should == @resource.size
|
127
|
+
end
|
128
|
+
|
129
|
+
it( 'should set the URI' ) do
|
130
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::URI_KEY ].should == @resource.uri
|
131
|
+
end
|
132
|
+
|
133
|
+
it( 'should set the dereferenced URI' ) do
|
134
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::DEREF_URI_KEY ].should == @resource.deref_uri
|
135
|
+
end
|
136
|
+
|
137
|
+
it( 'should set the digest' ) do
|
138
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::DIGEST_KEY ].should == @resource.digest
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context( 'which is valid' ) do
|
144
|
+
before( :each ) do
|
145
|
+
@resource = RCAP::CAP_1_2::Resource.new( :resource_desc => 'Resource Description', :mime_type => 'text/csv' )
|
146
|
+
@resource.should( be_valid )
|
147
|
+
end
|
148
|
+
|
149
|
+
describe( 'should not be valid if it' ) do
|
150
|
+
it( 'does not have a resource description (resource_desc)' ) do
|
151
|
+
@resource.resource_desc = nil
|
152
|
+
@resource.should_not( be_valid )
|
153
|
+
end
|
154
|
+
|
155
|
+
it( 'does not have a MIME type' ) do
|
156
|
+
@resource.mime_type = nil
|
157
|
+
@resource.should_not( be_valid )
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/validations_spec.rb
CHANGED
@@ -18,7 +18,19 @@ end
|
|
18
18
|
class DependencyWithObject
|
19
19
|
include Validation
|
20
20
|
attr_accessor( :dependent_value, :contingent_value )
|
21
|
-
validates_dependency_of( :dependent_value, :on => :contingent_value, :with_value =>
|
21
|
+
validates_dependency_of( :dependent_value, :on => :contingent_value, :with_value => 1 )
|
22
|
+
end
|
23
|
+
|
24
|
+
class ConditionalPresenceObject
|
25
|
+
include Validation
|
26
|
+
attr_accessor( :dependent_value, :contingent_value )
|
27
|
+
validates_conditional_presence_of( :dependent_value, when: :contingent_value )
|
28
|
+
end
|
29
|
+
|
30
|
+
class ConditionalPresenceIsObject
|
31
|
+
include Validation
|
32
|
+
attr_accessor( :dependent_value, :contingent_value )
|
33
|
+
validates_conditional_presence_of( :dependent_value, when: :contingent_value, is: 1 )
|
22
34
|
end
|
23
35
|
|
24
36
|
describe( Validation::ClassMethods ) do
|
@@ -28,12 +40,12 @@ describe( Validation::ClassMethods ) do
|
|
28
40
|
end
|
29
41
|
|
30
42
|
it( 'should be valid if all the members are valid' ) do
|
31
|
-
@object_with_collection.collection = Array.new(3){ RCAP::Point.new( :lattitude => 0, :longitude => 0 )}
|
43
|
+
@object_with_collection.collection = Array.new(3){ RCAP::CAP_1_1::Point.new( :lattitude => 0, :longitude => 0 )}
|
32
44
|
@object_with_collection.should( be_valid )
|
33
45
|
end
|
34
46
|
|
35
47
|
it( 'should not be valid some of the members are invalid' ) do
|
36
|
-
@object_with_collection.collection = Array.new( 2 ){ RCAP::Point.new( :lattitude => 0, :longitude => 0 )} + [ RCAP::Point.new( :lattitude => "not a number", :longitude => 0)]
|
48
|
+
@object_with_collection.collection = Array.new( 2 ){ RCAP::CAP_1_1::Point.new( :lattitude => 0, :longitude => 0 )} + [ RCAP::CAP_1_1::Point.new( :lattitude => "not a number", :longitude => 0)]
|
37
49
|
@object_with_collection.should_not( be_valid )
|
38
50
|
end
|
39
51
|
end
|
@@ -42,8 +54,8 @@ describe( Validation::ClassMethods ) do
|
|
42
54
|
context( 'without :with_value' ) do
|
43
55
|
before( :each ) do
|
44
56
|
@object = DependencyObject.new
|
45
|
-
@object.dependent_value =
|
46
|
-
@object.contingent_value =
|
57
|
+
@object.dependent_value = 1
|
58
|
+
@object.contingent_value = 1
|
47
59
|
@object.should( be_valid )
|
48
60
|
end
|
49
61
|
|
@@ -51,10 +63,12 @@ describe( Validation::ClassMethods ) do
|
|
51
63
|
@object.contingent_value = nil
|
52
64
|
@object.should_not( be_valid )
|
53
65
|
end
|
66
|
+
|
54
67
|
it( 'should be valid if the dependent value is nil' ) do
|
55
68
|
@object.dependent_value = nil
|
56
69
|
@object.should( be_valid )
|
57
70
|
end
|
71
|
+
|
58
72
|
it( 'should be valid if both are nil' ) do
|
59
73
|
@object.dependent_value = nil
|
60
74
|
@object.contingent_value = nil
|
@@ -65,8 +79,8 @@ describe( Validation::ClassMethods ) do
|
|
65
79
|
context( 'with :with_value' ) do
|
66
80
|
before( :each ) do
|
67
81
|
@object = DependencyWithObject.new
|
68
|
-
@object.dependent_value =
|
69
|
-
@object.contingent_value =
|
82
|
+
@object.dependent_value = 1
|
83
|
+
@object.contingent_value = 1
|
70
84
|
@object.should( be_valid )
|
71
85
|
end
|
72
86
|
|
@@ -92,4 +106,63 @@ describe( Validation::ClassMethods ) do
|
|
92
106
|
end
|
93
107
|
end
|
94
108
|
end
|
109
|
+
|
110
|
+
describe( 'validates_conditional_presence_of' ) do
|
111
|
+
context( 'without :is' ) do
|
112
|
+
before( :each ) do
|
113
|
+
@object = ConditionalPresenceObject.new
|
114
|
+
@object.dependent_value = 1
|
115
|
+
@object.contingent_value = 1
|
116
|
+
@object.should( be_valid )
|
117
|
+
end
|
118
|
+
|
119
|
+
it( 'should not be valid if dependent_value is nil' ) do
|
120
|
+
@object.dependent_value = nil
|
121
|
+
@object.should_not( be_valid )
|
122
|
+
end
|
123
|
+
|
124
|
+
it( 'should be valid if contingent_value is nil' ) do
|
125
|
+
@object.contingent_value = nil
|
126
|
+
@object.should( be_valid )
|
127
|
+
end
|
128
|
+
|
129
|
+
it( 'should be valid if both dependent_value and contingent_value is nil' ) do
|
130
|
+
@object.dependent_value = nil
|
131
|
+
@object.contingent_value = nil
|
132
|
+
@object.should( be_valid )
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
context( 'with :is' ) do
|
138
|
+
before( :each ) do
|
139
|
+
@object = ConditionalPresenceIsObject.new
|
140
|
+
@object.dependent_value = 1
|
141
|
+
@object.contingent_value = 1
|
142
|
+
@object.should( be_valid )
|
143
|
+
end
|
144
|
+
|
145
|
+
it( 'should not be valid if dependent_value is nil' ) do
|
146
|
+
@object.dependent_value = nil
|
147
|
+
@object.should_not( be_valid )
|
148
|
+
end
|
149
|
+
|
150
|
+
it( 'should be valid if contingent_value is nil' ) do
|
151
|
+
@object.contingent_value = nil
|
152
|
+
@object.should( be_valid )
|
153
|
+
end
|
154
|
+
|
155
|
+
it( 'should be valid if dependent_value is nil and contingent_value is not required value' ) do
|
156
|
+
@object.dependent_value = nil
|
157
|
+
@object.contingent_value = 2
|
158
|
+
@object.should( be_valid )
|
159
|
+
end
|
160
|
+
|
161
|
+
it( 'should be valid if both dependent_value and contingent_value is nil' ) do
|
162
|
+
@object.dependent_value = nil
|
163
|
+
@object.contingent_value = nil
|
164
|
+
@object.should( be_valid )
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
95
168
|
end
|