Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

hack to add support for dynamic segments

  • Loading branch information...
commit d7c5b1c5fbde702a1b2f06edcebc44bfa555b0e6 1 parent d104228
Steven Wilkin authored February 14, 2011
13  lib/garb/model.rb
@@ -62,8 +62,15 @@ def parse_filters(options)
62 62
     end
63 63
 
64 64
     def parse_segment(options)
65  
-      segment_id = "gaid::#{options[:segment_id].to_i}" if options.has_key?(:segment_id)
66  
-      {'segment' => segment_id}
  65
+      # dirty hack to support dynamic segments
  66
+      if options.has_key?(:segment_id)
  67
+        segment = "gaid::#{options[:segment_id].to_i}"
  68
+      elsif options.has_key?(:dynamic_segment)
  69
+        filters = FilterParameters.new
  70
+        filters.parameters << options[:dynamic_segment]
  71
+        segment = "dynamic::#{filters.to_params['filters']}"
  72
+      end
  73
+      {'segment' => segment}
67 74
     end
68 75
 
69 76
     def parse_sort(options)
@@ -88,4 +95,4 @@ def format_time(t)
88 95
       t.strftime('%Y-%m-%d')
89 96
     end
90 97
   end
91  
-end
  98
+end
11  test/unit/garb/model_test.rb
@@ -95,6 +95,17 @@ class ModelTest < MiniTest::Unit::TestCase
95 95
             assert_data_params(@params.merge({'segment' => 'gaid::1'}))
96 96
           end
97 97
 
  98
+          should "be able to filter with a dynamic segment" do
  99
+            # parse_filters called first...
  100
+            filter_parameters = stub(:<<)
  101
+            filters = stub(:parameters => filter_parameters, :to_params => {'filters' => nil})
  102
+            segments = stub(:parameters => filter_parameters, :to_params => {'filters' => 'dynamic_segment_params'})
  103
+            FilterParameters.stubs(:new).returns(filters).then.returns(segments)
  104
+
  105
+            assert_equal ['result'], @test_model.results(@profile, :dynamic_segment => 'dynamic_segment_params')
  106
+            assert_data_params(@params.merge({'segment' => 'dynamic::dynamic_segment_params'}))
  107
+          end
  108
+
98 109
           should "be able to sort" do
99 110
             sort_parameter = stub(:<<)
100 111
             sort_parameter.stubs(:to_params => {'sort' => 'sort value'})

0 notes on commit d7c5b1c

Please sign in to comment.
Something went wrong with that request. Please try again.