technicalpickles-daywalker 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 1
3
+ :patch: 2
4
4
  :major: 0
data/lib/daywalker.rb CHANGED
@@ -12,6 +12,7 @@ module Daywalker
12
12
  def self.api_key=(api_key)
13
13
  @api_key = api_key
14
14
  end
15
+
15
16
  # Get the API to be used
16
17
  def self.api_key
17
18
  @api_key
@@ -77,7 +77,9 @@ module Daywalker
77
77
  # Find one or many legislators, based on a set of conditions. See
78
78
  # VALID_ATTRIBUTES for possible attributes you can search for.
79
79
  #
80
- # If you want one legislators, and you expect there is exactly one legislator, use :one. An error will be raised if there are more than one result.
80
+ # If you want one legislators, and you expect there is exactly one
81
+ # legislator, use :one. An error will be raised if there are more than
82
+ # one result. An ArgumentErrror will be raised if multiple results come back.
81
83
  #
82
84
  # Daywalker::Legislator.find(:one, :state => 'NY', :district => 4)
83
85
  #
@@ -115,7 +117,6 @@ module Daywalker
115
117
  super
116
118
  end
117
119
  end
118
-
119
120
 
120
121
  def self.respond_to?(method_id) # :nodoc:
121
122
  match = DynamicFinderMatch.new(method_id)
@@ -128,6 +129,13 @@ module Daywalker
128
129
 
129
130
  protected
130
131
 
132
+ def self.handle_bad_request(body) # :nodoc:
133
+ case body
134
+ when "Multiple Legislators Returned" then raise(ArgumentError, "The conditions provided returned multiple results, by only one is expected")
135
+ else super
136
+ end
137
+ end
138
+
131
139
 
132
140
  def self.create_finder_method(method, finder, attribute_names) # :nodoc:
133
141
  class_eval %{
@@ -76,6 +76,18 @@ describe Daywalker::Legislator do
76
76
  }.should raise_error(Daywalker::BadApiKey)
77
77
  end
78
78
  end
79
+
80
+ describe 'by state and district, with multiple results' do
81
+ before do
82
+ register_uri_with_response 'legislators.get.xml?state=NY&title=Sen&apikey=redacted', 'legislators_find_one_by_ny_senators.xml'
83
+ end
84
+
85
+ it 'should raise an error about multiple legislators returned' do
86
+ lambda {
87
+ Daywalker::Legislator.find(:one, :state => 'NY', :title => :senator)
88
+ }.should raise_error(ArgumentError, "The conditions provided returned multiple results, by only one is expected")
89
+ end
90
+ end
79
91
  end
80
92
  end
81
93
 
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 400 Bad Request
2
+ Date: Fri, 13 Feb 2009 22:01:26 GMT
3
+ Server: Apache/2.2.3 (Debian) mod_python/3.2.10 Python/2.4.4 PHP/5.2.0-8+etch11
4
+ Content-Type: text/html; charset=utf-8
5
+ Vary: Accept-Encoding
6
+ Connection: close
7
+ Transfer-Encoding: chunked
8
+
9
+ Multiple Legislators Returned
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: technicalpickles-daywalker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Nichols
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-10 00:00:00 -08:00
12
+ date: 2009-02-13 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -50,6 +50,7 @@ files:
50
50
  - spec/fixtures/legislators_find_by_ny_district_4_bad_api.xml
51
51
  - spec/fixtures/legislators_find_ny_senators.xml
52
52
  - spec/fixtures/legislators_find_ny_senators_bad_api.xml
53
+ - spec/fixtures/legislators_find_one_by_ny_senators.xml
53
54
  - spec/spec_helper.rb
54
55
  has_rdoc: true
55
56
  homepage: http://github.com/technicalpickles/daywalker