govkit-ca 0.0.2 → 0.0.3

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.
Files changed (79) hide show
  1. data/LICENSE +1 -1
  2. data/README.md +2 -2
  3. data/Rakefile +1 -1
  4. data/govkit-ca.gemspec +8 -8
  5. data/lib/gov_kit-ca/postal_code/strategy/base.rb +33 -1
  6. data/lib/gov_kit-ca/postal_code/strategy/{cbc-ca.rb → cbc_ca.rb} +6 -13
  7. data/lib/gov_kit-ca/postal_code/strategy/{conservative-ca.rb → conservative_ca.rb} +2 -4
  8. data/lib/gov_kit-ca/postal_code/strategy/digital-copyright_ca.rb +27 -0
  9. data/lib/gov_kit-ca/postal_code/strategy/{elections-ca.rb → elections_ca.rb} +2 -4
  10. data/lib/gov_kit-ca/postal_code/strategy/{greenparty-ca.rb → greenparty_ca.rb} +3 -5
  11. data/lib/gov_kit-ca/postal_code/strategy/{liberal-ca.rb → liberal_ca.rb} +3 -5
  12. data/lib/gov_kit-ca/postal_code/strategy/{ndp-ca.rb → ndp_ca.rb} +3 -5
  13. data/lib/gov_kit-ca/postal_code/strategy/{parl-gc-ca.rb → parl_gc_ca.rb} +3 -5
  14. data/lib/gov_kit-ca/postal_code/{strategy.rb → strategy_set.rb} +1 -7
  15. data/lib/gov_kit-ca/postal_code.rb +9 -3
  16. data/lib/gov_kit-ca/version.rb +1 -1
  17. data/lib/gov_kit-ca.rb +2 -1
  18. data/spec/cbc_ca_spec.rb +13 -6
  19. data/spec/digital-copyright_ca_spec.rb +32 -0
  20. data/spec/elections_ca_spec.rb +7 -0
  21. data/spec/fixtures/cbc_ca/A1A1A1.response +11 -0
  22. data/spec/fixtures/cbc_ca/G0C2Y0.response +11 -0
  23. data/spec/fixtures/cbc_ca/H0H0H0.response +309 -0
  24. data/spec/fixtures/cbc_ca/K0A1K0.response +11 -0
  25. data/spec/fixtures/cbc_ca/T5S2B9.response +11 -0
  26. data/spec/fixtures/cbc_ca/X1B1B1.response +309 -0
  27. data/spec/fixtures/conservative_ca/A1A1A1.response +467 -0
  28. data/spec/fixtures/conservative_ca/G0C2Y0.response +467 -0
  29. data/spec/fixtures/conservative_ca/H0H0H0.response +467 -0
  30. data/spec/fixtures/conservative_ca/K0A1K0.response +467 -0
  31. data/spec/fixtures/conservative_ca/T5S2B9.response +467 -0
  32. data/spec/fixtures/conservative_ca/X1B1B1.response +467 -0
  33. data/spec/fixtures/digital-copyright_ca/A1A1A1.response +262 -0
  34. data/spec/fixtures/digital-copyright_ca/G0C2Y0.response +263 -0
  35. data/spec/fixtures/digital-copyright_ca/H0H0H0.response +278 -0
  36. data/spec/fixtures/digital-copyright_ca/K0A1K0.response +264 -0
  37. data/spec/fixtures/digital-copyright_ca/T5S2B9.response +267 -0
  38. data/spec/fixtures/digital-copyright_ca/X1B1B1.response +278 -0
  39. data/spec/fixtures/elections_ca/A1A1A1.response +12 -0
  40. data/spec/fixtures/elections_ca/G0C2Y0.response +12 -0
  41. data/spec/fixtures/elections_ca/H0H0H0.response +11 -0
  42. data/spec/fixtures/elections_ca/K0A1K0.response +11 -0
  43. data/spec/fixtures/elections_ca/T5S2B9.response +12 -0
  44. data/spec/fixtures/elections_ca/X1B1B1.response +11 -0
  45. data/spec/fixtures/greenparty_ca/A1A1A1.response +13 -0
  46. data/spec/fixtures/greenparty_ca/G0C2Y0.response +13 -0
  47. data/spec/fixtures/greenparty_ca/H0H0H0.response +13 -0
  48. data/spec/fixtures/greenparty_ca/K0A1K0.response +13 -0
  49. data/spec/fixtures/greenparty_ca/T5S2B9.response +13 -0
  50. data/spec/fixtures/greenparty_ca/X1B1B1.response +13 -0
  51. data/spec/fixtures/liberal_ca/A1A1A1.response +582 -0
  52. data/spec/fixtures/liberal_ca/G0C2Y0.response +582 -0
  53. data/spec/fixtures/liberal_ca/H0H0H0.response +663 -0
  54. data/spec/fixtures/liberal_ca/K0A1K0.response +663 -0
  55. data/spec/fixtures/liberal_ca/T5S2B9.response +663 -0
  56. data/spec/fixtures/liberal_ca/X1B1B1.response +663 -0
  57. data/spec/fixtures/ndp_ca/A1A1A1.response +12 -0
  58. data/spec/fixtures/ndp_ca/G0C2Y0.response +12 -0
  59. data/spec/fixtures/ndp_ca/H0H0H0.response +12 -0
  60. data/spec/fixtures/ndp_ca/K0A1K0.response +12 -0
  61. data/spec/fixtures/ndp_ca/T5S2B9.response +12 -0
  62. data/spec/fixtures/ndp_ca/X1B1B1.response +12 -0
  63. data/spec/fixtures/parl_gc_ca/A1A1A1.response +337 -0
  64. data/spec/fixtures/parl_gc_ca/G0C2Y0.response +337 -0
  65. data/spec/fixtures/parl_gc_ca/H0H0H0.response +226 -0
  66. data/spec/fixtures/parl_gc_ca/K0A1K0.response +784 -0
  67. data/spec/fixtures/parl_gc_ca/T5S2B9.response +511 -0
  68. data/spec/fixtures/parl_gc_ca/X1B1B1.response +226 -0
  69. data/spec/greenparty_ca_spec.rb +7 -0
  70. data/spec/liberal_ca_spec.rb +10 -2
  71. data/spec/ndp_ca_spec.rb +7 -0
  72. data/spec/postal_code_spec.rb +13 -0
  73. data/spec/spec_helper.rb +13 -0
  74. data/spec/strategy_set_spec.rb +0 -0
  75. data/tasks/postal-code-for-districts.csv +212 -0
  76. data/tasks/tasks.rb +73 -0
  77. metadata +180 -98
  78. data/lib/gov_kit-ca/postal_code/strategy/digital_copyright-ca.rb +0 -28
  79. data/tasks/rid_to_edid.rb +0 -136
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 James McKinney
1
+ Copyright (c) 2011 Open North Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -43,6 +43,6 @@ GovKit-CA will raise GovKit::CA::ResourceNotFound if the electoral districts wit
43
43
 
