Permalink
Browse files

Add Twitter::User#status? method

  • Loading branch information...
1 parent bf4f5cd commit 7d34bf36ec518c3357eed5369b2142085fce269e @sferik committed Aug 26, 2012
Showing with 27 additions and 8 deletions.
  1. +1 −1 README.md
  2. +4 −2 lib/twitter/creatable.rb
  3. +2 −0 lib/twitter/rate_limit_status.rb
  4. +4 −4 lib/twitter/tweet.rb
  5. +5 −1 lib/twitter/user.rb
  6. +11 −0 spec/twitter/user_spec.rb
View
@@ -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 671 examples and runs in under 2 seconds on a MacBook
+* The spec suite contains 673 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
@@ -7,10 +7,12 @@ module Creatable
#
# @return [Time]
def created_at
- @created_at ||= Time.parse(@attrs[:created_at]) if created_at?
+ @created_at ||= Time.parse(@attrs[:created_at]) if created?
end
- def created_at?
+ private
+
+ def created?
!@attrs[:created_at].nil?
end
@@ -11,6 +11,8 @@ def reset_time
@reset_time ||= Time.parse(@attrs[:reset_time]) if reset_time?
end
+ private
+
def reset_time?
!@attrs[:reset_time].nil?
end
View
@@ -111,10 +111,6 @@ def user
@user ||= Twitter::User.fetch_or_new(@attrs.dup[:user].merge(:status => @attrs.except(:user))) if user?
end
- def user?
- !@attrs[:user].nil?
- end
-
# @note Must include entities in your request for this method to work
# @return [Array<Twitter::Entity::UserMention>]
def user_mentions
@@ -140,6 +136,10 @@ def entities(klass, method)
end
end
+ def user?
+ !@attrs[:user].nil?
+ end
+
end
Status = Tweet
View
@@ -71,7 +71,11 @@ def profile_image_url_https(size=:normal)
# @return [Twitter::Tweet]
def status
- @status ||= Twitter::Tweet.fetch_or_new(@attrs.dup[:status].merge(:user => @attrs.except(:status))) unless @attrs[:status].nil?
+ @status ||= Twitter::Tweet.fetch_or_new(@attrs.dup[:status].merge(:user => @attrs.except(:status))) if status?
+ end
+
+ def status?
+ !@attrs[:status].nil?
end
private
View
@@ -113,4 +113,15 @@
end
end
+ describe "#status?" do
+ it "returns true when status is set" do
+ tweet = Twitter::User.new(:id => 7505382, :status => {:id => 25938088801}).status?
+ tweet.should be_true
+ end
+ it "returns false when status is not set" do
+ tweet = Twitter::User.new(:id => 7505382).status?
+ tweet.should be_false
+ end
+ end
+
end

0 comments on commit 7d34bf3

Please sign in to comment.