atdis 0.3.11 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +46 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +0 -4
  5. data/Gemfile +9 -7
  6. data/Guardfile +4 -3
  7. data/Rakefile +4 -2
  8. data/atdis.gemspec +10 -5
  9. data/lib/atdis.rb +2 -0
  10. data/lib/atdis/feed.rb +32 -24
  11. data/lib/atdis/model.rb +108 -95
  12. data/lib/atdis/models/address.rb +10 -4
  13. data/lib/atdis/models/application.rb +12 -9
  14. data/lib/atdis/models/authority.rb +11 -6
  15. data/lib/atdis/models/document.rb +8 -6
  16. data/lib/atdis/models/event.rb +10 -8
  17. data/lib/atdis/models/info.rb +73 -49
  18. data/lib/atdis/models/land_title_ref.rb +15 -7
  19. data/lib/atdis/models/location.rb +9 -7
  20. data/lib/atdis/models/page.rb +36 -21
  21. data/lib/atdis/models/pagination.rb +91 -32
  22. data/lib/atdis/models/person.rb +7 -5
  23. data/lib/atdis/models/reference.rb +7 -5
  24. data/lib/atdis/models/response.rb +5 -3
  25. data/lib/atdis/models/torrens_title.rb +9 -7
  26. data/lib/atdis/separated_url.rb +17 -15
  27. data/lib/atdis/validators.rb +46 -39
  28. data/lib/atdis/version.rb +3 -1
  29. data/spec/atdis/feed_spec.rb +128 -34
  30. data/spec/atdis/model_spec.rb +124 -51
  31. data/spec/atdis/models/address_spec.rb +18 -9
  32. data/spec/atdis/models/application_spec.rb +222 -155
  33. data/spec/atdis/models/authority_spec.rb +45 -15
  34. data/spec/atdis/models/document_spec.rb +10 -4
  35. data/spec/atdis/models/event_spec.rb +23 -11
  36. data/spec/atdis/models/info_spec.rb +197 -113
  37. data/spec/atdis/models/land_title_ref_spec.rb +32 -16
  38. data/spec/atdis/models/location_spec.rb +75 -60
  39. data/spec/atdis/models/page_spec.rb +244 -135
  40. data/spec/atdis/models/pagination_spec.rb +177 -77
  41. data/spec/atdis/models/person_spec.rb +8 -4
  42. data/spec/atdis/models/reference_spec.rb +29 -16
  43. data/spec/atdis/models/response_spec.rb +2 -1
  44. data/spec/atdis/models/torrens_title_spec.rb +24 -18
  45. data/spec/atdis/separated_url_spec.rb +14 -15
  46. data/spec/spec_helper.rb +14 -10
  47. 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({lot: "10"}).and_return(m)
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.should be_valid }
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.should be_valid }
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.should_not be_valid
23
- l.errors.messages.should == {torrens: [ATDIS::ErrorMessage.new("or other needs be present", "4.3.3")]}
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 receive(:interpret).with({lot: "10"}).and_return(m)
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) { ATDIS::Models::LandTitleRef.new(torrens: {lot: "10"}, other: {some: "foo", random: "stuff"})}
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.should_not be_valid
36
- l.errors.messages.should == {torrens: [ATDIS::ErrorMessage.new("and other can't both be present", "4.3.3")]}
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.should == [
6
- "address",
7
- "land_title_ref",
8
- "geometry"
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) { ATDIS::Models::Location.new(
15
- address: {
16
- street: "123 Fourfivesix Street",
17
- suburb: "Neutral Bay",
18
- postcode: "2089",
19
- state: "NSW"
20
- },
21
- land_title_ref: {
22
- torrens: {
23
- lot: "10",
24
- section: "ABC",
25
- dpsp_id: "DP2013-0381",
26
- }
27
- },
28
- geometry: {
29
- type: "Point",
30
- coordinates: [100.0, 0.0]
31
- }
32
- )}
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.should be_valid }
41
+ it { expect(l).to be_valid }
35
42
 
36
43
  it "address" do
37
44
  l.address = nil
38
- l.should_not be_valid
39
- l.errors.messages.should == {address: [ATDIS::ErrorMessage["can't be blank", "4.3.3"]]}
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.should be_nil
45
- l.should_not be_valid
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(address: {street: "123 Fourfivesix Street", suburb: "Neutral Bay", postcode: "2089"})
53
- l.land_title_ref.should be_nil
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
- geometry: {
60
- type: "Point",
61
- coordinates: [100.0, 0.0]
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.should == 100
66
- l.geometry.y.should == 0
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
- geometry: {
73
- type: "Polygon",
74
- coordinates: [
75
- [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
76
- [100.0, 1.0], [100.0, 0.0] ]
77
- ]
78
- }
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.should be_empty
82
- l.geometry.exterior_ring.points.count.should == 5
83
- l.geometry.exterior_ring.points[0].x.should == 100
84
- l.geometry.exterior_ring.points[0].y.should == 0
85
- l.geometry.exterior_ring.points[1].x.should == 101
86
- l.geometry.exterior_ring.points[1].y.should == 0
87
- l.geometry.exterior_ring.points[2].x.should == 101
88
- l.geometry.exterior_ring.points[2].y.should == 1
89
- l.geometry.exterior_ring.points[3].x.should == 100
90
- l.geometry.exterior_ring.points[3].y.should == 1
91
- l.geometry.exterior_ring.points[4].x.should == 100
92
- l.geometry.exterior_ring.points[4].y.should == 0
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.should == ["response", "count", "pagination"]
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(response: nil, count: 0, pagination: {pages: 1, per_page: 20, count: 0, current: 1})
10
- page.should_not be_valid
11
- page.errors.messages.should == {:response => [ATDIS::ErrorMessage["can't be blank", "4.3"]]}
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.should_receive(:interpret).with(description: "application1").and_return(double(valid?: true))
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.should_not be_valid
23
- page.errors.messages.should == {response: [ATDIS::ErrorMessage["should be an array", "6.4"]]}
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.should_receive(:interpret).with(description: "application1").and_return(double(valid?: true))
30
- ATDIS::Models::Response.should_receive(:interpret).with(description: "application2").and_return(double(valid?: true))
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.should be_valid}
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.should be_valid }
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(per_page: 25, current: 1, count: 2, pages: 1)
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.should be_valid }
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.should_not be_valid
58
- page.errors.messages.should == {count: [ATDIS::ErrorMessage["is not the same as the number of applications returned", "6.4"]]}
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.should_not be_valid
69
- page.errors.messages.should == {count: [ATDIS::ErrorMessage["should not be larger than the number of results per page", "6.4"]]}
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.should_not be_valid
80
- page.errors.messages.should == {count: [ATDIS::ErrorMessage["should be present if pagination is being used", "6.4"]]}
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.should_receive(:valid?).and_return(false)
123
+ expect(page.pagination).to receive(:valid?).and_return(false)
87
124
  end
