nytimes-congress 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe LegislatorVoteComparison do
4
+ describe "#initialize" do
5
+ attr_reader :comparison
6
+
7
+ def example_data
8
+ member_vote_comparison_response
9
+ end
10
+
11
+ before do
12
+ @comparison = LegislatorVoteComparison.new(JSON.parse(example_data)['results'].first)
13
+ end
14
+
15
+ it "should return the LegislatorVoteComparison for the two Legislators" do
16
+ comparison.should be_kind_of(LegislatorVoteComparison)
17
+ end
18
+
19
+ it "should return counts of the votes where the two Legislators agreed and disagreed" do
20
+ comparison.common_votes.should == 241
21
+ comparison.disagree_votes.should == 187
22
+ end
23
+
24
+ it "should return percents of votes where the two Legislators agreed and disagreed" do
25
+ comparison.disagree_percent.should == '77.59'
26
+ comparison.agree_percent.should == '22.41'
27
+ end
28
+
29
+ it "should return percents of votes where the two Legislators agreed and disagreed" do
30
+ comparison.first_member_id.should == 'F000062'
31
+ comparison.second_member_id.should == 'S001141'
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Position do
4
+ attr_reader :vote, :position
5
+
6
+ before do
7
+ @position = Position.new("W000779", "Yes")
8
+ end
9
+
10
+ describe "initializing" do
11
+ it "assigns attributes as expected" do
12
+ position.member_id.should == "W000779"
13
+ position.vote_position.should == "Yes"
14
+ end
15
+ end
16
+
17
+ describe "instance methods" do
18
+ describe "#legislator" do
19
+ it "returns the Legislator whose position this is" do
20
+ mock(Legislator).find("W000779") do |legislator|
21
+ stub(legislator).name {"Hank McPank"}
22
+ end
23
+ position.legislator.name.should == "Hank McPank"
24
+ end
25
+ end
26
+
27
+ describe "#to_s" do
28
+ it "returns the vote position" do
29
+ position.to_s.should == "Yes"
30
+ end
31
+ end
32
+
33
+ describe "#for?" do
34
+
35
+ it "returns true when the vote_position is 'Yes'" do
36
+ Position.new("W000779", 'Yes').should be_for
37
+ end
38
+ it "returns false when the vote_position is 'No'" do
39
+ Position.new("W000779", 'No').should_not be_for
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,104 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe NYTimes::Congress::Role do
4
+ attr_reader :role
5
+
6
+ def example_data
7
+ role_response_fragment
8
+ end
9
+
10
+ context "initializing with params hash", :shared => true do
11
+ before do
12
+ @role = Role.new(JSON.parse(example_data))
13
+ end
14
+
15
+ it "should set String attributes" do
16
+ role.chamber.should == 'Senate'
17
+ role.title.should == 'Senator, 2nd Class'
18
+ role.state.should == 'DE'
19
+ role.party.should == 'D'
20
+ end
21
+
22
+ it "should set the congress number as an Integer" do
23
+ role.congress.should == 111
24
+ end
25
+
26
+ it "should parse start and end dates into Date objects" do
27
+ role.start_date.should == Date.parse("2009-01-06")
28
+ role.end_date.should == Date.parse("2009-01-20")
29
+ end
30
+
31
+ it "should return nil for values that are 'N/A'" do
32
+ role.district.should be_nil
33
+ end
34
+ end
35
+
36
+ context "initializing through a Legislator" do
37
+ attr_reader :legislator
38
+ def example_data
39
+ <<-JSON
40
+ {
41
+ "member_id":"B000444",
42
+ "name":"Joseph Biden",
43
+ "date_of_birth":"1942-11-20",
44
+ "gender":"M",
45
+ "url":"http://biden.senate.gov",
46
+ "govtrack_id":"300008",
47
+ "roles":[
48
+ {
49
+ "congress":"111",
50
+ "chamber":"Senate",
51
+ "title":"Senator, 2nd Class",
52
+ "state":"DE",
53
+ "party":"D",
54
+ "district":"N/A",
55
+ "start_date":"2009-01-06",
56
+ "end_date":"2009-01-20"
57
+ },
58
+ {
59
+ "congress":"110",
60
+ "chamber":"Senate",
61
+ "title":"Senator, 2nd Class",
62
+ "state":"DE",
63
+ "party":"D",
64
+ "district":"N/A",
65
+ "start_date":"2007-01-04",
66
+ "end_date":"2009-01-03"
67
+ }
68
+ ]
69
+ }
70
+ JSON
71
+ end
72
+
73
+ before do
74
+ @legislator = Legislator.new(JSON.parse(example_data))
75
+ legislator.roles.should_not be_nil
76
+ @role = legislator.roles.sort_by{|r| r.congress}.first
77
+ end
78
+
79
+ it "should set String attributes" do
80
+ role.chamber.should == 'Senate'
81
+ role.title.should == 'Senator, 2nd Class'
82
+ role.state.should == 'DE'
83
+ role.party.should == 'D'
84
+ end
85
+
86
+ it "should set the congress number as an Integer" do
87
+ role.congress.should == 110
88
+ end
89
+
90
+ it "should parse start and end dates into Date objects" do
91
+ role.start_date.should == Date.parse("2007-01-04")
92
+ role.end_date.should == Date.parse("2009-01-03")
93
+ end
94
+
95
+ it "should return nil for values that are 'N/A'" do
96
+ role.district.should be_nil
97
+ end
98
+
99
+ it "can be found through the Legislator" do
100
+ legislator.roles.should include(role)
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe RollCallVote do
4
+ attr_reader :congress, :vote
5
+
6
+ def example_data
7
+ roll_call_votes_response
8
+ end
9
+
10
+ before do
11
+ FakeWeb.clean_registry
12
+ @congress = Congress.new(111, :senate)
13
+ end
14
+
15
+ describe "finding through a Congress by session and roll call number"do
16
+ before do
17
+ FakeWeb.register_uri(api_url_for('111/senate/sessions/1/votes/12.json'), :string => example_data)
18
+ @vote = congress.roll_call_vote(1, 12)
19
+ end
20
+
21
+ it "returns its outcome" do
22
+ vote.result.should == "Agreed to"
23
+ end
24
+
25
+ it "returns its Congress number and chamber" do
26
+ vote.congress.should == congress.number
27
+ vote.chamber.should == congress.chamber
28
+ end
29
+
30
+ it "can return its Congress object" do
31
+ vote.get_congress.number.should == congress.number
32
+ end
33
+
34
+ it "returns a Date object for the day of the vote" do
35
+ vote.date.should == Date.parse("2009-01-22")
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --loadby
3
+ mtime
4
+ --backtrace
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../lib/ny-times-congress'
2
+ require File.dirname(__FILE__) + '/example_data/example_data'
3
+
4
+ require "rubygems"
5
+ require "spec"
6
+ require 'fake_web'
7
+
8
+ gem 'rr'
9
+
10
+ include NYTimes::Congress
11
+
12
+ API_KEY = 'blahblah'
13
+ Base.api_key = API_KEY
14
+
15
+ Spec::Runner.configure do |config|
16
+ config.mock_with :rr
17
+ end
18
+
19
+ def api_url_for(path, params = {})
20
+ full_params = params.merge 'api-key' => API_KEY
21
+ Base.build_request_url(path, full_params).to_s
22
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nytimes-congress
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 4
9
+ - 0
10
+ version: 1.4.0
11
+ platform: ruby
12
+ authors:
13
+ - Patrick Ewing
14
+ - Derek Willis
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-06-09 00:00:00 -04:00
20
+ default_executable: congresh
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: json
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 21
31
+ segments:
32
+ - 1
33
+ - 1
34
+ - 3
35
+ version: 1.1.3
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ description:
39
+ email: dwillis@gmail.com
40
+ executables:
41
+ - congresh
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - LICENSE
46
+ - README.mkdn
47
+ - TODO
48
+ files:
49
+ - LICENSE
50
+ - README.mkdn
51
+ - Rakefile
52
+ - TODO
53
+ - VERSION.yml
54
+ - bin/congresh
55
+ - bin/setup.rb
56
+ - lib/ny-times-congress.rb
57
+ - lib/ny-times/congress/attribute_transformation.rb
58
+ - lib/ny-times/congress/base.rb
59
+ - lib/ny-times/congress/congress.rb
60
+ - lib/ny-times/congress/current_member.rb
61
+ - lib/ny-times/congress/floor.rb
62
+ - lib/ny-times/congress/legislator.rb
63
+ - lib/ny-times/congress/legislator_vote_comparison.rb
64
+ - lib/ny-times/congress/nomination.rb
65
+ - lib/ny-times/congress/position.rb
66
+ - lib/ny-times/congress/role.rb
67
+ - lib/ny-times/congress/roll_call_vote.rb
68
+ - spec/base_spec.rb
69
+ - spec/congress_spec.rb
70
+ - spec/example_data/example_data.rb
71
+ - spec/example_data/member.json
72
+ - spec/example_data/member_positions.json
73
+ - spec/example_data/member_vote_comparison.json
74
+ - spec/example_data/members.json
75
+ - spec/example_data/roll_call_votes.json
76
+ - spec/legislator_spec.rb
77
+ - spec/legislator_vote_comparison_spec.rb
78
+ - spec/position_spec.rb
79
+ - spec/role_spec.rb
80
+ - spec/roll_call_vote_spec.rb
81
+ - spec/spec.opts
82
+ - spec/spec_helper.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/dwillis/nytimes-congress
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.3.7
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Ruby wrapper and command shell for the New York Times Congress API
117
+ test_files:
118
+ - spec/base_spec.rb
119
+ - spec/congress_spec.rb
120
+ - spec/example_data/example_data.rb
121
+ - spec/legislator_spec.rb
122
+ - spec/legislator_vote_comparison_spec.rb
123
+ - spec/position_spec.rb
124
+ - spec/role_spec.rb
125
+ - spec/roll_call_vote_spec.rb
126
+ - spec/spec_helper.rb