44
44
  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
45
 
46
- Govkit-CA's main repository is on GitHub: [http://github.com/jpmckinney/govkit-ca](http://github.com/jpmckinney/govkit-ca), where your contributions, forks, bug reports, feature requests, and feedback are greatly welcomed.
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.
47
47
 
48
- Copyright (c) 2011 James McKinney, released under the MIT license
48
+ Copyright (c) 2011 Open North Inc., released under the MIT license
data/Rakefile CHANGED
@@ -15,4 +15,4 @@ rescue LoadError
15
15
  end
16
16
  end
17
17
 
18
- require File.expand_path('../tasks/rid_to_edid', __FILE__)
18
+ require File.expand_path('../tasks/tasks', __FILE__)
data/govkit-ca.gemspec CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.name = "govkit-ca"
7
7
  s.version = GovKit::CA::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["James McKinney"]
10
- s.email = ["james@slashpoundbang.com"]
11
- s.homepage = "http://github.com/jpmckinney/govkit-ca"
9
+ s.authors = ["Open North"]
10
+ s.email = ["info@opennorth.ca"]
11
+ s.homepage = "http://github.com/opennorth/govkit-ca"
12
12
  s.summary = %q{Easy access to Canadian civic data around the web}
13
13
  s.description = %q{GovKit-CA lets you quickly get encapsulated Ruby objects for Canadian civic data.}
14
14
 
