Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for getting single result from Garb::ResultSet using bracket nota…

…tion
  • Loading branch information...
commit a17ae8c6321b2174f73e95925ba536a4f3b42f2c 1 parent 7441306
@Sija authored
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- garb (0.9.6)
+ garb (0.9.7)
activesupport (>= 2.2)
multi_json (>= 1.3)
View
1  lib/garb/result_set.rb
@@ -26,6 +26,7 @@ def +(other)
end
def [](*args)
+ return @results[*args] if args.first.is_a? Integer
copy = self.dup
copy.results = @results[*args]
copy
View
10 test/unit/garb/model_test.rb
@@ -50,7 +50,7 @@ class ModelTest < MiniTest::Unit::TestCase
setup do
@response = stub(:body => "raw report data")
Request::Data.stubs(:new).returns(stub(:send_request => @response))
- @results = ResultSet.new(['result'] * 10)
+ @results = ResultSet.new(Array.new(10) { |i| 'result #%d' % i })
ReportResponse.stubs(:new).returns(stub(:results => @results))
@test_model.stubs(:metrics).returns(stub(:to_params => {'metrics' => 'ga:visits'}))
@@ -73,12 +73,18 @@ class ModelTest < MiniTest::Unit::TestCase
assert_data_params(@params)
end
- should "get subset of results" do
+ should "get subset of results using bracket notation" do
assert_equal @results[0..2], @test_model.results(@profile)[0..2]
assert_received(ReportResponse, :new) {|e| e.with('raw report data', OpenStruct)}
assert_data_params(@params)
end
+ should "get one of the results using bracket notation" do
+ assert_equal @results[2], @test_model.results(@profile)[2]
+ assert_received(ReportResponse, :new) {|e| e.with('raw report data', OpenStruct)}
+ assert_data_params(@params)
+ end
+
should "be able to filter" do
FilterParameters.stubs(:new).returns(stub(:to_params => {'filters' => 'params'}))
assert_equal @results, @test_model.results(@profile, :filters => {:page_path => '/'})
Please sign in to comment.
Something went wrong with that request. Please try again.