Commit 0090c221a4ba3bd06fbdbe10f1dd542286abd486
1 parent
7adfdd77
Exists in
master
and in
4 other branches
Raise ArgumentError when last option is not supported
Showing
3 changed files
with
13 additions
and
3 deletions
Show diff stats
CHANGELOG.md
lib/groupdate/magic.rb
... | ... | @@ -184,8 +184,10 @@ module Groupdate |
184 | 184 | elsif !time_range && options[:last] |
185 | 185 | if field == :quarter |
186 | 186 | step = 3.months |
187 | + elsif 1.respond_to?(field) | |
188 | + step = 1.send(field) | |
187 | 189 | else |
188 | - step = 1.send(field) if 1.respond_to?(field) | |
190 | + raise ArgumentError, "Cannot use last option with #{field}" | |
189 | 191 | end |
190 | 192 | if step |
191 | 193 | now = Time.now | ... | ... |
test/test_helper.rb
... | ... | @@ -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" |
... | ... | @@ -272,11 +277,13 @@ module TestDatabase |
272 | 277 | # permit |
273 | 278 | |
274 | 279 | def test_permit |
275 | - 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 | |
276 | 282 | end |
277 | 283 | |
278 | 284 | def test_permit_bad_period |
279 | - 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 | |
280 | 287 | end |
281 | 288 | |
282 | 289 | def test_permit_symbol_symbols | ... | ... |