Commit 09e6f14522231e33ece7eb28671ebc0d2c24e277

Authored by Andrew Kane
1 parent f1e1a36f

Fixed tests for ActiveRecord 3.1

lib/groupdate.rb
1 1 require "active_support/time"
2 2 require "groupdate/version"
3 3 require "groupdate/magic"
4   -require "groupdate/enumerable"
5 4 require "groupdate/active_record"
  5 +require "groupdate/enumerable"
6 6  
7 7 module Groupdate
8 8 mattr_accessor :week_start, :day_start, :time_zone
... ...
lib/groupdate/enumerable.rb
1 1 module Enumerable
2 2  
3   - [:second, :minute, :hour, :day, :week, :month, :year, :day_of_week, :hour_of_day].each do |field|
4   - define_method :"group_by_#{field}" do |options = {}, &block|
5   - Groupdate::Magic.new(field, options).group_by(self, &block)
  3 + # skip due to ActiveRecord bug
  4 + unless ActiveRecord::VERSION::MAJOR == 3 and ActiveRecord::VERSION::MINOR < 2
  5 + [:second, :minute, :hour, :day, :week, :month, :year, :day_of_week, :hour_of_day].each do |field|
  6 + define_method :"group_by_#{field}" do |options = {}, &block|
  7 + Groupdate::Magic.new(field, options).group_by(self, &block)
  8 + end
6 9 end
7 10 end
8 11  
... ...
test/array_test.rb
... ... @@ -1,10 +0,0 @@
1   -require_relative "test_helper"
2   -
3   -class TestArray < Minitest::Unit::TestCase
4   - include TestGroupdate
5   -
6   - def call_method(method, field, options)
7   - Hash[ User.all.to_a.send(:"group_by_#{method}", options){|u| u.send(field) }.map{|k, v| [k, v.size] } ]
8   - end
9   -
10   -end
test/enumerable_test.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +require_relative "test_helper"
  2 +
  3 +unless ActiveRecord::VERSION::MAJOR == 3 and ActiveRecord::VERSION::MINOR < 2
  4 + class TestEnumerable < Minitest::Unit::TestCase
  5 + include TestGroupdate
  6 +
  7 + def call_method(method, field, options)
  8 + Hash[ User.all.to_a.send(:"group_by_#{method}", options){|u| u.send(field) }.map{|k, v| [k, v.size] } ]
  9 + end
  10 +
  11 + end
  12 +end
... ...