@@ -19,9 +19,9 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- #s.add_runtime_dependency('graticule', '>= 0.2.8')
23
- s.add_runtime_dependency('httparty', '>= 0.6.1')
24
- s.add_runtime_dependency('nokogiri', '>= 1.4.4')
25
- s.add_runtime_dependency('yajl-ruby', '>= 0.7.8')
26
- s.add_development_dependency('rspec', '>= 2')
22
+ s.add_runtime_dependency('httparty', '~> 0.7.8')
23
+ s.add_runtime_dependency('nokogiri', '~> 1.5.0')
24
+ s.add_runtime_dependency('yajl-ruby', '~> 0.8.2')
25
+ s.add_development_dependency('rspec', '~> 2.6.0')
26
+ s.add_development_dependency('fakeweb', '~> 1.3.0')
27
27
  end
@@ -5,9 +5,14 @@ module GovKit
5
5
  # Abstract class for implementing postal code to electoral district
6
6
  # strategies.
7
7
  #
8
- # The following methods must be implemented in sub-classes:
8
+ # The following instance methods must be implemented in sub-classes:
9
9
  #
10
10
  # * `electoral_districts!`
11
+ #
12
+ # The following class methods must be called in sub-classes:
13
+ #
14
+ # * `http_method`
15
+ # * `path`
11
16
  class Base
12
17
  include HTTParty
13
18
  follow_redirects false
@@ -38,6 +43,33 @@ module GovKit
38
43
  def valid?
39
44
  true
40
45
  end
46
+
47
+ # Performs the request and returns the response.
48
+ # @return [HTTParty::Response] a HTTParty response object
49
+ def response
50
+ @response ||= self.class.send self.class.http_method, path
51
+ end
52
+
53
+ # Allows setting an HTTP method to be used for each request.
54
+ # @param [Symbol] http_method an HTTP method
55
+ # @return [Symbol] the HTTP method to use to send the request
56
+ def self.http_method(http_method = nil)
57
+ return default_options[:http_method] unless http_method
58
+ default_options[:http_method] = http_method
59
+ end
60
+
61
+ # Allows setting an absolute path to be used in each request.
62
+ # @param [String] path an ERB template for the absolute path
63
+ # @return [String] the absolute path to request
64
+ def self.path(path = nil)
65
+ return default_options[:path] unless path
66
+ default_options[:path] = path
67
+ end
68
+
69
+ # @return [String] the absolute path to be used in the request
70
+ def path
71
+ ERB.new(self.class.path).result binding
72
+ end
41
73
  end
42
74
  end
43
75
  end
@@ -5,32 +5,25 @@ module GovKit
5
5
  # cbc.ca ought to be a reliable source. It is unknown if its database
6
6
  # is kept up-to-date between elections, however.
7
7
  # @see https://github.com/danielharan/pc_scraper
8
- class CbcCa < Base
8
+ class CBCCa < Base
9
9
  base_uri 'www.cbc.ca'
10
+ http_method :get
11
+ path '/news/canadavotes/myriding/postalcodes/<%= @letter %>/<%= @fsa %>/<%= @ldu %>.html'
10
12
 
11
13
  def initialize(postal_code)
12
- @fsa, @letter, @ldu = postal_code.downcase.match(/\A((.).{2})(.{3})\Z/)[1..3]
14
+ @fsa, @letter, @ldu = postal_code.downcase.match(/\A((.).{2})(.{3})\z/)[1..3]
13
15
  super
14
16
  end
15
17
 
16
- def json_response # Yajl barfs on bad encoding
17
- Yajl::Parser.parse(response.parsed_response) rescue JSON.parse(response.parsed_response)
18
- end
19
-
20
18
  private
21
-
22
19
  def electoral_districts!
23
- json_response.map{|x| self.class.rid_to_edid[x['rid']]}
20
+ Yajl::Parser.parse(Iconv.new('UTF-8', 'ISO-8859-1').iconv(response.parsed_response)).map{|x| self.class.rid_to_edid[x['rid']]}
24
21
  end
25
22
 
26
23
  def valid?
27
24
  !!response.headers['expires']
28
25
  end
29
26
 
30
- def response
31
- @response ||= self.class.get "/news/canadavotes/myriding/postalcodes/#{@letter}/#{@fsa}/#{@ldu}.html"
32
- end
33
-
34
27
  # cbc.ca uses an internal riding ID, which must be matched to a
35
28
  # canonical electoral district ID.
36
29
  # @return [Hash] a map of cbc.ca riding ID to electoral district ID
@@ -39,7 +32,7 @@ module GovKit
39
32
  end
40
33
  end
41
34
 
42
- StrategySet.register CbcCa
35
+ StrategySet.register CBCCa
43
36
  end
44
37
  end
45
38
  end
