Permalink
Browse files

hack to add support for dynamic segments

  • Loading branch information...
stevenwilkin committed Feb 14, 2011
1 parent d104228 commit d7c5b1c5fbde702a1b2f06edcebc44bfa555b0e6
Showing with 21 additions and 3 deletions.
  1. +10 −3 lib/garb/model.rb
  2. +11 −0 test/unit/garb/model_test.rb
View
@@ -62,8 +62,15 @@ def parse_filters(options)
end
def parse_segment(options)
segment_id = "gaid::#{options[:segment_id].to_i}" if options.has_key?(:segment_id)
{'segment' => segment_id}
# dirty hack to support dynamic segments
if options.has_key?(:segment_id)
segment = "gaid::#{options[:segment_id].to_i}"
elsif options.has_key?(:dynamic_segment)
filters = FilterParameters.new
filters.parameters << options[:dynamic_segment]
segment = "dynamic::#{filters.to_params['filters']}"
end
{'segment' => segment}
end
def parse_sort(options)
@@ -88,4 +95,4 @@ def format_time(t)
t.strftime('%Y-%m-%d')
end
end
end
end
@@ -95,6 +95,17 @@ class ModelTest < MiniTest::Unit::TestCase
assert_data_params(@params.merge({'segment' => 'gaid::1'}))
end
should "be able to filter with a dynamic segment" do
# parse_filters called first...
filter_parameters = stub(:<<)
filters = stub(:parameters => filter_parameters, :to_params => {'filters' => nil})
segments = stub(:parameters => filter_parameters, :to_params => {'filters' => 'dynamic_segment_params'})
FilterParameters.stubs(:new).returns(filters).then.returns(segments)
assert_equal ['result'], @test_model.results(@profile, :dynamic_segment => 'dynamic_segment_params')
assert_data_params(@params.merge({'segment' => 'dynamic::dynamic_segment_params'}))
end
should "be able to sort" do
sort_parameter = stub(:<<)
sort_parameter.stubs(:to_params => {'sort' => 'sort value'})

0 comments on commit d7c5b1c

Please sign in to comment.