groupdate 2.0.1 → 2.0.2

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: 89762e723508e5431f4f03eccc43b9a1edb63847
4
- data.tar.gz: e78b217c7424bb628b284a143f8004d0ef159d93
3
+ metadata.gz: af27fcb8fcdb2e8bb300ca3ad248690b47b750df
4
+ data.tar.gz: c7db61278cb56b67bafdb01beceadaa2236e955b
5
5
  SHA512:
6
- metadata.gz: 3de4b5d5d7d05a10c77ef8b098bca4abbf7495cadd91381088f92bb299131ffac9b3c1cf86ada1ab0e1f202ae404f56ba1cfaba18f1a91233c9f6c7b93dfbcf2
7
- data.tar.gz: 917773b5b9c2a6c42ff061f11dc7fc31ad50313d53e5140b828c91dc8331abd3be2ee49ec3ba627e8f8d3749991d7535f94a953ff4459ad9c9a571667ead05a8
6
+ metadata.gz: 1f1be192a48bc96363a39627f69aaa0d1f598c39f91f3dd0728d47c1c49d2e4bafc15b54e7e3d7437247e5bda8e8b68a452db55e3fff156ab6ab1dce8fa77778
7
+ data.tar.gz: 681d43a72eb1c7b97c91d923b5de0de2517a114bb202e97a7f902ca9ff24cd71678a4a453736adf71331837058b43fde744aba26e08c419b20ae7a99ffd273ef
@@ -1,3 +1,7 @@
1
+ # 2.0.2
2
+
3
+ - where, joins, and includes no longer need to be before the group_by method
4
+
1
5
  # 2.0.1
2
6
 
3
7
  - Use time zone instead of UTC for results
data/README.md CHANGED
@@ -61,9 +61,9 @@ or
61
61
  ```ruby
62
62
  User.group_by_week(:created_at, time_zone: "Pacific Time (US & Canada)").count
63
63
  # {
64
- # 2013-03-03 08:00:00 UTC => 80,
65
- # 2013-03-10 08:00:00 UTC => 70,
66
- # 2013-03-17 07:00:00 UTC => 54
64
+ # 2013-03-10 00:00:00 PST => 70,
65
+ # 2013-03-17 00:00:00 PDT => 54,
66
+ # 2013-03-24 00:00:00 PDT => 80
67
67
  # }
68
68
  ```
69
69
 
@@ -135,29 +135,10 @@ gem "activerecord-jdbcmysql-adapter", :github => "jruby/activerecord-jdbc-adapte
135
135
 
136
136
  ## Upgrading to 2.0
137
137
 
138
- Groupdate 2.0 brings a number a great improvements.
138
+ Groupdate 2.0 brings a number a great improvements. Here are two things to be aware of:
139
139
 
140
140
  - the entire series is returned by default
141
- - the `day_start` option
142
- - an improved interface
143
-
144
- However, there are a few things to be aware of when upgrading.
145
-
146
- 1. Groupdate methods must come after any `where`, `joins`, or `includes`.
147
-
148
- Throws error
149
-
150
- ```ruby
151
- User.group_by_day(:created_at).where(company_id: 1).count
152
- ```
153
-
154
- :moneybag:
155
-
156
- ```ruby
157
- User.where(company_id: 1).group_by_day(:created_at).count
158
- ```
159
-
160
- 2. `Time` keys are now returned for every database adapter. Some older adapters previously returned `String` keys.
141
+ - `ActiveSupport::TimeWithZone` keys are now returned for every database adapter - adapters previously returned `Time` or `String` keys
161
142
 
162
143
  ## History
163
144
 
@@ -91,10 +91,11 @@ module Groupdate
91
91
  # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/calculations.rb
92
92
  if ActiveRecord::Calculations.method_defined?(method)
93
93
  build_series(@relation.send(method, *args, &block))
94
- elsif [:joins, :includes, :where].include?(method)
95
- raise NoMethodError, "#{method} must come before the group_by_#{@field} method"
94
+ elsif @relation.respond_to?(method)
95
+ @relation = @relation.send(method, *args, &block)
96
+ self
96
97
  else
97
- raise NoMethodError, "valid methods are: #{ActiveRecord::Calculations.instance_methods.join(", ")}"
98
+ super
98
99
  end
99
100
  end
100
101
 
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -480,6 +480,17 @@ module TestGroupdate
480
480
  assert_equal time_zone, User.group_by_day(:created_at, time_zone: time_zone).count.keys.first.time_zone.name
481
481
  end
482
482
 
483
+ def test_where_after
484
+ create_user "2013-05-01 00:00:00 UTC"
485
+ create_user "2013-05-02 00:00:00 UTC"
486
+ expected = {utc.parse("2013-05-02 00:00:00 UTC") => 1}
487
+ assert_equal expected, User.group_by_day(:created_at).where("created_at > ?", "2013-05-01 00:00:00 UTC").count
488
+ end
489
+
490
+ def test_bad_method
491
+ assert_raises(NoMethodError) { User.group_by_day(:created_at).no_such_method }
492
+ end
493
+
483
494
  # helpers
484
495
 
485
496
  def assert_result_time(method, expected, time_str, time_zone = false, options = {})
@@ -507,7 +518,11 @@ module TestGroupdate
507
518
  end
508
519
 
509
520
  def create_user(created_at)
510
- User.create! :name => "Andrew", :score => 1, :created_at => ActiveSupport::TimeZone["UTC"].parse(created_at)
521
+ User.create! :name => "Andrew", :score => 1, :created_at => utc.parse(created_at)
522
+ end
523
+
524
+ def utc
525
+ ActiveSupport::TimeZone["UTC"]
511
526
  end
512
527
 
513
528
  def teardown
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: 2.0.1
4
+ version: 2.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: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord