Skip to content

Commit

Permalink
Add Twitter::Tweet#retweet? method and Twitter::Tweet#retweet alias
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Sep 17, 2012
1 parent 23668bc commit 1e6ad05
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Here are some fun facts about the 3.0 release:

* The entire library is implemented in just 2,000 lines of code
* With over 5,000 lines of specs, the spec-to-code ratio is over 2.5:1
* The spec suite contains 659 examples and runs in under 2 seconds on a MacBook
* The spec suite contains 661 examples and runs in under 2 seconds on a MacBook
* This project has 100% C0 code coverage (the tests execute every line of
source code at least once)
* At the time of release, this library is comprehensive: you can request all
Expand Down
5 changes: 5 additions & 0 deletions lib/twitter/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ def repliers_count
end
alias reply_count repliers_count

def retweet?
!!retweeted_status
end

# If this Tweet is a retweet, the original Tweet is available here.
#
# @return [Twitter::Tweet]
def retweeted_status
@retweeted_status ||= self.class.fetch_or_new(@attrs[:retweeted_status])
end
alias retweeted_tweet retweeted_status
alias retweet retweeted_status

# @return [String]
def retweeters_count
Expand Down
35 changes: 23 additions & 12 deletions spec/twitter/tweet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,14 @@
end
end

describe "#retweeters_count" do
it "returns the count of favoriters when retweet_count is set" do
tweet = Twitter::Tweet.new(:id => 28669546014, :retweet_count => '1')
tweet.retweeters_count.should be_an Integer
tweet.retweeters_count.should eq 1
end
it "returns the count of favoriters when retweeters_count is set" do
tweet = Twitter::Tweet.new(:id => 28669546014, :retweeters_count => '1')
tweet.retweeters_count.should be_an Integer
tweet.retweeters_count.should eq 1
describe "#retweet?" do
it "returns true when there is a retweeted status" do
tweet = Twitter::Tweet.new(:id => 28669546014, :retweeted_status => {:id => 28561922516, :text => 'BOOSH'})
tweet.retweet?.should be_true
end
it "returns nil when not set" do
it "returns false when retweeted_status is not set" do
tweet = Twitter::Tweet.new(:id => 28669546014)
tweet.retweeters_count.should be_nil
tweet.retweet?.should be_false
end
end

Expand All @@ -205,6 +199,23 @@
end
end

describe "#retweeters_count" do
it "returns the count of favoriters when retweet_count is set" do
tweet = Twitter::Tweet.new(:id => 28669546014, :retweet_count => '1')
tweet.retweeters_count.should be_an Integer
tweet.retweeters_count.should eq 1
end
it "returns the count of favoriters when retweeters_count is set" do
tweet = Twitter::Tweet.new(:id => 28669546014, :retweeters_count => '1')
tweet.retweeters_count.should be_an Integer
tweet.retweeters_count.should eq 1
end
it "returns nil when not set" do
tweet = Twitter::Tweet.new(:id => 28669546014)
tweet.retweeters_count.should be_nil
end
end

describe "#entities?" do
it "returns false if there are no entities set" do
tweet = Twitter::Tweet.new(:id => 28669546014)
Expand Down

0 comments on commit 1e6ad05

Please sign in to comment.