atdis 0.3.11 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +46 -0
- data/.ruby-version +1 -1
- data/.travis.yml +0 -4
- data/Gemfile +9 -7
- data/Guardfile +4 -3
- data/Rakefile +4 -2
- data/atdis.gemspec +10 -5
- data/lib/atdis.rb +2 -0
- data/lib/atdis/feed.rb +32 -24
- data/lib/atdis/model.rb +108 -95
- data/lib/atdis/models/address.rb +10 -4
- data/lib/atdis/models/application.rb +12 -9
- data/lib/atdis/models/authority.rb +11 -6
- data/lib/atdis/models/document.rb +8 -6
- data/lib/atdis/models/event.rb +10 -8
- data/lib/atdis/models/info.rb +73 -49
- data/lib/atdis/models/land_title_ref.rb +15 -7
- data/lib/atdis/models/location.rb +9 -7
- data/lib/atdis/models/page.rb +36 -21
- data/lib/atdis/models/pagination.rb +91 -32
- data/lib/atdis/models/person.rb +7 -5
- data/lib/atdis/models/reference.rb +7 -5
- data/lib/atdis/models/response.rb +5 -3
- data/lib/atdis/models/torrens_title.rb +9 -7
- data/lib/atdis/separated_url.rb +17 -15
- data/lib/atdis/validators.rb +46 -39
- data/lib/atdis/version.rb +3 -1
- data/spec/atdis/feed_spec.rb +128 -34
- data/spec/atdis/model_spec.rb +124 -51
- data/spec/atdis/models/address_spec.rb +18 -9
- data/spec/atdis/models/application_spec.rb +222 -155
- data/spec/atdis/models/authority_spec.rb +45 -15
- data/spec/atdis/models/document_spec.rb +10 -4
- data/spec/atdis/models/event_spec.rb +23 -11
- data/spec/atdis/models/info_spec.rb +197 -113
- data/spec/atdis/models/land_title_ref_spec.rb +32 -16
- data/spec/atdis/models/location_spec.rb +75 -60
- data/spec/atdis/models/page_spec.rb +244 -135
- data/spec/atdis/models/pagination_spec.rb +177 -77
- data/spec/atdis/models/person_spec.rb +8 -4
- data/spec/atdis/models/reference_spec.rb +29 -16
- data/spec/atdis/models/response_spec.rb +2 -1
- data/spec/atdis/models/torrens_title_spec.rb +24 -18
- data/spec/atdis/separated_url_spec.rb +14 -15
- data/spec/spec_helper.rb +14 -10
- metadata +62 -33
@@ -1,21 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe ATDIS::Models::Address do
|
4
6
|
context "valid address" do
|
5
|
-
let(:a)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
let(:a) do
|
8
|
+
ATDIS::Models::Address.new(
|
9
|
+
{
|
10
|
+
street: "123 Fourfivesix Street",
|
11
|
+
suburb: "Neutral Bay",
|
12
|
+
postcode: "2780",
|
13
|
+
state: "NSW"
|
14
|
+
},
|
15
|
+
"UTC"
|
16
|
+
)
|
17
|
+
end
|
11
18
|
|
12
|
-
it { a.
|
19
|
+
it { expect(a).to be_valid }
|
13
20
|
|
14
21
|
context "postcode that is too short" do
|
15
22
|
before(:each) { a.postcode = "278" }
|
16
23
|
it {
|
17
|
-
a.
|
18
|
-
a.errors.messages.
|
24
|
+
expect(a).to_not be_valid
|
25
|
+
expect(a.errors.messages).to eq(
|
26
|
+
postcode: [ATDIS::ErrorMessage.new("is not a valid postcode", "4.3.3")]
|
27
|
+
)
|
19
28
|
}
|
20
29
|
end
|
21
30
|
end
|
@@ -1,39 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe ATDIS::Models::Application do
|
4
6
|
context "extra parameter in json" do
|
5
7
|
it "should not be valid" do
|
6
|
-
expect(ATDIS::Models::Location).to receive(:interpret).with("location"
|
7
|
-
|
8
|
-
expect(ATDIS::Models::
|
8
|
+
expect(ATDIS::Models::Location).to receive(:interpret).with("location", "UTC")
|
9
|
+
.and_return(double(valid?: true))
|
10
|
+
expect(ATDIS::Models::Document).to receive(:interpret).with("document", "UTC")
|
11
|
+
.and_return(double(valid?: true))
|
12
|
+
expect(ATDIS::Models::Event).to receive(:interpret).with("event", "UTC")
|
13
|
+
.and_return(double(valid?: true))
|
9
14
|
|
10
15
|
a = ATDIS::Models::Application.interpret(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
{
|
17
|
+
info: {
|
18
|
+
dat_id: "DA2013-0381",
|
19
|
+
development_type: "residential",
|
20
|
+
application_type: "DA",
|
21
|
+
last_modified_date: "2013-04-20T02:01:07Z",
|
22
|
+
description: "New pool plus deck",
|
23
|
+
authority: {
|
24
|
+
ref: "http://www.council.nsw.gov.au/atdis/1.0",
|
25
|
+
name: "Example Council Shire Council"
|
26
|
+
},
|
27
|
+
lodgement_date: "2013-04-20T02:01:07Z",
|
28
|
+
determination_date: "2013-06-20",
|
29
|
+
determination_type: "Pending",
|
30
|
+
status: "OPEN"
|
20
31
|
},
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
reference: {
|
33
|
+
more_info_url: "http://foo.com/bar"
|
34
|
+
},
|
35
|
+
# This is the extra parameter that shouldn't be here
|
36
|
+
foo: "bar",
|
37
|
+
locations: ["location"],
|
38
|
+
events: ["event"],
|
39
|
+
documents: ["document"]
|
28
40
|
},
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
41
|
+
"UTC"
|
42
|
+
)
|
43
|
+
expect(a).to_not be_valid
|
44
|
+
expect(a.errors.messages).to eq(
|
45
|
+
json: [
|
46
|
+
ATDIS::ErrorMessage['Unexpected parameters in json data: {"foo":"bar"}', "4"]
|
47
|
+
]
|
34
48
|
)
|
35
|
-
a.should_not be_valid
|
36
|
-
a.errors.messages.should == {json: [ATDIS::ErrorMessage['Unexpected parameters in json data: {"foo":"bar"}', "4"]]}
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
@@ -42,211 +54,266 @@ describe ATDIS::Models::Application do
|
|
42
54
|
application = double
|
43
55
|
|
44
56
|
expect(ATDIS::Models::Application).to receive(:new).with(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
{
|
58
|
+
info: {
|
59
|
+
dat_id: "DA2013-0381",
|
60
|
+
development_type: "residential",
|
61
|
+
last_modified_date: "2013-04-20T02:01:07Z",
|
62
|
+
description: "New pool plus deck",
|
63
|
+
authority: "Example Council Shire Council",
|
64
|
+
lodgement_date: "2013-04-20T02:01:07Z",
|
65
|
+
determination_date: "2013-06-20",
|
66
|
+
notification_start_date: "2013-04-20T02:01:07Z",
|
67
|
+
notification_end_date: "2013-05-20T02:01:07Z",
|
68
|
+
officer: "Ms Smith",
|
69
|
+
estimated_cost: "50,000",
|
70
|
+
status: "OPEN"
|
71
|
+
},
|
72
|
+
reference: {
|
73
|
+
more_info_url: "http://foo.com/bar",
|
74
|
+
comments_url: "http://foo.com/comment"
|
75
|
+
},
|
76
|
+
locations: [{ address: "123 Fourfivesix Street" }],
|
77
|
+
events: [{ id: "event1" }, { id: "event2" }],
|
78
|
+
documents: [{ ref: "27B/6/a" }, { ref: "27B/6/b" }],
|
79
|
+
people: [{ name: "Tuttle" }, { name: "Buttle" }],
|
80
|
+
extended: { another_parameter: "with some value", anything: "can go here" },
|
81
|
+
json_left_overs: {}
|
62
82
|
},
|
63
|
-
|
64
|
-
events: [ { id: "event1" }, { id: "event2" } ],
|
65
|
-
documents: [ { ref: "27B/6/a" }, { ref: "27B/6/b" } ],
|
66
|
-
people: [ { name: "Tuttle" }, { name: "Buttle" } ],
|
67
|
-
extended: {another_parameter: "with some value", anything: "can go here"},
|
68
|
-
json_left_overs: {}
|
83
|
+
"UTC"
|
69
84
|
).and_return(application)
|
70
85
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
86
|
+
expect(
|
87
|
+
ATDIS::Models::Application.interpret(
|
88
|
+
{
|
89
|
+
info: {
|
90
|
+
dat_id: "DA2013-0381",
|
91
|
+
development_type: "residential",
|
92
|
+
last_modified_date: "2013-04-20T02:01:07Z",
|
93
|
+
description: "New pool plus deck",
|
94
|
+
authority: "Example Council Shire Council",
|
95
|
+
lodgement_date: "2013-04-20T02:01:07Z",
|
96
|
+
determination_date: "2013-06-20",
|
97
|
+
notification_start_date: "2013-04-20T02:01:07Z",
|
98
|
+
notification_end_date: "2013-05-20T02:01:07Z",
|
99
|
+
officer: "Ms Smith",
|
100
|
+
# TODO: In ATDIS-1.0.3 it does not specify whether this is a float or a string
|
101
|
+
# and whether to include (or not) AUD or dollar sign. For the time being we'll
|
102
|
+
# just assume it's a free-form string
|
103
|
+
estimated_cost: "50,000",
|
104
|
+
status: "OPEN"
|
105
|
+
},
|
106
|
+
reference: {
|
107
|
+
more_info_url: "http://foo.com/bar",
|
108
|
+
comments_url: "http://foo.com/comment"
|
109
|
+
},
|
110
|
+
locations: [{ address: "123 Fourfivesix Street" }],
|
111
|
+
events: [{ id: "event1" }, { id: "event2" }],
|
112
|
+
documents: [{ ref: "27B/6/a" }, { ref: "27B/6/b" }],
|
113
|
+
people: [{ name: "Tuttle" }, { name: "Buttle" }],
|
114
|
+
extended: { another_parameter: "with some value", anything: "can go here" }
|
115
|
+
},
|
116
|
+
"UTC"
|
117
|
+
)
|
118
|
+
).to eq application
|
99
119
|
end
|
100
120
|
|
101
121
|
it "should create a nil valued application when there is no information in the json" do
|
102
122
|
application = double
|
103
|
-
expect(ATDIS::Models::Application).to receive(:new)
|
104
|
-
reference: {}}).and_return(application)
|
123
|
+
expect(ATDIS::Models::Application).to receive(:new)
|
124
|
+
.with({ json_left_overs: {}, info: {}, reference: {} }, "UTC").and_return(application)
|
105
125
|
|
106
|
-
|
126
|
+
expect(
|
127
|
+
ATDIS::Models::Application.interpret({ info: {}, reference: {} }, "UTC")
|
128
|
+
).to eq application
|
107
129
|
end
|
108
130
|
end
|
109
131
|
|
110
132
|
describe "#extended" do
|
111
133
|
it "should do no typecasting" do
|
112
|
-
a = ATDIS::Models::Application.new(
|
113
|
-
|
134
|
+
a = ATDIS::Models::Application.new(
|
135
|
+
{ extended: { another_parameter: "with some value", anything: "can go here" } },
|
136
|
+
"UTC"
|
137
|
+
)
|
138
|
+
expect(a.extended).to eq(another_parameter: "with some value", anything: "can go here")
|
114
139
|
end
|
115
140
|
end
|
116
141
|
|
117
142
|
describe "#location=" do
|
118
|
-
let(:a) { ATDIS::Models::Application.new }
|
143
|
+
let(:a) { ATDIS::Models::Application.new({}, "UTC") }
|
119
144
|
it "should type cast to a location" do
|
120
145
|
location = double
|
121
|
-
expect(ATDIS::Models::Location).to receive(:interpret).with(
|
146
|
+
expect(ATDIS::Models::Location).to receive(:interpret).with(
|
147
|
+
{ address: "123 Fourfivesix Street" },
|
148
|
+
"UTC"
|
149
|
+
).and_return(location)
|
122
150
|
a.locations = [{ address: "123 Fourfivesix Street" }]
|
123
|
-
a.locations.
|
151
|
+
expect(a.locations).to eq [location]
|
124
152
|
end
|
125
153
|
|
126
154
|
it "should not cast when it's already a location" do
|
127
|
-
l = ATDIS::Models::Location.new
|
155
|
+
l = ATDIS::Models::Location.new({}, "UTC")
|
128
156
|
a.locations = [l]
|
129
|
-
a.locations.
|
157
|
+
expect(a.locations).to eq [l]
|
130
158
|
end
|
131
159
|
end
|
132
160
|
|
133
161
|
describe "#events" do
|
134
|
-
let(:a) { ATDIS::Models::Application.new }
|
162
|
+
let(:a) { ATDIS::Models::Application.new({}, "UTC") }
|
135
163
|
it "should type cast to several events" do
|
136
|
-
event1
|
137
|
-
|
138
|
-
expect(ATDIS::Models::Event).to receive(:interpret).with(
|
139
|
-
|
140
|
-
|
164
|
+
event1 = double
|
165
|
+
event2 = double
|
166
|
+
expect(ATDIS::Models::Event).to receive(:interpret).with(
|
167
|
+
{ id: "event1" },
|
168
|
+
"UTC"
|
169
|
+
).and_return(event1)
|
170
|
+
expect(ATDIS::Models::Event).to receive(:interpret).with(
|
171
|
+
{ id: "event2" },
|
172
|
+
"UTC"
|
173
|
+
).and_return(event2)
|
174
|
+
a.events = [{ id: "event1" }, { id: "event2" }]
|
175
|
+
expect(a.events).to eq [event1, event2]
|
141
176
|
end
|
142
177
|
end
|
143
178
|
|
144
179
|
describe "#documents" do
|
145
|
-
let(:a) { ATDIS::Models::Application.new }
|
180
|
+
let(:a) { ATDIS::Models::Application.new({}, "UTC") }
|
146
181
|
it "should type cast to several documents" do
|
147
|
-
document1
|
148
|
-
|
149
|
-
expect(ATDIS::Models::Document).to receive(:interpret).with(ref: "27B/6/
|
150
|
-
|
151
|
-
|
182
|
+
document1 = double
|
183
|
+
document2 = double
|
184
|
+
expect(ATDIS::Models::Document).to receive(:interpret).with({ ref: "27B/6/a" }, "UTC")
|
185
|
+
.and_return(document1)
|
186
|
+
expect(ATDIS::Models::Document).to receive(:interpret).with({ ref: "27B/6/b" }, "UTC")
|
187
|
+
.and_return(document2)
|
188
|
+
a.documents = [{ ref: "27B/6/a" }, { ref: "27B/6/b" }]
|
189
|
+
expect(a.documents).to eq [document1, document2]
|
152
190
|
end
|
153
191
|
end
|
154
192
|
|
155
193
|
describe "#people" do
|
156
|
-
let(:a) { ATDIS::Models::Application.new }
|
194
|
+
let(:a) { ATDIS::Models::Application.new({}, "UTC") }
|
157
195
|
it "should type cast to several people" do
|
158
|
-
tuttle
|
159
|
-
|
160
|
-
expect(ATDIS::Models::Person).to
|
161
|
-
|
162
|
-
|
196
|
+
tuttle = double
|
197
|
+
buttle = double
|
198
|
+
expect(ATDIS::Models::Person).to(
|
199
|
+
receive(:interpret).with({ name: "Tuttle" }, "UTC").and_return(tuttle)
|
200
|
+
)
|
201
|
+
expect(ATDIS::Models::Person).to(
|
202
|
+
receive(:interpret).with({ name: "Buttle" }, "UTC").and_return(buttle)
|
203
|
+
)
|
204
|
+
a.people = [{ name: "Tuttle" }, { name: "Buttle" }]
|
205
|
+
expect(a.people).to eq [tuttle, buttle]
|
163
206
|
end
|
164
207
|
end
|
165
208
|
|
166
|
-
# TODO This should really be a test on the Model base class
|
209
|
+
# TODO: This should really be a test on the Model base class
|
167
210
|
describe "#attribute_names" do
|
168
211
|
it do
|
169
|
-
# These are also ordered in a way that corresponds to the specification.
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
212
|
+
# These are also ordered in a way that corresponds to the specification.
|
213
|
+
# Makes for easy reading by humans.
|
214
|
+
expect(ATDIS::Models::Application.attribute_names).to eq %w[
|
215
|
+
info
|
216
|
+
reference
|
217
|
+
locations
|
218
|
+
events
|
219
|
+
documents
|
220
|
+
people
|
221
|
+
extended
|
178
222
|
]
|
179
223
|
end
|
180
224
|
end
|
181
225
|
|
182
226
|
describe "validations" do
|
183
227
|
before :each do
|
184
|
-
expect(ATDIS::Models::Location).to receive(:interpret).with("address"
|
185
|
-
|
186
|
-
expect(ATDIS::Models::
|
228
|
+
expect(ATDIS::Models::Location).to receive(:interpret).with("address", "UTC")
|
229
|
+
.and_return(double(valid?: true))
|
230
|
+
expect(ATDIS::Models::Document).to receive(:interpret).with("document", "UTC")
|
231
|
+
.and_return(double(valid?: true))
|
232
|
+
expect(ATDIS::Models::Event).to receive(:interpret).with("event", "UTC")
|
233
|
+
.and_return(double(valid?: true))
|
187
234
|
end
|
188
235
|
|
189
|
-
let(:a)
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
236
|
+
let(:a) do
|
237
|
+
ATDIS::Models::Application.new(
|
238
|
+
{
|
239
|
+
info: ATDIS::Models::Info.new(
|
240
|
+
{
|
241
|
+
dat_id: "DA2013-0381",
|
242
|
+
development_type: "residential",
|
243
|
+
application_type: "DA",
|
244
|
+
last_modified_date: DateTime.new(2013, 4, 20, 2, 1, 7),
|
245
|
+
description: "New pool plus deck",
|
246
|
+
authority: {
|
247
|
+
ref: "http://www.council.nsw.gov.au/atdis/1.0",
|
248
|
+
name: "Example Council Shire Council"
|
249
|
+
},
|
250
|
+
lodgement_date: DateTime.new(2013, 4, 20, 2, 1, 7),
|
251
|
+
determination_date: DateTime.new(2013, 6, 20),
|
252
|
+
determination_type: "Pending",
|
253
|
+
status: "OPEN"
|
254
|
+
},
|
255
|
+
"UTC"
|
256
|
+
),
|
257
|
+
reference: ATDIS::Models::Reference.new(
|
258
|
+
{
|
259
|
+
more_info_url: URI.parse("http://foo.com/bar")
|
260
|
+
},
|
261
|
+
"UTC"
|
262
|
+
),
|
263
|
+
locations: ["address"],
|
264
|
+
events: ["event"],
|
265
|
+
documents: ["document"]
|
199
266
|
},
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
reference: ATDIS::Models::Reference.new(
|
206
|
-
more_info_url: URI.parse("http://foo.com/bar"),
|
207
|
-
),
|
208
|
-
locations: ["address"],
|
209
|
-
events: ["event"],
|
210
|
-
documents: ["document"]
|
211
|
-
) }
|
212
|
-
|
213
|
-
it { a.should be_valid }
|
267
|
+
"UTC"
|
268
|
+
)
|
269
|
+
end
|
270
|
+
|
271
|
+
it { expect(a).to be_valid }
|
214
272
|
|
215
273
|
describe ".location" do
|
216
274
|
it "should not be valid if the location is not valid" do
|
217
275
|
l = double(valid?: false)
|
218
|
-
expect(ATDIS::Models::Location).to
|
219
|
-
|
220
|
-
|
276
|
+
expect(ATDIS::Models::Location).to(
|
277
|
+
receive(:interpret).with({ foo: "some location data" }, "UTC").and_return(l)
|
278
|
+
)
|
279
|
+
a.locations = [{ foo: "some location data" }]
|
280
|
+
expect(a).to_not be_valid
|
221
281
|
end
|
222
282
|
end
|
223
283
|
|
224
284
|
describe "events" do
|
225
285
|
it "has to be an array" do
|
226
|
-
expect(ATDIS::Models::Event).to receive(:interpret).with(foo: "bar"
|
227
|
-
|
228
|
-
|
229
|
-
a.
|
230
|
-
a.
|
286
|
+
expect(ATDIS::Models::Event).to receive(:interpret).with({ foo: "bar" }, "UTC")
|
287
|
+
.and_return(double(valid?: true))
|
288
|
+
a.events = { foo: "bar" }
|
289
|
+
# expect(a.events).to be_nil
|
290
|
+
expect(a).to_not be_valid
|
291
|
+
expect(a.errors.messages).to eq(
|
292
|
+
events: [ATDIS::ErrorMessage["should be an array", "4.3"]]
|
293
|
+
)
|
231
294
|
end
|
232
295
|
|
233
296
|
it "can not be an empty array" do
|
234
297
|
a.events = []
|
235
|
-
a.
|
236
|
-
a.errors.messages.
|
298
|
+
expect(a).to_not be_valid
|
299
|
+
expect(a.errors.messages).to eq(
|
300
|
+
events: [ATDIS::ErrorMessage.new("should not be an empty array", "4.3")]
|
301
|
+
)
|
237
302
|
end
|
238
303
|
|
239
304
|
it "can not be empty" do
|
240
305
|
a.events = nil
|
241
|
-
a.
|
242
|
-
a.errors.messages.
|
306
|
+
expect(a).to_not be_valid
|
307
|
+
expect(a.errors.messages).to eq(
|
308
|
+
events: [ATDIS::ErrorMessage["can't be blank", "4.3"]]
|
309
|
+
)
|
243
310
|
end
|
244
311
|
end
|
245
312
|
|
246
313
|
describe "documents" do
|
247
314
|
it "can be an empty array" do
|
248
315
|
a.documents = []
|
249
|
-
a.
|
316
|
+
expect(a).to be_valid
|
250
317
|
end
|
251
318
|
end
|
252
319
|
end
|