Skip to content
This repository
Browse code

convert :order key to :sort

  • Loading branch information...
commit f83388bf151df316ed56871fffcd216811393b36 1 parent b006881
Patrick Roby authored
2  README.md
Source Rendered
@@ -143,7 +143,7 @@ Operators on dimensions:
143 143 * :end_date - The date to end, inclusive
144 144 * :limit - The maximum number of results to be returned
145 145 * :offset - The starting index
146   - * :order - metric/dimension to order by
  146 + * :sort - metric/dimension to sort by
147 147
148 148 ## License ##
149 149
12 lib/legato/query.rb
@@ -22,7 +22,7 @@ def #{method}(field, value, join_character=nil)
22 22
23 23 attr_reader :parent_klass
24 24 attr_accessor :profile, :start_date, :end_date
25   - attr_accessor :order, :limit, :offset#, :segment # individual, overwritten
  25 + attr_accessor :sort, :limit, :offset#, :segment # individual, overwritten
26 26 attr_accessor :filters # appended to, may add :segments later for dynamic segments
27 27
28 28 def initialize(klass)
@@ -60,7 +60,7 @@ def apply_filter(*args, &block)
60 60 def apply_options(options)
61 61 if options.has_key?(:sort)
62 62 # warn
63   - options[:order] = options.delete(:sort)
  63 + options[:sort] = options.delete(:sort)
64 64 end
65 65
66 66 apply_basic_options(options)
@@ -70,7 +70,7 @@ def apply_options(options)
70 70 end
71 71
72 72 def apply_basic_options(options)
73   - [:order, :limit, :offset, :start_date, :end_date].each do |key| #:segment
  73 + [:sort, :limit, :offset, :start_date, :end_date].each do |key| #:segment
74 74 self.send("#{key}=".to_sym, options[key]) if options.has_key?(key)
75 75 end
76 76 end
@@ -147,8 +147,8 @@ def dimensions
147 147 parent_klass.dimensions
148 148 end
149 149
150   - def order=(arr)
151   - @order = Legato::ListParameter.new(:order, arr)
  150 + def sort=(arr)
  151 + @sort = Legato::ListParameter.new(:sort, arr)
152 152 end
153 153
154 154 # def segment_id
@@ -170,7 +170,7 @@ def to_params
170 170 'filters' => filters.to_params # defaults to AND filtering
171 171 }
172 172
173   - [metrics, dimensions, order].each do |list|
  173 + [metrics, dimensions, sort].each do |list|
174 174 params.merge!(list.to_params) unless list.nil?
175 175 end
176 176
40 spec/lib/legato/query_spec.rb
@@ -104,10 +104,10 @@ def self.it_defines_operators(*operators)
104 104 @query.stubs(:profile=)
105 105 @query.stubs(:apply_options)
106 106
107   - @query.results({:order => [:city]}).should == @query
  107 + @query.results({:sort => [:city]}).should == @query
108 108
109 109 @query.should have_received(:profile=).never
110   - @query.should have_received(:apply_options).with({:order => [:city]})
  110 + @query.should have_received(:apply_options).with({:sort => [:city]})
111 111 end
112 112
113 113 context 'when applying filters' do
@@ -172,26 +172,26 @@ def self.it_defines_operators(*operators)
172 172 @query.apply_options({}).should == @query
173 173 end
174 174
175   - it "stores the order" do
176   - @query.apply_options({:order => [:page_path]})
177   - @query.order.should == Legato::ListParameter.new(:order, [:page_path])
  175 + it "stores the sort" do
  176 + @query.apply_options({:sort => [:page_path]})
  177 + @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
178 178 end
179 179
180   - it 'replaces the order' do
181   - @query.order = [:pageviews]
182   - @query.apply_options({:order => [:page_path]})
183   - @query.order.should == Legato::ListParameter.new(:order, [:page_path])
  180 + it 'replaces the sort' do
  181 + @query.sort = [:pageviews]
  182 + @query.apply_options({:sort => [:page_path]})
  183 + @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
184 184 end
185 185
186   - it "does not replace order if option is omitted" do
187   - @query.order = [:pageviews]
  186 + it "does not replace sort if option is omitted" do
  187 + @query.sort = [:pageviews]
188 188 @query.apply_options({})
189   - @query.order.should == Legato::ListParameter.new(:order, [:pageviews])
  189 + @query.sort.should == Legato::ListParameter.new(:sort, [:pageviews])
190 190 end
191 191
192   - it "moves :sort option into order" do
  192 + it "moves :sort option into sort" do
193 193 @query.apply_options({:sort => [:page_path]})
194   - @query.order.should == Legato::ListParameter.new(:order, [:page_path])
  194 + @query.sort.should == Legato::ListParameter.new(:sort, [:page_path])
195 195 end
196 196
197 197 it "sets the limit" do
@@ -321,13 +321,13 @@ def self.it_defines_operators(*operators)
321 321 @query.to_params['dimensions'].should == 'browser,country'
322 322 end
323 323
324   - it 'includes order' do
325   - order = Legato::ListParameter.new(:order)
326   - order.stubs(:to_params).returns({'order' => 'pageviews'})
327   - order.stubs(:empty?).returns(false)
328   - @query.stubs(:order).returns(order)
  324 + it 'includes sort' do
  325 + sort = Legato::ListParameter.new(:sort)
  326 + sort.stubs(:to_params).returns({'sort' => 'pageviews'})
  327 + sort.stubs(:empty?).returns(false)
  328 + @query.stubs(:sort).returns(sort)
329 329
330   - @query.to_params['order'].should == 'pageviews'
  330 + @query.to_params['sort'].should == 'pageviews'
331 331 end
332 332 end
333 333 end

0 comments on commit f83388b

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