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,39 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe ATDIS::Models::LandTitleRef do
|
4
6
|
context "torrens" do
|
5
|
-
before(:each)
|
7
|
+
before(:each) do
|
6
8
|
m = double
|
7
|
-
expect(ATDIS::Models::TorrensTitle).to receive(:interpret).with(
|
9
|
+
expect(ATDIS::Models::TorrensTitle).to receive(:interpret).with(
|
10
|
+
{ lot: "10" },
|
11
|
+
"UTC"
|
12
|
+
).and_return(m)
|
8
13
|
expect(m).to receive(:valid?).and_return(true)
|
9
|
-
|
10
|
-
let(:l) { ATDIS::Models::LandTitleRef.new(torrens: {lot: "10"}) }
|
11
|
-
it { l.
|
14
|
+
end
|
15
|
+
let(:l) { ATDIS::Models::LandTitleRef.new({ torrens: { lot: "10" } }, "UTC") }
|
16
|
+
it { expect(l).to be_valid }
|
12
17
|
end
|
13
18
|
|
14
19
|
context "other" do
|
15
|
-
let(:l) { ATDIS::Models::LandTitleRef.new(other: {some: "foo", random: "stuff"})}
|
16
|
-
it { l.
|
20
|
+
let(:l) { ATDIS::Models::LandTitleRef.new({ other: { some: "foo", random: "stuff" } }, "UTC") }
|
21
|
+
it { expect(l).to be_valid }
|
17
22
|
end
|
18
23
|
|
19
24
|
context "no torrens or other" do
|
20
|
-
let(:l) { ATDIS::Models::LandTitleRef.new }
|
25
|
+
let(:l) { ATDIS::Models::LandTitleRef.new({}, "UTC") }
|
21
26
|
it {
|
22
|
-
l.
|
23
|
-
l.errors.messages.
|
27
|
+
expect(l).to_not be_valid
|
28
|
+
expect(l.errors.messages).to eq(
|
29
|
+
torrens: [ATDIS::ErrorMessage.new("or other needs be present", "4.3.3")]
|
30
|
+
)
|
24
31
|
}
|
25
32
|
end
|
26
33
|
|
27
34
|
context "both torrens and other" do
|
28
|
-
before(:each)
|
35
|
+
before(:each) do
|
29
36
|
m = double
|
30
|
-
expect(ATDIS::Models::TorrensTitle).to
|
37
|
+
expect(ATDIS::Models::TorrensTitle).to(
|
38
|
+
receive(:interpret).with({ lot: "10" }, "UTC").and_return(m)
|
39
|
+
)
|
31
40
|
expect(m).to receive(:valid?).and_return(true)
|
32
|
-
|
33
|
-
let(:l)
|
41
|
+
end
|
42
|
+
let(:l) do
|
43
|
+
ATDIS::Models::LandTitleRef.new(
|
44
|
+
{ torrens: { lot: "10" }, other: { some: "foo", random: "stuff" } },
|
45
|
+
"UTC"
|
46
|
+
)
|
47
|
+
end
|
34
48
|
it {
|
35
|
-
l.
|
36
|
-
l.errors.messages.
|
49
|
+
expect(l).to_not be_valid
|
50
|
+
expect(l.errors.messages).to eq(
|
51
|
+
torrens: [ATDIS::ErrorMessage.new("and other can't both be present", "4.3.3")]
|
52
|
+
)
|
37
53
|
}
|
38
54
|
end
|
39
55
|
end
|
@@ -1,95 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe ATDIS::Models::Location do
|
4
6
|
it ".attribute_names" do
|
5
|
-
ATDIS::Models::Location.attribute_names.
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
expect(ATDIS::Models::Location.attribute_names).to eq %w[
|
8
|
+
address
|
9
|
+
land_title_ref
|
10
|
+
geometry
|
9
11
|
]
|
10
12
|
end
|
11
13
|
|
12
14
|
describe "validation" do
|
13
15
|
context "valid location" do
|
14
|
-
let(:l)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
16
|
+
let(:l) do
|
17
|
+
ATDIS::Models::Location.new(
|
18
|
+
{
|
19
|
+
address: {
|
20
|
+
street: "123 Fourfivesix Street",
|
21
|
+
suburb: "Neutral Bay",
|
22
|
+
postcode: "2089",
|
23
|
+
state: "NSW"
|
24
|
+
},
|
25
|
+
land_title_ref: {
|
26
|
+
torrens: {
|
27
|
+
lot: "10",
|
28
|
+
section: "ABC",
|
29
|
+
dpsp_id: "DP2013-0381"
|
30
|
+
}
|
31
|
+
},
|
32
|
+
geometry: {
|
33
|
+
type: "Point",
|
34
|
+
coordinates: [100.0, 0.0]
|
35
|
+
}
|
36
|
+
},
|
37
|
+
"UTC"
|
38
|
+
)
|
39
|
+
end
|
33
40
|
|
34
|
-
it { l.
|
41
|
+
it { expect(l).to be_valid }
|
35
42
|
|
36
43
|
it "address" do
|
37
44
|
l.address = nil
|
38
|
-
l.
|
39
|
-
l.errors.messages.
|
45
|
+
expect(l).to_not be_valid
|
46
|
+
expect(l.errors.messages).to eq(address: [ATDIS::ErrorMessage["can't be blank", "4.3.3"]])
|
40
47
|
end
|
41
48
|
|
42
49
|
it "geometry" do
|
43
|
-
l.geometry = {type: "Point"}
|
44
|
-
l.geometry.
|
45
|
-
l.
|
50
|
+
l.geometry = { type: "Point" }
|
51
|
+
expect(l.geometry).to be_nil
|
52
|
+
expect(l).to_not be_valid
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
50
57
|
describe ".interpret" do
|
51
58
|
it "should gracefully handle the land_title_ref block being missing" do
|
52
|
-
l = ATDIS::Models::Location.interpret(
|
53
|
-
|
59
|
+
l = ATDIS::Models::Location.interpret(
|
60
|
+
{ address: { street: "123 Fourfivesix Street", suburb: "Neutral Bay", postcode: "2089" } },
|
61
|
+
"UTC"
|
62
|
+
)
|
63
|
+
expect(l.land_title_ref).to be_nil
|
54
64
|
end
|
55
65
|
|
56
66
|
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
|
67
|
+
# TODO: Not 100% clear from section 4.3.3 of ATDIS-1.0.3 if this is the correct indentation
|
58
68
|
l = ATDIS::Models::Location.interpret(
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
69
|
+
{
|
70
|
+
geometry: {
|
71
|
+
type: "Point",
|
72
|
+
coordinates: [100.0, 0.0]
|
73
|
+
}
|
74
|
+
},
|
75
|
+
"UTC"
|
63
76
|
)
|
64
|
-
# TODO Check that the returned geometry is a point
|
65
|
-
l.geometry.x.
|
66
|
-
l.geometry.y.
|
77
|
+
# TODO: Check that the returned geometry is a point
|
78
|
+
expect(l.geometry.x).to eq 100
|
79
|
+
expect(l.geometry.y).to eq 0
|
67
80
|
end
|
68
81
|
|
69
82
|
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
|
83
|
+
# TODO: Not 100% clear from section 4.3.3 of ATDIS-1.0.3 if this is the correct indentation
|
71
84
|
l = ATDIS::Models::Location.interpret(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
[100.0, 1.0], [100.0,
|
77
|
-
|
78
|
-
|
85
|
+
{
|
86
|
+
geometry: {
|
87
|
+
type: "Polygon",
|
88
|
+
coordinates: [
|
89
|
+
[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]
|
90
|
+
]
|
91
|
+
}
|
92
|
+
},
|
93
|
+
"UTC"
|
79
94
|
)
|
80
|
-
# TODO Check that the returned geometry is a polygon
|
81
|
-
l.geometry.interior_rings.
|
82
|
-
l.geometry.exterior_ring.points.count.
|
83
|
-
l.geometry.exterior_ring.points[0].x.
|
84
|
-
l.geometry.exterior_ring.points[0].y.
|
85
|
-
l.geometry.exterior_ring.points[1].x.
|
86
|
-
l.geometry.exterior_ring.points[1].y.
|
87
|
-
l.geometry.exterior_ring.points[2].x.
|
88
|
-
l.geometry.exterior_ring.points[2].y.
|
89
|
-
l.geometry.exterior_ring.points[3].x.
|
90
|
-
l.geometry.exterior_ring.points[3].y.
|
91
|
-
l.geometry.exterior_ring.points[4].x.
|
92
|
-
l.geometry.exterior_ring.points[4].y.
|
95
|
+
# TODO: Check that the returned geometry is a polygon
|
96
|
+
expect(l.geometry.interior_rings).to be_empty
|
97
|
+
expect(l.geometry.exterior_ring.points.count).to eq 5
|
98
|
+
expect(l.geometry.exterior_ring.points[0].x).to eq 100
|
99
|
+
expect(l.geometry.exterior_ring.points[0].y).to eq 0
|
100
|
+
expect(l.geometry.exterior_ring.points[1].x).to eq 101
|
101
|
+
expect(l.geometry.exterior_ring.points[1].y).to eq 0
|
102
|
+
expect(l.geometry.exterior_ring.points[2].x).to eq 101
|
103
|
+
expect(l.geometry.exterior_ring.points[2].y).to eq 1
|
104
|
+
expect(l.geometry.exterior_ring.points[3].x).to eq 100
|
105
|
+
expect(l.geometry.exterior_ring.points[3].y).to eq 1
|
106
|
+
expect(l.geometry.exterior_ring.points[4].x).to eq 100
|
107
|
+
expect(l.geometry.exterior_ring.points[4].y).to eq 0
|
93
108
|
end
|
94
109
|
end
|
95
110
|
end
|
@@ -1,37 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe ATDIS::Models::Page do
|
4
6
|
it ".attribute_names" do
|
5
|
-
ATDIS::Models::Page.attribute_names.
|
7
|
+
expect(ATDIS::Models::Page.attribute_names).to eq %w[response count pagination]
|
6
8
|
end
|
7
9
|
|
8
10
|
it "should error if response is null" do
|
9
|
-
page = ATDIS::Models::Page.new(
|
10
|
-
|
11
|
-
|
11
|
+
page = ATDIS::Models::Page.new(
|
12
|
+
{ response: nil, count: 0, pagination: { pages: 1, per_page: 20, count: 0, current: 1 } },
|
13
|
+
"UTC"
|
14
|
+
)
|
15
|
+
expect(page).to_not be_valid
|
16
|
+
expect(page.errors.messages).to eq(response: [ATDIS::ErrorMessage["can't be blank", "4.3"]])
|
12
17
|
end
|
13
18
|
|
14
19
|
describe "validations" do
|
15
20
|
context "results block that is a hash" do
|
16
21
|
before :each do
|
17
|
-
ATDIS::Models::Response.
|
22
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
23
|
+
{ description: "application1" },
|
24
|
+
"UTC"
|
25
|
+
).and_return(double(valid?: true))
|
18
26
|
end
|
19
|
-
let(:page) { ATDIS::Models::Page.new(response: {description: "application1"}) }
|
27
|
+
let(:page) { ATDIS::Models::Page.new({ response: { description: "application1" } }, "UTC") }
|
20
28
|
|
21
29
|
it do
|
22
|
-
page.
|
23
|
-
page.errors.messages.
|
30
|
+
expect(page).to_not be_valid
|
31
|
+
expect(page.errors.messages).to eq(
|
32
|
+
response: [ATDIS::ErrorMessage["should be an array", "6.4"]]
|
33
|
+
)
|
24
34
|
end
|
25
35
|
end
|
26
36
|
|
27
37
|
context "two valid applications no paging" do
|
28
38
|
before :each do
|
29
|
-
ATDIS::Models::Response.
|
30
|
-
|
39
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
40
|
+
{ description: "application1" },
|
41
|
+
"UTC"
|
42
|
+
).and_return(double(valid?: true))
|
43
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
44
|
+
{ description: "application2" },
|
45
|
+
"UTC"
|
46
|
+
).and_return(double(valid?: true))
|
47
|
+
end
|
48
|
+
let(:page) do
|
49
|
+
ATDIS::Models::Page.new(
|
50
|
+
{ response: [{ description: "application1" }, { description: "application2" }] },
|
51
|
+
"UTC"
|
52
|
+
)
|
31
53
|
end
|
32
|
-
let(:page) { ATDIS::Models::Page.new(response: [{description: "application1"}, {description: "application2"}]) }
|
33
54
|
|
34
|
-
it {page.
|
55
|
+
it { expect(page).to be_valid }
|
35
56
|
|
36
57
|
# It's not super clear in the spec whether this should be allowed but it seems sensible to
|
37
58
|
# allow it.
|
@@ -39,23 +60,30 @@ describe ATDIS::Models::Page do
|
|
39
60
|
before :each do
|
40
61
|
page.count = 2
|
41
62
|
end
|
42
|
-
it { page.
|
63
|
+
it { expect(page).to be_valid }
|
43
64
|
end
|
44
65
|
|
45
66
|
context "with pagination" do
|
46
67
|
before :each do
|
47
68
|
page.count = 2
|
48
|
-
page.pagination = ATDIS::Models::Pagination.new(
|
69
|
+
page.pagination = ATDIS::Models::Pagination.new(
|
70
|
+
{ per_page: 25, current: 1, count: 2, pages: 1 },
|
71
|
+
"UTC"
|
72
|
+
)
|
49
73
|
end
|
50
|
-
it { page.
|
74
|
+
it { expect(page).to be_valid }
|
51
75
|
|
52
76
|
context "count is not consistent" do
|
53
77
|
before :each do
|
54
78
|
page.count = 1
|
55
79
|
end
|
56
80
|
it do
|
57
|
-
page.
|
58
|
-
page.errors.messages.
|
81
|
+
expect(page).to_not be_valid
|
82
|
+
expect(page.errors.messages).to eq(
|
83
|
+
count: [
|
84
|
+
ATDIS::ErrorMessage["is not the same as the number of applications returned", "6.4"]
|
85
|
+
]
|
86
|
+
)
|
59
87
|
end
|
60
88
|
end
|
61
89
|
|
@@ -65,8 +93,15 @@ describe ATDIS::Models::Page do
|
|
65
93
|
page.pagination.count = 1
|
66
94
|
end
|
67
95
|
it do
|
68
|
-
page.
|
69
|
-
page.errors.messages.
|
96
|
+
expect(page).to_not be_valid
|
97
|
+
expect(page.errors.messages).to eq(
|
98
|
+
count: [
|
99
|
+
ATDIS::ErrorMessage[
|
100
|
+
"should not be larger than the number of results per page",
|
101
|
+
"6.4"
|
102
|
+
]
|
103
|
+
]
|
104
|
+
)
|
70
105
|
end
|
71
106
|
end
|
72
107
|
|
@@ -76,19 +111,25 @@ describe ATDIS::Models::Page do
|
|
76
111
|
end
|
77
112
|
|
78
113
|
it do
|
79
|
-
page.
|
80
|
-
page.errors.messages.
|
114
|
+
expect(page).to_not be_valid
|
115
|
+
expect(page.errors.messages).to eq(
|
116
|
+
count: [ATDIS::ErrorMessage["should be present if pagination is being used", "6.4"]]
|
117
|
+
)
|
81
118
|
end
|
82
119
|
end
|
83
120
|
|
84
121
|
context "pagination not valid" do
|
85
122
|
before :each do
|
86
|
-
page.pagination.
|
123
|
+
expect(page.pagination).to receive(:valid?).and_return(false)
|
87
124
|
end
|
88
125
|
|
89
126
|
it do
|
90
|
-
page.
|
91
|
-
page.errors.messages.
|
127
|
+
expect(page).to_not be_valid
|
128
|
+
expect(page.errors.messages).to eq(
|
129
|
+
pagination: [
|
130
|
+
ATDIS::ErrorMessage["is not valid (see further errors for details)", nil]
|
131
|
+
]
|
132
|
+
)
|
92
133
|
end
|
93
134
|
end
|
94
135
|
end
|
@@ -96,101 +137,144 @@ describe ATDIS::Models::Page do
|
|
96
137
|
|
97
138
|
context "one valid application out of two no paging" do
|
98
139
|
before :each do
|
99
|
-
ATDIS::Models::Response.
|
100
|
-
|
140
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
141
|
+
{ description: "application1" },
|
142
|
+
"UTC"
|
143
|
+
).and_return(double(valid?: true))
|
144
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
145
|
+
{ description: "application2" },
|
146
|
+
"UTC"
|
147
|
+
).and_return(double(valid?: false))
|
148
|
+
end
|
149
|
+
let(:page) do
|
150
|
+
ATDIS::Models::Page.new(
|
151
|
+
{ response: [{ description: "application1" }, { description: "application2" }] },
|
152
|
+
"UTC"
|
153
|
+
)
|
101
154
|
end
|
102
|
-
let(:page) { ATDIS::Models::Page.new(response: [{description: "application1"}, {description: "application2"}]) }
|
103
155
|
|
104
156
|
it do
|
105
|
-
page.
|
106
|
-
page.errors.messages.
|
157
|
+
expect(page).to_not be_valid
|
158
|
+
expect(page.errors.messages).to eq(
|
159
|
+
response: [ATDIS::ErrorMessage["is not valid (see further errors for details)", nil]]
|
160
|
+
)
|
107
161
|
end
|
108
162
|
end
|
109
163
|
|
110
164
|
context "two invalid applications no paging" do
|
111
|
-
let(:a1) { double(valid?: false, json_errors: [[{dat_id: "null"}, ["can not be empty"]]]) }
|
165
|
+
let(:a1) { double(valid?: false, json_errors: [[{ dat_id: "null" }, ["can not be empty"]]]) }
|
112
166
|
let(:a2) { double(valid?: false) }
|
113
167
|
before :each do
|
114
|
-
ATDIS::Models::Response.
|
115
|
-
|
168
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
169
|
+
{ description: "application1" },
|
170
|
+
"UTC"
|
171
|
+
).and_return(a1)
|
172
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
173
|
+
{ description: "application2" },
|
174
|
+
"UTC"
|
175
|
+
).and_return(a2)
|
176
|
+
end
|
177
|
+
let(:page) do
|
178
|
+
ATDIS::Models::Page.new(
|
179
|
+
{ response: [{ description: "application1" }, { description: "application2" }] },
|
180
|
+
"UTC"
|
181
|
+
)
|
116
182
|
end
|
117
|
-
let(:page) { ATDIS::Models::Page.new(response: [{description: "application1"}, {description: "application2"}]) }
|
118
183
|
|
119
184
|
it do
|
120
|
-
page.
|
121
|
-
page.errors.messages.
|
185
|
+
expect(page).to_not be_valid
|
186
|
+
expect(page.errors.messages).to eq(
|
187
|
+
response: [ATDIS::ErrorMessage["is not valid (see further errors for details)", nil]]
|
188
|
+
)
|
122
189
|
end
|
123
190
|
|
124
191
|
it "the errors from the first errored application should be here" do
|
125
|
-
page.
|
126
|
-
page.json_errors.
|
192
|
+
expect(page).to_not be_valid
|
193
|
+
expect(page.json_errors).to eq(
|
194
|
+
[
|
195
|
+
[
|
196
|
+
{ response: [{ description: "application1" }, { description: "application2" }] },
|
197
|
+
[ATDIS::ErrorMessage["response is not valid (see further errors for details)"]]
|
198
|
+
],
|
199
|
+
[
|
200
|
+
{ response: [{ dat_id: "null" }] },
|
201
|
+
["can not be empty"]
|
202
|
+
]
|
203
|
+
]
|
204
|
+
)
|
127
205
|
end
|
128
|
-
|
129
206
|
end
|
130
207
|
end
|
131
208
|
|
132
209
|
context "paging supported by vendor" do
|
133
210
|
context "read a from an invalid json string" do
|
134
|
-
let(:page)
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
211
|
+
let(:page) do
|
212
|
+
json = <<~JSON
|
213
|
+
{
|
214
|
+
"response": [
|
215
|
+
{
|
216
|
+
"application": {
|
217
|
+
"description": "application2"
|
218
|
+
}
|
219
|
+
}
|
220
|
+
],
|
221
|
+
}
|
222
|
+
JSON
|
223
|
+
ATDIS::Models::Page.read_json(json, "UTC")
|
224
|
+
end
|
146
225
|
|
147
226
|
it do
|
148
|
-
page.
|
149
|
-
page.errors.messages.
|
150
|
-
page.errors.messages.count.
|
151
|
-
|
152
|
-
ruby19_message = ATDIS::ErrorMessage["Invalid JSON: 784: unexpected token at '{\n \"response\": [\n {\n \"application\": {\n \"description\": \"application2\"\n }\n }\n ],\n}\n'", nil]
|
153
|
-
ruby20_message = ATDIS::ErrorMessage["Invalid JSON: 795: unexpected token at '{\n \"response\": [\n {\n \"application\": {\n \"description\": \"application2\"\n }\n }\n ],\n}\n'", nil]
|
154
|
-
page.errors.messages[:json].count.should == 1
|
227
|
+
expect(page).to_not be_valid
|
228
|
+
expect(page.errors.messages.key?(:json)).to be_truthy
|
229
|
+
expect(page.errors.messages.count).to eq 1
|
230
|
+
expect(page.errors.messages[:json].count).to eq 1
|
155
231
|
message = page.errors.messages[:json].first
|
156
|
-
(message
|
232
|
+
expect(message.message).to match(/Invalid JSON: .*: unexpected token at '{/)
|
157
233
|
end
|
158
234
|
end
|
159
235
|
|
160
236
|
context "read from a json string" do
|
161
|
-
let(:page)
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
}
|
185
|
-
|
186
|
-
|
237
|
+
let(:page) do
|
238
|
+
json = <<~JSON
|
239
|
+
{
|
240
|
+
"response": [
|
241
|
+
{
|
242
|
+
"application": {
|
243
|
+
"description": "application1"
|
244
|
+
}
|
245
|
+
},
|
246
|
+
{
|
247
|
+
"application": {
|
248
|
+
"description": "application2"
|
249
|
+
}
|
250
|
+
}
|
251
|
+
],
|
252
|
+
"count": 2,
|
253
|
+
"pagination": {
|
254
|
+
"previous": 1,
|
255
|
+
"next": 3,
|
256
|
+
"current": 2,
|
257
|
+
"per_page": 2,
|
258
|
+
"count": 50,
|
259
|
+
"pages": 25
|
260
|
+
}
|
261
|
+
}
|
262
|
+
JSON
|
263
|
+
ATDIS::Models::Page.read_json(json, "UTC")
|
264
|
+
end
|
187
265
|
it ".results" do
|
188
266
|
application1 = double("Application")
|
189
267
|
application2 = double("Application")
|
190
|
-
ATDIS::Models::Response.
|
191
|
-
|
192
|
-
|
193
|
-
|
268
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
269
|
+
{ application: { description: "application1" } },
|
270
|
+
"UTC"
|
271
|
+
).and_return(application1)
|
272
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
273
|
+
{ application: { description: "application2" } },
|
274
|
+
"UTC"
|
275
|
+
).and_return(application2)
|
276
|
+
|
277
|
+
expect(page.response).to eq [application1, application2]
|
194
278
|
end
|
195
279
|
|
196
280
|
it ".next_page" do
|
@@ -201,7 +285,7 @@ describe ATDIS::Models::Page do
|
|
201
285
|
context "read from a url" do
|
202
286
|
before :each do
|
203
287
|
# Mock network response
|
204
|
-
|
288
|
+
json = <<-JSON
|
205
289
|
{
|
206
290
|
"response": [
|
207
291
|
{
|
@@ -216,96 +300,121 @@ describe ATDIS::Models::Page do
|
|
216
300
|
}
|
217
301
|
]
|
218
302
|
}
|
219
|
-
|
220
|
-
))
|
303
|
+
JSON
|
304
|
+
expect(ATDIS::Model).to receive(:read_url_raw).with(
|
305
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json",
|
306
|
+
false
|
307
|
+
).and_return(json)
|
221
308
|
end
|
222
309
|
|
223
|
-
let(:applications_results)
|
310
|
+
let(:applications_results) do
|
311
|
+
ATDIS::Models::Page.read_url(
|
312
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json",
|
313
|
+
"UTC"
|
314
|
+
)
|
315
|
+
end
|
224
316
|
|
225
317
|
it ".response" do
|
226
318
|
application1 = double("Application")
|
227
319
|
application2 = double("Application")
|
228
|
-
ATDIS::Models::Response.
|
229
|
-
|
230
|
-
|
231
|
-
|
320
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
321
|
+
{ application: { description: "application1" } },
|
322
|
+
"UTC"
|
323
|
+
).and_return(application1)
|
324
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
325
|
+
{ application: { description: "application2" } },
|
326
|
+
"UTC"
|
327
|
+
).and_return(application2)
|
328
|
+
|
329
|
+
expect(applications_results.response).to eq [application1, application2]
|
232
330
|
end
|
233
331
|
|
234
332
|
it ".next_page" do
|
235
|
-
applications_results.next_page.
|
333
|
+
expect(applications_results.next_page).to be_nil
|
236
334
|
end
|
237
335
|
|
238
336
|
it ".pagination" do
|
239
|
-
applications_results.pagination.
|
240
|
-
end
|
337
|
+
expect(applications_results.pagination).to be_nil
|
241
338
|
end
|
339
|
+
end
|
242
340
|
end
|
243
341
|
|
244
342
|
context "paging supported by vendor" do
|
245
343
|
before :each do
|
246
|
-
|
247
|
-
{
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
))
|
344
|
+
json = <<~JSON
|
345
|
+
{
|
346
|
+
"response": [
|
347
|
+
{
|
348
|
+
"application": {
|
349
|
+
"description": "application1"
|
350
|
+
}
|
351
|
+
},
|
352
|
+
{
|
353
|
+
"application": {
|
354
|
+
"description": "application2"
|
355
|
+
}
|
356
|
+
}
|
357
|
+
],
|
358
|
+
"count": 2,
|
359
|
+
"pagination": {
|
360
|
+
"previous": 1,
|
361
|
+
"next": 3,
|
362
|
+
"current": 2,
|
363
|
+
"per_page": 2,
|
364
|
+
"count": 50,
|
365
|
+
"pages": 25
|
366
|
+
}
|
367
|
+
}
|
368
|
+
JSON
|
369
|
+
expect(ATDIS::Model).to receive(:read_url_raw).with(
|
370
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2",
|
371
|
+
false
|
372
|
+
).and_return(json)
|
272
373
|
end
|
273
374
|
|
274
|
-
let(:applications_results)
|
375
|
+
let(:applications_results) do
|
376
|
+
ATDIS::Models::Page.read_url(
|
377
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2",
|
378
|
+
"UTC"
|
379
|
+
)
|
380
|
+
end
|
275
381
|
|
276
382
|
it ".previous" do
|
277
|
-
applications_results.pagination.previous.
|
383
|
+
expect(applications_results.pagination.previous).to eq 1
|
278
384
|
end
|
279
385
|
|
280
386
|
it ".next" do
|
281
|
-
applications_results.pagination.next.
|
387
|
+
expect(applications_results.pagination.next).to eq 3
|
282
388
|
end
|
283
389
|
|
284
390
|
it ".current" do
|
285
|
-
applications_results.pagination.current.
|
391
|
+
expect(applications_results.pagination.current).to eq 2
|
286
392
|
end
|
287
393
|
|
288
394
|
it ".per_page" do
|
289
|
-
applications_results.pagination.per_page.
|
395
|
+
expect(applications_results.pagination.per_page).to eq 2
|
290
396
|
end
|
291
397
|
|
292
398
|
it ".count" do
|
293
|
-
applications_results.pagination.count.
|
399
|
+
expect(applications_results.pagination.count).to eq 50
|
294
400
|
end
|
295
401
|
|
296
402
|
it ".pages" do
|
297
|
-
applications_results.pagination.pages.
|
403
|
+
expect(applications_results.pagination.pages).to eq 25
|
298
404
|
end
|
299
405
|
|
300
406
|
it ".next_url" do
|
301
|
-
applications_results.next_url.
|
407
|
+
expect(applications_results.next_url).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=3"
|
302
408
|
end
|
303
409
|
|
304
410
|
it ".next_page" do
|
305
411
|
n = double("Page")
|
306
412
|
applications_results
|
307
|
-
ATDIS::Models::Page.
|
308
|
-
|
413
|
+
expect(ATDIS::Models::Page).to receive(:read_url).with(
|
414
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=3",
|
415
|
+
"UTC"
|
416
|
+
).and_return(n)
|
417
|
+
expect(applications_results.next_page).to eq n
|
309
418
|
end
|
310
419
|
end
|
311
420
|
end
|