Skip to content

Commit

Permalink
Make Twitter::Place inhert directly from Twitter::Base
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Sep 24, 2013
1 parent ea70f3e commit 3e3b234
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
12 changes: 5 additions & 7 deletions lib/twitter/place.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
require 'twitter/identity'
require 'equalizer'
require 'twitter/base'

module Twitter
class Place < Twitter::Identity
class Place < Twitter::Base
include Equalizer.new(:woeid)
attr_reader :attributes, :country, :full_name, :name, :woeid
alias woe_id woeid
alias id woeid
object_attr_reader :GeoCreator, :bounding_box
object_attr_reader :Place, :contained_within
alias contained? contained_within?
Expand All @@ -24,10 +27,5 @@ def place_type
@attrs[:place_type] || @attrs[:placeType] && @attrs[:placeType][:name]
end

# return [Integer]
def id
@attrs[:id] || @attrs[:woeid]
end

end
end
56 changes: 28 additions & 28 deletions spec/twitter/place_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,127 +3,127 @@
describe Twitter::Place do

describe "#==" do
it "returns true when objects IDs are the same" do
place = Twitter::Place.new(:id => 1, :name => "foo")
other = Twitter::Place.new(:id => 1, :name => "bar")
it "returns true when objects WOE IDs are the same" do
place = Twitter::Place.new(:woeid => 1, :name => "foo")
other = Twitter::Place.new(:woeid => 1, :name => "bar")
expect(place == other).to be_true
end
it "returns false when objects IDs are different" do
place = Twitter::Place.new(:id => 1)
other = Twitter::Place.new(:id => 2)
it "returns false when objects WOE IDs are different" do
place = Twitter::Place.new(:woeid => 1)
other = Twitter::Place.new(:woeid => 2)
expect(place == other).to be_false
end
it "returns false when classes are different" do
place = Twitter::Place.new(:id => 1)
other = Twitter::Identity.new(:id => 1)
place = Twitter::Place.new(:woeid => 1)
other = Twitter::Base.new(:woeid => 1)
expect(place == other).to be_false
end
end

describe "#bounding_box" do
it "returns a Twitter::Geo when bounding_box is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
place = Twitter::Place.new(:woeid => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
expect(place.bounding_box).to be_a Twitter::Geo::Polygon
end
it "returns nil when not bounding_box is not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.bounding_box).to be_nil
end
end

describe "#bounding_box?" do
it "returns true when bounding_box is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
place = Twitter::Place.new(:woeid => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
expect(place.bounding_box?).to be_true
end
it "returns false when bounding_box is not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.bounding_box?).to be_false
end
end

describe "#contained_within" do
it "returns a Twitter::Place when contained_within is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :contained_within => {:id => "247f43d441defc04"})
place = Twitter::Place.new(:woeid => "247f43d441defc03", :contained_within => {:woeid => "247f43d441defc04"})
expect(place.contained_within).to be_a Twitter::Place
end
it "returns nil when not contained_within is not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.contained_within).to be_nil
end
end

describe "#contained_within?" do
it "returns true when contained_within is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :contained_within => {:id => "247f43d441defc04"})
place = Twitter::Place.new(:woeid => "247f43d441defc03", :contained_within => {:woeid => "247f43d441defc04"})
expect(place.contained?).to be_true
end
it "returns false when contained_within is not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.contained?).to be_false
end
end

describe "#country_code" do
it "returns a country code when set with country_code" do
place = Twitter::Place.new(:id => "247f43d441defc03", :country_code => "US")
place = Twitter::Place.new(:woeid => "247f43d441defc03", :country_code => "US")
expect(place.country_code).to eq("US")
end
it "returns a country code when set with countryCode" do
place = Twitter::Place.new(:id => "247f43d441defc03", :countryCode => "US")
place = Twitter::Place.new(:woeid => "247f43d441defc03", :countryCode => "US")
expect(place.country_code).to eq("US")
end
it "returns nil when not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.country_code).to be_nil
end
end

describe "#parent_id" do
it "returns a parent ID when set with parentid" do
place = Twitter::Place.new(:id => "247f43d441defc03", :parentid => 1)
place = Twitter::Place.new(:woeid => "247f43d441defc03", :parentid => 1)
expect(place.parent_id).to eq(1)
end
it "returns nil when not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.parent_id).to be_nil
end
end

describe "#place_type" do
it "returns a place type when set with place_type" do
place = Twitter::Place.new(:id => "247f43d441defc03", :place_type => "city")
place = Twitter::Place.new(:woeid => "247f43d441defc03", :place_type => "city")
expect(place.place_type).to eq("city")
end
it "returns a place type when set with placeType[name]" do
place = Twitter::Place.new(:id => "247f43d441defc03", :placeType => {:name => "Town"})
place = Twitter::Place.new(:woeid => "247f43d441defc03", :placeType => {:name => "Town"})
expect(place.place_type).to eq("Town")
end
it "returns nil when not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.place_type).to be_nil
end
end

describe "#uri" do
it "returns a URI when the url is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :url => "https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
place = Twitter::Place.new(:woeid => "247f43d441defc03", :url => "https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
expect(place.uri).to be_a URI
expect(place.uri.to_s).to eq("https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
end
it "returns nil when the url is not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.uri).to be_nil
end
end

describe "#uri?" do
it "returns true when the url is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :url => "https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
place = Twitter::Place.new(:woeid => "247f43d441defc03", :url => "https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
expect(place.uri).to be_true
end
it "returns false when the url is not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
place = Twitter::Place.new(:woeid => "247f43d441defc03")
expect(place.uri).to be_false
end
end
Expand Down

0 comments on commit 3e3b234

Please sign in to comment.