Skip to content

Commit

Permalink
Add a reader for retweeted_status
Browse files Browse the repository at this point in the history
The Twitter::Status class needs a reader to access the retweeted_status when the status is itself
a retweet. The retweeted_status should be an instance of Twitter::Status.
  • Loading branch information
raykrueger committed Dec 27, 2011
1 parent 5068238 commit 617ebcc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/twitter/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,12 @@ def user
@user ||= Twitter::User.new(@attrs.dup['user'].merge('status' => @attrs.except('user'))) unless @attrs['user'].nil?
end

# If this status is itself a retweet, the original tweet is available here.
#
# @return [Twitter::Status]
def retweeted_status
@retweeted_status ||= self.class.new(@attrs['retweeted_status']) unless @attrs['retweeted_status'].nil?
end

end
end
17 changes: 17 additions & 0 deletions spec/twitter/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,21 @@
end
end

describe "#retweeted_status" do
before do
@a_retweeted_status = Twitter::Status.new('retweeted_status' => {'text' => 'BOOSH'})
end
it "should return a Status when retweeted_status is set" do
@a_retweeted_status.retweeted_status.should be_a Twitter::Status
end
it "should return nil when a retweeted_status is NOT set" do
status = Twitter::Status.new
status.retweeted_status.should be_nil
end
it "should have text when retweeted_status is set" do
status = Twitter::Status.new('retweeted_status' => {'text' => 'BOOSH'})
status.retweeted_status.text.should == 'BOOSH'
end
end

end

0 comments on commit 617ebcc

Please sign in to comment.