govkit-ca 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +4 -0
  3. data/README.md +1 -1
  4. data/govkit-ca.gemspec +4 -2
  5. data/lib/gov_kit-ca/postal_code/strategy/cbc_ca.rb +1 -1
  6. data/lib/gov_kit-ca/postal_code/strategy/conservative_ca.rb +3 -4
  7. data/lib/gov_kit-ca/postal_code/strategy/elections_ca.rb +4 -6
  8. data/lib/gov_kit-ca/postal_code/strategy/liberal_ca.rb +0 -1
  9. data/lib/gov_kit-ca/postal_code/strategy/parl_gc_ca.rb +5 -1
  10. data/lib/gov_kit-ca/postal_code.rb +19 -7
  11. data/lib/gov_kit-ca/represent.rb +108 -0
  12. data/lib/gov_kit-ca/version.rb +1 -1
  13. data/lib/gov_kit-ca.rb +2 -1
  14. data/spec/cbc_ca_spec.rb +14 -25
  15. data/spec/conservative_ca_spec.rb +1 -10
  16. data/spec/digital-copyright_ca_spec.rb +0 -9
  17. data/spec/elections_ca_spec.rb +0 -9
  18. data/spec/greenparty_ca_spec.rb +0 -9
  19. data/spec/liberal_ca_spec.rb +1 -10
  20. data/spec/ndp_ca_spec.rb +0 -9
  21. data/spec/parl_gc_ca_spec.rb +8 -0
  22. data/spec/postal_code_spec.rb +69 -87
  23. data/spec/represent_spec.rb +279 -0
  24. data/spec/spec_helper.rb +1 -4
  25. data/spec/strategy_set_spec.rb +55 -2
  26. data/tasks/tasks.rb +0 -28
  27. metadata +47 -133
  28. data/spec/fixtures/cbc_ca/A1A1A1.response +0 -11
  29. data/spec/fixtures/cbc_ca/G0C2Y0.response +0 -11
  30. data/spec/fixtures/cbc_ca/H0H0H0.response +0 -11
  31. data/spec/fixtures/cbc_ca/K0A1K0.response +0 -11
  32. data/spec/fixtures/cbc_ca/T5S2B9.response +0 -11
  33. data/spec/fixtures/cbc_ca/X1B1B1.response +0 -11
  34. data/spec/fixtures/conservative_ca/A1A1A1.response +0 -452
  35. data/spec/fixtures/conservative_ca/G0C2Y0.response +0 -452
  36. data/spec/fixtures/conservative_ca/H0H0H0.response +0 -452
  37. data/spec/fixtures/conservative_ca/K0A1K0.response +0 -455
  38. data/spec/fixtures/conservative_ca/T5S2B9.response +0 -453
  39. data/spec/fixtures/conservative_ca/X1B1B1.response +0 -452
  40. data/spec/fixtures/digital-copyright_ca/A1A1A1.response +0 -227
  41. data/spec/fixtures/digital-copyright_ca/G0C2Y0.response +0 -229
  42. data/spec/fixtures/digital-copyright_ca/H0H0H0.response +0 -243
  43. data/spec/fixtures/digital-copyright_ca/K0A1K0.response +0 -230
  44. data/spec/fixtures/digital-copyright_ca/T5S2B9.response +0 -233
  45. data/spec/fixtures/digital-copyright_ca/X1B1B1.response +0 -243
  46. data/spec/fixtures/elections_ca/A1A1A1.response +0 -10
  47. data/spec/fixtures/elections_ca/G0C2Y0.response +0 -11
  48. data/spec/fixtures/elections_ca/H0H0H0.response +0 -10
  49. data/spec/fixtures/elections_ca/K0A1K0.response +0 -10
  50. data/spec/fixtures/elections_ca/T5S2B9.response +0 -10
  51. data/spec/fixtures/elections_ca/X1B1B1.response +0 -10
  52. data/spec/fixtures/greenparty_ca/A1A1A1.response +0 -13
  53. data/spec/fixtures/greenparty_ca/G0C2Y0.response +0 -13
  54. data/spec/fixtures/greenparty_ca/H0H0H0.response +0 -13
  55. data/spec/fixtures/greenparty_ca/K0A1K0.response +0 -13
  56. data/spec/fixtures/greenparty_ca/T5S2B9.response +0 -13
  57. data/spec/fixtures/greenparty_ca/X1B1B1.response +0 -13
  58. data/spec/fixtures/liberal_ca/A1A1A1.response +0 -702
  59. data/spec/fixtures/liberal_ca/G0C2Y0.response +0 -570
  60. data/spec/fixtures/liberal_ca/H0H0H0.response +0 -649
  61. data/spec/fixtures/liberal_ca/K0A1K0.response +0 -650
  62. data/spec/fixtures/liberal_ca/T5S2B9.response +0 -570
  63. data/spec/fixtures/liberal_ca/X1B1B1.response +0 -649
  64. data/spec/fixtures/ndp_ca/A1A1A1.response +0 -610
  65. data/spec/fixtures/ndp_ca/G0C2Y0.response +0 -610
  66. data/spec/fixtures/ndp_ca/H0H0H0.response +0 -593
  67. data/spec/fixtures/ndp_ca/K0A1K0.response +0 -641
  68. data/spec/fixtures/ndp_ca/T5S2B9.response +0 -605
  69. data/spec/fixtures/ndp_ca/X1B1B1.response +0 -593
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e88d9a36dfcf9ce1825f8a204c801d2c3c902ee
4
+ data.tar.gz: 527b1088c8bffbd00458b6e7855c3e365994fbb6
5
+ SHA512:
6
+ metadata.gz: 3cb1d44087529a014496717a00a38435f66aa1db7e02dddc7ecfb3a78d958e2f0f754a449a33329d73123690ed7178d99faf9ea19e4d630dc46c95e08a4f0596
7
+ data.tar.gz: 9a46ef38c43306f7c733dd8eb105d4e6b03c39a3db644c4b205e26820a3f0e6a60928e87feeb4abd7f6dbc93f4a69402bb1b04fe89e28f19af7e21ce89b3c859
data/.travis.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.8.7
4
+ - 1.9.2
3
5
  - 1.9.3
6
+ - 2.0.0
7
+ - ree
data/README.md CHANGED
@@ -50,4 +50,4 @@ GovKit-CA interoperates with [Participatory Politics Foundation](http://www.part
50
50
 
51
51
  This gem's main repository is on GitHub: [http://github.com/opennorth/govkit-ca](http://github.com/opennorth/govkit-ca), where your contributions, forks, bug reports, feature requests, and feedback are greatly welcomed.
52
52
 
53
- Copyright (c) 2011 Open North Inc., released under the MIT license
53
+ Copyright (c) 2011-2013 Open North Inc., released under the MIT license
data/govkit-ca.gemspec CHANGED
@@ -12,17 +12,19 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{GovKit-CA lets you quickly get encapsulated Ruby objects for Canadian civic data.}
13
13
 
14
14
  s.rubyforge_project = "govkit-ca"
15
+ s.license = 'MIT'
15
16
 
16
17
  s.files = `git ls-files`.split("\n")
17
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
20
  s.require_paths = ["lib"]
20
21
 
22
+ s.add_runtime_dependency('faraday')
21
23
  s.add_runtime_dependency('httparty', '~> 0.10.0')
22
24
  s.add_runtime_dependency('nokogiri', '~> 1.5.0')
23
- s.add_runtime_dependency('yajl-ruby', '~> 0.8.2')
25
+ s.add_development_dependency('json')
24
26
  s.add_development_dependency('rspec', '~> 2.6.0')
25
- s.add_development_dependency('fakeweb', '~> 1.3.0')
26
27
  s.add_development_dependency('rake')
27
28
  s.add_development_dependency('coveralls')
29
+ s.add_development_dependency('mime-types', '~> 1.16')
28
30
  end
@@ -10,7 +10,7 @@ module GovKit
10
10
  private
11
11
 
12
12
  def electoral_districts!
13
- Yajl::Parser.parse(response.parsed_response).map{|x| self.class.rid_to_edid[x['rid'].to_i]}
13
+ JSON.load(response.parsed_response).map{|x| self.class.rid_to_edid[x['rid'].to_i]}
14
14
  end
15
15
 
16
16
  def valid?
@@ -4,9 +4,8 @@ module GovKit
4
4
  module Strategy
5
5
  class ConservativeCa < Base
6
6
  base_uri 'www.conservative.ca'
7
- http_method :post
8
- path '/?page_id=35'
9
- post_data 'findmymp=35&pc=<%= @postal_code %>'
7
+ http_method :get
8
+ path '/wp-content/themes/conservative/functions-process.php?x=vldpc&fpc=<%= @postal_code %>'
10
9
 
11
10
  private
12
11
 
@@ -19,7 +18,7 @@ module GovKit
19
18
  end
20
19
 
21
20
  def images
22
- @document ||= Nokogiri::HTML(response.parsed_response, nil, 'utf-8').css('#type img')
21
+ @images ||= Nokogiri::HTML(response.parsed_response, nil, 'utf-8').css('img')
23
22
  end
24
23
  end
25
24
 
@@ -2,13 +2,11 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  module Strategy
5
- # elections.ca is a reliable source, but it does not return electoral
6
- # districts for postal codes that contain multiple electoral districts.
7
- # @see https://github.com/danielharan/postal_code_to_edid_webservice
8
5
  class ElectionsCa < Base
9
6
  base_uri 'elections.ca'
10
- http_method :head
11
- path '/scripts/pss/FindED.aspx?PC=<%= @postal_code %>'
7
+ http_method :post
8
+ path '/Scripts/vis/FindED'
9
+ post_data 'CommonSearchTxt=<%= @postal_code %>'
12
10
 
13
11
  private
14
12
 
@@ -17,7 +15,7 @@ module GovKit
17
15
  end
18
16
 
19
17
  def valid?
20
- !!response.headers['location']
18
+ !response.headers['location'][/EDNotFound|MultipleEDs/]
21
19
  end
22
20
  end
23
21
 
@@ -2,7 +2,6 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  module Strategy
5
- # liberal.ca seems unreliable. It returns three ridings for K0A1K0.
6
5
  class LiberalCa < Base
7
6
  follow_redirects true
8
7
  base_uri 'www.liberal.ca'
@@ -14,7 +14,11 @@ module GovKit
14
14
  end
15
15
 
16
16
  def valid?
17
- # @todo
17
+ !!div
18
+ end
19
+
20
+ def div
21
+ @div ||= Nokogiri::HTML(response.parsed_response, nil, 'utf-8').at_css('#ctl00_cphContent_pnlWithMP')
18
22
  end
19
23
  end
20
24
 
@@ -79,14 +79,26 @@ end
79
79
 
80
80
  require 'gov_kit-ca/postal_code/strategy_set'
81
81
  require 'gov_kit-ca/postal_code/strategy/base'
82
- #require 'gov_kit-ca/postal_code/strategy/parl_gc_ca' # only riding name
83
- require 'gov_kit-ca/postal_code/strategy/elections_ca' # only one-to-one
82
+
83
+ # Only riding name and not implemented.
84
+ # require 'gov_kit-ca/postal_code/strategy/parl_gc_ca'
85
+
86
+ # Only one-to-one.
87
+ require 'gov_kit-ca/postal_code/strategy/elections_ca'
88
+
84
89
  require 'gov_kit-ca/postal_code/strategy/ndp_ca'
85
- require 'gov_kit-ca/postal_code/strategy/liberal_ca' # incomplete database
86
- require 'gov_kit-ca/postal_code/strategy/greenparty_ca' # only one-to-one
87
- require 'gov_kit-ca/postal_code/strategy/cbc_ca' # disagrees with elections.ca
88
90
 
89
- # If not held by Conservative MP, returns only riding name.
91
+ # Only one-to-one.
92
+ require 'gov_kit-ca/postal_code/strategy/greenparty_ca'
93
+
94
+ # Only riding name if not held by a Conservative MP.
90
95
  # require 'gov_kit-ca/postal_code/strategy/conservative_ca'
91
- # Returns too many or too few ridings.
96
+
97
+ # 2014-02-12: Occasionally renders HTML instead of redirect.
98
+ # require 'gov_kit-ca/postal_code/strategy/liberal_ca'
99
+
100
+ # 2014-02-12: Broken until next election.
101
+ # require 'gov_kit-ca/postal_code/strategy/cbc_ca'
102
+
103
+ # Too many or too few ridings.
92
104
  # require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
@@ -0,0 +1,108 @@
1
+ module GovKit
2
+ module CA
3
+ # A Ruby wrapper for the Represent API.
4
+ # @see http://represent.opennorth.ca/api/
5
+ class Represent
6
+ # Get boundary sets.
7
+ #
8
+ # @param [Hash] opts optional arguments
9
+ # @option opts [String] :boundary_set a boundary set
10
+ # @option opts [Integer] :limit
11
+ # @option opts [Integer] :offset
12
+ # @see http://represent.opennorth.ca/api/#boundaryset
13
+ def boundary_sets(opts = {})
14
+ request(['boundary-sets', opts.delete(:boundary_set)], opts)
15
+ end
16
+
17
+ # Get boundaries.
18
+ #
19
+ # @param [Hash] opts optional arguments
20
+ # @option opts [String] :boundary_set a boundary set
21
+ # @option opts [String] :boundary a boundary
22
+ # @option opts [Boolean] :representatives
23
+ # @option opts [Array<String>,String] :sets comma-separated list of boundary sets
24
+ # @option opts [Array<Float>,String] :contains comma-separated latitude and longitude
25
+ # @option opts [String] :touches a boundary
26
+ # @option opts [String] :intersects a boundary
27
+ # @option opts [Integer] :limit
28
+ # @option opts [Integer] :offset
29
+ # @see http://represent.opennorth.ca/api/#boundary
30
+ def boundaries(opts = {})
31
+ if Array === opts[:sets]
32
+ opts[:sets] = opts[:sets].join(',')
33
+ end
34
+ if Array === opts[:contains]
35
+ opts[:contains] = opts[:contains].join(',')
36
+ end
37
+ if opts.has_key?(:boundary) && !opts.has_key?(:boundary_set)
38
+ raise ArgumentError, ':boundary_set must be set if :boundary is set'
39
+ end
40
+ if opts[:representatives] && !(opts.has_key?(:boundary) && opts.has_key?(:boundary_set))
41
+ raise ArgumentError, ':boundary_set and :boundary must be set if :representatives is true'
42
+ end
43
+ request(['boundaries', opts.delete(:boundary_set), opts.delete(:boundary), opts.delete(:representatives) && 'representatives'], opts)
44
+ end
45
+
46
+ # Get boundaries and representatives by postal code.
47
+ #
48
+ # @param [Hash] opts optional arguments
49
+ # @option opts [Array<String>,String] :sets comma-separated list of boundary sets
50
+ # @option opts [Integer] :limit
51
+ # @option opts [Integer] :offset
52
+ # @see http://represent.opennorth.ca/api/#postcode
53
+ def postcodes(postcode, opts = {})
54
+ if Array === opts[:sets]
55
+ opts[:sets] = opts[:sets].join(',')
56
+ end
57
+ request(['postcodes', postcode], opts)
58
+ end
59
+
60
+ # Get representative sets.
61
+ #
62
+ # @param [Hash] opts optional arguments
63
+ # @option opts [String] :representative_set a representative set
64
+ # @option opts [Integer] :limit
65
+ # @option opts [Integer] :offset
66
+ # @see http://represent.opennorth.ca/api/#representativeset
67
+ def representative_sets(opts = {})
68
+ request ['representative-sets', opts.delete(:representative_set)], opts
69
+ end
70
+
71
+ # Get representatives.
72
+ #
73
+ # @param [Hash] opts optional arguments
74
+ # @option opts [String] :representative_set a representative set
75
+ # @option opts [Array<Float>,String] :point a comma-separated latitude and longitude
76
+ # @option opts [Array<Strong>,String] :districts a comma-separated list of boundaries
77
+ # @option opts [Integer] :limit
78
+ # @option opts [Integer] :offset
79
+ # @see http://represent.opennorth.ca/api/#representative
80
+ def representatives(opts = {})
81
+ if Array === opts[:point]
82
+ opts[:point] = opts[:point].join(',')
83
+ end
84
+ if Array === opts[:districts]
85
+ opts[:districts] = opts[:districts].join(',')
86
+ end
87
+ request(['representatives', opts.delete(:representative_set)], opts)
88
+ end
89
+
90
+ private
91
+
92
+ def request(parts, opts)
93
+ begin
94
+ url = "http://represent.opennorth.ca/#{parts.compact.join('/')}/"
95
+ response = Faraday.get(url, opts)
96
+ case response.status
97
+ when 200
98
+ JSON.parse(response.body)
99
+ when 404
100
+ raise ResourceNotFound, "#{response.status} #{url}?#{opts.map{|k,v| "#{k}=#{v}"}.join('&')}"
101
+ else
102
+ raise InvalidRequest, "#{response.status} #{url}?#{opts.map{|k,v| "#{k}=#{v}"}.join('&')} #{response.body}"
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -1,5 +1,5 @@
1
1
  module GovKit
2
2
  module CA
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/lib/gov_kit-ca.rb CHANGED
@@ -2,9 +2,9 @@ require 'erb'
2
2
  require 'json'
3
3
  require 'yaml'
4
4
 
5
+ require 'faraday'
5
6
  require 'httparty'
6
7
  require 'nokogiri'
7
- require 'yajl'
8
8
 
9
9
  module GovKit
10
10
  module CA
@@ -15,3 +15,4 @@ module GovKit
15
15
  end
16
16
 
17
17
  require 'gov_kit-ca/postal_code'
18
+ require 'gov_kit-ca/represent'
data/spec/cbc_ca_spec.rb CHANGED
@@ -1,34 +1,23 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'gov_kit-ca/postal_code/strategy/cbc_ca'
3
3
 
4
- class GovKit::CA::PostalCode::Strategy::CBCCa
5
- describe GovKit::CA::PostalCode::Strategy::CBCCa do
6
- describe '#electoral_districts' do
7
- before :all do
8
- %w(G0C2Y0 T5S2B9 K0A1K0 H0H0H0 X1B1B1).each do |postal_code|
9
- strategy = GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code)
10
- unless FakeWeb.allow_net_connect?
11
- FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('cbc_ca', "#{postal_code}.response")
12
- end
13
- end
14
- end
15
-
16
- it 'should return the electoral districts within a postal code' do
17
- { 'G0C2Y0' => [24019],
18
- 'T5S2B9' => [48015, 48017],
19
- 'K0A1K0' => [35025, 35052, 35063, 35064],
20
- }.each do |postal_code,electoral_districts|
21
- GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code).electoral_districts.should == electoral_districts
22
- end
4
+ describe GovKit::CA::PostalCode::Strategy::CBCCa do
5
+ describe '#electoral_districts', :broken => true do
6
+ it 'should return the electoral districts within a postal code' do
7
+ { 'G0C2Y0' => [24019],
8
+ 'T5S2B9' => [48015, 48017],
9
+ 'K0A1K0' => [35025, 35052, 35063, 35064],
10
+ }.each do |postal_code,electoral_districts|
11
+ GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code).electoral_districts.should == electoral_districts
23
12
  end
13
+ end
24
14
 
25
- it 'should return false if a postal code contains no electoral districts' do
26
- GovKit::CA::PostalCode::Strategy::CBCCa.new('H0H0H0').electoral_districts.should be_false
27
- end
15
+ it 'should return false if a postal code contains no electoral districts' do
16
+ GovKit::CA::PostalCode::Strategy::CBCCa.new('H0H0H0').electoral_districts.should be_false
17
+ end
28
18
 
29
- it 'should return false if a postal code does not exist' do
30
- GovKit::CA::PostalCode::Strategy::CBCCa.new('X1B1B1').electoral_districts.should be_false
31
- end
19
+ it 'should return false if a postal code does not exist' do
20
+ GovKit::CA::PostalCode::Strategy::CBCCa.new('X1B1B1').electoral_districts.should be_false
32
21
  end
33
22
  end
34
23
  end
@@ -3,17 +3,8 @@ require 'gov_kit-ca/postal_code/strategy/conservative_ca'
3
3
 
4
4
  describe GovKit::CA::PostalCode::Strategy::ConservativeCa do
5
5
  describe '#electoral_districts' do
6
- before :all do
7
- %w(G0C2Y0 T5S2B9 K0A1K0 H0H0H0 X1B1B1).each do |postal_code|
8
- strategy = GovKit::CA::PostalCode::Strategy::ConservativeCa.new(postal_code)
9
- unless FakeWeb.allow_net_connect?
10
- FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('digital-copyright_ca', "#{postal_code}.response")
11
- end
12
- end
13
- end
14
-
15
6
  it 'should return the electoral districts within a postal code' do
