atdis 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-version +1 -1
- data/.travis.yml +0 -1
- data/Gemfile +1 -1
- data/README.md +25 -2
- data/Rakefile +1 -1
- data/docs/ATDIS-1.0.2 Application Tracking Data Interchange Specification (v1.0.2).doc +0 -0
- data/docs/ATDIS-1.0.2 Application Tracking Data Interchange Specification (v1.0.2).pdf +0 -0
- data/lib/atdis.rb +2 -7
- data/lib/atdis/feed.rb +80 -8
- data/lib/atdis/model.rb +74 -128
- data/lib/atdis/models/address.rb +17 -0
- data/lib/atdis/models/application.rb +31 -0
- data/lib/atdis/models/authority.rb +19 -0
- data/lib/atdis/models/document.rb +16 -0
- data/lib/atdis/models/event.rb +16 -0
- data/lib/atdis/models/info.rb +81 -0
- data/lib/atdis/models/land_title_ref.rb +26 -0
- data/lib/atdis/models/location.rb +23 -0
- data/lib/atdis/models/page.rb +56 -0
- data/lib/atdis/models/pagination.rb +68 -0
- data/lib/atdis/models/person.rb +14 -0
- data/lib/atdis/models/reference.rb +13 -0
- data/lib/atdis/models/response.rb +16 -0
- data/lib/atdis/models/torrens_title.rb +24 -0
- data/lib/atdis/validators.rb +26 -10
- data/lib/atdis/version.rb +1 -1
- data/spec/atdis/feed_spec.rb +78 -22
- data/spec/atdis/model_spec.rb +80 -131
- data/spec/atdis/models/address_spec.rb +22 -0
- data/spec/atdis/models/application_spec.rb +246 -0
- data/spec/atdis/models/authority_spec.rb +34 -0
- data/spec/atdis/models/document_spec.rb +19 -0
- data/spec/atdis/models/event_spec.rb +29 -0
- data/spec/atdis/models/info_spec.rb +303 -0
- data/spec/atdis/models/land_title_ref_spec.rb +39 -0
- data/spec/atdis/models/location_spec.rb +95 -0
- data/spec/atdis/models/page_spec.rb +296 -0
- data/spec/atdis/models/pagination_spec.rb +153 -0
- data/spec/atdis/models/person_spec.rb +19 -0
- data/spec/atdis/models/reference_spec.rb +55 -0
- data/spec/atdis/models/response_spec.rb +5 -0
- data/spec/atdis/models/torrens_title_spec.rb +52 -0
- data/spec/atdis/separated_url_spec.rb +4 -4
- metadata +141 -135
- data/docs/ATDIS-1.0.7 Application Tracking Data Interchange Specification (v1.0).doc +0 -0
- data/docs/ATDIS-1.0.7 Application Tracking Data Interchange Specification (v1.0).pdf +0 -0
- data/lib/atdis/application.rb +0 -78
- data/lib/atdis/document.rb +0 -14
- data/lib/atdis/event.rb +0 -17
- data/lib/atdis/location.rb +0 -21
- data/lib/atdis/page.rb +0 -130
- data/lib/atdis/person.rb +0 -12
- data/spec/atdis/application_spec.rb +0 -539
- data/spec/atdis/document_spec.rb +0 -19
- data/spec/atdis/event_spec.rb +0 -29
- data/spec/atdis/location_spec.rb +0 -148
- data/spec/atdis/page_spec.rb +0 -492
- data/spec/atdis/person_spec.rb +0 -19
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ATDIS::Models::Authority do
|
4
|
+
describe "validations" do
|
5
|
+
context "a valid ref" do
|
6
|
+
let(:a) { ATDIS::Models::Authority.new(ref: "http://www.council.nsw.gov.au/atdis/1.0", name: "Council")}
|
7
|
+
it {a.should be_valid}
|
8
|
+
end
|
9
|
+
|
10
|
+
context "a valid ref with https" do
|
11
|
+
let(:a) { ATDIS::Models::Authority.new(ref: "https://www.council.nsw.gov.au/atdis/1.0", name: "Council")}
|
12
|
+
it {a.should be_valid}
|
13
|
+
end
|
14
|
+
|
15
|
+
context "an invalid ref that isn't a url" do
|
16
|
+
let(:a) { ATDIS::Models::Authority.new(ref: "foobar", name: "Council")}
|
17
|
+
it {
|
18
|
+
a.should_not be_valid
|
19
|
+
a.errors.messages.should == {ref: [
|
20
|
+
ATDIS::ErrorMessage.new("is not a valid URL", "4.3.1"),
|
21
|
+
ATDIS::ErrorMessage.new("is not a valid Unique Authority Identifier", "4.3.1")
|
22
|
+
]}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
context "an invalid ref because it doesn't end in atdis/1.0" do
|
27
|
+
let(:a) { ATDIS::Models::Authority.new(ref: "http://www.council.nsw.gov.au/foobar", name: "Council")}
|
28
|
+
it {
|
29
|
+
a.should_not be_valid
|
30
|
+
a.errors.messages.should == {ref: [ATDIS::ErrorMessage.new("is not a valid Unique Authority Identifier", "4.3.1")]}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ATDIS::Models::Document do
|
4
|
+
it ".attribute_names" do
|
5
|
+
ATDIS::Models::Document.attribute_names.should == ["ref", "title", "document_url"]
|
6
|
+
end
|
7
|
+
|
8
|
+
it ".ref" do
|
9
|
+
ATDIS::Models::Document.interpret(ref: "27B/6").ref.should == "27B/6"
|
10
|
+
end
|
11
|
+
|
12
|
+
it ".title" do
|
13
|
+
ATDIS::Models::Document.interpret(title: "Authorisation for Repairs").title.should == "Authorisation for Repairs"
|
14
|
+
end
|
15
|
+
|
16
|
+
it ".document_url" do
|
17
|
+
ATDIS::Models::Document.interpret(document_url: "http://foo.com/bar").document_url.should == URI.parse("http://foo.com/bar")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ATDIS::Models::Event do
|
4
|
+
it ".attribute_names" do
|
5
|
+
ATDIS::Models::Event.attribute_names.should == ["id", "timestamp", "description", "event_type", "status"]
|
6
|
+
end
|
7
|
+
|
8
|
+
it ".id" do
|
9
|
+
ATDIS::Models::Event.interpret(id: "27B/6").id.should == "27B/6"
|
10
|
+
end
|
11
|
+
|
12
|
+
it ".date" do
|
13
|
+
ATDIS::Models::Event.interpret(timestamp: "2013-06-18").timestamp.should == DateTime.new(2013,6,18)
|
14
|
+
end
|
15
|
+
|
16
|
+
it ".description" do
|
17
|
+
ATDIS::Models::Event.interpret(description: "A very fine event").description.should == "A very fine event"
|
18
|
+
end
|
19
|
+
|
20
|
+
it ".event_type" do
|
21
|
+
# TODO Is event_type always a string? ATDIS-1.0.3 doesn't say
|
22
|
+
ATDIS::Models::Event.interpret(event_type: "approval").event_type.should == "approval"
|
23
|
+
end
|
24
|
+
|
25
|
+
it ".status" do
|
26
|
+
# TODO Is status always a string? ATDIS-1.0.3 doesn't say
|
27
|
+
ATDIS::Models::Event.interpret(status: "approved").status.should == "approved"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,303 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ATDIS::Models::Info do
|
4
|
+
let(:a) { ATDIS::Models::Info.new(
|
5
|
+
dat_id: "DA2013-0381",
|
6
|
+
development_type: "residential",
|
7
|
+
application_type: "DA",
|
8
|
+
last_modified_date: DateTime.new(2013,4,20,2,1,7),
|
9
|
+
description: "New pool plus deck",
|
10
|
+
authority: {
|
11
|
+
ref: "http://www.council.nsw.gov.au/atdis/1.0",
|
12
|
+
name: "Example Council Shire Council"
|
13
|
+
},
|
14
|
+
lodgement_date: DateTime.new(2013,4,20,2,1,7),
|
15
|
+
determination_date: DateTime.new(2013,6,20),
|
16
|
+
determination_type: "Pending",
|
17
|
+
status: "OPEN",
|
18
|
+
)}
|
19
|
+
|
20
|
+
describe "determination_type" do
|
21
|
+
context "is missing" do
|
22
|
+
before(:each) { a.determination_type = nil}
|
23
|
+
it {
|
24
|
+
a.should_not be_valid
|
25
|
+
a.errors.messages.should == {determination_type: [ATDIS::ErrorMessage.new("does not have one of the allowed types", "4.3.1")]}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
context "is valid and Pending" do
|
30
|
+
before(:each) { a.determination_type = "Pending" }
|
31
|
+
it { a.should be_valid }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "is not valid because it's not one of the set of allowed ones" do
|
35
|
+
before(:each) { a.determination_type = "Something random" }
|
36
|
+
it {
|
37
|
+
a.should_not be_valid
|
38
|
+
a.errors.messages.should == {determination_type: [ATDIS::ErrorMessage.new("does not have one of the allowed types", "4.3.1")]}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "notification_date" do
|
44
|
+
it "both valid start and end dates" do
|
45
|
+
a.notification_start_date = DateTime.new(2013,4,20,2,1,7)
|
46
|
+
a.notification_end_date = DateTime.new(2013,5,20,0,0,0)
|
47
|
+
a.should be_valid
|
48
|
+
end
|
49
|
+
|
50
|
+
it "invalid start date" do
|
51
|
+
a.notification_start_date = "18 January 2013"
|
52
|
+
a.notification_end_date = DateTime.new(2013,2,1,0,0,0)
|
53
|
+
a.should_not be_valid
|
54
|
+
a.errors.messages.should == {notification_start_date: [ATDIS::ErrorMessage["is not a valid date", "4.3.1"]]}
|
55
|
+
end
|
56
|
+
|
57
|
+
it "invalid end date" do
|
58
|
+
a.notification_start_date = DateTime.new(2013,1,10,0,0,0)
|
59
|
+
a.notification_end_date = "18 January 2013"
|
60
|
+
a.should_not be_valid
|
61
|
+
a.errors.messages.should == {notification_end_date: [ATDIS::ErrorMessage["is not a valid date", "4.3.1"]]}
|
62
|
+
end
|
63
|
+
|
64
|
+
it "only start date set" do
|
65
|
+
a.notification_start_date = DateTime.new(2013,4,20,2,1,7)
|
66
|
+
a.should_not be_valid
|
67
|
+
a.errors.messages.should == {notification_end_date: [ATDIS::ErrorMessage["can not be blank if notification_start_date is set", "4.3.1"]]}
|
68
|
+
end
|
69
|
+
|
70
|
+
it "only end date set" do
|
71
|
+
a.notification_end_date = DateTime.new(2013,4,20,2,1,7)
|
72
|
+
a.should_not be_valid
|
73
|
+
a.errors.messages.should == {notification_start_date: [ATDIS::ErrorMessage["can not be blank if notification_end_date is set", "4.3.1"]]}
|
74
|
+
end
|
75
|
+
|
76
|
+
it "end date is before start date" do
|
77
|
+
a.notification_start_date = DateTime.new(2013,5,20,0,0,0)
|
78
|
+
a.notification_end_date = DateTime.new(2013,4,20,2,1,7)
|
79
|
+
a.should_not be_valid
|
80
|
+
a.errors.messages.should == {notification_end_date: [ATDIS::ErrorMessage["can not be earlier than notification_start_date", "4.3.1"]]}
|
81
|
+
end
|
82
|
+
|
83
|
+
it "both dates set to null" do
|
84
|
+
a.notification_start_date = nil
|
85
|
+
a.notification_end_date = nil
|
86
|
+
a.notification_start_date.should be_nil
|
87
|
+
a.notification_end_date.should be_nil
|
88
|
+
a.should be_valid
|
89
|
+
end
|
90
|
+
|
91
|
+
it "only start date set to null" do
|
92
|
+
a.notification_start_date = nil
|
93
|
+
a.notification_end_date = DateTime.new(2013,2,1,0,0,0)
|
94
|
+
a.should_not be_valid
|
95
|
+
a.errors.messages.should == {notification_start_date: [ATDIS::ErrorMessage["can not be blank if notification_end_date is set", "4.3.1"]]}
|
96
|
+
end
|
97
|
+
|
98
|
+
it "only end date set to null" do
|
99
|
+
a.notification_start_date = DateTime.new(2013,2,1,0,0,0)
|
100
|
+
a.notification_end_date = nil
|
101
|
+
a.should_not be_valid
|
102
|
+
a.errors.messages.should == {notification_end_date: [ATDIS::ErrorMessage["can not be blank if notification_start_date is set", "4.3.1"]]}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe ".status" do
|
107
|
+
it do
|
108
|
+
a.status = nil
|
109
|
+
a.should_not be_valid
|
110
|
+
a.errors.messages.should == {status: [ATDIS::ErrorMessage["can't be blank", "4.3.1"]]}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe ".determination_date" do
|
115
|
+
it do
|
116
|
+
a.determination_date = nil
|
117
|
+
a.should be_valid
|
118
|
+
end
|
119
|
+
it do
|
120
|
+
a.determination_date = "18 January 2013"
|
121
|
+
a.should_not be_valid
|
122
|
+
a.errors.messages.should == {determination_date: [ATDIS::ErrorMessage["is not a valid date", "4.3.1"]]}
|
123
|
+
end
|
124
|
+
it "nil should be allowed if the application is not yet determined" do
|
125
|
+
a.determination_date = nil
|
126
|
+
a.determination_date.should be_nil
|
127
|
+
a.should be_valid
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe ".lodgement_date" do
|
132
|
+
it do
|
133
|
+
a.lodgement_date = nil
|
134
|
+
a.should_not be_valid
|
135
|
+
a.errors.messages.should == {lodgement_date: [ATDIS::ErrorMessage["can't be blank", "4.3.1"]]}
|
136
|
+
end
|
137
|
+
it do
|
138
|
+
a.lodgement_date = "18 January 2013"
|
139
|
+
a.should_not be_valid
|
140
|
+
a.errors.messages.should == {lodgement_date: [ATDIS::ErrorMessage["is not a valid date", "4.3.1"]]}
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe ".authority" do
|
145
|
+
it do
|
146
|
+
a.authority = nil
|
147
|
+
a.should_not be_valid
|
148
|
+
a.errors.messages.should == {authority: [ATDIS::ErrorMessage["can't be blank", "4.3.1"]]}
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe ".description" do
|
153
|
+
it do
|
154
|
+
a.description = ""
|
155
|
+
a.should_not be_valid
|
156
|
+
a.errors.messages.should == {description: [ATDIS::ErrorMessage["can't be blank", "4.3.1"]]}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe ".last_modified_date" do
|
161
|
+
it do
|
162
|
+
a.last_modified_date = nil
|
163
|
+
a.should_not be_valid
|
164
|
+
a.errors.messages.should == {last_modified_date: [ATDIS::ErrorMessage["can't be blank", "4.3.1"]]}
|
165
|
+
end
|
166
|
+
it do
|
167
|
+
a.last_modified_date = "18 January 2013"
|
168
|
+
a.should_not be_valid
|
169
|
+
a.errors.messages.should == {last_modified_date: [ATDIS::ErrorMessage["is not a valid date", "4.3.1"]]}
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe ".dat_id" do
|
174
|
+
it ".dat_id" do
|
175
|
+
a.dat_id = nil
|
176
|
+
a.should_not be_valid
|
177
|
+
a.errors.messages.should == {dat_id: [ATDIS::ErrorMessage["can't be blank", "4.3.1"]]}
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should be url encoded" do
|
181
|
+
a.dat_id = "foo bar"
|
182
|
+
a.should_not be_valid
|
183
|
+
a.errors.messages.should == {dat_id: [ATDIS::ErrorMessage["should be url encoded", "4.3.1"]]}
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "#description=" do
|
188
|
+
let(:a) { ATDIS::Models::Info.new }
|
189
|
+
it "should do not type casting when it's already a String" do
|
190
|
+
a.description = "foo"
|
191
|
+
a.description.should == "foo"
|
192
|
+
end
|
193
|
+
context "not a string" do
|
194
|
+
before :each do
|
195
|
+
a.description = 123
|
196
|
+
end
|
197
|
+
it "should cast to a string when it's not a string" do
|
198
|
+
a.description.should == "123"
|
199
|
+
end
|
200
|
+
it "should keep the original value" do
|
201
|
+
a.description_before_type_cast.should == 123
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "#lodgement_date=" do
|
207
|
+
let(:a) { ATDIS::Models::Info.new }
|
208
|
+
it "should do no type casting when it's already a date" do
|
209
|
+
a.lodgement_date = DateTime.new(2013,1,1)
|
210
|
+
a.lodgement_date.should == DateTime.new(2013,1,1)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should cast a string to a date when it's a valid date" do
|
214
|
+
a.lodgement_date = "2013-01-01"
|
215
|
+
a.lodgement_date.should == DateTime.new(2013,1,1)
|
216
|
+
end
|
217
|
+
|
218
|
+
context "not a valid date" do
|
219
|
+
before :each do
|
220
|
+
a.lodgement_date = "2013/01/01"
|
221
|
+
end
|
222
|
+
it "should be nil" do
|
223
|
+
a.lodgement_date.should be_nil
|
224
|
+
end
|
225
|
+
it "should keep the original string" do
|
226
|
+
a.lodgement_date_before_type_cast.should == "2013/01/01"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "#last_modified_date=" do
|
232
|
+
let(:a) { ATDIS::Models::Info.new }
|
233
|
+
it "should do no type casting when it's already a date" do
|
234
|
+
a.last_modified_date = DateTime.new(2013,1,1)
|
235
|
+
a.last_modified_date.should == DateTime.new(2013,1,1)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should cast a string to a date when it's a valid date" do
|
239
|
+
a.last_modified_date = "2013-01-01"
|
240
|
+
a.last_modified_date.should == DateTime.new(2013,1,1)
|
241
|
+
end
|
242
|
+
|
243
|
+
context "not a valid date" do
|
244
|
+
before :each do
|
245
|
+
a.last_modified_date = "2013/01/01"
|
246
|
+
end
|
247
|
+
it "should be nil" do
|
248
|
+
a.last_modified_date.should be_nil
|
249
|
+
end
|
250
|
+
it "should keep the original string" do
|
251
|
+
a.last_modified_date_before_type_cast.should == "2013/01/01"
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe "related_apps" do
|
257
|
+
context "is missing" do
|
258
|
+
before(:each) { a.related_apps = nil }
|
259
|
+
it { a.should be_valid }
|
260
|
+
end
|
261
|
+
|
262
|
+
context "is not an array" do
|
263
|
+
before(:each) { a.related_apps = "http://www.council.nsw.gov.au/atdis/1.0/2014_20-022DA.json"}
|
264
|
+
it {
|
265
|
+
a.should_not be_valid
|
266
|
+
a.errors.messages.should == {related_apps: [ATDIS::ErrorMessage.new("should be an array", "4.3.1")]}
|
267
|
+
}
|
268
|
+
end
|
269
|
+
|
270
|
+
context "are all valid URLs that uniquely identifies a DA" do
|
271
|
+
before(:each) { a.related_apps = [
|
272
|
+
"http://www.council.nsw.gov.au/atdis/1.0/2014_20-022DA.json",
|
273
|
+
"http://www.council.nsw.gov.au/foo/bar/atdis/1.0/sdjfsd.json"
|
274
|
+
]}
|
275
|
+
it { a.should be_valid }
|
276
|
+
end
|
277
|
+
|
278
|
+
context "are all valid URLs but one does not end in json" do
|
279
|
+
before(:each) { a.related_apps = [
|
280
|
+
"http://www.council.nsw.gov.au/atdis/1.0/2014_20-022DA.json",
|
281
|
+
"http://www.council.nsw.gov.au/foo/bar/atdis/1.0/sdjfsd"
|
282
|
+
]}
|
283
|
+
it {
|
284
|
+
a.should_not be_valid
|
285
|
+
a.errors.messages.should == {related_apps: [ATDIS::ErrorMessage.new("contains url(s) not in the expected format", "4.3.1")]}
|
286
|
+
}
|
287
|
+
end
|
288
|
+
|
289
|
+
context "contains an invalid URL" do
|
290
|
+
before(:each) { a.related_apps = [
|
291
|
+
"http://www.council.nsw.gov.au/atdis/1.0/2014_20-022DA.json",
|
292
|
+
"foobar"
|
293
|
+
]}
|
294
|
+
it {
|
295
|
+
a.should_not be_valid
|
296
|
+
a.errors.messages.should == {related_apps: [
|
297
|
+
ATDIS::ErrorMessage.new("contains an invalid URL", "4.3.1"),
|
298
|
+
ATDIS::ErrorMessage.new("contains url(s) not in the expected format", "4.3.1")
|
299
|
+
]}
|
300
|
+
}
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ATDIS::Models::LandTitleRef do
|
4
|
+
context "torrens" do
|
5
|
+
before(:each) {
|
6
|
+
m = double
|
7
|
+
ATDIS::Models::TorrensTitle.should_receive(:interpret).with({lot: "10"}).and_return(m)
|
8
|
+
m.should_receive(:valid?).and_return(true)
|
9
|
+
}
|
10
|
+
let(:l) { ATDIS::Models::LandTitleRef.new(torrens: {lot: "10"}) }
|
11
|
+
it { l.should be_valid }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "other" do
|
15
|
+
let(:l) { ATDIS::Models::LandTitleRef.new(other: {some: "foo", random: "stuff"})}
|
16
|
+
it { l.should be_valid }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "no torrens or other" do
|
20
|
+
let(:l) { ATDIS::Models::LandTitleRef.new }
|
21
|
+
it {
|
22
|
+
l.should_not be_valid
|
23
|
+
l.errors.messages.should == {torrens: [ATDIS::ErrorMessage.new("or other needs be present", "4.3.3")]}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
context "both torrens and other" do
|
28
|
+
before(:each) {
|
29
|
+
m = double
|
30
|
+
ATDIS::Models::TorrensTitle.should_receive(:interpret).with({lot: "10"}).and_return(m)
|
31
|
+
m.should_receive(:valid?).and_return(true)
|
32
|
+
}
|
33
|
+
let(:l) { ATDIS::Models::LandTitleRef.new(torrens: {lot: "10"}, other: {some: "foo", random: "stuff"})}
|
34
|
+
it {
|
35
|
+
l.should_not be_valid
|
36
|
+
l.errors.messages.should == {torrens: [ATDIS::ErrorMessage.new("and other can't both be present", "4.3.3")]}
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ATDIS::Models::Location do
|
4
|
+
it ".attribute_names" do
|
5
|
+
ATDIS::Models::Location.attribute_names.should == [
|
6
|
+
"address",
|
7
|
+
"land_title_ref",
|
8
|
+
"geometry"
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "validation" do
|
13
|
+
context "valid location" do
|
14
|
+
let(:l) { ATDIS::Models::Location.new(
|
15
|
+
address: {
|
16
|
+
street: "123 Fourfivesix Street",
|
17
|
+
suburb: "Neutral Bay",
|
18
|
+
postcode: "2089",
|
19
|
+
state: "NSW"
|
20
|
+
},
|
21
|
+
land_title_ref: {
|
22
|
+
torrens: {
|
23
|
+
lot: "10",
|
24
|
+
section: "ABC",
|
25
|
+
dpsp_id: "DP2013-0381",
|
26
|
+
}
|
27
|
+
},
|
28
|
+
geometry: {
|
29
|
+
type: "Point",
|
30
|
+
coordinates: [100.0, 0.0]
|
31
|
+
}
|
32
|
+
)}
|
33
|
+
|
34
|
+
it { l.should be_valid }
|
35
|
+
|
36
|
+
it "address" do
|
37
|
+
l.address = nil
|
38
|
+
l.should_not be_valid
|
39
|
+
l.errors.messages.should == {address: [ATDIS::ErrorMessage["can't be blank", "4.3.3"]]}
|
40
|
+
end
|
41
|
+
|
42
|
+
it "geometry" do
|
43
|
+
l.geometry = {type: "Point"}
|
44
|
+
l.geometry.should be_nil
|
45
|
+
l.should_not be_valid
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".interpret" do
|
51
|
+
it "should gracefully handle the land_title_ref block being missing" do
|
52
|
+
l = ATDIS::Models::Location.interpret(address: {street: "123 Fourfivesix Street", suburb: "Neutral Bay", postcode: "2089"})
|
53
|
+
l.land_title_ref.should be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should pass on the responsibility for parsing the geometry section" do
|
57
|
+
# TODO Not 100% clear from section 4.3.3 of ATDIS-1.0.3 if this is the correct indentation
|
58
|
+
l = ATDIS::Models::Location.interpret(
|
59
|
+
geometry: {
|
60
|
+
type: "Point",
|
61
|
+
coordinates: [100.0, 0.0]
|
62
|
+
}
|
63
|
+
)
|
64
|
+
# TODO Check that the returned geometry is a point
|
65
|
+
l.geometry.x.should == 100
|
66
|
+
l.geometry.y.should == 0
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should interpret a polygon in the geometry section" do
|
70
|
+
# TODO Not 100% clear from section 4.3.3 of ATDIS-1.0.3 if this is the correct indentation
|
71
|
+
l = ATDIS::Models::Location.interpret(
|
72
|
+
geometry: {
|
73
|
+
type: "Polygon",
|
74
|
+
coordinates: [
|
75
|
+
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
|
76
|
+
[100.0, 1.0], [100.0, 0.0] ]
|
77
|
+
]
|
78
|
+
}
|
79
|
+
)
|
80
|
+
# TODO Check that the returned geometry is a polygon
|
81
|
+
l.geometry.interior_rings.should be_empty
|
82
|
+
l.geometry.exterior_ring.points.count.should == 5
|
83
|
+
l.geometry.exterior_ring.points[0].x.should == 100
|
84
|
+
l.geometry.exterior_ring.points[0].y.should == 0
|
85
|
+
l.geometry.exterior_ring.points[1].x.should == 101
|
86
|
+
l.geometry.exterior_ring.points[1].y.should == 0
|
87
|
+
l.geometry.exterior_ring.points[2].x.should == 101
|
88
|
+
l.geometry.exterior_ring.points[2].y.should == 1
|
89
|
+
l.geometry.exterior_ring.points[3].x.should == 100
|
90
|
+
l.geometry.exterior_ring.points[3].y.should == 1
|
91
|
+
l.geometry.exterior_ring.points[4].x.should == 100
|
92
|
+
l.geometry.exterior_ring.points[4].y.should == 0
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|