govkit-ca 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.travis.yml +3 -0
  2. data/README.md +5 -1
  3. data/govkit-ca.gemspec +1 -0
  4. data/lib/gov_kit-ca/postal_code/strategy/base.rb +20 -1
  5. data/lib/gov_kit-ca/postal_code/strategy/cbc_ca.rb +1 -3
  6. data/lib/gov_kit-ca/postal_code/strategy/conservative_ca.rb +9 -6
  7. data/lib/gov_kit-ca/postal_code/strategy/digital-copyright_ca.rb +0 -3
  8. data/lib/gov_kit-ca/postal_code/strategy/greenparty_ca.rb +3 -6
  9. data/lib/gov_kit-ca/postal_code/strategy/ndp_ca.rb +4 -6
  10. data/lib/gov_kit-ca/postal_code/strategy/parl_gc_ca.rb +0 -1
  11. data/lib/gov_kit-ca/postal_code.rb +7 -5
  12. data/lib/gov_kit-ca/version.rb +1 -1
  13. data/lib/gov_kit-ca.rb +0 -2
  14. data/spec/cbc_ca_spec.rb +2 -2
  15. data/spec/conservative_ca_spec.ca +36 -0
  16. data/spec/digital-copyright_ca_spec.rb +21 -22
  17. data/spec/elections_ca_spec.rb +23 -24
  18. data/spec/greenparty_ca_spec.rb +23 -24
  19. data/spec/liberal_ca_spec.rb +24 -22
  20. data/spec/ndp_ca_spec.rb +21 -24
  21. data/spec/postal_code_spec.rb +3 -2
  22. metadata +58 -109
  23. data/spec/fixtures/cbc_ca/A1A1A1.response +0 -11
  24. data/spec/fixtures/cbc_ca/G0C2Y0.response +0 -11
  25. data/spec/fixtures/cbc_ca/H0H0H0.response +0 -11
  26. data/spec/fixtures/cbc_ca/K0A1K0.response +0 -11
  27. data/spec/fixtures/cbc_ca/T5S2B9.response +0 -11
  28. data/spec/fixtures/cbc_ca/X1B1B1.response +0 -11
  29. data/spec/fixtures/conservative_ca/A1A1A1.response +0 -467
  30. data/spec/fixtures/conservative_ca/G0C2Y0.response +0 -467
  31. data/spec/fixtures/conservative_ca/H0H0H0.response +0 -467
  32. data/spec/fixtures/conservative_ca/K0A1K0.response +0 -467
  33. data/spec/fixtures/conservative_ca/T5S2B9.response +0 -467
  34. data/spec/fixtures/conservative_ca/X1B1B1.response +0 -467
  35. data/spec/fixtures/digital-copyright_ca/A1A1A1.response +0 -262
  36. data/spec/fixtures/digital-copyright_ca/G0C2Y0.response +0 -263
  37. data/spec/fixtures/digital-copyright_ca/H0H0H0.response +0 -278
  38. data/spec/fixtures/digital-copyright_ca/K0A1K0.response +0 -264
  39. data/spec/fixtures/digital-copyright_ca/T5S2B9.response +0 -267
  40. data/spec/fixtures/digital-copyright_ca/X1B1B1.response +0 -278
  41. data/spec/fixtures/elections_ca/A1A1A1.response +0 -12
  42. data/spec/fixtures/elections_ca/G0C2Y0.response +0 -12
  43. data/spec/fixtures/elections_ca/H0H0H0.response +0 -11
  44. data/spec/fixtures/elections_ca/K0A1K0.response +0 -11
  45. data/spec/fixtures/elections_ca/T5S2B9.response +0 -12
  46. data/spec/fixtures/elections_ca/X1B1B1.response +0 -11
  47. data/spec/fixtures/greenparty_ca/A1A1A1.response +0 -13
  48. data/spec/fixtures/greenparty_ca/G0C2Y0.response +0 -13
  49. data/spec/fixtures/greenparty_ca/H0H0H0.response +0 -13
  50. data/spec/fixtures/greenparty_ca/K0A1K0.response +0 -13
  51. data/spec/fixtures/greenparty_ca/T5S2B9.response +0 -13
  52. data/spec/fixtures/greenparty_ca/X1B1B1.response +0 -13
  53. data/spec/fixtures/liberal_ca/A1A1A1.response +0 -582
  54. data/spec/fixtures/liberal_ca/G0C2Y0.response +0 -582
  55. data/spec/fixtures/liberal_ca/H0H0H0.response +0 -663
  56. data/spec/fixtures/liberal_ca/K0A1K0.response +0 -663
  57. data/spec/fixtures/liberal_ca/T5S2B9.response +0 -663
  58. data/spec/fixtures/liberal_ca/X1B1B1.response +0 -663
  59. data/spec/fixtures/ndp_ca/A1A1A1.response +0 -12
  60. data/spec/fixtures/ndp_ca/G0C2Y0.response +0 -12
  61. data/spec/fixtures/ndp_ca/H0H0H0.response +0 -12
  62. data/spec/fixtures/ndp_ca/K0A1K0.response +0 -12
  63. data/spec/fixtures/ndp_ca/T5S2B9.response +0 -12
  64. data/spec/fixtures/ndp_ca/X1B1B1.response +0 -12
  65. data/spec/fixtures/parl_gc_ca/A1A1A1.response +0 -337
  66. data/spec/fixtures/parl_gc_ca/G0C2Y0.response +0 -337
  67. data/spec/fixtures/parl_gc_ca/H0H0H0.response +0 -226
  68. data/spec/fixtures/parl_gc_ca/K0A1K0.response +0 -784
  69. data/spec/fixtures/parl_gc_ca/T5S2B9.response +0 -511
  70. data/spec/fixtures/parl_gc_ca/X1B1B1.response +0 -226
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # GovKit-CA
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/opennorth/govkit-ca.png)](http://travis-ci.org/opennorth/govkit-ca)
4
+ [![Dependency Status](https://gemnasium.com/opennorth/govkit-ca.png)](https://gemnasium.com/opennorth/govkit-ca)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/opennorth/govkit-ca)
6
+
3
7
  GovKit-CA is a Ruby gem that provides easy access to Canadian civic data around the web. It currently provides an API for free postal code to electoral district lookups, using the following sources:
4
8
 
5
9
  * [elections.ca](http://elections.ca/)
@@ -43,6 +47,6 @@ GovKit-CA will raise GovKit::CA::ResourceNotFound if the electoral districts wit
43
47
 
44
48
  GovKit-CA interoperates with [Participatory Politics Foundation](http://www.participatorypolitics.org/)'s [GovKit](https://github.com/opengovernment/govkit). Please join the [GovKit Google Group](http://groups.google.com/group/govkit), especially if you'd like to talk about a new feature and get announcements.
45
49
 
46
- Govkit-CA'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.
50
+ 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.
47
51
 
48
52
  Copyright (c) 2011 Open North Inc., released under the MIT license
data/govkit-ca.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency('yajl-ruby', '~> 0.8.2')
25
25
  s.add_development_dependency('rspec', '~> 2.6.0')
26
26
  s.add_development_dependency('fakeweb', '~> 1.3.0')
27
+ s.add_development_dependency('rake')
27
28
  end
@@ -47,7 +47,13 @@ module GovKit
47
47
  # Performs the request and returns the response.
48
48
  # @return [HTTParty::Response] a HTTParty response object
49
49
  def response
50
- @response ||= self.class.send self.class.http_method, path
50
+ @response ||= begin
51
+ if self.class.http_method == :post
52
+ self.class.post path, :body => post_data
53
+ else
54
+ self.class.send self.class.http_method, path
55
+ end
56
+ end
51
57
  end
52
58
 
53
59
  # Allows setting an HTTP method to be used for each request.
@@ -70,6 +76,19 @@ module GovKit
70
76
  def path
71
77
  ERB.new(self.class.path).result binding
72
78
  end
79
+
80
+ # Allows setting POST data to be sent in each request.
81
+ # @param [String] post_data an ERB template for the POST data
82
+ # @return [String] the POST data for the request
83
+ def self.post_data(post_data = nil)
84
+ return default_options[:post_data] unless post_data
85
+ default_options[:post_data] = post_data
86
+ end
87
+
88
+ # @return [String] the POST data for the request
89
+ def post_data
90
+ ERB.new(self.class.post_data).result binding
91
+ end
73
92
  end
74
93
  end
75
94
  end
@@ -2,15 +2,13 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  module Strategy
5
- # cbc.ca ought to be a reliable source. It is unknown if its database
6
- # is kept up-to-date between elections, however.
7
- # @see https://github.com/danielharan/pc_scraper
8
5
  class CBCCa < Base
9
6
  base_uri 'www.cbc.ca'
10
7
  http_method :get
11
8
  path '/news/politics/canadavotes2011/myelection/postalcodes/index.php?pc=<%= @postal_code %>'
12
9
 
13
10
  private
11
+
14
12
  def electoral_districts!
15
13
  Yajl::Parser.parse(response.parsed_response).map{|x| self.class.rid_to_edid[x['rid'].to_i]}
16
14
  end
@@ -2,21 +2,24 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  module Strategy
5
- # conservative.ca seems unreliable. In the case of B0J2L0, for example,
6
- # it does not return three ridings like other sources.
7
5
  class ConservativeCa < Base
8
6
  base_uri 'www.conservative.ca'
9
- http_method :get
10
- path '/?section_id=1051&postal_code=<%= @postal_code %>'
7
+ http_method :post
8
+ path '/?page_id=35'
9
+ post_data 'findmymp=35&pc=<%= @postal_code %>'
11
10
 
12
11
  private
13
12
 
14
13
  def electoral_districts!
15
- # TODO returns HTML with electoral district names only
14
+ images.map{|a| a[:src][/\d+\.jpg\z/]}
16
15
  end
17
16
 
18
17
  def valid?
19
- # TODO
18
+ !images.empty?
19
+ end
20
+
21
+ def images
22
+ @document ||= Nokogiri::HTML(response.parsed_response, nil, 'utf-8').css('#type img')
20
23
  end
21
24
  end
22
25
 
@@ -2,9 +2,6 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  module Strategy
5
- # digital-copyright.ca often returns more or fewer electoral districts
6
- # than others. It says it uses makethechange.ca, but makethechange.ca
7
- # returns different results for, e.g., K0A1K0.
8
5
  class DigitalCopyrightCa < Base
9
6
  base_uri 'www.digital-copyright.ca'
10
7
  http_method :get
@@ -2,13 +2,10 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  module Strategy
5
- # greenparty.ca does not return electoral districts for postal codes
6
- # that contain multiple electoral districts. It has no lookup service
7
- # between elections.
8
5
  class GreenPartyCa < Base
9
- base_uri 'greenparty.ca'
6
+ base_uri 'www.greenparty.ca'
10
7
  http_method :head
11
- path '/search/civicrm_lookup/<%= @postal_code %>'
8
+ path '/search/green_geo/<%= @postal_code %>'
12
9
 
13
10
  private
14
11
 
@@ -17,7 +14,7 @@ module GovKit
17
14
  end
18
15
 
19
16
  def valid?
20
- response.headers['location'] != 'http://greenparty.ca/find_your_riding'
17
+ response.headers['location'] != 'http://www.greenparty.ca/find_your_riding'
21
18
  end
22
19
  end
23
20
 
@@ -2,21 +2,19 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  module Strategy
5
- # ndp.ca does not return electoral districts for postal codes that
6
- # contain multiple electoral districts.
7
5
  class NDPCa < Base
8
6
  base_uri 'www.ndp.ca'
9
- http_method :head
10
- path '/riding/<%= @postal_code %>'
7
+ http_method :get
8
+ path '/your-riding/?search=<%= @postal_code %>'
11
9
 
12
10
  private
13
11
 
14
12
  def electoral_districts!
15
- [ response.headers['location'][/\d+\z/] ]
13
+ Nokogiri::HTML(response.parsed_response, nil, 'utf-8').css('a.mp-riding-link,a.no-mp').map{|a| a[:href][/\d+\z/]}
16
14
  end
17
15
 
18
16
  def valid?
19
- response.headers['location'] != 'http://www.ndp.ca/'
17
+ !response.parsed_response['No ridings or MPs match this search.']
20
18
  end
21
19
  end
22
20
 
@@ -2,7 +2,6 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  module Strategy
5
- # parl.gc.ca is a reliable source.
6
5
  class ParlGcCa < Base
7
6
  base_uri 'www.parl.gc.ca'
8
7
  http_method :get
@@ -80,13 +80,15 @@ module GovKit
80
80
  end
81
81
 
82
82
  require 'gov_kit-ca/postal_code/strategy/base'
83
- require 'gov_kit-ca/postal_code/strategy/elections_ca'
83
+ # Returns only riding name.
84
84
  #require 'gov_kit-ca/postal_code/strategy/parl_gc_ca'
85
- require 'gov_kit-ca/postal_code/strategy/cbc_ca'
85
+ require 'gov_kit-ca/postal_code/strategy/elections_ca' # only one-to-one
86
86
  require 'gov_kit-ca/postal_code/strategy/ndp_ca'
87
+ require 'gov_kit-ca/postal_code/strategy/liberal_ca' # incomplete database
88
+ require 'gov_kit-ca/postal_code/strategy/greenparty_ca' # only one-to-one
89
+ require 'gov_kit-ca/postal_code/strategy/cbc_ca' # disagrees with elections.ca
87
90
 
88
- # These strategies are suboptimal:
91
+ # If not held by Conservative MP, returns only riding name.
89
92
  # require 'gov_kit-ca/postal_code/strategy/conservative_ca'
93
+ # Returns too many or too few ridings.
90
94
  # require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
91
- # require 'gov_kit-ca/postal_code/strategy/greenparty_ca'
92
- # require 'gov_kit-ca/postal_code/strategy/liberal_ca'
@@ -1,5 +1,5 @@
1
1
  module GovKit
2
2
  module CA
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
data/lib/gov_kit-ca.rb CHANGED
@@ -1,5 +1,3 @@
1
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
2
-
3
1
  require 'erb'
4
2
  require 'json'
5
3
  require 'yaml'
data/spec/cbc_ca_spec.rb CHANGED
@@ -14,8 +14,8 @@ class GovKit::CA::PostalCode::Strategy::CBCCa
14
14
 
15
15
  it 'should return the electoral districts within a postal code' do
16
16
  { 'G0C2Y0' => [24019],
17
- 'T5S2B9' => [48015, 48017], # differs from elections.ca, ndp.ca, greenparty.ca, liberal.ca
18
- 'K0A1K0' => [35025, 35052, 35063, 35064], # differs from liberal.ca, digital-copyright.ca
17
+ 'T5S2B9' => [48015, 48017],
18
+ 'K0A1K0' => [35025, 35052, 35063, 35064],
19
19
  }.each do |postal_code,electoral_districts|
20
20
  GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code).electoral_districts.should == electoral_districts
21
21
  end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'gov_kit-ca/postal_code/strategy/conservative_ca'
3
+
4
+ describe GovKit::CA::PostalCode::Strategy::ConservativeCa 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::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
+ it 'should return the electoral districts within a postal code' do
16
+ { 'T5S2B9' => [48015],
17
+ 'K0A1K0' => [35025, 35052, 35063],
18
+ 'B0J2L0' => [12002, 12006, 12009, 12011],
19
+ }.each do |postal_code,electoral_districts|
20
+ GovKit::CA::PostalCode::Strategy::ConservativeCa.new(postal_code).electoral_districts.should == electoral_districts
21
+ end
22
+ end
23
+
24
+ it 'should (unfortunately) return false if a postal code is held by another party' do
25
+ GovKit::CA::PostalCode::Strategy::ConservativeCa.new('G0C2Y0').electoral_districts.should be_false
26
+ end
27
+
28
+ it 'should return false if a postal code contains no electoral districts' do
29
+ GovKit::CA::PostalCode::Strategy::ConservativeCa.new('H0H0H0').electoral_districts.should be_false
30
+ end
31
+
32
+ it 'should return false if a postal code does not exist' do
33
+ GovKit::CA::PostalCode::Strategy::ConservativeCa.new('X1B1B1').electoral_districts.should be_false
34
+ end
35
+ end
36
+ end
@@ -1,34 +1,33 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
3
3
 
4
- class GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa
5
- describe GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa 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::DigitalCopyrightCa.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('digital-copyright_ca', "#{postal_code}.response")
12
- end
4
+ describe GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa 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::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")
13
11
  end
14
12
  end
13
+ end
15
14
 
16
- it 'should return the electoral districts within a postal code' do
17
- { 'G0C2Y0' => [24019, 24039], # differs from all
18
- 'T5S2B9' => [48012, 48013, 48014, 48015, 48017, 48018], # differs from all
19
- 'K0A1K0' => [35025, 35052, 35063], # differs from cbc.ca
20
- }.each do |postal_code,electoral_districts|
21
- GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new(postal_code).electoral_districts.should == electoral_districts
22
- end
15
+ it 'should return the electoral districts within a postal code' do
16
+ { 'G0C2Y0' => [24019, 24039], # differs from all
17
+ 'T5S2B9' => [48012, 48013, 48014, 48015, 48017, 48018], # differs from all
18
+ 'K0A1K0' => [35025, 35052, 35063],
19
+ 'B0J2L0' => [12002, 12007, 12008],
20
+ }.each do |postal_code,electoral_districts|
21
+ GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new(postal_code).electoral_districts.should == electoral_districts
23
22
  end
23
+ end
24
24
 
25
- it 'should return false if a postal code contains no electoral districts' do
26
- GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('H0H0H0').electoral_districts.should be_false
27
- end
25
+ it 'should return false if a postal code contains no electoral districts' do
26
+ GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('H0H0H0').electoral_districts.should be_false
27
+ end
28
28
 
29
- it 'should return false if a postal code does not exist' do
30
- GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('X1B1B1').electoral_districts.should be_false
31
- end
29
+ it 'should return false if a postal code does not exist' do
30
+ GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('X1B1B1').electoral_districts.should be_false
32
31
  end
33
32
  end
34
33
  end
@@ -1,36 +1,35 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- class GovKit::CA::PostalCode::Strategy::ElectionsCa
4
- describe GovKit::CA::PostalCode::Strategy::ElectionsCa 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::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
3
 
15
- it 'should return the electoral districts within a postal code' do
16
- { 'G0C2Y0' => [24019],
17
- 'T5S2B9' => [48015], # differs from cbc.ca
18
- }.each do |postal_code,electoral_districts|
19
- GovKit::CA::PostalCode::Strategy::ElectionsCa.new(postal_code).electoral_districts.should == electoral_districts
4
+ describe GovKit::CA::PostalCode::Strategy::ElectionsCa 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::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")
20
11
  end
21
12
  end
13
+ end
22
14
 
23
- it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
24
- GovKit::CA::PostalCode::Strategy::ElectionsCa.new('K0A1K0').electoral_districts.should be_false
15
+ it 'should return the electoral districts within a postal code' do
16
+ { 'G0C2Y0' => [24019],
17
+ 'T5S2B9' => [48015],
18
+ }.each do |postal_code,electoral_districts|
19
+ GovKit::CA::PostalCode::Strategy::ElectionsCa.new(postal_code).electoral_districts.should == electoral_districts
25
20
  end
21
+ end
26
22
 
27
- it 'should return false if a postal code contains no electoral districts' do
28
- GovKit::CA::PostalCode::Strategy::ElectionsCa.new('H0H0H0').electoral_districts.should be_false
29
- end
23
+ it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
24
+ GovKit::CA::PostalCode::Strategy::ElectionsCa.new('K0A1K0').electoral_districts.should be_false # B0J2L0
25
+ end
30
26
 
31
- it 'should return false if a postal code does not exist' do
32
- GovKit::CA::PostalCode::Strategy::ElectionsCa.new('X1B1B1').electoral_districts.should be_false
33
- end
27
+ it 'should return false if a postal code contains no electoral districts' do
28
+ GovKit::CA::PostalCode::Strategy::ElectionsCa.new('H0H0H0').electoral_districts.should be_false
29
+ end
30
+
31
+ it 'should return false if a postal code does not exist' do
32
+ GovKit::CA::PostalCode::Strategy::ElectionsCa.new('X1B1B1').electoral_districts.should be_false
34
33
  end
35
34
  end
36
35
  end
@@ -1,36 +1,35 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'gov_kit-ca/postal_code/strategy/greenparty_ca'
2
3
 
3
- class GovKit::CA::PostalCode::Strategy::GreenPartyCa
4
- describe GovKit::CA::PostalCode::Strategy::GreenPartyCa, broken: true 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::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
4
+ describe GovKit::CA::PostalCode::Strategy::GreenPartyCa 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::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")
12
11
  end
13
12
  end
13
+ end
14
14
 
15
- it 'should return the electoral districts within a postal code' do
16
- { 'G0C2Y0' => [24019],
17
- 'T5S2B9' => [48015], # differs from cbc.ca
18
- }.each do |postal_code,electoral_districts|
19
- GovKit::CA::PostalCode::Strategy::GreenPartyCa.new(postal_code).electoral_districts.should == electoral_districts
20
- end
15
+ it 'should return the electoral districts within a postal code' do
16
+ { 'G0C2Y0' => [24019],
17
+ 'T5S2B9' => [48015],
18
+ }.each do |postal_code,electoral_districts|
19
+ GovKit::CA::PostalCode::Strategy::GreenPartyCa.new(postal_code).electoral_districts.should == electoral_districts
21
20
  end
21
+ end
22
22
 
23
- it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
24
- GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('K0A1K0').electoral_districts.should be_false
25
- end
23
+ it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
24
+ GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('K0A1K0').electoral_districts.should be_false # B0J2L0
25
+ end
26
26
 
27
- it 'should return false if a postal code contains no electoral districts' do
28
- GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('H0H0H0').electoral_districts.should be_false
29
- end
27
+ it 'should return false if a postal code contains no electoral districts' do
28
+ GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('H0H0H0').electoral_districts.should be_false
29
+ end
30
30
 
31
- it 'should return false if a postal code does not exist' do
32
- GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('X1B1B1').electoral_districts.should be_false
33
- end
31
+ it 'should return false if a postal code does not exist' do
32
+ GovKit::CA::PostalCode::Strategy::GreenPartyCa.new('X1B1B1').electoral_districts.should be_false
34
33
  end
35
34
  end
36
35
  end
@@ -1,34 +1,36 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'gov_kit-ca/postal_code/strategy/liberal_ca'
3
3
 
4
- class GovKit::CA::PostalCode::Strategy::LiberalCa
5
- describe GovKit::CA::PostalCode::Strategy::LiberalCa 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::LiberalCa.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('liberal_ca', "#{postal_code}.response")
12
- end
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")
13
11
  end
14
12
  end
13
+ end
15
14
 
16
- it 'should return the electoral districts within a postal code' do
17
- { 'G0C2Y0' => [24019], # this postal code intermittently fails
18
- 'T5S2B9' => [48015], # differs from cbc.ca
19
- 'K0A1K0' => [35025, 35052, 35063], # differs from cbc.ca
20
- }.each do |postal_code,electoral_districts|
21
- GovKit::CA::PostalCode::Strategy::LiberalCa.new(postal_code).electoral_districts.should == electoral_districts
22
- end
15
+ it 'should return the electoral districts within a postal code' do
16
+ { 'G0C2Y0' => [24019],
17
+ 'T5S2B9' => [48015],
18
+ 'K0A1K0' => [35025, 35052, 35063],
19
+ }.each do |postal_code,electoral_districts|
20
+ GovKit::CA::PostalCode::Strategy::LiberalCa.new(postal_code).electoral_districts.should == electoral_districts
23
21
  end
22
+ end
24
23
 
25
- it 'should return false if a postal code contains no electoral districts' do
26
- GovKit::CA::PostalCode::Strategy::LiberalCa.new('H0H0H0').electoral_districts.should be_false
27
- end
24
+ it 'should (unfortunately) return false if a postal code is rare or ambiguous' do
25
+ GovKit::CA::PostalCode::Strategy::LiberalCa.new('B0J2L0').electoral_districts.should be_false
26
+ end
28
27
 
29
- it 'should return false if a postal code does not exist' do
30
- GovKit::CA::PostalCode::Strategy::LiberalCa.new('X1B1B1').electoral_districts.should be_false
31
- end
28
+ it 'should return false if a postal code contains no electoral districts' do
29
+ GovKit::CA::PostalCode::Strategy::LiberalCa.new('H0H0H0').electoral_districts.should be_false
30
+ end
31
+
32
+ it 'should return false if a postal code does not exist' do
33
+ GovKit::CA::PostalCode::Strategy::LiberalCa.new('X1B1B1').electoral_districts.should be_false
32
34
  end
33
35
  end
34
36
  end
data/spec/ndp_ca_spec.rb CHANGED
@@ -1,36 +1,33 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- class GovKit::CA::PostalCode::Strategy::NDPCa
4
- describe GovKit::CA::PostalCode::Strategy::NDPCa 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::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
3
 
15
- it 'should return the electoral districts within a postal code' do
16
- { 'G0C2Y0' => [24019],
17
- 'T5S2B9' => [48015], # differs from cbc.ca
18
- }.each do |postal_code,electoral_districts|
19
- GovKit::CA::PostalCode::Strategy::NDPCa.new(postal_code).electoral_districts.should == electoral_districts
4
+ describe GovKit::CA::PostalCode::Strategy::NDPCa 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::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")
20
11
  end
21
12
  end
13
+ end
22
14
 
23
- it 'should (unfortunately) return false if a postal code contains multiple electoral districts' do
24
- GovKit::CA::PostalCode::Strategy::NDPCa.new('K0A1K0').electoral_districts.should be_false
15
+ it 'should return the electoral districts within a postal code' do
16
+ { 'G0C2Y0' => [24019],
17
+ 'T5S2B9' => [48015],
18
+ 'K0A1K0' => [35012, 35025, 35040, 35052],
19
+ 'B0J2L0' => [12002, 12006, 12009, 12011],
20
+ }.each do |postal_code,electoral_districts|
21
+ GovKit::CA::PostalCode::Strategy::NDPCa.new(postal_code).electoral_districts.should == electoral_districts
25
22
  end
23
+ end
26
24
 
27
- it 'should return false if a postal code contains no electoral districts' do
28
- GovKit::CA::PostalCode::Strategy::NDPCa.new('H0H0H0').electoral_districts.should be_false
29
- end
25
+ it 'should return false if a postal code contains no electoral districts' do
26
+ GovKit::CA::PostalCode::Strategy::NDPCa.new('H0H0H0').electoral_districts.should be_false
27
+ end
30
28
 
31
- it 'should return false if a postal code does not exist' do
32
- GovKit::CA::PostalCode::Strategy::NDPCa.new('X1B1B1').electoral_districts.should be_false
33
- end
29
+ it 'should return false if a postal code does not exist' do
30
+ GovKit::CA::PostalCode::Strategy::NDPCa.new('X1B1B1').electoral_districts.should be_false
34
31
  end
35
32
  end
36
33
  end
@@ -33,7 +33,8 @@ module GovKit::CA::PostalCode
33
33
  { 'ElectionsCa' => 'elections_ca',
34
34
  'CBCCa' => 'cbc_ca',
35
35
  'NDPCa' => 'ndp_ca',
36
- 'GreenPartyCa' => 'greenparty_ca',
36
+ # GreenPartyCa is broken.
37
+ #'GreenPartyCa' => 'greenparty_ca',
37
38
  }.each do |const,path|
38
39
  %w(A1A1A1 K0A1K0 H0H0H0).each do |postal_code|
39
40
  strategy = GovKit::CA::PostalCode::Strategy.const_get(const).new(postal_code)
@@ -46,7 +47,7 @@ module GovKit::CA::PostalCode
46
47
 
47
48
  it 'should return the electoral districts within a postal code' do
48
49
  { 'A1A1A1' => [10007],
49
- 'K0A1K0' => [35025, 35052, 35063, 35064],
50
+ 'K0A1K0' => [35012, 35025, 35040, 35052],
50
51
  }.each do |postal_code,electoral_districts|
51
52
  subject.find_electoral_districts_by_postal_code(postal_code).should == electoral_districts
52
53
  end