Commit 09e6f14522231e33ece7eb28671ebc0d2c24e277
1 parent
f1e1a36f
Exists in
master
and in
17 other branches
Fixed tests for ActiveRecord 3.1
Showing
4 changed files
with
19 additions
and
14 deletions
Show diff stats
lib/groupdate.rb
1 | require "active_support/time" | 1 | require "active_support/time" |
2 | require "groupdate/version" | 2 | require "groupdate/version" |
3 | require "groupdate/magic" | 3 | require "groupdate/magic" |
4 | -require "groupdate/enumerable" | ||
5 | require "groupdate/active_record" | 4 | require "groupdate/active_record" |
5 | +require "groupdate/enumerable" | ||
6 | 6 | ||
7 | module Groupdate | 7 | module Groupdate |
8 | mattr_accessor :week_start, :day_start, :time_zone | 8 | mattr_accessor :week_start, :day_start, :time_zone |
lib/groupdate/enumerable.rb
1 | module Enumerable | 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 | end | 9 | end |
7 | end | 10 | end |
8 | 11 |
test/array_test.rb
@@ -1,10 +0,0 @@ | @@ -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 |
@@ -0,0 +1,12 @@ | @@ -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 |