Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update GovKit::Resource.parse case statement to return error expected…

… by spec. Minor changes to specs to reflect changed code; specs all pass.
  • Loading branch information...
commit b31d2a168d017f3f37b351b33cdf6acb014f5fa1 1 parent 438b177
Jeff Roush Jeff-R authored
6 lib/gov_kit/resource.rb
@@ -24,12 +24,12 @@ def self.parse(response)
24 24 # This method handles the basic responses we might get back from
25 25 # Net::HTTP. But if a service returns something other than a 404 when an object is not found,
26 26 # you'll need to handle that in the subclass.
27   - raise ResourceNotFound, "Resource not found" unless !response.blank?
28   -
29 27 if response.class == HTTParty::Response
30 28 case response.response
31 29 when Net::HTTPNotFound
32 30 raise ResourceNotFound, "404 Not Found"
  31 + when Net::HTTPGone
  32 + raise ResourceNotFound, "404 Not Found"
33 33 when Net::HTTPUnauthorized
34 34 raise NotAuthorized, "401 Not Authorized; have you set up your API key?"
35 35 when Net::HTTPServerError
@@ -39,6 +39,8 @@ def self.parse(response)
39 39 end
40 40 end
41 41
  42 + raise ResourceNotFound, "Resource not found" unless !response.blank?
  43 +
42 44 instantiate(response)
43 45 end
44 46
4 spec/follow_the_money_spec.rb
... ... @@ -1,5 +1,9 @@
1 1 require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2 2
  3 +# Provides "String.singularize"
  4 +# which is used by resource_for_collection, in resource.rb
  5 +require 'active_support/inflector'
  6 +
3 7 module GovKit::FollowTheMoney
4 8 describe GovKit::FollowTheMoney do
5 9
30 spec/open_states_spec.rb
... ... @@ -1,19 +1,27 @@
1 1 require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2 2
  3 +# Provides "String.singularize"
  4 +# which is used by resource_for_collection, in resource.rb
  5 +require 'active_support/inflector'
  6 +
  7 +# Provides string.last()
  8 +# which is used by method_missing in resource.rb
  9 +require 'active_support/core_ext/string'
  10 +
3 11 module GovKit::OpenStates
4 12 describe GovKit::OpenStates do
5 13 before(:all) do
6 14 base_uri = GovKit::OpenStatesResource.base_uri.gsub(/\./, '\.')
7 15
8 16 urls = [
9   - ['/ca/\?', 'state.response'],
10   - ['/bills/ca/20092010/AB667/', 'bill.response'],
11   - ['/bills/search/\?', 'bill_query.response'],
  17 + ['/metadata/ca/\?', 'state.response'],
  18 + ['/bills/ca/20092010/AB667/', 'bill.response'],
  19 + ['/bills/\?', 'bill_query.response'],
12 20 ['/bills/latest/\?', 'bill_query.response'],
13 21 ['/legislators/2462/\?', 'legislator.response'],
14 22 ['/legislators/410/\?', '410.response'],
15 23 ['/legislators/401/\?', '401.response'],
16   - ['/legislators/search/\?', 'legislator_query.response']
  24 + ['/legislators/\?', 'legislator_query.response']
17 25 ]
18 26
19 27 urls.each do |u|
@@ -23,15 +31,15 @@ module GovKit::OpenStates
23 31
24 32 it "should have the base uri set properly" do
25 33 [State, Bill, Legislator].each do |klass|
26   - klass.base_uri.should == "http://fiftystates-dev.sunlightlabs.com/api"
  34 + klass.base_uri.should == "http://openstates.sunlightlabs.com/api/v1"
27 35 end
28 36 end
29 37
30   - it "should raise NotAuthorizedError if the api key is not valid" do
  38 + it "should raise NotAuthorized if the api key is not valid" do
31 39 # The Open States API returns a 401 Not Authorized if the API key is invalid.
32 40 lambda do
33 41 @legislator = Legislator.find(401)
34   - end.should raise_error(GovKit::NotAuthorizedError)
  42 + end.should raise_error(GovKit::NotAuthorized)
35 43
36 44 @legislator.should be_nil
37 45 end
@@ -55,9 +63,9 @@ module GovKit::OpenStates
55 63
56 64 describe Bill do
57 65 context "#find" do
58   - it "should find a bill by stat abbreviation, session, chamber, bill_id" do
  66 + it "should find a bill by state abbreviation, session, chamber, bill_id" do
59 67 lambda do
60   - @bill = Bill.find('ca', 20092010, 'lower', 'AB667')
  68 + @bill = Bill.find('ca', '20092010', 'lower', 'AB667')
61 69 end.should_not raise_error
62 70
63 71 @bill.should be_an_instance_of(Bill)
@@ -80,7 +88,7 @@ module GovKit::OpenStates
80 88 context "#latest" do
81 89 it "should get the latest bills by given criteria" do
82 90 lambda do
83   - @latest = Bill.latest('2010-01-01','tx')
  91 + @latest = Bill.latest('2010-01-01', :state => 'tx')
84 92 end.should_not raise_error
85 93
86 94 @latest.should be_an_instance_of(Array)
@@ -107,7 +115,7 @@ module GovKit::OpenStates
107 115 it "should raise a GovKitError if the legislator is not found" do
108 116 lambda do
109 117 @legislator = Legislator.find(410)
110   - end.should raise_error(GovKit::ResourceNotFoundError)
  118 + end.should raise_error(GovKit::ResourceNotFound)
111 119
112 120 @legislator.should be_nil
113 121 end

0 comments on commit b31d2a1

Please sign in to comment.
Something went wrong with that request. Please try again.