groupdate 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/groupdate/magic.rb +19 -3
- data/lib/groupdate/version.rb +1 -1
- data/test/test_helper.rb +23 -3
- 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: a75601315268495e473958ab19c6a39197efb3b9
|
4
|
+
data.tar.gz: 1b0e1d8b246e49e5e4d3abb76c40bc617f97e7bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c0edf976534abc2ccb263b39e48b3664991122ed50b541d4535f139243e5d657a2a525054a2906a1d037a4a65f7dbe1ea9d5f932d70f1d1fd507433cb00d499
|
7
|
+
data.tar.gz: 073ec218da11f747a93af186e5c82ed7e4035f0904816013b34f89130608befe984af491acbc3fcfd8da55ffd6d92d6545eeffb2a3ed15f946e821f3eb45dcf3
|
data/CHANGELOG.md
CHANGED
data/lib/groupdate/magic.rb
CHANGED
@@ -182,11 +182,27 @@ module Groupdate
|
|
182
182
|
last += 1.day unless time_range.exclude_end?
|
183
183
|
time_range = Range.new(time_zone.parse(time_range.first.to_s), last, true)
|
184
184
|
elsif !time_range && options[:last]
|
185
|
-
|
185
|
+
if field == :quarter
|
186
|
+
step = 3.months
|
187
|
+
elsif 1.respond_to?(field)
|
188
|
+
step = 1.send(field)
|
189
|
+
else
|
190
|
+
raise ArgumentError, "Cannot use last option with #{field}"
|
191
|
+
end
|
186
192
|
if step
|
187
193
|
now = Time.now
|
188
|
-
|
189
|
-
|
194
|
+
# loop instead of multiply to change start_at - see #151
|
195
|
+
start_at = now
|
196
|
+
(options[:last].to_i - 1).times do
|
197
|
+
start_at -= step
|
198
|
+
end
|
199
|
+
|
200
|
+
time_range =
|
201
|
+
if options[:current] == false
|
202
|
+
round_time(start_at - step)...round_time(now)
|
203
|
+
else
|
204
|
+
round_time(start_at)..now
|
205
|
+
end
|
190
206
|
end
|
191
207
|
end
|
192
208
|
time_range
|
data/lib/groupdate/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -225,6 +225,11 @@ module TestDatabase
|
|
225
225
|
assert_equal expected, User.group_by_year(:created_at, last: 3).count
|
226
226
|
end
|
227
227
|
|
228
|
+
def test_last_hour_of_day
|
229
|
+
error = assert_raises(ArgumentError) { User.group_by_hour_of_day(:created_at, last: 3).count }
|
230
|
+
assert_equal "Cannot use last option with hour_of_day", error.message
|
231
|
+
end
|
232
|
+
|
228
233
|
def test_current
|
229
234
|
create_user "#{this_year - 3}-01-01"
|
230
235
|
create_user "#{this_year - 1}-01-01"
|
@@ -235,6 +240,16 @@ module TestDatabase
|
|
235
240
|
assert_equal expected, User.group_by_year(:created_at, last: 2, current: false).count
|
236
241
|
end
|
237
242
|
|
243
|
+
def test_quarter_and_last
|
244
|
+
create_user "#{this_year}-#{this_quarters_month}-01"
|
245
|
+
create_user "#{this_year}-#{this_quarters_month - 6}-01"
|
246
|
+
expected = {
|
247
|
+
Date.parse("#{this_year}-#{this_quarters_month - 3}-01") => 0,
|
248
|
+
Date.parse("#{this_year}-#{this_quarters_month}-01") => 1
|
249
|
+
}
|
250
|
+
assert_equal expected, User.group_by_quarter(:created_at, last: 2).count
|
251
|
+
end
|
252
|
+
|
238
253
|
def test_format_locale
|
239
254
|
create_user "2014-10-01"
|
240
255
|
assert_equal ({"Okt" => 1}), User.group_by_day(:created_at, format: "%b", locale: :de).count
|
@@ -262,11 +277,13 @@ module TestDatabase
|
|
262
277
|
# permit
|
263
278
|
|
264
279
|
def test_permit
|
265
|
-
assert_raises(ArgumentError
|
280
|
+
error = assert_raises(ArgumentError) { User.group_by_period(:day, :created_at, permit: %w(week)).count }
|
281
|
+
assert_equal "Unpermitted period", error.message
|
266
282
|
end
|
267
283
|
|
268
284
|
def test_permit_bad_period
|
269
|
-
assert_raises(ArgumentError
|
285
|
+
error = assert_raises(ArgumentError) { User.group_by_period(:bad_period, :created_at).count }
|
286
|
+
assert_equal "Unpermitted period", error.message
|
270
287
|
end
|
271
288
|
|
272
289
|
def test_permit_symbol_symbols
|
@@ -1046,7 +1063,6 @@ module TestGroupdate
|
|
1046
1063
|
end
|
1047
1064
|
|
1048
1065
|
def test_date_column_with_time_zone
|
1049
|
-
# TODO change for Groupdate 3.0
|
1050
1066
|
expected = {
|
1051
1067
|
Date.parse("2013-05-02") => 1
|
1052
1068
|
}
|
@@ -1148,6 +1164,10 @@ module TestGroupdate
|
|
1148
1164
|
assert_equal expected, call_method(method, :created_at, options.merge(series: true, time_zone: time_zone ? "Pacific Time (US & Canada)" : nil, range: Time.parse(range_start)..Time.parse(range_end)))
|
1149
1165
|
end
|
1150
1166
|
|
1167
|
+
def this_quarters_month
|
1168
|
+
Time.now.utc.beginning_of_quarter.month
|
1169
|
+
end
|
1170
|
+
|
1151
1171
|
def this_year
|
1152
1172
|
Time.now.utc.year
|
1153
1173
|
end
|
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.1.
|
4
|
+
version: 3.1.1
|
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-10-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|