atdis 0.3.13 → 0.4.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 +4 -4
- data/.rubocop.yml +46 -0
- data/.ruby-version +1 -1
- 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 +31 -24
- data/lib/atdis/model.rb +101 -99
- 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 +34 -19
- 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 +126 -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 +191 -116
- 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 +241 -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 +56 -27
@@ -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,118 @@ describe ATDIS::Models::Page do
|
|
216
300
|
}
|
217
301
|
]
|
218
302
|
}
|
219
|
-
|
220
|
-
))
|
303
|
+
JSON
|
304
|
+
expect(RestClient).to receive(:get).with(
|
305
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json"
|
306
|
+
).and_return(double(to_str: json))
|
221
307
|
end
|
222
308
|
|
223
|
-
let(:applications_results)
|
309
|
+
let(:applications_results) do
|
310
|
+
ATDIS::Models::Page.read_url(
|
311
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json",
|
312
|
+
"UTC"
|
313
|
+
)
|
314
|
+
end
|
224
315
|
|
225
316
|
it ".response" do
|
226
317
|
application1 = double("Application")
|
227
318
|
application2 = double("Application")
|
228
|
-
ATDIS::Models::Response.
|
229
|
-
|
230
|
-
|
231
|
-
|
319
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
320
|
+
{ application: { description: "application1" } },
|
321
|
+
"UTC"
|
322
|
+
).and_return(application1)
|
323
|
+
expect(ATDIS::Models::Response).to receive(:interpret).with(
|
324
|
+
{ application: { description: "application2" } },
|
325
|
+
"UTC"
|
326
|
+
).and_return(application2)
|
327
|
+
|
328
|
+
expect(applications_results.response).to eq [application1, application2]
|
232
329
|
end
|
233
330
|
|
234
331
|
it ".next_page" do
|
235
|
-
applications_results.next_page.
|
332
|
+
expect(applications_results.next_page).to be_nil
|
236
333
|
end
|
237
334
|
|
238
335
|
it ".pagination" do
|
239
|
-
applications_results.pagination.
|
240
|
-
end
|
336
|
+
expect(applications_results.pagination).to be_nil
|
241
337
|
end
|
338
|
+
end
|
242
339
|
end
|
243
340
|
|
244
341
|
context "paging supported by vendor" do
|
245
342
|
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
|
-
))
|
343
|
+
json = <<~JSON
|
344
|
+
{
|
345
|
+
"response": [
|
346
|
+
{
|
347
|
+
"application": {
|
348
|
+
"description": "application1"
|
349
|
+
}
|
350
|
+
},
|
351
|
+
{
|
352
|
+
"application": {
|
353
|
+
"description": "application2"
|
354
|
+
}
|
355
|
+
}
|
356
|
+
],
|
357
|
+
"count": 2,
|
358
|
+
"pagination": {
|
359
|
+
"previous": 1,
|
360
|
+
"next": 3,
|
361
|
+
"current": 2,
|
362
|
+
"per_page": 2,
|
363
|
+
"count": 50,
|
364
|
+
"pages": 25
|
365
|
+
}
|
366
|
+
}
|
367
|
+
JSON
|
368
|
+
expect(RestClient).to receive(:get).with(
|
369
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2"
|
370
|
+
).and_return(double(to_str: json))
|
272
371
|
end
|
273
372
|
|
274
|
-
let(:applications_results)
|
373
|
+
let(:applications_results) do
|
374
|
+
ATDIS::Models::Page.read_url(
|
375
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2",
|
376
|
+
"UTC"
|
377
|
+
)
|
378
|
+
end
|
275
379
|
|
276
380
|
it ".previous" do
|
277
|
-
applications_results.pagination.previous.
|
381
|
+
expect(applications_results.pagination.previous).to eq 1
|
278
382
|
end
|
279
383
|
|
280
384
|
it ".next" do
|
281
|
-
applications_results.pagination.next.
|
385
|
+
expect(applications_results.pagination.next).to eq 3
|
282
386
|
end
|
283
387
|
|
284
388
|
it ".current" do
|
285
|
-
applications_results.pagination.current.
|
389
|
+
expect(applications_results.pagination.current).to eq 2
|
286
390
|
end
|
287
391
|
|
288
392
|
it ".per_page" do
|
289
|
-
applications_results.pagination.per_page.
|
393
|
+
expect(applications_results.pagination.per_page).to eq 2
|
290
394
|
end
|
291
395
|
|
292
396
|
it ".count" do
|
293
|
-
applications_results.pagination.count.
|
397
|
+
expect(applications_results.pagination.count).to eq 50
|
294
398
|
end
|
295
399
|
|
296
400
|
it ".pages" do
|
297
|
-
applications_results.pagination.pages.
|
401
|
+
expect(applications_results.pagination.pages).to eq 25
|
298
402
|
end
|
299
403
|
|
300
404
|
it ".next_url" do
|
301
|
-
applications_results.next_url.
|
405
|
+
expect(applications_results.next_url).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=3"
|
302
406
|
end
|
303
407
|
|
304
408
|
it ".next_page" do
|
305
409
|
n = double("Page")
|
306
410
|
applications_results
|
307
|
-
ATDIS::Models::Page.
|
308
|
-
|
411
|
+
expect(ATDIS::Models::Page).to receive(:read_url).with(
|
412
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=3"
|
413
|
+
).and_return(n)
|
414
|
+
expect(applications_results.next_page).to eq n
|
309
415
|
end
|
310
416
|
end
|
311
417
|
end
|