diff --git a/lib/twitter/tweet.rb b/lib/twitter/tweet.rb index c4e7a1c56..bb500ba68 100644 --- a/lib/twitter/tweet.rb +++ b/lib/twitter/tweet.rb @@ -85,6 +85,15 @@ def repliers_count end alias reply_count repliers_count + # @return [Boolean] + def reply? + !!in_reply_to_status_id + end + + def retweet? + !!retweeted_status + end + # If this Tweet is a retweet, the original Tweet is available here. # # @return [Twitter::Tweet] diff --git a/spec/twitter/tweet_spec.rb b/spec/twitter/tweet_spec.rb index 2d06b2828..f2911c2f7 100644 --- a/spec/twitter/tweet_spec.rb +++ b/spec/twitter/tweet_spec.rb @@ -193,6 +193,40 @@ end end + describe "#reply?" do + it "returns true when there is an in-reply-to status" do + tweet = Twitter::Tweet.new(:id => 28669546014, :in_reply_to_status_id => 114749583439036416) + tweet.reply?.should be_true + end + it "returns false when in_reply_to_status_id is not set" do + tweet = Twitter::Tweet.new(:id => 28669546014) + tweet.reply?.should be_false + end + end + + 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 false when retweeted_status is not set" do + tweet = Twitter::Tweet.new(:id => 28669546014) + tweet.retweet?.should be_false + end + end + + describe "#retweeted_status" do + it "has text when retweeted_status is set" do + tweet = Twitter::Tweet.new(:id => 28669546014, :retweeted_status => {:id => 28561922516, :text => 'BOOSH'}) + tweet.retweeted_tweet.should be_a Twitter::Tweet + tweet.retweeted_tweet.text.should eq 'BOOSH' + end + it "returns nil when retweeted_status is not set" do + tweet = Twitter::Tweet.new(:id => 28669546014) + tweet.retweeted_tweet.should be_nil + 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')