Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 1e6ad051f488cae7bf18a45eea8008b448323fe4 1 parent 23668bc
@sferik authored
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
2  README.md
@@ -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
5 lib/twitter/tweet.rb
@@ -79,6 +79,10 @@ 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]
@@ -86,6 +90,7 @@ 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
35 spec/twitter/tweet_spec.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.