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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87e6343538ca0aa70041863153b514d765952ca9
4
- data.tar.gz: a5121f5bab5c8f9de575e5adcf09885c88abd08a
3
+ metadata.gz: a75601315268495e473958ab19c6a39197efb3b9
4
+ data.tar.gz: 1b0e1d8b246e49e5e4d3abb76c40bc617f97e7bf
5
5
  SHA512:
6
- metadata.gz: 62c9cc55ca4f808911727d3513a50f79b379b041589b38a52214b9d87fe38d2d321ce6bb4d41a7b0fc9a8fc9a780f039d626582ce71cd65fdfe81467ac1a9107
7
- data.tar.gz: b0dd02d55c7f72247e1bb5c7b9f221cddd4321fcb4e77d2101b9b759948e145385987e938134d5888ee95864066fbb943aae7a6226b7bc26fc334ffb6c219402
6
+ metadata.gz: 4c0edf976534abc2ccb263b39e48b3664991122ed50b541d4535f139243e5d657a2a525054a2906a1d037a4a65f7dbe1ea9d5f932d70f1d1fd507433cb00d499
7
+ data.tar.gz: 073ec218da11f747a93af186e5c82ed7e4035f0904816013b34f89130608befe984af491acbc3fcfd8da55ffd6d92d6545eeffb2a3ed15f946e821f3eb45dcf3
@@ -1,3 +1,9 @@
1
+ ## 3.1.1
2
+
3
+ - Fixed `current: false`
4
+ - Fixed `last` with `group_by_quarter`
5
+ - Raise `ArgumentError` when `last` option is not supported
6
+
1
7
  ## 3.1.0
2
8
 
3
9
  - Better support for date columns with `time_zone: false`
@@ -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
- step = 1.send(field) if 1.respond_to?(field)
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
- now -= step if options[:current] == false
189
- time_range = round_time(now - (options[:last].to_i - 1).send(field))..now
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
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
@@ -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, "Unpermitted period") { User.group_by_period(:day, :created_at, permit: %w(week)).count }
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, "Unpermitted period") { User.group_by_period(:bad_period, :created_at).count }
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.0
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-22 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport