technicalpickles-daywalker 0.1.2 → 0.2.0
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.
- data/README.rdoc +1 -1
- data/VERSION.yml +2 -2
- data/lib/daywalker.rb +40 -2
- data/lib/daywalker/base.rb +5 -2
- data/lib/daywalker/district.rb +24 -10
- data/lib/daywalker/dynamic_finder_match.rb +2 -6
- data/lib/daywalker/geocoder.rb +18 -0
- data/lib/daywalker/legislator.rb +154 -57
- data/lib/daywalker/type_converter.rb +25 -4
- data/spec/daywalker/district_spec.rb +67 -45
- data/spec/daywalker/dynamic_finder_match_spec.rb +9 -9
- data/spec/daywalker/geocoder_spec.rb +46 -0
- data/spec/daywalker/legislator_spec.rb +258 -71
- data/spec/daywalker/type_converter_spec.rb +45 -9
- data/spec/fixtures/get_nonexistent_legislator.xml +9 -0
- data/spec/fixtures/rpi_location.yml +5 -0
- data/spec/spec_helper.rb +40 -6
- metadata +37 -4
@@ -4,7 +4,7 @@ module Daywalker
|
|
4
4
|
case letter
|
5
5
|
when 'M' then :male
|
6
6
|
when 'F' then :female
|
7
|
-
else raise ArgumentError, "
|
7
|
+
else raise ArgumentError, "Unknown gender #{letter.inspect}. Only M and F allowed."
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -13,7 +13,7 @@ module Daywalker
|
|
13
13
|
when 'D' then :democrat
|
14
14
|
when 'R' then :republican
|
15
15
|
when 'I' then :independent
|
16
|
-
else raise ArgumentError, "
|
16
|
+
else raise ArgumentError, "Unknown party #{letter.inspect}. Only D, R, and I allowed."
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,25 @@ module Daywalker
|
|
21
21
|
case abbr
|
22
22
|
when 'Sen' then :senator
|
23
23
|
when 'Rep' then :representative
|
24
|
-
else raise ArgumentError, "Unknown title #{abbr.inspect}"
|
24
|
+
else raise ArgumentError, "Unknown title #{abbr.inspect}. Only Sen and Rep allowed."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.district_to_sym_or_i(district)
|
29
|
+
case district
|
30
|
+
when 'Junior Seat' then :junior_seat
|
31
|
+
when 'Senior Seat' then :senior_seat
|
32
|
+
when /^(\d+)$/ then $1.to_i
|
33
|
+
else raise ArgumentError, "Unknown district #{district.inspect}. Only Junior Seat, Senior Seat, and numbers allowed."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.sym_or_i_to_district(sym)
|
38
|
+
case sym
|
39
|
+
when :junior_seat then 'Junior Seat'
|
40
|
+
when :senior_seat then 'Senior Seat'
|
41
|
+
when Fixnum then sym.to_s
|
42
|
+
else raise ArgumentError, "Unknown district #{sym.inspect}. Only :junior_seat, :senior_seat, and Fixnum are allowed."
|
25
43
|
end
|
26
44
|
end
|
27
45
|
|
@@ -55,11 +73,14 @@ module Daywalker
|
|
55
73
|
end
|
56
74
|
|
57
75
|
def self.normalize_conditions(conditions)
|
76
|
+
if conditions[:district].kind_of?(Symbol) || conditions[:district].kind_of?(Fixnum)
|
77
|
+
conditions[:district] = sym_or_i_to_district(conditions[:district])
|
78
|
+
end
|
79
|
+
|
58
80
|
if conditions[:title].kind_of? Symbol
|
59
81
|
conditions[:title] = sym_to_title_abbr(conditions[:title])
|
60
82
|
end
|
61
83
|
|
62
|
-
move_value_in_hash(conditions, :district_number, :district)
|
63
84
|
move_value_in_hash(conditions, :official_rss_url, :official_rss)
|
64
85
|
|
65
86
|
if conditions[:party].kind_of? Symbol
|
@@ -1,32 +1,32 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Daywalker::District do
|
4
|
+
describe 'parsed from xml' do
|
5
|
+
before do
|
6
|
+
@xml = <<-XML
|
7
|
+
<district>
|
8
|
+
<state>NC</state>
|
9
|
+
<number>4</number>
|
10
|
+
</district>
|
11
|
+
XML
|
12
|
+
end
|
13
|
+
subject { Daywalker::District.parse(@xml) }
|
4
14
|
|
5
|
-
|
6
|
-
FakeWeb.clean_registry
|
7
|
-
end
|
8
|
-
|
9
|
-
before :all do
|
10
|
-
Daywalker.api_key = 'redacted'
|
11
|
-
end
|
12
|
-
|
13
|
-
after :all do
|
14
|
-
Daywalker.api_key = nil
|
15
|
+
specify_its_attributes :state => 'NC', :number => 4
|
15
16
|
end
|
16
17
|
|
17
|
-
describe '
|
18
|
+
describe 'unique_by_latitude_and_longitude' do
|
18
19
|
describe 'happy path' do
|
19
20
|
before do
|
20
21
|
# curl -i "http://services.sunlightlabs.com/api/districts.getDistrictFromLatLong.xml?apikey=urkeyhere&latitude=40.739157&longitude=-73.990929" > districts_by_latlng.xml
|
21
22
|
register_uri_with_response 'districts.getDistrictFromLatLong.xml?apikey=redacted&latitude=40.739157&longitude=-73.990929', 'districts_by_latlng.xml'
|
22
|
-
|
23
|
+
@district = Daywalker::District.unique_by_latitude_and_longitude(40.739157, -73.990929)
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
specify { subject.first.number.should == 14 }
|
26
|
+
it 'should return NY district 4' do
|
27
|
+
@district.state.should == 'NY'
|
28
|
+
@district.number.should == 14
|
29
|
+
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe 'bad api key' do
|
@@ -35,43 +35,42 @@ describe Daywalker::District do
|
|
35
35
|
register_uri_with_response('districts.getDistrictFromLatLong.xml?apikey=redacted&latitude=40.739157&longitude=-73.990929', 'districts_by_latlng_bad_api.xml')
|
36
36
|
end
|
37
37
|
|
38
|
-
specify 'should raise Daywalker::
|
38
|
+
specify 'should raise Daywalker::BadApiKeyError' do
|
39
39
|
lambda {
|
40
|
-
Daywalker::District.
|
41
|
-
}.should raise_error(Daywalker::
|
40
|
+
Daywalker::District.unique_by_latitude_and_longitude(40.739157, -73.990929)
|
41
|
+
}.should raise_error(Daywalker::BadApiKeyError)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe 'missing latitude' do
|
46
|
-
setup do
|
47
|
-
# curl -i "http://services.sunlightlabs.com/api/districts.getDistrictFromLatLong.xml?apikey=urkeyhere&longitude=-73.990929" > 'districts_by_latlng_missing_lat.xml'
|
48
|
-
register_uri_with_response('districts.getDistrictFromLatLong.xml?apikey=redacted&longitude=-73.990929', 'districts_by_latlng_missing_lat.xml')
|
49
|
-
end
|
50
|
-
|
51
46
|
specify 'should raise ArgumentError for latitude' do
|
52
47
|
lambda {
|
53
|
-
Daywalker::District.
|
48
|
+
Daywalker::District.unique_by_latitude_and_longitude(nil, -73.990929)
|
54
49
|
}.should raise_error(ArgumentError, /latitude/)
|
55
50
|
end
|
56
51
|
end
|
52
|
+
|
53
|
+
describe 'missing longitude' do
|
54
|
+
specify 'should raise ArgumentError for longitude' do
|
55
|
+
lambda {
|
56
|
+
Daywalker::District.unique_by_latitude_and_longitude(40.739157, nil)
|
57
|
+
}.should raise_error(ArgumentError, /longitude/)
|
58
|
+
end
|
59
|
+
end
|
57
60
|
end
|
58
61
|
|
59
|
-
describe '
|
62
|
+
describe 'all_by_zipcode' do
|
60
63
|
describe 'happy path' do
|
61
64
|
setup do
|
62
65
|
# curl -i "http://services.sunlightlabs.com/api/districts.getDistrictsFromZip.xml?apikey=urkeyhere&zip=27511" > districts_by_zip.xml
|
63
66
|
register_uri_with_response('districts.getDistrictsFromZip.xml?apikey=redacted&zip=27511', 'districts_by_zip.xml')
|
67
|
+
@districts = Daywalker::District.all_by_zipcode(27511)
|
64
68
|
end
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
specify { subject[0].state.should == 'NC' }
|
71
|
-
specify { subject[0].number.should == 13 }
|
72
|
-
|
73
|
-
specify { subject[1].state.should == 'NC' }
|
74
|
-
specify { subject[1].number.should == 4 }
|
70
|
+
it 'should find NC district 13 and 4' do
|
71
|
+
@districts.map{|d| d.state}.should == ['NC', 'NC']
|
72
|
+
@districts.map{|d| d.number}.should == [13, 4]
|
73
|
+
end
|
75
74
|
end
|
76
75
|
|
77
76
|
describe 'bad api key' do
|
@@ -80,25 +79,48 @@ describe Daywalker::District do
|
|
80
79
|
register_uri_with_response 'districts.getDistrictsFromZip.xml?apikey=redacted&zip=27511', 'districts_by_zip_bad_api.xml'
|
81
80
|
end
|
82
81
|
|
83
|
-
specify 'should raise
|
82
|
+
specify 'should raise BadApiKeyError' do
|
84
83
|
lambda {
|
85
|
-
Daywalker::District.
|
86
|
-
}.should raise_error(Daywalker::
|
84
|
+
Daywalker::District.all_by_zipcode(27511)
|
85
|
+
}.should raise_error(Daywalker::BadApiKeyError)
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
89
|
describe 'missing zip' do
|
91
|
-
setup do
|
92
|
-
# curl -i "http://services.sunlightlabs.com/api/districts.getDistrictsFromZip.xml?apikey=urkeyhere" > districts_by_zip_missing_zip.xml
|
93
|
-
register_uri_with_response 'districts.getDistrictsFromZip.xml?apikey=redacted', 'districts_by_zip_missing_zip.xml'
|
94
|
-
end
|
95
|
-
|
96
90
|
specify 'should raise ArgumentError for missing zip' do
|
97
91
|
lambda {
|
98
|
-
Daywalker::District.
|
92
|
+
Daywalker::District.all_by_zipcode(nil)
|
99
93
|
}.should raise_error(ArgumentError, /zip/)
|
100
94
|
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'unique_by_address' do
|
99
|
+
describe 'happy path' do
|
100
|
+
before do
|
101
|
+
Daywalker.geocoder.stub!(:locate).with("110 8th St., Troy, NY 12180").and_return({:longitude => -73.684236, :latitude => 42.731245})
|
102
|
+
|
103
|
+
Daywalker::District.stub!(:unique_by_latitude_and_longitude).with(42.731245, -73.684236)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should use unique_by_latitude_and_longitude' do
|
107
|
+
Daywalker::District.should_receive(:unique_by_latitude_and_longitude).with(42.731245, -73.684236)
|
101
108
|
|
109
|
+
Daywalker::District.unique_by_address("110 8th St., Troy, NY 12180")
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should use the geocoder to locate a latitude and longitude' do
|
113
|
+
Daywalker.geocoder.should_receive(:locate).with("110 8th St., Troy, NY 12180").and_return({:longitude => -73.684236, :latitude => 42.731245})
|
114
|
+
Daywalker::District.unique_by_address("110 8th St., Troy, NY 12180")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'with nil address' do
|
119
|
+
it 'should raise ArgumentError if address is not given' do
|
120
|
+
lambda {
|
121
|
+
Daywalker::District.unique_by_address(nil)
|
122
|
+
}.should raise_error(ArgumentError, /address/)
|
123
|
+
end
|
102
124
|
end
|
103
125
|
end
|
104
126
|
end
|
@@ -1,33 +1,33 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Daywalker::DynamicFinderMatch do
|
4
|
-
describe '
|
5
|
-
subject { Daywalker::DynamicFinderMatch.new(:
|
4
|
+
describe 'all by valid attributes (state and district number)' do
|
5
|
+
subject { Daywalker::DynamicFinderMatch.new(:all_by_state_and_district) }
|
6
6
|
|
7
7
|
specify 'should have :all finder' do
|
8
8
|
subject.finder.should == :all
|
9
9
|
end
|
10
10
|
|
11
|
-
specify 'should have attributes named [:state, :
|
12
|
-
subject.attribute_names.should == [:state, :
|
11
|
+
specify 'should have attributes named [:state, :district]' do
|
12
|
+
subject.attribute_names.should == [:state, :district]
|
13
13
|
end
|
14
14
|
|
15
15
|
specify { should be_a_match }
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'finding all by invalid attributes (foo and bar)' do
|
19
|
-
subject { Daywalker::DynamicFinderMatch.new(:
|
19
|
+
subject { Daywalker::DynamicFinderMatch.new(:all_by_foo_and_bar) }
|
20
20
|
specify { should_not be_a_match }
|
21
21
|
end
|
22
22
|
|
23
|
-
describe 'finding
|
24
|
-
subject { Daywalker::DynamicFinderMatch.new(:
|
23
|
+
describe 'finding unique by valid attrribute (govtrack_id)' do
|
24
|
+
subject { Daywalker::DynamicFinderMatch.new(:unique_by_govtrack_id) }
|
25
25
|
specify { should be_a_match }
|
26
26
|
specify 'should have :govtrack_id attribute' do
|
27
27
|
subject.attribute_names.should == [:govtrack_id]
|
28
28
|
end
|
29
|
-
specify 'should have :
|
30
|
-
subject.finder.should == :
|
29
|
+
specify 'should have :unique finder' do
|
30
|
+
subject.finder.should == :unique
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Daywalker::Geocoder do
|
4
|
+
|
5
|
+
describe 'locate for 110 8th St., Troy, NY 12180' do
|
6
|
+
before do
|
7
|
+
@geocoder = mock('geocoder')
|
8
|
+
Graticule::Geocoder::GeocoderUs.stub!(:new).and_return(@geocoder)
|
9
|
+
|
10
|
+
@geocoder.stub!(:locate).and_return(build_location)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return longitude -73.684236, latitude 42.731245' do
|
14
|
+
subject.locate('110 8th St., Troy, NY 12180').should == {
|
15
|
+
:longitude => -73.684236,
|
16
|
+
:latitude => 42.731245
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should use geocoder.us geocoder to locate' do
|
21
|
+
@geocoder.should_receive(:locate).with('110 8th St., Troy, NY 12180').and_return(build_location)
|
22
|
+
|
23
|
+
subject.locate('110 8th St., Troy, NY 12180')
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_location
|
27
|
+
Graticule::Location.new(:longitude => -73.684236, :latitude => 42.731245)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'locate an address that is fake' do
|
32
|
+
before do
|
33
|
+
@geocoder = mock('geocoder')
|
34
|
+
Graticule::Geocoder::GeocoderUs.stub!(:new).and_return(@geocoder)
|
35
|
+
|
36
|
+
@geocoder.stub!(:locate).and_raise(Graticule::AddressError)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should raise AddressError' do
|
40
|
+
lambda {
|
41
|
+
subject.locate('zomg')
|
42
|
+
}.should raise_error(Daywalker::AddressError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -2,26 +2,14 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe Daywalker::Legislator do
|
4
4
|
|
5
|
-
|
6
|
-
FakeWeb.clean_registry
|
7
|
-
end
|
8
|
-
|
9
|
-
before :all do
|
10
|
-
Daywalker.api_key = 'redacted'
|
11
|
-
end
|
12
|
-
|
13
|
-
after :all do
|
14
|
-
Daywalker.api_key = nil
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'find_all_by_zip' do
|
5
|
+
describe 'all_by_zip' do
|
18
6
|
|
19
7
|
describe 'happy path' do
|
20
8
|
setup do
|
21
9
|
# curl -i "http://services.sunlightlabs.com/api/legislators.allForZip.xml?zip=27511&apikey=redacted" > legislators_by_zip.xml
|
22
10
|
register_uri_with_response 'legislators.allForZip.xml?zip=27511&apikey=redacted', 'legislators_by_zip.xml'
|
23
11
|
|
24
|
-
@legislators = Daywalker::Legislator.
|
12
|
+
@legislators = Daywalker::Legislator.all_by_zip 27511
|
25
13
|
end
|
26
14
|
|
27
15
|
it 'return legislators identified by votersmart ids 119, 21082, 21787, and 10205' do
|
@@ -37,67 +25,78 @@ describe Daywalker::Legislator do
|
|
37
25
|
|
38
26
|
it 'should raise bad API key error' do
|
39
27
|
lambda {
|
40
|
-
Daywalker::Legislator.
|
41
|
-
}.should raise_error(Daywalker::
|
28
|
+
Daywalker::Legislator.all_by_zip 27511
|
29
|
+
}.should raise_error(Daywalker::BadApiKeyError)
|
42
30
|
end
|
43
31
|
end
|
44
32
|
|
45
33
|
describe 'without a zip code' do
|
46
34
|
it 'should raise ArgumentError for missing zip' do
|
47
35
|
lambda {
|
48
|
-
Daywalker::Legislator.
|
36
|
+
Daywalker::Legislator.all_by_zip nil
|
49
37
|
}.should raise_error(ArgumentError, /zip/)
|
50
38
|
end
|
51
39
|
end
|
52
40
|
end
|
53
41
|
|
54
|
-
describe 'found with
|
42
|
+
describe 'found with unique' do
|
55
43
|
describe 'by state and district, with one result,' do
|
56
44
|
describe 'happy path' do
|
57
45
|
before do
|
58
46
|
register_uri_with_response 'legislators.get.xml?apikey=redacted&state=NY&district=4', 'legislators_find_by_ny_district_4.xml'
|
59
|
-
@legislator = Daywalker::Legislator.
|
47
|
+
@legislator = Daywalker::Legislator.unique(:state => 'NY', :district => 4)
|
60
48
|
end
|
61
49
|
|
62
|
-
|
63
50
|
it 'should have votesmart id 119' do
|
64
51
|
@legislator.votesmart_id.should == 119
|
65
52
|
end
|
66
53
|
end
|
67
54
|
|
68
|
-
describe '
|
55
|
+
describe 'with bad API key' do
|
69
56
|
before do
|
70
57
|
register_uri_with_response 'legislators.get.xml?apikey=redacted&state=NY&district=4', 'legislators_find_by_ny_district_4_bad_api.xml'
|
71
58
|
end
|
72
59
|
|
73
60
|
it 'should raise a missing parameter error for zip' do
|
74
61
|
lambda {
|
75
|
-
Daywalker::Legislator.
|
76
|
-
}.should raise_error(Daywalker::
|
62
|
+
Daywalker::Legislator.unique(:state => 'NY', :district => 4)
|
63
|
+
}.should raise_error(Daywalker::BadApiKeyError)
|
77
64
|
end
|
78
65
|
end
|
79
66
|
|
80
|
-
describe '
|
67
|
+
describe 'with multiple results' do
|
81
68
|
before do
|
82
69
|
register_uri_with_response 'legislators.get.xml?state=NY&title=Sen&apikey=redacted', 'legislators_find_one_by_ny_senators.xml'
|
83
70
|
end
|
84
71
|
|
85
72
|
it 'should raise an error about multiple legislators returned' do
|
86
73
|
lambda {
|
87
|
-
Daywalker::Legislator.
|
74
|
+
Daywalker::Legislator.unique(:state => 'NY', :title => :senator)
|
88
75
|
}.should raise_error(ArgumentError, "The conditions provided returned multiple results, by only one is expected")
|
89
76
|
end
|
90
77
|
end
|
78
|
+
|
79
|
+
describe 'with no results' do
|
80
|
+
before do
|
81
|
+
register_uri_with_response 'legislators.get.xml?state=JK&title=Sen&apikey=redacted', 'get_nonexistent_legislator.xml'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should raise NotFoundError' do
|
85
|
+
lambda {
|
86
|
+
Daywalker::Legislator.unique(:state => 'JK', :title => :senator)
|
87
|
+
}.should raise_error(Daywalker::NotFoundError)
|
88
|
+
end
|
89
|
+
end
|
91
90
|
end
|
92
91
|
end
|
93
92
|
|
94
|
-
describe 'found with
|
93
|
+
describe 'found with all' do
|
95
94
|
describe 'by state and title, with multiple results,' do
|
96
95
|
describe 'happy path' do
|
97
96
|
before do
|
98
97
|
# curl -i "http://services.sunlightlabs.com/api/legislators.getList.xml?state=NY&title=Sen&apikey=redacted" > legislators_find_ny_senators.xml
|
99
98
|
register_uri_with_response 'legislators.getList.xml?state=NY&apikey=redacted&title=Sen', 'legislators_find_ny_senators.xml'
|
100
|
-
@legislators = Daywalker::Legislator.
|
99
|
+
@legislators = Daywalker::Legislator.all(:state => 'NY', :title => :senator)
|
101
100
|
end
|
102
101
|
|
103
102
|
it 'should return legislators with votesmart ids 55463 and 26976' do
|
@@ -110,30 +109,21 @@ describe Daywalker::Legislator do
|
|
110
109
|
register_uri_with_response 'legislators.getList.xml?state=NY&apikey=redacted&title=Sen', 'legislators_find_ny_senators_bad_api.xml'
|
111
110
|
end
|
112
111
|
|
113
|
-
it 'should raise
|
112
|
+
it 'should raise BadApiKeyError' do
|
114
113
|
lambda {
|
115
|
-
Daywalker::Legislator.
|
116
|
-
}.should raise_error(Daywalker::
|
117
|
-
|
114
|
+
Daywalker::Legislator.all(:state => 'NY', :title => :senator)
|
115
|
+
}.should raise_error(Daywalker::BadApiKeyError)
|
118
116
|
end
|
119
117
|
end
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
123
|
-
describe 'found with find(:zomg)' do
|
124
|
-
it 'should raise ArgumentError' do
|
125
|
-
lambda {
|
126
|
-
Daywalker::Legislator.find(:zomg, {})
|
127
|
-
}.should raise_error(ArgumentError, /zomg/)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
121
|
# TODO switch this to mocking
|
132
|
-
describe 'dynamic finder
|
122
|
+
describe 'dynamic finder all_by_state_and_title' do
|
133
123
|
before do
|
134
124
|
register_uri_with_response 'legislators.getList.xml?state=NY&apikey=redacted&title=Sen', 'legislators_find_ny_senators.xml'
|
135
125
|
|
136
|
-
@legislators = Daywalker::Legislator.
|
126
|
+
@legislators = Daywalker::Legislator.all_by_state_and_title('NY', :senator)
|
137
127
|
end
|
138
128
|
|
139
129
|
it 'should return legislators with votesmart ids 55463 and 26976' do
|
@@ -141,12 +131,79 @@ describe Daywalker::Legislator do
|
|
141
131
|
end
|
142
132
|
|
143
133
|
it 'should respond to find_all_by_state_and_title' do
|
144
|
-
Daywalker::Legislator.should respond_to(:
|
134
|
+
Daywalker::Legislator.should respond_to(:all_by_state_and_title)
|
145
135
|
end
|
146
136
|
end
|
147
137
|
|
138
|
+
describe 'all_by_latitude_and_longitude' do
|
139
|
+
before do
|
140
|
+
@district = mock('district', :state => 'NY', :number => 21)
|
141
|
+
Daywalker::District.stub!(:unique_by_latitude_and_longitude).with(42.731245, -73.684236).and_return(@district)
|
142
|
+
|
143
|
+
@representative = mock('representative')
|
144
|
+
@junior_senator = mock('junior senator')
|
145
|
+
@senior_senator = mock('senior senator')
|
148
146
|
|
149
|
-
|
147
|
+
Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', 21).and_return(@representative)
|
148
|
+
Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', :junior_seat).and_return(@junior_senator)
|
149
|
+
Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', :senior_seat).and_return(@senior_senator)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should find district by lat & lng' do
|
153
|
+
Daywalker::District.should_receive(:unique_by_latitude_and_longitude).with(42.731245, -73.684236).and_return(@district)
|
154
|
+
|
155
|
+
Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should find the representative for the district' do
|
159
|
+
Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', 21).and_return(@representative)
|
160
|
+
|
161
|
+
Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should find the junior senator for the state' do
|
165
|
+
Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', :junior_seat).and_return(@junior_senator)
|
166
|
+
|
167
|
+
Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should find the senior senator for the state' do
|
171
|
+
Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', :senior_seat).and_return(@senior_senator)
|
172
|
+
|
173
|
+
Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should return the representative, junior senator, and senior senator' do
|
177
|
+
Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236).should == {
|
178
|
+
:representative => @representative,
|
179
|
+
:junior_senator => @junior_senator,
|
180
|
+
:senior_senator => @senior_senator
|
181
|
+
}
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'all_by_address' do
|
186
|
+
before do
|
187
|
+
Daywalker.geocoder.stub!(:locate).with("110 8th St., Troy, NY 12180").and_return({:longitude => -73.684236, :latitude => 42.731245})
|
188
|
+
|
189
|
+
Daywalker::Legislator.stub!(:all_by_latitude_and_longitude).with(42.731245, -73.684236)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should geocode the address' do
|
193
|
+
Daywalker.geocoder.should_receive(:locate).with("110 8th St., Troy, NY 12180").and_return({:longitude => -73.684236, :latitude => 42.731245})
|
194
|
+
|
195
|
+
Daywalker::Legislator.all_by_address("110 8th St., Troy, NY 12180")
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should find legislators by latitude and longitude' do
|
199
|
+
Daywalker::Legislator.should_receive(:all_by_latitude_and_longitude).with(42.731245, -73.684236)
|
200
|
+
|
201
|
+
Daywalker::Legislator.all_by_address("110 8th St., Troy, NY 12180")
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
describe 'representative parsed from XML' do
|
150
207
|
setup do
|
151
208
|
@xml = <<-XML
|
152
209
|
<legislator>
|
@@ -181,36 +238,166 @@ describe Daywalker::Legislator do
|
|
181
238
|
</legislator>
|
182
239
|
XML
|
183
240
|
end
|
241
|
+
|
242
|
+
subject { Daywalker::Legislator.parse(@xml) }
|
243
|
+
|
244
|
+
specify_its_attributes :district => 4,
|
245
|
+
:title => :representative,
|
246
|
+
:eventful_id => 'P0-001-000016562-5',
|
247
|
+
:in_office => true,
|
248
|
+
:state => 'NC',
|
249
|
+
:votesmart_id => 119,
|
250
|
+
:official_rss_url => nil,
|
251
|
+
:party => :democrat,
|
252
|
+
:email => nil,
|
253
|
+
:crp_id => 'N00002260',
|
254
|
+
:website_url => 'http://price.house.gov/',
|
255
|
+
:fax_number => '202-225-2014',
|
256
|
+
:govtrack_id => 400326,
|
257
|
+
:first_name => 'David',
|
258
|
+
:middle_name => 'Eugene',
|
259
|
+
:last_name => 'Price',
|
260
|
+
:congress_office => '2162 Rayburn House Office Building',
|
261
|
+
:bioguide_id => 'P000523',
|
262
|
+
:webform_url => 'http://price.house.gov/contact/contact_form.shtml',
|
263
|
+
:youtube_url => 'http://www.youtube.com/repdavidprice',
|
264
|
+
:nickname => nil,
|
265
|
+
:phone => '202-225-1784',
|
266
|
+
:fec_id => 'H6NC04037',
|
267
|
+
:gender => :male,
|
268
|
+
:name_suffix => nil,
|
269
|
+
:twitter_id => nil,
|
270
|
+
:sunlight_old_id => 'fakeopenID319',
|
271
|
+
:congresspedia_url => 'http://www.sourcewatch.org/index.php?title=David_Price'
|
272
|
+
end
|
273
|
+
|
274
|
+
describe 'senior senator parsed from XML' do
|
275
|
+
before do
|
276
|
+
@xml = <<-XML
|
277
|
+
<legislator>
|
278
|
+
<district>Senior Seat</district>
|
279
|
+
<title>Sen</title>
|
280
|
+
<eventful_id>P0-001-000016060-2</eventful_id>
|
281
|
+
<in_office>1</in_office>
|
282
|
+
<state>NC</state>
|
283
|
+
<votesmart_id>41533</votesmart_id>
|
284
|
+
<party>R</party>
|
285
|
+
<email/>
|
286
|
+
<crp_id>N00008071</crp_id>
|
287
|
+
<website>http://dole.senate.gov</website>
|
288
|
+
<fax>202-224-1100</fax>
|
289
|
+
<govtrack_id>300035</govtrack_id>
|
290
|
+
<firstname>Elizabeth</firstname>
|
291
|
+
<middlename>H.</middlename>
|
292
|
+
<lastname>Dole</lastname>
|
293
|
+
<congress_office>555 Dirksen Office Building</congress_office>
|
294
|
+
<bioguide_id>D000601</bioguide_id>
|
295
|
+
<webform>http://dole.senate.gov/public/index.cfm?FuseAction=ContactInformation.ContactForm</webform>
|
296
|
+
<nickname/>
|
297
|
+
<phone>202-224-6342</phone>
|
298
|
+
<fec_id>S2NC00083</fec_id>
|
299
|
+
<gender>F</gender>
|
300
|
+
<name_suffix/>
|
301
|
+
<twitter_id/>
|
302
|
+
<sunlight_old_id>fakeopenID468</sunlight_old_id>
|
303
|
+
<congresspedia_url>http://www.sourcewatch.org/index.php?title=Elizabeth_Dole</congresspedia_url>
|
304
|
+
</legislator>
|
305
|
+
XML
|
306
|
+
end
|
307
|
+
|
184
308
|
subject { Daywalker::Legislator.parse(@xml) }
|
185
309
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
specify { subject.sunlight_old_id.should == 'fakeopenID319' }
|
213
|
-
specify { subject.congresspedia_url.should == 'http://www.sourcewatch.org/index.php?title=David_Price' }
|
310
|
+
specify_its_attributes :district => :senior_seat,
|
311
|
+
:title => :senator,
|
312
|
+
:eventful_id => 'P0-001-000016060-2',
|
313
|
+
:in_office => true,
|
314
|
+
:state => 'NC',
|
315
|
+
:votesmart_id => 41533,
|
316
|
+
:party => :republican,
|
317
|
+
:email => nil,
|
318
|
+
:crp_id => 'N00008071',
|
319
|
+
:website_url => 'http://dole.senate.gov',
|
320
|
+
:fax_number => '202-224-1100',
|
321
|
+
:govtrack_id => 300035,
|
322
|
+
:first_name => 'Elizabeth',
|
323
|
+
:middle_name => 'H.',
|
324
|
+
:last_name => 'Dole',
|
325
|
+
:congress_office => '555 Dirksen Office Building',
|
326
|
+
:bioguide_id => 'D000601',
|
327
|
+
:webform_url => 'http://dole.senate.gov/public/index.cfm?FuseAction=ContactInformation.ContactForm',
|
328
|
+
:nickname => nil,
|
329
|
+
:phone => '202-224-6342',
|
330
|
+
:fec_id => 'S2NC00083',
|
331
|
+
:gender => :female,
|
332
|
+
:name_suffix => nil,
|
333
|
+
:twitter_id => nil,
|
334
|
+
:sunlight_old_id => 'fakeopenID468',
|
335
|
+
:congresspedia_url => 'http://www.sourcewatch.org/index.php?title=Elizabeth_Dole'
|
214
336
|
end
|
215
337
|
|
338
|
+
describe 'junior senator parsed from XML' do
|
339
|
+
before do
|
340
|
+
@xml = <<-XML
|
341
|
+
<legislator>
|
342
|
+
<district>Junior Seat</district>
|
343
|
+
<title>Sen</title>
|
344
|
+
<eventful_id>P0-001-000016040-8</eventful_id>
|
345
|
+
<in_office>1</in_office>
|
346
|
+
<state>NC</state>
|
347
|
+
<votesmart_id>21787</votesmart_id>
|
348
|
+
<party>R</party>
|
349
|
+
<email/>
|
350
|
+
<crp_id>N00002221</crp_id>
|
351
|
+
<website>http://burr.senate.gov/</website>
|
352
|
+
<fax>202-228-2981</fax>
|
353
|
+
<govtrack_id>400054</govtrack_id>
|
354
|
+
<firstname>Richard</firstname>
|
355
|
+
<middlename>M.</middlename>
|
356
|
+
<lastname>Burr</lastname>
|
357
|
+
<congress_office>217 Russell Senate Office Building</congress_office>
|
358
|
+
<bioguide_id>B001135</bioguide_id>
|
359
|
+
<webform>http://burr.senate.gov/public/index.cfm?FuseAction=Contact.Home</webform>
|
360
|
+
<nickname/>
|
361
|
+
<phone>202-224-3154</phone>
|
362
|
+
<fec_id>S4NC00089</fec_id>
|
363
|
+
<gender>M</gender>
|
364
|
+
<name_suffix/>
|
365
|
+
<twitter_id/>
|
366
|
+
<sunlight_old_id>fakeopenID449</sunlight_old_id>
|
367
|
+
<congresspedia_url>http://www.sourcewatch.org/index.php?title=Richard_Burr</congresspedia_url>
|
368
|
+
</legislator>
|
369
|
+
XML
|
370
|
+
end
|
371
|
+
|
372
|
+
subject { Daywalker::Legislator.parse(@xml) }
|
373
|
+
|
374
|
+
specify_its_attributes :district => :junior_seat,
|
375
|
+
:title => :senator,
|
376
|
+
:eventful_id => 'P0-001-000016040-8',
|
377
|
+
:in_office => true,
|
378
|
+
:state => 'NC',
|
379
|
+
:votesmart_id => 21787,
|
380
|
+
:party => :republican,
|
381
|
+
:email => nil,
|
382
|
+
:crp_id => 'N00002221',
|
383
|
+
:website_url => 'http://burr.senate.gov/',
|
384
|
+
:fax_number => '202-228-2981',
|
385
|
+
:govtrack_id => 400054,
|
386
|
+
:first_name => 'Richard',
|
387
|
+
:middle_name => 'M.',
|
388
|
+
:last_name => 'Burr',
|
389
|
+
:congress_office => '217 Russell Senate Office Building',
|
390
|
+
:bioguide_id => 'B001135',
|
391
|
+
:webform_url => 'http://burr.senate.gov/public/index.cfm?FuseAction=Contact.Home',
|
392
|
+
:nickname => nil,
|
393
|
+
:phone => '202-224-3154',
|
394
|
+
:fec_id => 'S4NC00089',
|
395
|
+
:gender => :male,
|
396
|
+
:name_suffix => nil,
|
397
|
+
:twitter_id => nil,
|
398
|
+
:sunlight_old_id => 'fakeopenID449',
|
399
|
+
:congresspedia_url => 'http://www.sourcewatch.org/index.php?title=Richard_Burr'
|
400
|
+
end
|
401
|
+
|
402
|
+
|
216
403
|
end
|