@@ -6,6 +6,8 @@ module GovKit
6
6
  # it does not return three ridings like other sources.
7
7
  class ConservativeCa < Base
8
8
  base_uri 'www.conservative.ca'
9
+ http_method :get
10
+ path '/?section_id=1051&postal_code=<%= @postal_code %>'
9
11
 
10
12
  private
11
13
 
@@ -16,10 +18,6 @@ module GovKit
16
18
  def valid?
17
19
  # TODO
18
20
  end
19
-
20
- def response
21
- @response ||= self.class.get "/?section_id=1051&postal_code=#{@postal_code}"
22
- end
23
21
  end
24
22
 
25
23
  StrategySet.register ConservativeCa
@@ -0,0 +1,27 @@
1
+ module GovKit
2
+ module CA
3
+ module PostalCode
4
+ module Strategy
5
+ # digital-copyright.ca often returns more or fewer electoral districts
6
+ # than others. Occasionally suffers from timeout errors.
7
+ class DigitalCopyrightCa < Base
8
+ base_uri 'www.digital-copyright.ca'
9
+ http_method :get
10
+ path '/edid/postal?postalcode=<%= @postal_code %>'
11
+
12
+ private
13
+
14
+ def electoral_districts!
15
+ Nokogiri::HTML(response.parsed_response, nil, 'utf-8').css('.node .content a').map{|a| a[:href][/\d+\z/]}
16
+ end
17
+
18
+ def valid?
19
+ !response.parsed_response.match /\b(invalid postal code|not found)\b/
20
+ end
21
+ end
22
+
23
+ StrategySet.register DigitalCopyrightCa
24
+ end
25
+ end
26
+ end
27
+ end
@@ -7,6 +7,8 @@ module GovKit
7
7
  # @see https://github.com/danielharan/postal_code_to_edid_webservice
8
8
  class ElectionsCa < Base
9
9
  base_uri 'elections.ca'
10
+ http_method :head
11
+ path '/scripts/pss/FindED.aspx?PC=<%= @postal_code %>'
10
12
 
11
13
  private
12
14
 
@@ -17,10 +19,6 @@ module GovKit
17
19
  def valid?
18
20
  !!response.headers['location']
19
21
  end
20
-
21
- def response
22
- @response ||= self.class.head "/scripts/pss/FindED.aspx?PC=#{@postal_code}"
23
- end
24
22
  end
25
23
 
26
24
  StrategySet.register ElectionsCa
@@ -6,20 +6,18 @@ module GovKit
6
6
  # that contain multiple electoral districts.
7
7
  class GreenPartyCa < Base
8
8
  base_uri 'greenparty.ca'
9
+ http_method :head
10
+ path '/search/civicrm_lookup/<%= @postal_code %>'
9
11
 
10
12
  private
11
13
 
12
14
  def electoral_districts!
13
- [ response.headers['location'][/\d+\Z/] ]
15
+ [ response.headers['location'][/\d+\z/] ]
14
16
  end
15
17
 
16
18
  def valid?
17
19
  response.headers['location'] != 'http://greenparty.ca/find_your_riding'
18
20
  end
19
-
20
- def response
21
- @response ||= self.class.head "/search/civicrm_lookup/#{@postal_code}"
22
- end
23
21
  end
24
22
 
25
23
  StrategySet.register GreenPartyCa
@@ -5,20 +5,18 @@ module GovKit
5
5
  # liberal.ca is unreliable during elections.
6
6
  class LiberalCa < Base
7
7
  base_uri 'www.liberal.ca'
8
+ http_method :get
9
+ path '/riding/postal/<%= @postal_code %>/'
8
10
 
9
11
  private
10
12
 
11
13
  def electoral_districts!
12
- Nokogiri::HTML(response.parsed_response).css('img.RidingListImage').map{|img| img[:src][/\d{5}/]}
14
+ Nokogiri::HTML(response.parsed_response, nil, 'utf-8').css('img.RidingListImage').map{|img| img[:src][/\d{5}/]}
13
15
  end
14
16
 
15
17
  def valid?
16
18
  !response.parsed_response.match /\bOopsies!/
17
19
  end
18
-
19
- def response
20
- @response ||= self.class.get "/riding/postal/#{@postal_code}/"
21
- end
22
20
  end
23
21
 
24
22
  StrategySet.register LiberalCa
@@ -6,20 +6,18 @@ module GovKit
6
6
  # contain multiple electoral districts.
7
7
  class NDPCa < Base