16
- { 'T5S2B9' => [48015],
7
+ { 'T1P1K1' => [48010],
17
8
  'K0A1K0' => [35025, 35052, 35063],
18
9
  # returns nothing for B0J2L0
19
10
  }.each do |postal_code,electoral_districts|
@@ -3,15 +3,6 @@ require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
3
3
 
4
4
  describe GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa do
5
5
  describe '#electoral_districts' do
6
- before :all do
7
- %w(G0C2Y0 T5S2B9 K0A1K0 H0H0H0 X1B1B1).each do |postal_code|
8
- strategy = GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new(postal_code)
9
- unless FakeWeb.allow_net_connect?
10
- FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('digital-copyright_ca', "#{postal_code}.response")
11
- end
12
- end
13
- end
14
-
15
6
  it 'should return the electoral districts within a postal code' do
16
7
  { 'G0C2Y0' => [24019, 24039], # differs from all
17
8
  'T5S2B9' => [48012, 48013, 48014, 48015, 48017, 48018], # differs from all
@@ -3,15 +3,6 @@ require 'gov_kit-ca/postal_code/strategy/elections_ca'
3
3
 
4
4
  describe GovKit::CA::PostalCode::Strategy::ElectionsCa do
5
5
  describe '#electoral_districts' do
6
- before :all do
7
- %w(G0C2Y0 T5S2B9 K0A1K0 H0H0H0 X1B1B1).each do |postal_code|
8
- strategy = GovKit::CA::PostalCode::Strategy::ElectionsCa.new(postal_code)
9
- unless FakeWeb.allow_net_connect?
10
- FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('elections_ca', "#{postal_code}.response")
11
- end
12
- end
13
- end
14
-
15
6
  it 'should return the electoral districts within a postal code' do
16
7
  { 'G0C2Y0' => [24019],
17
8
  # returns nothing for T5S2B9
@@ -3,15 +3,6 @@ require 'gov_kit-ca/postal_code/strategy/greenparty_ca'
3
3
 
4
4
  describe GovKit::CA::PostalCode::Strategy::GreenPartyCa do
5
5
  describe '#electoral_districts' do
6
- before :all do
7
- %w(G0C2Y0 T5S2B9 K0A1K0 H0H0H0 X1B1B1).each do |postal_code|
8
- strategy = GovKit::CA::PostalCode::Strategy::GreenPartyCa.new(postal_code)
9
- unless FakeWeb.allow_net_connect?
10
- FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('greenparty_ca', "#{postal_code}.response")
11
- end
12
- end
13
- end
14
-
15
6
  it 'should return the electoral districts within a postal code' do
16
7
  { 'G0C2Y0' => [24019],
17
8
  'T5S2B9' => [48015],
@@ -2,16 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'gov_kit-ca/postal_code/strategy/liberal_ca'
3
3
 
4
4
  describe GovKit::CA::PostalCode::Strategy::LiberalCa do
5
- describe '#electoral_districts' do
6
- before :all do
7
- %w(G0C2Y0 T5S2B9 K0A1K0 H0H0H0 X1B1B1).each do |postal_code|
8
- strategy = GovKit::CA::PostalCode::Strategy::LiberalCa.new(postal_code)
9
- unless FakeWeb.allow_net_connect?
10
- FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('liberal_ca', "#{postal_code}.response")
11
- end
12
- end
13
- end
14
-
5
+ describe '#electoral_districts', :broken => true do
15
6
  it 'should return the electoral districts within a postal code' do
16
7
  { 'G0C2Y0' => [24019],
17
8
  'T5S2B9' => [48015],
data/spec/ndp_ca_spec.rb CHANGED
@@ -3,15 +3,6 @@ require 'gov_kit-ca/postal_code/strategy/ndp_ca'
3
3
 
4
4
  describe GovKit::CA::PostalCode::Strategy::NDPCa do
5
5
  describe '#electoral_districts' do
6
- before :all do
7
- %w(G0C2Y0 T5S2B9 K0A1K0 H0H0H0 X1B1B1).each do |postal_code|
8
- strategy = GovKit::CA::PostalCode::Strategy::NDPCa.new(postal_code)
9
- unless FakeWeb.allow_net_connect?
10
- FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('ndp_ca', "#{postal_code}.response")
11
- end
12
- end
13
- end
14
-
15
6
  it 'should return the electoral districts within a postal code' do
16
7
  { 'G0C2Y0' => [24019],
17
8
  'T5S2B9' => [48015],
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'gov_kit-ca/postal_code/strategy/parl_gc_ca'
3
+
4
+ describe GovKit::CA::PostalCode::Strategy::ParlGcCa do
5
+ describe '#electoral_districts' do
6
+ pending
7
+ end
8
+ end
@@ -1,106 +1,88 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- module GovKit::CA::PostalCode
4
- describe GovKit::CA::PostalCode do
5
- describe '#valid?' do
6
- it 'should return false if the postal code is not properly formatted' do
7
- [ 'A1A1A', # too short
8
- 'A1A1A1A', # too long
9
- "A1A1A1\nA1A1A1", # multiline
10
- 'AAAAAA', # no digits
11
- '111111', # no letters
12
- '1A1A1A', # wrong order
13
- 'Z1Z1Z1', # Z as first letter
14
- 'Q1Q1Q1', # Q as letter
15
- 'a1a1a1', # lowercase
16
- ].each do |postal_code|
17
- subject.valid?(postal_code).should be_false
18
- end
19
- end
20
-
21
- it 'should return true if the postal code is properly formatted' do
22
- [ 'A1Z1Z1', # Z not as first letter
23
- 'H0H0H0', # doesn't exist
24
- 'A1A1A1', # does exist
25
- ].each do |postal_code|
26
- subject.valid?(postal_code).should be_true
27
- end
3
+ describe GovKit::CA::PostalCode do
4
+ describe '#valid?' do
5
+ it 'should return false if the postal code is not properly formatted' do
6
+ [ 'A1A1A', # too short
7
+ 'A1A1A1A', # too long
8
+ "A1A1A1\nA1A1A1", # multiline
9
+ 'AAAAAA', # no digits
10
+ '111111', # no letters
11
+ '1A1A1A', # wrong order
12
+ 'Z1Z1Z1', # Z as first letter
13
+ 'Q1Q1Q1', # Q as letter
14
+ 'a1a1a1', # lowercase
15
+ ].each do |postal_code|
16
+ subject.valid?(postal_code).should be_false
28
17
  end
29
18
  end
30
19
 
31
- describe '#find_electoral_districts_by_postal_code' do
32
- before :all do
33
- { 'ElectionsCa' => 'elections_ca',
34
- 'CBCCa' => 'cbc_ca',
35
- 'NDPCa' => 'ndp_ca',
36
- # GreenPartyCa is broken.
37
- #'GreenPartyCa' => 'greenparty_ca',
38
- }.each do |const,path|
39
- %w(A1A1A1 K0A1K0 H0H0H0).each do |postal_code|
40
- strategy = GovKit::CA::PostalCode::Strategy.const_get(const).new(postal_code)
41
- unless FakeWeb.allow_net_connect?
42
- FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path(path, "#{postal_code}.response")
43
- end
44
- end
45
- end
20
+ it 'should return true if the postal code is properly formatted' do
21
+ [ 'A1Z1Z1', # Z not as first letter
22
+ 'H0H0H0', # doesn't exist
23
+ 'A1A1A1', # does exist
24
+ ].each do |postal_code|
25
+ subject.valid?(postal_code).should be_true
46
26
  end
27
+ end
28
+ end
47
29
 
48
- it 'should return the electoral districts within a postal code' do
49
- { 'A1A1A1' => [10007],
50
- 'K0A1K0' => [35012, 35025, 35040, 35052],
51
- }.each do |postal_code,electoral_districts|
52
- subject.find_electoral_districts_by_postal_code(postal_code).should == electoral_districts
53
- end
30
+ describe '#find_electoral_districts_by_postal_code' do
31
+ it 'should return the electoral districts within a postal code' do
32
+ { 'A1A1A1' => [10007],
33
+ 'K0A1K0' => [35012, 35025, 35040, 35052],
34
+ }.each do |postal_code,electoral_districts|
35
+ subject.find_electoral_districts_by_postal_code(postal_code).should == electoral_districts
54
36
  end
37
+ end
55
38
 
56
- it 'should raise an error if the postal code cannot be determined' do
57
- lambda{subject.find_electoral_districts_by_postal_code('H0H0H0')}.should raise_error(GovKit::CA::ResourceNotFound)
58
- end
39
+ it 'should raise an error if the postal code cannot be determined' do
40
+ lambda{subject.find_electoral_districts_by_postal_code('H0H0H0')}.should raise_error(GovKit::CA::ResourceNotFound)
41
+ end
59
42
 
60
- it 'should raise an error if the postal code is invalid' do
61
- lambda{subject.find_electoral_districts_by_postal_code('AAAAAA')}.should raise_error(GovKit::CA::InvalidRequest)
62
- end
43
+ it 'should raise an error if the postal code is invalid' do
44
+ lambda{subject.find_electoral_districts_by_postal_code('AAAAAA')}.should raise_error(GovKit::CA::InvalidRequest)
63
45
  end
46
+ end
64
47
 
65
- describe '#find_province_by_postal_code' do
66
- it 'should return the province that a postal code belongs to' do
67
- { 'A' => 'Newfoundland and Labrador',
68
- 'B' => 'Nova Scotia',
69
- 'C' => 'Prince Edward Island',
70
- 'E' => 'New Brunswick',
71
- 'G' => 'Quebec',
72
- 'H' => 'Quebec',
73
- 'J' => 'Quebec',
74
- 'K' => 'Ontario',
75
- 'L' => 'Ontario',
76
- 'M' => 'Ontario',
77
- 'N' => 'Ontario',
78
- 'P' => 'Ontario',
79
- 'R' => 'Manitoba',
80
- 'S' => 'Saskatchewan',
81
- 'T' => 'Alberta',
82
- 'V' => 'British Columbia',
83
- 'X0A' => 'Nunavut',
84
- 'X0B' => 'Nunavut',
85
- 'X0C' => 'Nunavut',
86
- 'X0E' => 'Northwest Territories',
87
- 'X0G' => 'Northwest Territories',
88
- 'X1A' => 'Northwest Territories',
89
- 'Y' => 'Yukon',
90
- }.each do |postal_code, province|
91
- subject.find_province_by_postal_code(postal_code).should == province
92
- end
48
+ describe '#find_province_by_postal_code' do
49
+ it 'should return the province that a postal code belongs to' do
50
+ { 'A' => 'Newfoundland and Labrador',
51
+ 'B' => 'Nova Scotia',
52
+ 'C' => 'Prince Edward Island',
53
+ 'E' => 'New Brunswick',
54
+ 'G' => 'Quebec',
55
+ 'H' => 'Quebec',
56
+ 'J' => 'Quebec',
57
+ 'K' => 'Ontario',
58
+ 'L' => 'Ontario',
59
+ 'M' => 'Ontario',
60
+ 'N' => 'Ontario',
61
+ 'P' => 'Ontario',
62
+ 'R' => 'Manitoba',
63
+ 'S' => 'Saskatchewan',
64
+ 'T' => 'Alberta',
65
+ 'V' => 'British Columbia',
66
+ 'X0A' => 'Nunavut',
67
+ 'X0B' => 'Nunavut',
68
+ 'X0C' => 'Nunavut',
69
+ 'X0E' => 'Northwest Territories',
70
+ 'X0G' => 'Northwest Territories',
71
+ 'X1A' => 'Northwest Territories',
72
+ 'Y' => 'Yukon',
73
+ }.each do |postal_code, province|
74
+ subject.find_province_by_postal_code(postal_code).should == province
93
75
  end
76
+ end
94
77
 
95
- it 'should raise an error if the province cannot be determined' do
96
- lambda{subject.find_province_by_postal_code('X1B1B1')}.should raise_error(GovKit::CA::ResourceNotFound)
97
- end
78
+ it 'should raise an error if the province cannot be determined' do
79
+ lambda{subject.find_province_by_postal_code('X1B1B1')}.should raise_error(GovKit::CA::ResourceNotFound)
98
80
  end
81
+ end
99
82
 
100
- describe '#format_postal_code' do
101
- it 'should format a postal code' do
102
- subject.format_postal_code("+a1a 1a1\n").should == 'A1A1A1'
103
- end
83
+ describe '#format_postal_code' do
84
+ it 'should format a postal code' do
85
+ subject.format_postal_code("+a1a 1a1\n").should == 'A1A1A1'
104
86
  end
105
87
  end
106
88
  end