Skip to content

Commit

Permalink
Add Twitter::Tweet#reply?
Browse files Browse the repository at this point in the history
  • Loading branch information
stve authored and sferik committed Oct 6, 2012
1 parent 74b17f5 commit 029d815
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/twitter/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
34 changes: 34 additions & 0 deletions spec/twitter/tweet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 029d815

Please sign in to comment.