8
8
  base_uri 'www.ndp.ca'
9
+ http_method :head
10
+ path '/riding/<%= @postal_code %>'
9
11
 
10
12
  private
11
13
 
12
14
  def electoral_districts!
13
- [ response.headers['location'][/\d+\Z/] ]
15
+ [ response.headers['location'][/\d+\z/] ]
14
16
  end
15
17
 
16
18
  def valid?
17
19
  response.headers['location'] != 'http://www.ndp.ca/'
18
20
  end
19
-
20
- def response
21
- @response ||= self.class.head "/riding/#{@postal_code}"
22
- end
23
21
  end
24
22
 
25
23
  StrategySet.register NDPCa
@@ -5,7 +5,9 @@ module GovKit
5
5
  # parl.gc.ca seems unreliable. In the case of K0A1K0, for example, it
6
6
  # does not return seven ridings like other sources.
7
7
  class ParlGcCa < Base
8
- base_uri 'www2.parl.gc.ca'
8
+ base_uri 'www.parl.gc.ca'
9
+ http_method :get
10
+ path '/ParlInfo/Compilations/HouseOfCommons/MemberByPostalCode.aspx?PostalCode=<%= @postal_code %>'
9
11
 
10
12
  private
11
13
 
@@ -16,10 +18,6 @@ module GovKit
16
18
  def valid?
17
19
  # TODO
18
20
  end
19
-
20
- def response
21
- @response ||= self.class.get "/parlinfo/Compilations/HouseOfCommons/MemberByPostalCode.aspx?PostalCode=#{@postal_code}"
22
- end
23
21
  end
24
22
 
25
23
  StrategySet.register ParlGcCa
@@ -2,7 +2,7 @@ module GovKit
2
2
  module CA
3
3
  module PostalCode
4
4
  # The set of postal code to electoral district strategies.
5
- class StrategySet
5
+ module StrategySet
6
6
  # Stores the strategy set.
7
7
  # @return [Array<Strategy::Base>] the strategy set
8
8
  def self.strategies
@@ -40,9 +40,3 @@ module GovKit
40
40
  end
41
41
  end
42
42
  end
43
-
44
- require 'gov_kit-ca/postal_code/strategy/base'
45
- require 'gov_kit-ca/postal_code/strategy/elections-ca'
46
- require 'gov_kit-ca/postal_code/strategy/cbc-ca'
47
- require 'gov_kit-ca/postal_code/strategy/ndp-ca'
48
- require 'gov_kit-ca/postal_code/strategy/greenparty-ca'
@@ -1,15 +1,15 @@
1
- require 'gov_kit-ca/postal_code/strategy'
2
-
3
1
  module GovKit
4
2
  module CA
5
3
  # A collection of postal code helpers.
6
4
  # @see http://en.wikipedia.org/wiki/Postal_codes_in_Canada Postal codes in Canada
7
5
  module PostalCode
6
+ autoload :StrategySet, 'gov_kit-ca/postal_code/strategy_set'
7
+
8
8
  # @param [String] postal_code a postal code
9
9
  # @return [Boolean] whether the postal code is properly formatted
10
10
  # @see http://en.wikipedia.org/wiki/Postal_codes_in_Canada#Number_of_possible_postal_codes Possible postal codes
11
11
  def self.valid?(postal_code)
12
- !!postal_code.match(/\A[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]\Z/)
12
+ !!postal_code.match(/\A[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]\z/)
13
13
  end
14
14
 
15
15
  # Returns the electoral districts within a postal code.
@@ -78,3 +78,9 @@ module GovKit
78
78
  end
79
79
  end
80
80
  end
81
+
82
+ require 'gov_kit-ca/postal_code/strategy/base'
83
+ require 'gov_kit-ca/postal_code/strategy/elections_ca'
84
+ require 'gov_kit-ca/postal_code/strategy/cbc_ca'
85
+ require 'gov_kit-ca/postal_code/strategy/ndp_ca'
86
+ require 'gov_kit-ca/postal_code/strategy/greenparty_ca'
@@ -1,5 +1,5 @@
1
1
  module GovKit
2
2
  module CA
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/lib/gov_kit-ca.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
2
2
 
3
+ require 'erb'
4
+ require 'iconv'
3
5
  require 'json'
4
6
  require 'yaml'
5
7
 
6
- #require 'graticule'
7
8
  require 'httparty'
8
9
  require 'nokogiri'
