groupdate 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +0 -2
- data/lib/groupdate.rb +1 -1
- data/lib/groupdate/enumerable.rb +13 -6
- data/lib/groupdate/magic.rb +1 -1
- data/lib/groupdate/version.rb +1 -1
- data/test/test_helper.rb +19 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a15c2188ffbf51536333cfad342a88325d5866c
|
4
|
+
data.tar.gz: 962f3ddeffa87168994308c6740ad126393db9e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caf2a8b62b7d05e4934f3035b1d7e16c739bef41d316ced765ceb48b0b5c36cb29bad12579ca90b3cfdacdb870d4ab721bc0d925aa5d1c791b15a393a067d4ba
|
7
|
+
data.tar.gz: dabd8ea049f07f730c219348dc247996838831221252eecb3a58a40fd650aa6a16b552a707db4aba1e6b522e984300888e4a7615fb8737bb0360ae2f2ff8e73b
|
data/.travis.yml
CHANGED
@@ -10,7 +10,7 @@ gemfile:
|
|
10
10
|
- test/gemfiles/activerecord41.gemfile
|
11
11
|
- test/gemfiles/activerecord42.gemfile
|
12
12
|
sudo: false
|
13
|
-
script: bundle exec rake test
|
13
|
+
script: RUBYOPT=W0 bundle exec rake test
|
14
14
|
before_install:
|
15
15
|
- gem install bundler
|
16
16
|
- mysql -e 'create database groupdate_test;'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,8 +11,6 @@ The simplest way to group by:
|
|
11
11
|
|
12
12
|
:cake: Get the entire series - **the other best part**
|
13
13
|
|
14
|
-
Works with Rails 3.1+
|
15
|
-
|
16
14
|
Supports PostgreSQL, MySQL, and Redshift, plus arrays and hashes
|
17
15
|
|
18
16
|
[](https://travis-ci.org/ankane/groupdate)
|
data/lib/groupdate.rb
CHANGED
@@ -7,7 +7,7 @@ module Groupdate
|
|
7
7
|
PERIODS = [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week, :hour_of_day, :day_of_month, :month_of_year]
|
8
8
|
# backwards compatibility for anyone who happened to use it
|
9
9
|
FIELDS = PERIODS
|
10
|
-
METHODS = PERIODS.map { |v| :"group_by_#{v}" }
|
10
|
+
METHODS = PERIODS.map { |v| :"group_by_#{v}" } + [:group_by_period]
|
11
11
|
|
12
12
|
mattr_accessor :week_start, :day_start, :time_zone, :dates
|
13
13
|
self.week_start = :sun
|
data/lib/groupdate/enumerable.rb
CHANGED
@@ -11,13 +11,20 @@ module Enumerable
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def group_by_period(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def group_by_period(*args, &block)
|
15
|
+
if block || !respond_to?(:scoping)
|
16
|
+
period = args[0]
|
17
|
+
options = args[1] || {}
|
18
|
+
|
19
|
+
# to_sym is unsafe on user input, so convert to strings
|
20
|
+
permitted_periods = ((options[:permit] || Groupdate::PERIODS).map(&:to_sym) & Groupdate::PERIODS).map(&:to_s)
|
21
|
+
if permitted_periods.include?(period.to_s)
|
22
|
+
send("group_by_#{period}", options, &block)
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Unpermitted period"
|
25
|
+
end
|
19
26
|
else
|
20
|
-
|
27
|
+
scoping { @klass.send(:group_by_period, *args, &block) }
|
21
28
|
end
|
22
29
|
end
|
23
30
|
end
|
data/lib/groupdate/magic.rb
CHANGED
data/lib/groupdate/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -293,6 +293,15 @@ module TestDatabase
|
|
293
293
|
assert_equal expected, user.posts.group_by_day(:created_at).count
|
294
294
|
end
|
295
295
|
|
296
|
+
def test_associations_period
|
297
|
+
user = create_user("2014-03-01")
|
298
|
+
user.posts.create!(created_at: "2014-04-01 00:00:00 UTC")
|
299
|
+
expected = {
|
300
|
+
Date.parse("2014-04-01") => 1
|
301
|
+
}
|
302
|
+
assert_equal expected, user.posts.group_by_period(:day, :created_at).count
|
303
|
+
end
|
304
|
+
|
296
305
|
# activerecord default_timezone option
|
297
306
|
|
298
307
|
def test_default_timezone_local
|
@@ -378,7 +387,7 @@ module TestGroupdate
|
|
378
387
|
# second
|
379
388
|
|
380
389
|
def test_second_end_of_second
|
381
|
-
if enumerable_test? ||
|
390
|
+
if enumerable_test? || ActiveRecord::Base.connection.adapter_name == "Mysql2"
|
382
391
|
skip # no millisecond precision
|
383
392
|
else
|
384
393
|
assert_result_time :second, "2013-05-03 00:00:00 UTC", "2013-05-03 00:00:00.999"
|
@@ -962,17 +971,22 @@ module TestGroupdate
|
|
962
971
|
|
963
972
|
def test_format_hour_of_day_day_start
|
964
973
|
create_user "2014-03-01"
|
965
|
-
assert_format :hour_of_day, "
|
974
|
+
assert_format :hour_of_day, "12 am", "%-l %P", day_start: 2
|
966
975
|
end
|
967
976
|
|
968
977
|
def test_format_day_of_week
|
969
978
|
create_user "2014-03-01"
|
970
|
-
assert_format :day_of_week, "
|
979
|
+
assert_format :day_of_week, "Sat", "%a"
|
980
|
+
end
|
981
|
+
|
982
|
+
def test_format_day_of_week_day_start
|
983
|
+
create_user "2014-03-01"
|
984
|
+
assert_format :day_of_week, "Fri", "%a", day_start: 2
|
971
985
|
end
|
972
986
|
|
973
987
|
def test_format_day_of_week_week_start
|
974
988
|
create_user "2014-03-01"
|
975
|
-
assert_format :day_of_week, "
|
989
|
+
assert_format :day_of_week, "Sat", "%a", week_start: :mon
|
976
990
|
end
|
977
991
|
|
978
992
|
def test_format_day_of_month
|
@@ -1016,7 +1030,7 @@ module TestGroupdate
|
|
1016
1030
|
# helpers
|
1017
1031
|
|
1018
1032
|
def assert_format(method, expected, format, options = {})
|
1019
|
-
assert_equal
|
1033
|
+
assert_equal({expected => 1}, call_method(method, :created_at, options.merge(format: format, series: false)))
|
1020
1034
|
end
|
1021
1035
|
|
1022
1036
|
def assert_result_time(method, expected, time_str, time_zone = false, options = {})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupdate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|