From 6829994f4d8ca1e6d444fa75dc78c06bd01a5d74 Mon Sep 17 00:00:00 2001 From: David Aaron Fendley Date: Tue, 28 Feb 2012 21:23:04 -0600 Subject: [PATCH] Added Twitter::Mention#source --- lib/twitter/mention.rb | 7 +++++++ spec/twitter/mention_spec.rb | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/twitter/mention.rb b/lib/twitter/mention.rb index b4637bcda..26cc8e783 100644 --- a/lib/twitter/mention.rb +++ b/lib/twitter/mention.rb @@ -14,6 +14,13 @@ def sources end end + # The user who mentioned a user + # + # @return [Twitter::User] + def source + @source = sources.first + end + # A collection of statuses that mention a user # # @return [Array] diff --git a/spec/twitter/mention_spec.rb b/spec/twitter/mention_spec.rb index 8e7df5ea3..c6c5eb4cb 100644 --- a/spec/twitter/mention_spec.rb +++ b/spec/twitter/mention_spec.rb @@ -14,6 +14,17 @@ end end + describe "#source" do + it "should return the user who mentioned a user" do + source = Twitter::Mention.new('sources' => [{}]).source + source.should be_a Twitter::User + end + it "should be nil when not set" do + source = Twitter::Mention.new.source + source.should be_nil + end + end + describe "#target_objects" do it "should return a collection of statuses that mention a user" do targets = Twitter::Mention.new('target_objects' => [{}]).target_objects