Skip to content

Commit

Permalink
more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Palmer committed Jan 22, 2009
1 parent db945eb commit a66fc04
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
30 changes: 16 additions & 14 deletions examples/lobbyist_example.rb
Expand Up @@ -4,20 +4,22 @@

Sunshine.api_key = File.read(File.join(dir, '..', '.sunlight_api_key'))

# filing = Sunshine::DisclosureFiling.find('29D4D19E-CB7D-46D2-99F0-27FF15901A4C')
# filing.lobbyists.each do |lob|
# puts lob.full_name
# end
#
# filing = Sunshine::DisclosureFiling.find(:first, {:client_name => 'Sunlight Foundation'})
# filing.lobbyists.each do |lob|
# puts "-- #{lob.full_name}"
# end
#
# results = Sunshine::Lobbyist.search('Thompson')
# results.each do |score, lobbyist|
# puts "SCORE:#{score} LOBBYIST:#{lobbyist.full_name}"
# end
# search_results = Sunshine::Lobbyist.search('Willian Corr')

filing = Sunshine::DisclosureFiling.find('29D4D19E-CB7D-46D2-99F0-27FF15901A4C')
filing.lobbyists.each do |lob|
puts lob.full_name
end

filing = Sunshine::DisclosureFiling.find(:first, {:client_name => 'Sunlight Foundation'})
filing.lobbyists.each do |lob|
puts "-- #{lob.full_name}"
end

results = Sunshine::Lobbyist.search('Thompson')
results.each do |score, lobbyist|
puts "SCORE:#{score} LOBBYIST:#{lobbyist.full_name}"
end

results = Sunshine::Lobbyist.search('Willian Corr')
william = results.first[1]
Expand Down
9 changes: 8 additions & 1 deletion lib/sunshine/lobbyist.rb
Expand Up @@ -28,9 +28,16 @@ def lastname
# == Examples
#
# Lobbyist.search('Thompson')
# Lobbyist.search('Thompson', {:threshold => 0.5})
# Lobbyist.search('Thompson', {:threshold => 0.9})
# Lobbyist.search('Thompson', {:year => 2008})
#
# Note: Sunlight recommends that you do not set the threshold below 0.9, which
# is the default Sunlight uses. Also, all searches are scoped to the current year
# unless you explicitly set one.
#
# ATTN: There is a bug in the Sunlight API that shows an invalid param when you set
# the year.
#
# Returns an <tt>Array<tt> of <tt>[score, <Lobbyist>]<tt> results.
def self.search(name_query, options = {})
options = {:name => name_query}.merge!(options)
Expand Down
28 changes: 25 additions & 3 deletions spec/lobbyists_spec.rb
@@ -1,11 +1,33 @@
require 'spec/spec_helper'
include Sunshine

describe Lobbyist do
before do
#@lobbyists.search('Sunlight Foundation')
@lobbyists = Lobbyist.search('William Corr')
end

it "should exclude firstname and lastname from instance" do
@speaker.class.keys_to_exclude.should be(['firstname', 'lastname'])
it "should find lobbyists" do
score = @lobbyists.first[0]
lobbyist = @lobbyists.first[1]

score.should == 1.0
lobbyist.should be_instance_of(Lobbyist)
end

it "should lazily load filings" do
lobbyist = @lobbyists.first[1]

filing_var = lobbyist.send(:instance_variable_get, "@filings")
filing_var.should be(nil)

filings = lobbyist.filings
filings.first.should be_instance_of(DisclosureFiling)

filing_var = lobbyist.send(:instance_variable_get, "@filings")
filing_var.should_not == nil
end

it "should exclude keys from instance" do
Lobbyist.keys_to_exclude.should == [:firstname, :lastname, :filings]
end
end

0 comments on commit a66fc04

Please sign in to comment.