88
125
 
89
126
  it do
90
- page.should_not be_valid
91
- page.errors.messages.should == {pagination: [ATDIS::ErrorMessage["is not valid (see further errors for details)", nil]]}
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.should_receive(:interpret).with(description: "application1").and_return(double(valid?: true))
100
- ATDIS::Models::Response.should_receive(:interpret).with(description: "application2").and_return(double(valid?: false))
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.should_not be_valid
106
- page.errors.messages.should == {response: [ATDIS::ErrorMessage["is not valid (see further errors for details)", nil]]}
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.should_receive(:interpret).with(description: "application1").and_return(a1)
115
- ATDIS::Models::Response.should_receive(:interpret).with(description: "application2").and_return(a2)
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.should_not be_valid
121
- page.errors.messages.should == {response: [ATDIS::ErrorMessage["is not valid (see further errors for details)", nil]]}
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.should_not be_valid
126
- page.json_errors.should == [[{response: [{description: "application1"}, {description: "application2"}]}, [ATDIS::ErrorMessage["response is not valid (see further errors for details)"]]], [{response: [{dat_id: "null"}]} , ["can not be empty"]]]
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) { ATDIS::Models::Page.read_json(<<-EOF
135
- {
136
- "response": [
137
- {
138
- "application": {
139
- "description": "application2"
140
- }
141
- }
142
- ],
143
- }
144
- EOF
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.should_not be_valid
149
- page.errors.messages.has_key?(:json).should be_truthy
150
- page.errors.messages.count.should == 1
151
- # The error messages returned by the library are different for different Ruby versions
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 == ruby19_message || message == ruby20_message).should be_truthy
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) { ATDIS::Models::Page.read_json(<<-EOF
162
- {
163
- "response": [
164
- {
165
- "application": {
166
- "description": "application1"
167
- }
168
- },
169
- {
170
- "application": {
171
- "description": "application2"
172
- }
173
- }
174
- ],
175
- "count": 2,
176
- "pagination": {
177
- "previous": 1,
178
- "next": 3,
179
- "current": 2,
180
- "per_page": 2,
181
- "count": 50,
182
- "pages": 25
183
- }
184
- }
185
- EOF
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.should_receive(:interpret).with(application: {description: "application1"}).and_return(application1)
191
- ATDIS::Models::Response.should_receive(:interpret).with(application: {description: "application2"}).and_return(application2)
192
-
193
- page.response.should == [application1, application2]
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
- RestClient.should_receive(:get).with("http://www.council.nsw.gov.au/atdis/1.0/applications.json").and_return(double(to_str: <<-EOF
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
- EOF
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) { ATDIS::Models::Page.read_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json") }
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.should_receive(:interpret).with(application: {description: "application1"}).and_return(application1)
229
- ATDIS::Models::Response.should_receive(:interpret).with(application: {description: "application2"}).and_return(application2)
230
-
231
- applications_results.response.should == [application1, application2]
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.should be_nil
333
+ expect(applications_results.next_page).to be_nil
236
334
  end
237
335
 
238
336
  it ".pagination" do
239
- applications_results.pagination.should be_nil
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
- RestClient.should_receive(:get).with("http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2").and_return(double(to_str: <<-EOF
247
- {
248
- "response": [
249
- {
250
- "application": {
251
- "description": "application1"
252
- }
253
- },
254
- {
255
- "application": {
256
- "description": "application2"
257
- }
258
- }
259
- ],
260
- "count": 2,
261
- "pagination": {
262
- "previous": 1,
263
- "next": 3,
264
- "current": 2,
265
- "per_page": 2,
266
- "count": 50,
267
- "pages": 25
268
- }
269
- }
270
- EOF
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) { ATDIS::Models::Page.read_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2") }
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.should == 1
383
+ expect(applications_results.pagination.previous).to eq 1
278
384
  end
279
385
 
280
386
  it ".next" do
281
- applications_results.pagination.next.should == 3
387
+ expect(applications_results.pagination.next).to eq 3
282
388
  end
283
389
 
284
390
  it ".current" do
285
- applications_results.pagination.current.should == 2
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.should == 2
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.should == 50
399
+ expect(applications_results.pagination.count).to eq 50
294
400
  end
295
401
 
296
402
  it ".pages" do
297
- applications_results.pagination.pages.should == 25
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.should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=3"
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.should_receive(:read_url).with("http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=3").and_return(n)
308
- applications_results.next_page.should == n
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