govkit-ca 0.0.6 → 0.0.7
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 +7 -0
- data/.travis.yml +4 -0
- data/README.md +1 -1
- data/govkit-ca.gemspec +4 -2
- data/lib/gov_kit-ca/postal_code/strategy/cbc_ca.rb +1 -1
- data/lib/gov_kit-ca/postal_code/strategy/conservative_ca.rb +3 -4
- data/lib/gov_kit-ca/postal_code/strategy/elections_ca.rb +4 -6
- data/lib/gov_kit-ca/postal_code/strategy/liberal_ca.rb +0 -1
- data/lib/gov_kit-ca/postal_code/strategy/parl_gc_ca.rb +5 -1
- data/lib/gov_kit-ca/postal_code.rb +19 -7
- data/lib/gov_kit-ca/represent.rb +108 -0
- data/lib/gov_kit-ca/version.rb +1 -1
- data/lib/gov_kit-ca.rb +2 -1
- data/spec/cbc_ca_spec.rb +14 -25
- data/spec/conservative_ca_spec.rb +1 -10
- data/spec/digital-copyright_ca_spec.rb +0 -9
- data/spec/elections_ca_spec.rb +0 -9
- data/spec/greenparty_ca_spec.rb +0 -9
- data/spec/liberal_ca_spec.rb +1 -10
- data/spec/ndp_ca_spec.rb +0 -9
- data/spec/parl_gc_ca_spec.rb +8 -0
- data/spec/postal_code_spec.rb +69 -87
- data/spec/represent_spec.rb +279 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/strategy_set_spec.rb +55 -2
- data/tasks/tasks.rb +0 -28
- metadata +47 -133
- data/spec/fixtures/cbc_ca/A1A1A1.response +0 -11
- data/spec/fixtures/cbc_ca/G0C2Y0.response +0 -11
- data/spec/fixtures/cbc_ca/H0H0H0.response +0 -11
- data/spec/fixtures/cbc_ca/K0A1K0.response +0 -11
- data/spec/fixtures/cbc_ca/T5S2B9.response +0 -11
- data/spec/fixtures/cbc_ca/X1B1B1.response +0 -11
- data/spec/fixtures/conservative_ca/A1A1A1.response +0 -452
- data/spec/fixtures/conservative_ca/G0C2Y0.response +0 -452
- data/spec/fixtures/conservative_ca/H0H0H0.response +0 -452
- data/spec/fixtures/conservative_ca/K0A1K0.response +0 -455
- data/spec/fixtures/conservative_ca/T5S2B9.response +0 -453
- data/spec/fixtures/conservative_ca/X1B1B1.response +0 -452
- data/spec/fixtures/digital-copyright_ca/A1A1A1.response +0 -227
- data/spec/fixtures/digital-copyright_ca/G0C2Y0.response +0 -229
- data/spec/fixtures/digital-copyright_ca/H0H0H0.response +0 -243
- data/spec/fixtures/digital-copyright_ca/K0A1K0.response +0 -230
- data/spec/fixtures/digital-copyright_ca/T5S2B9.response +0 -233
- data/spec/fixtures/digital-copyright_ca/X1B1B1.response +0 -243
- data/spec/fixtures/elections_ca/A1A1A1.response +0 -10
- data/spec/fixtures/elections_ca/G0C2Y0.response +0 -11
- data/spec/fixtures/elections_ca/H0H0H0.response +0 -10
- data/spec/fixtures/elections_ca/K0A1K0.response +0 -10
- data/spec/fixtures/elections_ca/T5S2B9.response +0 -10
- data/spec/fixtures/elections_ca/X1B1B1.response +0 -10
- data/spec/fixtures/greenparty_ca/A1A1A1.response +0 -13
- data/spec/fixtures/greenparty_ca/G0C2Y0.response +0 -13
- data/spec/fixtures/greenparty_ca/H0H0H0.response +0 -13
- data/spec/fixtures/greenparty_ca/K0A1K0.response +0 -13
- data/spec/fixtures/greenparty_ca/T5S2B9.response +0 -13
- data/spec/fixtures/greenparty_ca/X1B1B1.response +0 -13
- data/spec/fixtures/liberal_ca/A1A1A1.response +0 -702
- data/spec/fixtures/liberal_ca/G0C2Y0.response +0 -570
- data/spec/fixtures/liberal_ca/H0H0H0.response +0 -649
- data/spec/fixtures/liberal_ca/K0A1K0.response +0 -650
- data/spec/fixtures/liberal_ca/T5S2B9.response +0 -570
- data/spec/fixtures/liberal_ca/X1B1B1.response +0 -649
- data/spec/fixtures/ndp_ca/A1A1A1.response +0 -610
- data/spec/fixtures/ndp_ca/G0C2Y0.response +0 -610
- data/spec/fixtures/ndp_ca/H0H0H0.response +0 -593
- data/spec/fixtures/ndp_ca/K0A1K0.response +0 -641
- data/spec/fixtures/ndp_ca/T5S2B9.response +0 -605
- data/spec/fixtures/ndp_ca/X1B1B1.response +0 -593
@@ -0,0 +1,279 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe GovKit::CA::Represent do
|
4
|
+
describe '#boundary_sets' do
|
5
|
+
let :api do
|
6
|
+
GovKit::CA::Represent.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return boundary sets' do
|
10
|
+
response = api.boundary_sets
|
11
|
+
response.should be_a(Hash)
|
12
|
+
response.should have_key('objects')
|
13
|
+
response.should have_key('meta')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return a boundary set' do
|
17
|
+
response = api.boundary_sets(:boundary_set => 'federal-electoral-districts')
|
18
|
+
response.should be_a(Hash)
|
19
|
+
response.should have_key('related')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should raise an error if the boundary set does not exist' do
|
23
|
+
expect{api.boundary_sets(:boundary_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 http://represent.opennorth.ca/boundary-sets/foo/?")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise an error if the limit is invalid' do
|
27
|
+
expect{api.boundary_sets(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/boundary-sets/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should raise an error if the offset is invalid' do
|
31
|
+
expect{api.boundary_sets(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/boundary-sets/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#representative_sets' do
|
36
|
+
let :api do
|
37
|
+
GovKit::CA::Represent.new
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return representative sets' do
|
41
|
+
response = api.representative_sets
|
42
|
+
response.should be_a(Hash)
|
43
|
+
response.should have_key('objects')
|
44
|
+
response.should have_key('meta')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should return a representative set' do
|
48
|
+
response = api.representative_sets(:representative_set => 'house-of-commons')
|
49
|
+
response.should be_a(Hash)
|
50
|
+
response.should have_key('related')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should raise an error if the representative set does not exist' do
|
54
|
+
expect{api.representative_sets(:representative_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 http://represent.opennorth.ca/representative-sets/foo/?")
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should raise an error if the limit is invalid' do
|
58
|
+
expect{api.representative_sets(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/representative-sets/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should raise an error if the offset is invalid' do
|
62
|
+
expect{api.representative_sets(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/representative-sets/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#postcodes' do
|
67
|
+
let :api do
|
68
|
+
GovKit::CA::Represent.new
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should query by postal code' do
|
72
|
+
response = api.postcodes('A1A1A1')
|
73
|
+
response.should be_a(Hash)
|
74
|
+
response.should have_key('code')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should accept an array of boundary sets' do
|
78
|
+
response = api.postcodes('A1A1A1', :sets => ['federal-electoral-districts', 'census-subdivisions'])
|
79
|
+
response.should be_a(Hash)
|
80
|
+
response['boundaries_centroid'].should have(2).items
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should accept a comma-separated list of boundary sets' do
|
84
|
+
response = api.postcodes('A1A1A1', :sets => 'federal-electoral-districts,census-subdivisions')
|
85
|
+
response.should be_a(Hash)
|
86
|
+
response['boundaries_centroid'].should have(2).items
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should raise an error if the postal code does not exist' do
|
90
|
+
expect{api.postcodes('foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 http://represent.opennorth.ca/postcodes/foo/?")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#boundaries' do
|
95
|
+
let :api do
|
96
|
+
GovKit::CA::Represent.new
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should return boundaries' do
|
100
|
+
response = api.boundaries
|
101
|
+
response.should be_a(Hash)
|
102
|
+
response.should have_key('objects')
|
103
|
+
response.should have_key('meta')
|
104
|
+
response['meta']['next'].should_not be_nil
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should return boundaries from a boundary set' do
|
108
|
+
response = api.boundaries(:boundary_set => 'st-johns-wards')
|
109
|
+
response.should be_a(Hash)
|
110
|
+
response.should have_key('objects')
|
111
|
+
response.should have_key('meta')
|
112
|
+
response['objects'].should have(5).items
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should return a boundary from a boundary set' do
|
116
|
+
response = api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'ward-1')
|
117
|
+
response.should be_a(Hash)
|
118
|
+
response.should have_key('related')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should return the representatives of a boundary from a boundary set' do
|
122
|
+
response = api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'ward-1', :representatives => true)
|
123
|
+
response.should be_a(Hash)
|
124
|
+
response.should have_key('objects')
|
125
|
+
response.should have_key('meta')
|
126
|
+
response['meta']['next'].should be_nil
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should return boundaries from many boundary sets as an array' do
|
130
|
+
response = api.boundaries(:sets => ['st-johns-wards','caledon-wards'])
|
131
|
+
response.should be_a(Hash)
|
132
|
+
response.should have_key('objects')
|
133
|
+
response.should have_key('meta')
|
134
|
+
response['objects'].should have(10).items
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should return boundaries from many boundary sets as a comma-separated list' do
|
138
|
+
response = api.boundaries(:sets => 'st-johns-wards,caledon-wards')
|
139
|
+
response.should be_a(Hash)
|
140
|
+
response.should have_key('objects')
|
141
|
+
response.should have_key('meta')
|
142
|
+
response['objects'].should have(10).items
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should accept a point as an array' do
|
146
|
+
response = api.boundaries(:contains => ['47.5699', '-52.6954'])
|
147
|
+
response.should be_a(Hash)
|
148
|
+
response.should have_key('objects')
|
149
|
+
response.should have_key('meta')
|
150
|
+
response['meta']['next'].should be_nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should accept a point as a comma-separated list' do
|
154
|
+
response = api.boundaries(:contains => '47.5699,-52.6954')
|
155
|
+
response.should be_a(Hash)
|
156
|
+
response.should have_key('objects')
|
157
|
+
response.should have_key('meta')
|
158
|
+
response['meta']['next'].should be_nil
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should raise an error if the point is invalid' do
|
162
|
+
expect{api.boundaries(:contains => '0,0,0')}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/boundaries/?contains=0,0,0 Invalid lat/lon values")
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should raise an error if the boundary set does not exist' do
|
166
|
+
expect{api.boundaries(:boundary_set => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 http://represent.opennorth.ca/boundaries/foo/?")
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'when retrieving a boundary' do
|
170
|
+
it 'should raise an error if the boundary set does not exist' do
|
171
|
+
expect{api.boundaries(:boundary_set => 'foo', :boundary => 'ward-1')}.to raise_error(GovKit::CA::ResourceNotFound, "404 http://represent.opennorth.ca/boundaries/foo/ward-1/?")
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should raise an error if the boundary does not exist' do
|
175
|
+
expect{api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'foo')}.to raise_error(GovKit::CA::ResourceNotFound, "404 http://represent.opennorth.ca/boundaries/st-johns-wards/foo/?")
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should raise an error if the boundary set is not given' do
|
179
|
+
expect{api.boundaries(:boundary => 'ward-1')}.to raise_error(ArgumentError, ':boundary_set must be set if :boundary is set')
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'when retrieving the representatives of a boundary' do
|
184
|
+
it 'should not raise an error if the boundary set does not exist' do
|
185
|
+
expect{api.boundaries(:boundary_set => 'foo', :boundary => 'ward-1', :representatives => true)}.to_not raise_error
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should not raise an error if the boundary does not exist' do
|
189
|
+
expect{api.boundaries(:boundary_set => 'st-johns-wards', :boundary => 'foo', :representatives => true)}.to_not raise_error
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should raise an error if the boundary set is not given' do
|
193
|
+
expect{api.boundaries(:representatives => true)}.to raise_error(ArgumentError, ':boundary_set and :boundary must be set if :representatives is true')
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'should raise an error if the boundary is not given' do
|
197
|
+
expect{api.boundaries(:boundary_set => 'st-johns-wards', :representatives => true)}.to raise_error(ArgumentError, ':boundary_set and :boundary must be set if :representatives is true')
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should raise an error if the limit is invalid' do
|
202
|
+
expect{api.boundaries(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/boundaries/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should raise an error if the offset is invalid' do
|
206
|
+
expect{api.boundaries(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/boundaries/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe '#representatives' do
|
211
|
+
let :api do
|
212
|
+
GovKit::CA::Represent.new
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should return representatives' do
|
216
|
+
response = api.representatives
|
217
|
+
response.should be_a(Hash)
|
218
|
+
response.should have_key('objects')
|
219
|
+
response.should have_key('meta')
|
220
|
+
response['meta']['next'].should_not be_nil
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should return representatives from a representative set' do
|
224
|
+
response = api.representatives(:representative_set => 'st-johns-city-council')
|
225
|
+
response.should be_a(Hash)
|
226
|
+
response.should have_key('objects')
|
227
|
+
response.should have_key('meta')
|
228
|
+
response['meta']['next'].should be_nil
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'should accept a point as an array' do
|
232
|
+
response = api.representatives(:point => ['47.5699', '-52.6954'])
|
233
|
+
response.should be_a(Hash)
|
234
|
+
response.should have_key('objects')
|
235
|
+
response.should have_key('meta')
|
236
|
+
response['meta']['next'].should be_nil
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'should accept a point as a comma-separated list' do
|
240
|
+
response = api.representatives(:point => '47.5699,-52.6954')
|
241
|
+
response.should be_a(Hash)
|
242
|
+
response.should have_key('objects')
|
243
|
+
response.should have_key('meta')
|
244
|
+
response['meta']['next'].should be_nil
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should accept an array of districts' do
|
248
|
+
response = api.representatives(:districts => ['federal-electoral-districts/10007', 'census-subdivisions/1001519'])
|
249
|
+
response.should be_a(Hash)
|
250
|
+
response.should have_key('objects')
|
251
|
+
response.should have_key('meta')
|
252
|
+
response['meta']['next'].should be_nil
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'should accept a comma-separated list of districts' do
|
256
|
+
response = api.representatives(:districts => 'federal-electoral-districts/10007,census-subdivisions/1001519')
|
257
|
+
response.should be_a(Hash)
|
258
|
+
response.should have_key('objects')
|
259
|
+
response.should have_key('meta')
|
260
|
+
response['meta']['next'].should be_nil
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'should raise an error if the point is invalid' do
|
264
|
+
expect{api.representatives(:point => '0,0,0')}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/representatives/?point=0,0,0 Invalid lat/lon values")
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should not raise an error if the representative set does not exist' do
|
268
|
+
expect{api.representatives(:representative_set => 'foo')}.to_not raise_error
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'should raise an error if the limit is invalid' do
|
272
|
+
expect{api.representatives(:limit => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/representatives/?limit=-1 Invalid limit '-1' provided. Please provide a positive integer >= 0.")
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'should raise an error if the offset is invalid' do
|
276
|
+
expect{api.representatives(:offset => -1)}.to raise_error(GovKit::CA::InvalidRequest, "400 http://represent.opennorth.ca/representatives/?offset=-1 Invalid offset '-1' provided. Please provide a positive integer >= 0.")
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,11 +4,8 @@ require 'coveralls'
|
|
4
4
|
Coveralls.wear!
|
5
5
|
|
6
6
|
require 'rspec'
|
7
|
-
require 'fakeweb'
|
8
7
|
require File.dirname(__FILE__) + '/../lib/gov_kit-ca'
|
9
8
|
|
10
|
-
FakeWeb.allow_net_connect = true
|
11
|
-
|
12
9
|
module Helpers
|
13
10
|
def fixture_path(*args)
|
14
11
|
File.join(File.dirname(__FILE__), 'fixtures', *args)
|
@@ -17,5 +14,5 @@ end
|
|
17
14
|
|
18
15
|
RSpec.configure do |config|
|
19
16
|
config.include Helpers
|
20
|
-
config.filter_run_excluding broken
|
17
|
+
config.filter_run_excluding :broken => true
|
21
18
|
end
|
data/spec/strategy_set_spec.rb
CHANGED
@@ -1,5 +1,58 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
describe GovKit::CA::PostalCode::StrategySet do
|
4
|
+
let :strategy do
|
5
|
+
Class.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#strategies' do
|
9
|
+
it 'should return the strategies' do
|
10
|
+
GovKit::CA::PostalCode::StrategySet.strategies[0..4].should == [
|
11
|
+
GovKit::CA::PostalCode::Strategy::ElectionsCa,
|
12
|
+
GovKit::CA::PostalCode::Strategy::NDPCa,
|
13
|
+
# GovKit::CA::PostalCode::Strategy::LiberalCa,
|
14
|
+
GovKit::CA::PostalCode::Strategy::GreenPartyCa,
|
15
|
+
GovKit::CA::PostalCode::Strategy::CBCCa,
|
16
|
+
GovKit::CA::PostalCode::Strategy::ConservativeCa,
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#register' do
|
22
|
+
it 'should append a strategy' do
|
23
|
+
GovKit::CA::PostalCode::StrategySet.register(strategy)
|
24
|
+
GovKit::CA::PostalCode::StrategySet.strategies.last.should == strategy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#run' do
|
29
|
+
it 'should run the strategies' do
|
30
|
+
GovKit::CA::PostalCode::StrategySet.run('A1A1A1').should == [10007]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with empty strategy set' do
|
35
|
+
before :each do
|
36
|
+
GovKit::CA::PostalCode::StrategySet.strategies.clear
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#strategies' do
|
40
|
+
it 'should return the strategies' do
|
41
|
+
GovKit::CA::PostalCode::StrategySet.strategies.should == []
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#register' do
|
46
|
+
it 'should add a strategy' do
|
47
|
+
GovKit::CA::PostalCode::StrategySet.register(strategy)
|
48
|
+
GovKit::CA::PostalCode::StrategySet.strategies.should == [strategy]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#run' do
|
53
|
+
it 'should raise an error' do
|
54
|
+
expect{GovKit::CA::PostalCode::StrategySet.run('A1A1A1')}.to raise_error(GovKit::CA::ResourceNotFound)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
5
58
|
end
|
data/tasks/tasks.rb
CHANGED
@@ -42,31 +42,3 @@ task :trim_postal_codes, :file do |t,args|
|
|
42
42
|
|
43
43
|
puts postal_codes.sort
|
44
44
|
end
|
45
|
-
|
46
|
-
desc "Generate RSpec fixtures"
|
47
|
-
task :generate_rspec_fixtures do |t,args|
|
48
|
-
require 'fileutils'
|
49
|
-
|
50
|
-
{ 'CBCCa' => 'cbc_ca',
|
51
|
-
'ConservativeCa' => 'conservative_ca',
|
52
|
-
'DigitalCopyrightCa' => 'digital-copyright_ca',
|
53
|
-
'ElectionsCa' => 'elections_ca',
|
54
|
-
'GreenPartyCa' => 'greenparty_ca',
|
55
|
-
'LiberalCa' => 'liberal_ca',
|
56
|
-
'NDPCa' => 'ndp_ca',
|
57
|
-
}.each do |const,path|
|
58
|
-
require "gov_kit-ca/postal_code/strategy/#{path}"
|
59
|
-
FileUtils.mkdir_p File.expand_path("../../spec/fixtures/#{path}", __FILE__)
|
60
|
-
|
61
|
-
%w(A1A1A1 G0C2Y0 T5S2B9 K0A1K0 H0H0H0 X1B1B1).each do |postal_code|
|
62
|
-
File.open(File.expand_path("../../spec/fixtures/#{path}/#{postal_code}.response", __FILE__), 'w') do |f|
|
63
|
-
response = GovKit::CA::PostalCode::Strategy.const_get(const).new(postal_code).send(:response)
|
64
|
-
f.write "HTTP/#{response.http_version} #{response.code} #{response.message}\n"
|
65
|
-
response.headers.each_capitalized do |name,value|
|
66
|
-
f.write "#{name}: #{value}\n"
|
67
|
-
end
|
68
|
-
f.write "\n#{response.body}"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|