Skip to content

Commit

Permalink
Fix behavior of Twitter::Tweet.entities? method.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelherold committed Sep 16, 2013
1 parent 554ff7c commit 8ef885c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/twitter/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/twitter/tweet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down

0 comments on commit 8ef885c

Please sign in to comment.