From 8ef885c00a392ad5610f4985448f2885a034674a Mon Sep 17 00:00:00 2001 From: Michael Herold Date: Mon, 16 Sep 2013 18:12:28 -0400 Subject: [PATCH] Fix behavior of Twitter::Tweet.entities? method. Previously, this method returned true when inflating a tweet that has no entities because the inflated model does not set @attrs[:entities] to nil, but to a hash of empty lists. --- lib/twitter/tweet.rb | 4 +++- spec/twitter/tweet_spec.rb | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/twitter/tweet.rb b/lib/twitter/tweet.rb index a2f8b9170..b069657f8 100644 --- a/lib/twitter/tweet.rb +++ b/lib/twitter/tweet.rb @@ -27,7 +27,9 @@ class Tweet < Twitter::Identity # @return [Boolean] def entities? - !@attrs[:entities].nil? + return false if @attrs[:entities].nil? + + @attrs[:entities].any? { |k, v| !v.empty? } end def filter_level diff --git a/spec/twitter/tweet_spec.rb b/spec/twitter/tweet_spec.rb index 55e9a982e..63e9eaf07 100644 --- a/spec/twitter/tweet_spec.rb +++ b/spec/twitter/tweet_spec.rb @@ -57,6 +57,12 @@ expect(tweet.entities?).to be_false end + it "returns false if there are blank lists of entities set" do + urls_array = [] + tweet = Twitter::Tweet.new(:id => 28669546014, :entities => {:urls => urls_array}) + expect(tweet.entities?).to be_false + end + it "returns true if there are entities set" do urls_array = [ {