Permalink
Browse files

Create Twitter::SearchResults#search_metadata? method

  • Loading branch information...
1 parent 02bf97e commit 13df503b1de8c36a714dd825a1db6027a465f702 @sferik committed Nov 27, 2012
Showing with 21 additions and 6 deletions.
  1. +10 −6 lib/twitter/search_results.rb
  2. +11 −0 spec/twitter/search_results_spec.rb
@@ -15,33 +15,37 @@ def statuses
# @return [Float]
def completed_in
- @attrs[:search_metadata][:completed_in] unless @attrs[:search_metadata].nil?
+ @attrs[:search_metadata][:completed_in] if search_metadata?
end
# @return [Integer]
def max_id
- @attrs[:search_metadata][:max_id] unless @attrs[:search_metadata].nil?
+ @attrs[:search_metadata][:max_id] if search_metadata?
end
# @return [Integer]
def page
- @attrs[:search_metadata][:page] unless @attrs[:search_metadata].nil?
+ @attrs[:search_metadata][:page] if search_metadata?
end
# @return [String]
def query
- @attrs[:search_metadata][:query] unless @attrs[:search_metadata].nil?
+ @attrs[:search_metadata][:query] if search_metadata?
end
# @return [Integer]
def results_per_page
- @attrs[:search_metadata][:results_per_page] unless @attrs[:search_metadata].nil?
+ @attrs[:search_metadata][:results_per_page] if search_metadata?
end
alias rpp results_per_page
+ def search_metadata?
+ !@attrs[:search_metadata].nil?
+ end
+
# @return [Integer]
def since_id
- @attrs[:search_metadata][:since_id] unless @attrs[:search_metadata].nil?
+ @attrs[:search_metadata][:since_id] if search_metadata?
end
end
@@ -74,6 +74,17 @@
end
end
+ describe "#search_metadata?" do
+ it "returns true when search_metadata is set" do
+ search_metadata = Twitter::SearchResults.new(:search_metadata => {}).search_metadata?
+ expect(search_metadata).to be_true
+ end
+ it "returns false when search_metadata is not set" do
+ search_metadata = Twitter::SearchResults.new.search_metadata?
+ expect(search_metadata).to be_false
+ end
+ end
+
describe "#since_id" do
it "returns an ID" do
since_id = Twitter::SearchResults.new(:search_metadata => {:since_id => 250126199840518145}).since_id

0 comments on commit 13df503

Please sign in to comment.