Commit cdfacb2501b8a2c97b76454d798f1fac796037c8

Authored by Andrew Kane
1 parent 10b8ce87
Exists in auto_calculations

Fixed tests

Showing 2 changed files with 14 additions and 4 deletions   Show diff stats
lib/groupdate/magic.rb
... ... @@ -164,12 +164,10 @@ module Groupdate
164 164 end
165 165  
166 166 def perform(relation, method, *args, &block)
167   - raw_relation = relation.is_a?(Groupdate::Series) ? relation.relation : relation
168   -
169 167 # undo reverse since we do not want this to appear in the query
170 168 reverse = relation.send(:reverse_order_value)
171 169 relation = relation.except(:reverse_order) if reverse
172   - order = raw_relation.order_values.first
  170 + order = relation.order_values.first
173 171 if order.is_a?(String)
174 172 parts = order.split(" ")
175 173 reverse_order = (parts.size == 2 && (parts[0].to_sym == period || (activerecord42? && parts[0] == "#{relation.quoted_table_name}.#{relation.quoted_primary_key}")) && parts[1].to_s.downcase == "desc")
... ... @@ -182,7 +180,7 @@ module Groupdate
182 180 result = relation.send(method, *args, &block)
183 181  
184 182 if result.is_a?(Hash)
185   - multiple_groups = raw_relation.group_values.size > 1
  183 + multiple_groups = relation.group_values.size > 1
186 184 missing_time_zone_support = multiple_groups ? (result.keys.first && result.keys.first[@group_index].nil?) : result.key?(nil)
187 185 if missing_time_zone_support
188 186 raise Groupdate::Error, "Be sure to install time zone support - https://github.com/ankane/groupdate#for-mysql"
... ...
lib/groupdate/series.rb
... ... @@ -19,5 +19,17 @@ module Groupdate
19 19 def respond_to?(method, include_all = false)
20 20 relation.respond_to?(method) || super
21 21 end
  22 +
  23 + def order_values
  24 + relation.order_values
  25 + end
  26 +
  27 + def group_values
  28 + relation.group_values
  29 + end
  30 +
  31 + def reverse_order_value
  32 + nil
  33 + end
22 34 end
23 35 end
... ...