Commit 3bc715eda15168004e51e4aae39baeade1002861
1 parent
c5d487e5
Exists in
master
and in
15 other branches
Added carry_forward option
Showing
3 changed files
with
10 additions
and
2 deletions
Show diff stats
CHANGELOG.md
lib/groupdate/magic.rb
... | ... | @@ -254,10 +254,8 @@ module Groupdate |
254 | 254 | end |
255 | 255 | |
256 | 256 | value = nil |
257 | - | |
258 | 257 | Hash[series.map do |k| |
259 | 258 | value = count[k] || (@options[:carry_forward] ? value : false) || default_value |
260 | - | |
261 | 259 | [multiple_groups ? k[0...@group_index] + [key_format.call(k[@group_index])] + k[(@group_index + 1)..-1] : key_format.call(k), value] |
262 | 260 | end] |
263 | 261 | end | ... | ... |
test/test_helper.rb
... | ... | @@ -772,6 +772,15 @@ module TestGroupdate |
772 | 772 | assert_equal expected, User.group_by_day(:created_at, time_zone: "Brasilia").count |
773 | 773 | end |
774 | 774 | |
775 | + # carry_forward option | |
776 | + | |
777 | + def test_carry_forward | |
778 | + create_user "2014-05-01 00:00:00 UTC" | |
779 | + create_user "2014-05-01 00:00:00 UTC" | |
780 | + create_user "2014-05-03 00:00:00 UTC" | |
781 | + assert_equal 2, User.group_by_day(:created_at, carry_forward: true).count[utc.parse("2014-05-02 00:00:00 UTC")] | |
782 | + end | |
783 | + | |
775 | 784 | # helpers |
776 | 785 | |
777 | 786 | def assert_format(method, expected, format, options = {}) | ... | ... |