Permalink
Browse files

Add `Twitter::Tweet#retweet?` method and `Twitter::Tweet#retweet` alias

  • Loading branch information...
1 parent 23668bc commit 1e6ad051f488cae7bf18a45eea8008b448323fe4 @sferik committed Sep 7, 2012
Showing with 29 additions and 13 deletions.
  1. +1 −1 README.md
  2. +5 −0 lib/twitter/tweet.rb
  3. +23 −12 spec/twitter/tweet_spec.rb
View
@@ -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
View
@@ -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
View
@@ -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
@@ -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)

0 comments on commit 1e6ad05

Please sign in to comment.