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
data/spec/atdis/document_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe ATDIS::Document do
|
4
|
-
it ".attribute_names" do
|
5
|
-
ATDIS::Document.attribute_names.should == ["ref", "title", "document_url"]
|
6
|
-
end
|
7
|
-
|
8
|
-
it ".ref" do
|
9
|
-
ATDIS::Document.interpret(:ref => "27B/6").ref.should == "27B/6"
|
10
|
-
end
|
11
|
-
|
12
|
-
it ".title" do
|
13
|
-
ATDIS::Document.interpret(:title => "Authorisation for Repairs").title.should == "Authorisation for Repairs"
|
14
|
-
end
|
15
|
-
|
16
|
-
it ".document_url" do
|
17
|
-
ATDIS::Document.interpret(:document_url => "http://foo.com/bar").document_url.should == URI.parse("http://foo.com/bar")
|
18
|
-
end
|
19
|
-
end
|
data/spec/atdis/event_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe ATDIS::Event do
|
4
|
-
it ".attribute_names" do
|
5
|
-
ATDIS::Event.attribute_names.should == ["id", "date", "description", "event_type", "status"]
|
6
|
-
end
|
7
|
-
|
8
|
-
it ".id" do
|
9
|
-
ATDIS::Event.interpret(:id => "27B/6").id.should == "27B/6"
|
10
|
-
end
|
11
|
-
|
12
|
-
it ".date" do
|
13
|
-
ATDIS::Event.interpret(:date => "2013-06-18").date.should == DateTime.new(2013,6,18)
|
14
|
-
end
|
15
|
-
|
16
|
-
it ".description" do
|
17
|
-
ATDIS::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::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::Event.interpret(:status => "approved").status.should == "approved"
|
28
|
-
end
|
29
|
-
end
|
data/spec/atdis/location_spec.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe ATDIS::Location do
|
4
|
-
it ".attribute_names" do
|
5
|
-
ATDIS::Location.attribute_names.should == [
|
6
|
-
"address",
|
7
|
-
"lot",
|
8
|
-
"section",
|
9
|
-
"dpsp_id",
|
10
|
-
"geometry"
|
11
|
-
]
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "validation" do
|
15
|
-
context "valid location" do
|
16
|
-
let(:l) { ATDIS::Location.new(
|
17
|
-
:address => "123 Fourfivesix Street Neutral Bay NSW 2089",
|
18
|
-
:lot => "10",
|
19
|
-
:section => "ABC",
|
20
|
-
:dpsp_id => "DP2013-0381",
|
21
|
-
:geometry => {
|
22
|
-
:type => "Point",
|
23
|
-
:coordinates => [100.0, 0.0]
|
24
|
-
}
|
25
|
-
)}
|
26
|
-
|
27
|
-
it { l.should be_valid }
|
28
|
-
|
29
|
-
it "address" do
|
30
|
-
l.address = ""
|
31
|
-
l.should_not be_valid
|
32
|
-
l.errors.messages.should == {:address => [ATDIS::ErrorMessage["can't be blank", "4.3.3"]]}
|
33
|
-
end
|
34
|
-
|
35
|
-
it "geometry" do
|
36
|
-
l.geometry = {:type => "Point"}
|
37
|
-
l.geometry.should be_nil
|
38
|
-
l.should_not be_valid
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "lot" do
|
42
|
-
it "can not be blank" do
|
43
|
-
l.lot = ""
|
44
|
-
l.should_not be_valid
|
45
|
-
l.errors.messages.should == {:lot => [ATDIS::ErrorMessage["can't be blank", "4.3.3"]]}
|
46
|
-
end
|
47
|
-
|
48
|
-
it "can be none but is not interpreted in any special way" do
|
49
|
-
l.lot = "none"
|
50
|
-
l.lot.should == "none"
|
51
|
-
l.should be_valid
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "section" do
|
56
|
-
it "can not be blank" do
|
57
|
-
l.section = ""
|
58
|
-
l.should_not be_valid
|
59
|
-
l.errors.messages.should == {:section => [ATDIS::ErrorMessage["can't be blank", "4.3.3"]]}
|
60
|
-
end
|
61
|
-
|
62
|
-
it "can be none" do
|
63
|
-
l.section = "none"
|
64
|
-
l.section.should be_nil
|
65
|
-
l.should be_valid
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "dpsp_id" do
|
70
|
-
it "can not be blank" do
|
71
|
-
l.dpsp_id = ""
|
72
|
-
l.should_not be_valid
|
73
|
-
l.errors.messages.should == {:dpsp_id => [ATDIS::ErrorMessage["can't be blank", "4.3.3"]]}
|
74
|
-
end
|
75
|
-
|
76
|
-
it "can be none but is not interpreted in any special way" do
|
77
|
-
l.dpsp_id = "none"
|
78
|
-
l.dpsp_id.should == "none"
|
79
|
-
l.should be_valid
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe ".interpret" do
|
86
|
-
it "should interpret a parsed json block of location data" do
|
87
|
-
l = ATDIS::Location.interpret(
|
88
|
-
:address => "123 Fourfivesix Street Neutral Bay NSW 2089",
|
89
|
-
:land_title_ref => {
|
90
|
-
:lot => "10",
|
91
|
-
:section => "ABC",
|
92
|
-
:dpsp_id => "DP2013-0381"
|
93
|
-
})
|
94
|
-
|
95
|
-
l.address.should == "123 Fourfivesix Street Neutral Bay NSW 2089"
|
96
|
-
l.lot.should == "10"
|
97
|
-
l.section.should == "ABC"
|
98
|
-
l.dpsp_id.should == "DP2013-0381"
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should gracefully handle the land_title_ref block being missing" do
|
102
|
-
l = ATDIS::Location.interpret(:address => "123 Fourfivesix Street Neutral Bay NSW 2089")
|
103
|
-
l.address.should == "123 Fourfivesix Street Neutral Bay NSW 2089"
|
104
|
-
l.lot.should == ""
|
105
|
-
l.section.should == ""
|
106
|
-
l.dpsp_id.should == ""
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should pass on the responsibility for parsing the geometry section" do
|
110
|
-
# TODO Not 100% clear from section 4.3.3 of ATDIS-1.0.3 if this is the correct indentation
|
111
|
-
l = ATDIS::Location.interpret(
|
112
|
-
:geometry => {
|
113
|
-
:type => "Point",
|
114
|
-
:coordinates => [100.0, 0.0]
|
115
|
-
}
|
116
|
-
)
|
117
|
-
# TODO Check that the returned geometry is a point
|
118
|
-
l.geometry.x.should == 100
|
119
|
-
l.geometry.y.should == 0
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should interpret a polygon in the geometry section" do
|
123
|
-
# TODO Not 100% clear from section 4.3.3 of ATDIS-1.0.3 if this is the correct indentation
|
124
|
-
l = ATDIS::Location.interpret(
|
125
|
-
:geometry => {
|
126
|
-
:type => "Polygon",
|
127
|
-
:coordinates => [
|
128
|
-
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
|
129
|
-
[100.0, 1.0], [100.0, 0.0] ]
|
130
|
-
]
|
131
|
-
}
|
132
|
-
)
|
133
|
-
# TODO Check that the returned geometry is a polygon
|
134
|
-
l.geometry.interior_rings.should be_empty
|
135
|
-
l.geometry.exterior_ring.points.count.should == 5
|
136
|
-
l.geometry.exterior_ring.points[0].x.should == 100
|
137
|
-
l.geometry.exterior_ring.points[0].y.should == 0
|
138
|
-
l.geometry.exterior_ring.points[1].x.should == 101
|
139
|
-
l.geometry.exterior_ring.points[1].y.should == 0
|
140
|
-
l.geometry.exterior_ring.points[2].x.should == 101
|
141
|
-
l.geometry.exterior_ring.points[2].y.should == 1
|
142
|
-
l.geometry.exterior_ring.points[3].x.should == 100
|
143
|
-
l.geometry.exterior_ring.points[3].y.should == 1
|
144
|
-
l.geometry.exterior_ring.points[4].x.should == 100
|
145
|
-
l.geometry.exterior_ring.points[4].y.should == 0
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
data/spec/atdis/page_spec.rb
DELETED
@@ -1,492 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe ATDIS::Page do
|
4
|
-
it ".attribute_names" do
|
5
|
-
ATDIS::Page.attribute_names.should == ["results", "count", "previous_page_no", "next_page_no", "current_page_no",
|
6
|
-
"no_results_per_page", "total_no_results", "total_no_pages"]
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "validations" do
|
10
|
-
context "two valid applications no paging" do
|
11
|
-
before :each do
|
12
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application1").and_return(double(:valid? => true))
|
13
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application2").and_return(double(:valid? => true))
|
14
|
-
end
|
15
|
-
let(:page) { ATDIS::Page.new(:results => [{:description => "application1"}, {:description => "application2"}]) }
|
16
|
-
|
17
|
-
it {page.should be_valid}
|
18
|
-
|
19
|
-
context "with pagination" do
|
20
|
-
before :each do
|
21
|
-
page.count = 2
|
22
|
-
page.no_results_per_page = 25
|
23
|
-
page.current_page_no = 1
|
24
|
-
page.total_no_results = 2
|
25
|
-
page.total_no_pages = 1
|
26
|
-
end
|
27
|
-
it { page.should be_valid }
|
28
|
-
|
29
|
-
context "count is not consistent" do
|
30
|
-
before :each do
|
31
|
-
page.count = 1
|
32
|
-
end
|
33
|
-
it do
|
34
|
-
page.should_not be_valid
|
35
|
-
page.errors.messages.should == {:count => [ATDIS::ErrorMessage["is not the same as the number of applications returned", "6.5"]]}
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "count is larger than number of results per page" do
|
40
|
-
before :each do
|
41
|
-
page.no_results_per_page = 1
|
42
|
-
page.total_no_results = 1
|
43
|
-
end
|
44
|
-
it do
|
45
|
-
page.should_not be_valid
|
46
|
-
page.errors.messages.should == {:count => [ATDIS::ErrorMessage["should not be larger than the number of results per page", "6.5"]]}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "count is absent" do
|
51
|
-
before :each do
|
52
|
-
page.count = nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it do
|
56
|
-
page.should_not be_valid
|
57
|
-
page.errors.messages.should == {:count => [ATDIS::ErrorMessage["should be present if pagination is being used", "6.5"]]}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "previous page number is pointing to a weird page number" do
|
62
|
-
before :each do
|
63
|
-
page.previous_page_no = 5
|
64
|
-
page.current_page_no = 2
|
65
|
-
page.total_no_results = 50
|
66
|
-
page.total_no_pages = 2
|
67
|
-
end
|
68
|
-
it do
|
69
|
-
page.should_not be_valid
|
70
|
-
page.errors.messages.should == {:previous_page_no => [ATDIS::ErrorMessage["should be one less than current page number or null if first page", "6.5"]]}
|
71
|
-
page.json_errors.should == [[{:pagination => {:previous => 5}}, [ATDIS::ErrorMessage["should be one less than current page number or null if first page", "6.5"]]]]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "previous page number if nil but not on first page" do
|
76
|
-
before :each do
|
77
|
-
page.current_page_no = 4
|
78
|
-
page.next_page_no = 5
|
79
|
-
page.previous_page_no = nil
|
80
|
-
page.total_no_results = 240
|
81
|
-
page.total_no_pages = 10
|
82
|
-
end
|
83
|
-
it do
|
84
|
-
page.should_not be_valid
|
85
|
-
page.errors.messages.should == {:previous_page_no => [ATDIS::ErrorMessage["can't be null if not on the first page", "6.5"]]}
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "previous page number not nil but on first page" do
|
90
|
-
before :each do
|
91
|
-
page.current_page_no = 1
|
92
|
-
page.next_page_no = 2
|
93
|
-
page.previous_page_no = 0
|
94
|
-
page.total_no_results = 240
|
95
|
-
page.total_no_pages = 10
|
96
|
-
end
|
97
|
-
it do
|
98
|
-
page.should_not be_valid
|
99
|
-
page.errors.messages.should == {:previous_page_no => [ATDIS::ErrorMessage["should be null if on the first page", "6.5"]]}
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "next page number is pointing to a weird page number" do
|
104
|
-
before :each do
|
105
|
-
page.next_page_no = 5
|
106
|
-
page.total_no_results = 50
|
107
|
-
page.total_no_pages = 2
|
108
|
-
end
|
109
|
-
it do
|
110
|
-
page.should_not be_valid
|
111
|
-
page.errors.messages.should == {:next_page_no => [ATDIS::ErrorMessage["should be one greater than current page number or null if last page", "6.5"]]}
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "next page number is nil but not on last page" do
|
116
|
-
before :each do
|
117
|
-
page.current_page_no = 4
|
118
|
-
page.previous_page_no = 3
|
119
|
-
page.next_page_no = nil
|
120
|
-
page.total_no_results = 140
|
121
|
-
page.total_no_pages = 6
|
122
|
-
end
|
123
|
-
it do
|
124
|
-
page.should_not be_valid
|
125
|
-
page.errors.messages.should == {:next_page_no => [ATDIS::ErrorMessage["can't be null if not on the last page", "6.5"]]}
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "next page number is not nil but on last page" do
|
130
|
-
before :each do
|
131
|
-
page.previous_page_no = 3
|
132
|
-
page.current_page_no = 4
|
133
|
-
page.next_page_no = 5
|
134
|
-
page.total_no_results = 100
|
135
|
-
page.total_no_pages = 4
|
136
|
-
end
|
137
|
-
it do
|
138
|
-
page.should_not be_valid
|
139
|
-
page.errors.messages.should == {:next_page_no => [ATDIS::ErrorMessage["should be null if on the last page", "6.5"]]}
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context "current page is larger than the number of pages" do
|
144
|
-
before :each do
|
145
|
-
page.current_page_no = 2
|
146
|
-
page.previous_page_no = 1
|
147
|
-
page.next_page_no = 3
|
148
|
-
page.total_no_pages = 1
|
149
|
-
end
|
150
|
-
it do
|
151
|
-
page.should_not be_valid
|
152
|
-
page.errors.messages.should == {:current_page_no => [ATDIS::ErrorMessage["is larger than the number of pages", "6.5"]]}
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context "current page is zero" do
|
157
|
-
before :each do
|
158
|
-
page.current_page_no = 0
|
159
|
-
page.next_page_no = 1
|
160
|
-
end
|
161
|
-
it do
|
162
|
-
page.should_not be_valid
|
163
|
-
page.errors.messages.should == {:current_page_no => [ATDIS::ErrorMessage["can not be less than 1", "6.5"]]}
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context "total_no_results is larger than would be expected" do
|
168
|
-
before :each do
|
169
|
-
page.current_page_no = 1
|
170
|
-
page.next_page_no = 2
|
171
|
-
page.no_results_per_page = 25
|
172
|
-
page.total_no_pages = 4
|
173
|
-
page.total_no_results = 101
|
174
|
-
end
|
175
|
-
it do
|
176
|
-
page.should_not be_valid
|
177
|
-
page.errors.messages.should == {:total_no_results => [ATDIS::ErrorMessage["is larger than can be retrieved through paging", "6.5"]]}
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context "total no_results is less than would be expected" do
|
182
|
-
before :each do
|
183
|
-
page.current_page_no = 1
|
184
|
-
page.next_page_no = 2
|
185
|
-
page.no_results_per_page = 25
|
186
|
-
page.total_no_pages = 4
|
187
|
-
page.total_no_results = 75
|
188
|
-
end
|
189
|
-
it do
|
190
|
-
page.should_not be_valid
|
191
|
-
page.errors.messages.should == {:total_no_results => [ATDIS::ErrorMessage["could fit into a smaller number of pages", "6.5"]]}
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "one valid application out of two no paging" do
|
198
|
-
before :each do
|
199
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application1").and_return(double(:valid? => true))
|
200
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application2").and_return(double(:valid? => false))
|
201
|
-
end
|
202
|
-
let(:page) { ATDIS::Page.new(:results => [{:description => "application1"}, {:description => "application2"}]) }
|
203
|
-
|
204
|
-
it do
|
205
|
-
page.should_not be_valid
|
206
|
-
page.errors.messages.should == {:results => [ATDIS::ErrorMessage["is not valid", nil]]}
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context "two invalid applications no paging" do
|
211
|
-
let(:a1) { double(:valid? => false, :json_errors => [[{:dat_id => "null"}, ["can not be empty"]]]) }
|
212
|
-
let(:a2) { double(:valid? => false) }
|
213
|
-
before :each do
|
214
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application1").and_return(a1)
|
215
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application2").and_return(a2)
|
216
|
-
end
|
217
|
-
let(:page) { ATDIS::Page.new(:results => [{:description => "application1"}, {:description => "application2"}]) }
|
218
|
-
|
219
|
-
it do
|
220
|
-
page.should_not be_valid
|
221
|
-
page.errors.messages.should == {:results => [ATDIS::ErrorMessage["is not valid", nil]]}
|
222
|
-
end
|
223
|
-
|
224
|
-
it "the errors from the first errored application should be here" do
|
225
|
-
page.should_not be_valid
|
226
|
-
page.json_errors.should == [[{:response => {:dat_id => "null"}} , ["can not be empty"]]]
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
describe ".level_used?" do
|
233
|
-
describe "level 1" do
|
234
|
-
context "two applications" do
|
235
|
-
before :each do
|
236
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application1").and_return(double)
|
237
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application2").and_return(double)
|
238
|
-
end
|
239
|
-
let(:page) { ATDIS::Page.new(:results => [{:description => "application1"}, {:description => "application2"}]) }
|
240
|
-
|
241
|
-
it { page.level_used?(1).should be_true }
|
242
|
-
end
|
243
|
-
|
244
|
-
context "no L1 features used" do
|
245
|
-
let(:page) { ATDIS::Page.new }
|
246
|
-
it { page.level_used?(1).should be_false }
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
describe "level 2" do
|
251
|
-
context "two applications with only L1 features" do
|
252
|
-
let(:a1) { double }
|
253
|
-
let(:a2) { double }
|
254
|
-
before :each do
|
255
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application1").and_return(a1)
|
256
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application2").and_return(a2)
|
257
|
-
end
|
258
|
-
let(:page) { ATDIS::Page.new(:results => [{:description => "application1"}, {:description => "application2"}]) }
|
259
|
-
|
260
|
-
it do
|
261
|
-
a1.should_receive(:level_used?).with(2).and_return(false)
|
262
|
-
a2.should_receive(:level_used?).with(2).and_return(false)
|
263
|
-
page.level_used?(2).should be_false
|
264
|
-
end
|
265
|
-
|
266
|
-
context "L2 feature used on Page" do
|
267
|
-
before :each do
|
268
|
-
page.count = 2
|
269
|
-
end
|
270
|
-
|
271
|
-
it { page.level_used?(2).should be_true }
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
context "two applications with L2 features" do
|
276
|
-
let(:a1) { double }
|
277
|
-
let(:a2) { double }
|
278
|
-
before :each do
|
279
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application1").and_return(a1)
|
280
|
-
ATDIS::Application.should_receive(:interpret).with(:description => "application2").and_return(a2)
|
281
|
-
end
|
282
|
-
let(:page) { ATDIS::Page.new(:results => [{:description => "application1"}, {:description => "application2"}]) }
|
283
|
-
|
284
|
-
it "should ask the applications whether they have L2 features" do
|
285
|
-
a1.should_receive(:level_used?).with(2).and_return(true)
|
286
|
-
page.level_used?(2).should be_true
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context "paging supported by vendor" do
|
293
|
-
context "read a from an invalid json string" do
|
294
|
-
let(:page) { ATDIS::Page.read_json(<<-EOF
|
295
|
-
{
|
296
|
-
"response": [
|
297
|
-
{
|
298
|
-
"application": {
|
299
|
-
"description": "application2"
|
300
|
-
}
|
301
|
-
}
|
302
|
-
],
|
303
|
-
}
|
304
|
-
EOF
|
305
|
-
)}
|
306
|
-
|
307
|
-
it do
|
308
|
-
page.should_not be_valid
|
309
|
-
page.errors.messages.has_key?(:json).should be_true
|
310
|
-
page.errors.messages.count.should == 1
|
311
|
-
# The error messages returned by the library are different for different Ruby versions
|
312
|
-
ruby18_message = ATDIS::ErrorMessage['Invalid JSON: unexpected "}"', nil]
|
313
|
-
ruby19_message = ATDIS::ErrorMessage["Invalid JSON: 784: unexpected token at '{\n \"response\": [\n {\n \"application\": {\n \"description\": \"application2\"\n } \n }\n ],\n} \n'", nil]
|
314
|
-
ruby20_message = ATDIS::ErrorMessage["Invalid JSON: 795: unexpected token at '{\n \"response\": [\n {\n \"application\": {\n \"description\": \"application2\"\n } \n }\n ],\n} \n'", nil]
|
315
|
-
page.errors.messages[:json].count.should == 1
|
316
|
-
message = page.errors.messages[:json].first
|
317
|
-
(message == ruby18_message || message == ruby19_message || message == ruby20_message).should be_true
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
context "read from a json string" do
|
322
|
-
let(:page) { ATDIS::Page.read_json(<<-EOF
|
323
|
-
{
|
324
|
-
"response": [
|
325
|
-
{
|
326
|
-
"application": {
|
327
|
-
"description": "application1"
|
328
|
-
}
|
329
|
-
},
|
330
|
-
{
|
331
|
-
"application": {
|
332
|
-
"description": "application2"
|
333
|
-
}
|
334
|
-
}
|
335
|
-
],
|
336
|
-
"count": 2,
|
337
|
-
"pagination": {
|
338
|
-
"previous": 1,
|
339
|
-
"next": 3,
|
340
|
-
"current": 2,
|
341
|
-
"per_page": 2,
|
342
|
-
"count": 50,
|
343
|
-
"pages": 25
|
344
|
-
}
|
345
|
-
}
|
346
|
-
EOF
|
347
|
-
)}
|
348
|
-
it ".results" do
|
349
|
-
application1 = double("Application")
|
350
|
-
application2 = double("Application")
|
351
|
-
ATDIS::Application.should_receive(:interpret).with(:application => {:description => "application1"}).and_return(application1)
|
352
|
-
ATDIS::Application.should_receive(:interpret).with(:application => {:description => "application2"}).and_return(application2)
|
353
|
-
|
354
|
-
page.results.should == [application1, application2]
|
355
|
-
end
|
356
|
-
|
357
|
-
it ".next" do
|
358
|
-
expect { page.next }.to raise_error "Can't use next_url when loaded with read_json"
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
context "read from a url" do
|
363
|
-
before :each do
|
364
|
-
# Mock network response
|
365
|
-
RestClient.should_receive(:get).with("http://www.council.nsw.gov.au/atdis/1.0/applications.json").and_return(double(:to_str => <<-EOF
|
366
|
-
{
|
367
|
-
"response": [
|
368
|
-
{
|
369
|
-
"application": {
|
370
|
-
"description": "application1"
|
371
|
-
}
|
372
|
-
},
|
373
|
-
{
|
374
|
-
"application": {
|
375
|
-
"description": "application2"
|
376
|
-
}
|
377
|
-
}
|
378
|
-
]
|
379
|
-
}
|
380
|
-
EOF
|
381
|
-
))
|
382
|
-
end
|
383
|
-
|
384
|
-
let(:applications_results) { ATDIS::Page.read_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json") }
|
385
|
-
|
386
|
-
it ".results" do
|
387
|
-
application1 = double("Application")
|
388
|
-
application2 = double("Application")
|
389
|
-
ATDIS::Application.should_receive(:interpret).with(:application => {:description => "application1"}).and_return(application1)
|
390
|
-
ATDIS::Application.should_receive(:interpret).with(:application => {:description => "application2"}).and_return(application2)
|
391
|
-
|
392
|
-
applications_results.results.should == [application1, application2]
|
393
|
-
end
|
394
|
-
|
395
|
-
it ".next" do
|
396
|
-
applications_results.next.should be_nil
|
397
|
-
end
|
398
|
-
|
399
|
-
it ".previous_page_no" do
|
400
|
-
applications_results.previous_page_no.should be_nil
|
401
|
-
end
|
402
|
-
|
403
|
-
it ".next_page_no" do
|
404
|
-
applications_results.next_page_no.should be_nil
|
405
|
-
end
|
406
|
-
|
407
|
-
it ".current_page_no" do
|
408
|
-
applications_results.current_page_no.should be_nil
|
409
|
-
end
|
410
|
-
|
411
|
-
it ".no_results_per_page" do
|
412
|
-
applications_results.no_results_per_page.should be_nil
|
413
|
-
end
|
414
|
-
|
415
|
-
it ".total_no_results" do
|
416
|
-
applications_results.total_no_results.should be_nil
|
417
|
-
end
|
418
|
-
|
419
|
-
it ".total_no_pages" do
|
420
|
-
applications_results.total_no_pages.should be_nil
|
421
|
-
end
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
context "paging supported by vendor" do
|
426
|
-
before :each do
|
427
|
-
RestClient.should_receive(:get).with("http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2").and_return(double(:to_str => <<-EOF
|
428
|
-
{
|
429
|
-
"response": [
|
430
|
-
{
|
431
|
-
"application": {
|
432
|
-
"description": "application1"
|
433
|
-
}
|
434
|
-
},
|
435
|
-
{
|
436
|
-
"application": {
|
437
|
-
"description": "application2"
|
438
|
-
}
|
439
|
-
}
|
440
|
-
],
|
441
|
-
"count": 2,
|
442
|
-
"pagination": {
|
443
|
-
"previous": 1,
|
444
|
-
"next": 3,
|
445
|
-
"current": 2,
|
446
|
-
"per_page": 2,
|
447
|
-
"count": 50,
|
448
|
-
"pages": 25
|
449
|
-
}
|
450
|
-
}
|
451
|
-
EOF
|
452
|
-
))
|
453
|
-
end
|
454
|
-
|
455
|
-
let(:applications_results) { ATDIS::Page.read_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2") }
|
456
|
-
|
457
|
-
it ".previous_page_no" do
|
458
|
-
applications_results.previous_page_no.should == 1
|
459
|
-
end
|
460
|
-
|
461
|
-
it ".next_page_no" do
|
462
|
-
applications_results.next_page_no.should == 3
|
463
|
-
end
|
464
|
-
|
465
|
-
it ".current_page_no" do
|
466
|
-
applications_results.current_page_no.should == 2
|
467
|
-
end
|
468
|
-
|
469
|
-
it ".no_results_per_page" do
|
470
|
-
applications_results.no_results_per_page.should == 2
|
471
|
-
end
|
472
|
-
|
473
|
-
it ".total_no_results" do
|
474
|
-
applications_results.total_no_results.should == 50
|
475
|
-
end
|
476
|
-
|
477
|
-
it ".total_no_pages" do
|
478
|
-
applications_results.total_no_pages.should == 25
|
479
|
-
end
|
480
|
-
|
481
|
-
it ".next_url" do
|
482
|
-
applications_results.next_url.should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=3"
|
483
|
-
end
|
484
|
-
|
485
|
-
it ".next" do
|
486
|
-
n = double("Page")
|
487
|
-
applications_results
|
488
|
-
ATDIS::Page.should_receive(:read_url).with("http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=3").and_return(n)
|
489
|
-
applications_results.next.should == n
|
490
|
-
end
|
491
|
-
end
|
492
|
-
end
|