Permalink
Browse files

fix or in filter parameters

  • Loading branch information...
1 parent 0f4d4bf commit 87444735b71425cfbb7cd3f69c1ee61ebdb0143a @tpitale tpitale committed Jul 1, 2011
Showing with 12 additions and 18 deletions.
  1. +1 −0 CHANGELOG.md
  2. +2 −2 lib/garb/filter_parameters.rb
  3. +1 −3 lib/garb/model.rb
  4. +6 −10 test/unit/garb/filter_parameters_test.rb
  5. +2 −3 test/unit/garb/model_test.rb
View
@@ -2,6 +2,7 @@ Version 0.9.2
* Removed all deprecated features: Garb::Report, Garb::Resource, Garb::Profile, and Garb::Account
* Moved the differing types of requests into a module, will refactor to share more code
+ * Fixed OR'ing in :filters option for results
Version 0.9.0
@@ -15,8 +15,8 @@ class FilterParameters
attr_accessor :parameters
- def initialize
- self.parameters = []
+ def initialize(parameters)
+ self.parameters = (Array.wrap(parameters) || [])
end
def to_params
View
@@ -56,9 +56,7 @@ def build_params(param_set)
end
def parse_filters(options)
- filters = FilterParameters.new
- filters.parameters << options[:filters] if options.has_key?(:filters)
- filters
+ FilterParameters.new(options[:filters])
end
def parse_segment(options)
@@ -20,30 +20,26 @@ class FilterParametersTest < MiniTest::Unit::TestCase
# end
context "A FilterParameters" do
- setup do
- @filter_parameters = FilterParameters.new
- end
-
context "when converting parameters hash into query string parameters" do
should "parameterize hash operators and join elements with AND" do
- @filter_parameters.parameters << {:city.eql => 'New York City', :state.eql => 'New York'}
+ filters = FilterParameters.new({:city.eql => 'New York City', :state.eql => 'New York'})
params = ['ga:city%3D%3DNew+York+City', 'ga:state%3D%3DNew+York']
- assert_equal params, @filter_parameters.to_params['filters'].split('%3B').sort
+ assert_equal params, filters.to_params['filters'].split('%3B').sort
end
should "properly encode operators" do
- @filter_parameters.parameters << {:page_path.contains => 'New York'}
+ filters = FilterParameters.new({:page_path.contains => 'New York'})
params = {'filters' => 'ga:pagePath%3D~New+York'}
- assert_equal params, @filter_parameters.to_params
+ assert_equal params, filters.to_params
end
should "escape comma, semicolon, and backslash in values" do
- @filter_parameters.parameters << {:url.eql => 'this;that,thing\other'}
+ filters = FilterParameters.new({:url.eql => 'this;that,thing\other'})
params = {'filters' => 'ga:url%3D%3Dthis%5C%3Bthat%5C%2Cthing%5C%5Cother'}
- assert_equal params, @filter_parameters.to_params
+ assert_equal params, filters.to_params
end
end
end
@@ -82,12 +82,11 @@ class ModelTest < MiniTest::Unit::TestCase
end
should "be able to filter" do
- filter_parameters = stub(:<<)
- FilterParameters.stubs(:new).returns(stub(:parameters => filter_parameters, :to_params => {'filters' => "params"}))
+ FilterParameters.stubs(:new).returns(stub(:to_params => {'filters' => "params"}))
assert_equal ['result'], @test_model.results(@profile, :filters => {:page_path => '/'})
assert_data_params(@params.merge({'filters' => 'params'}))
- assert_received(filter_parameters, :<<) {|e| e.with({:page_path => '/'})}
+ assert_received(FilterParameters, :new) {|e| e.with({:page_path => '/'})}
end
should "be able to set the filter segment by id" do

0 comments on commit 8744473

Please sign in to comment.