9
10
  require 'yajl'
data/spec/cbc_ca_spec.rb CHANGED
@@ -1,23 +1,30 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- class GovKit::CA::PostalCode::Strategy::CbcCa
4
- describe GovKit::CA::PostalCode::Strategy::CbcCa do
3
+ class GovKit::CA::PostalCode::Strategy::CBCCa
4
+ describe GovKit::CA::PostalCode::Strategy::CBCCa 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::CBCCa.new(postal_code)
9
+ FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('cbc_ca', "#{postal_code}.response")
10
+ end
11
+ end
12
+
6
13
  it 'should return the electoral districts within a postal code' do
7
14
  { 'G0C2Y0' => [24019],
8
- 'T5S2B9' => [48015, 48017], # differs from elections.ca, ndp.ca
15
+ 'T5S2B9' => [48015, 48017], # differs from elections.ca, ndp.ca, greenparty.ca
9
16
  'K0A1K0' => [35012, 35025, 35040, 35052, 35063, 35064, 35087],
10
17
  }.each do |postal_code,electoral_districts|
11
- GovKit::CA::PostalCode::Strategy::CbcCa.new(postal_code).electoral_districts.should == electoral_districts
18
+ GovKit::CA::PostalCode::Strategy::CBCCa.new(postal_code).electoral_districts.should == electoral_districts
12
19
  end
13
20
  end
14
21
 
15
22
  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
23
+ GovKit::CA::PostalCode::Strategy::CBCCa.new('H0H0H0').electoral_districts.should be_false
17
24
  end
18
25
 
19
26
  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
27
+ GovKit::CA::PostalCode::Strategy::CBCCa.new('X1B1B1').electoral_districts.should be_false
21
28
  end
22
29
  end
23
30
  end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'gov_kit-ca/postal_code/strategy/digital-copyright_ca'
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
+ 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
+
14
+ it 'should return the electoral districts within a postal code' do
15
+ { 'G0C2Y0' => [24019, 24039], # differs from all
16
+ 'T5S2B9' => [48012, 48013, 48014, 48015, 48017, 48018], # differs from all
17
+ 'K0A1K0' => [35025, 35052, 35063], # differs from all
18
+ }.each do |postal_code,electoral_districts|
19
+ GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new(postal_code).electoral_districts.should == electoral_districts
20
+ end
21
+ end
22
+
23
+ it 'should return false if a postal code contains no electoral districts' do
24
+ GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('H0H0H0').electoral_districts.should be_false
25
+ end
26
+
27
+ it 'should return false if a postal code does not exist' do
28
+ GovKit::CA::PostalCode::Strategy::DigitalCopyrightCa.new('X1B1B1').electoral_districts.should be_false
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3,6 +3,13 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  class GovKit::CA::PostalCode::Strategy::ElectionsCa
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
+ FakeWeb.register_uri strategy.class.http_method, "#{strategy.class.base_uri}#{strategy.send(:path)}", :response => fixture_path('elections_ca', "#{postal_code}.response")
10
+ end
11
+ end
12
+
6
13
  it 'should return the electoral districts within a postal code' do
7
14
  { 'G0C2Y0' => [24019],
8
15
  'T5S2B9' => [48015], # differs from cbc.ca
@@ -0,0 +1,11 @@
1
+ HTTP/1.1 200 OK
2
+ Server: Apache/2.2.3 (Red Hat)
3
+ Content-Length: 52
4
+ Content-Type: text/html
5
+ X-Origin-Server: web15:sb10
6
+ Cache-Control: max-age=10
7
+ Expires: Sun, 05 Jun 2011 03:16:49 GMT
8
+ Date: Sun, 05 Jun 2011 03:16:39 GMT
9
+ Connection: close
10
+
11
+ [{"rid":7,"name":"St. John's South - Mount Pearl"}]
@@ -0,0 +1,11 @@
1
+ HTTP/1.1 200 OK
2
+ Server: Apache/2.2.3 (Red Hat)
3
+ Content-Length: 54
4
+ Content-Type: text/html
5
+ X-Origin-Server: web20:sb10
6
+ Cache-Control: max-age=10
7
+ Expires: Sun, 05 Jun 2011 03:16:49 GMT
8
+ Date: Sun, 05 Jun 2011 03:16:39 GMT
9
+ Connection: close
10
+
11
+ [{"rid":52,"name":"Gasp�sie - �les-de-la-Madeleine"}]