groupdate 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96aed6d659f986f853f50f45bc93663f884235ac
4
+ data.tar.gz: b33a101116de8a25f3fde64ab7824aeb5e09d72b
5
+ SHA512:
6
+ metadata.gz: a7756158b511af490af7f6c6c6f516674161c5e2f5957380d4d6c7eb30cf733f25b4d7acdd203d9f835c7a98b9126ec91c3027910f71717eeb455ad993c37200
7
+ data.tar.gz: 3c1998ad9aec8d3a93001e86ad6d4e54d43547cc32689a32a247566b3bb010b9792799077a5c9485fbfdb906cf2f830d080d3c05856a432988d5d9764c75637b
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.8.7
3
4
  - 1.9.3
4
5
  - 2.0.0
5
6
  - jruby
data/Gemfile CHANGED
@@ -6,6 +6,6 @@ gemspec
6
6
  # gem "activerecord", github: "rails/rails"
7
7
 
8
8
  platform :jruby do
9
- gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter"
10
- gem "activerecord-jdbcmysql-adapter", github: "jruby/activerecord-jdbc-adapter"
9
+ gem "activerecord-jdbcpostgresql-adapter", :github => "jruby/activerecord-jdbc-adapter"
10
+ gem "activerecord-jdbcmysql-adapter", :github => "jruby/activerecord-jdbc-adapter"
11
11
  end
data/README.md CHANGED
@@ -123,12 +123,12 @@ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
123
123
 
124
124
  Use the master version of your JDBC adapter. You will get incorrect results for versions before [this commit](https://github.com/jruby/activerecord-jdbc-adapter/commit/c1cdb7cec8d3f06fc54995e8d872d830bd0a4d91).
125
125
 
126
- ```sh
126
+ ```ruby
127
127
  # postgresql
128
- gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter"
128
+ gem "activerecord-jdbcpostgresql-adapter", :github => "jruby/activerecord-jdbc-adapter"
129
129
 
130
130
  # mysql
131
- gem "activerecord-jdbcmysql-adapter", github: "jruby/activerecord-jdbc-adapter"
131
+ gem "activerecord-jdbcmysql-adapter", :github => "jruby/activerecord-jdbc-adapter"
132
132
  ```
133
133
 
134
134
  ## Complete list
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/groupdate.rb CHANGED
@@ -30,9 +30,9 @@ module Groupdate
30
30
  # http://www.postgresql.org/docs/9.1/static/functions-datetime.html
31
31
  fields = %w(second minute hour day week month year day_of_week hour_of_day)
32
32
  fields.each do |field|
33
- self.scope :"group_by_#{field}", lambda {|unsafe_column, time_zone = Time.zone|
34
- column = connection.quote_column_name(unsafe_column)
35
- time_zone ||= "Etc/UTC"
33
+ self.scope :"group_by_#{field}", lambda {|*args|
34
+ column = connection.quote_table_name(args[0])
35
+ time_zone = args[1] || Time.zone || "Etc/UTC"
36
36
  if time_zone.is_a?(ActiveSupport::TimeZone) or time_zone = ActiveSupport::TimeZone[time_zone]
37
37
  time_zone = time_zone.tzinfo.name
38
38
  else
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  # migrations
18
18
  %w(postgresql mysql2).each do |adapter|
19
- ActiveRecord::Base.establish_connection adapter: adapter, database: "groupdate_test", username: adapter == "mysql2" ? "root" : nil
19
+ ActiveRecord::Base.establish_connection :adapter => adapter, :database => "groupdate_test", :username => adapter == "mysql2" ? "root" : nil
20
20
 
21
21
  unless ActiveRecord::Base.connection.table_exists? "users"
22
22
  ActiveRecord::Migration.create_table :users do |t|
@@ -32,22 +32,22 @@ describe Groupdate do
32
32
  describe adapter do
33
33
 
34
34
  before do
35
- User.establish_connection adapter: adapter, database: "groupdate_test", username: adapter == "mysql2" ? "root" : nil
35
+ User.establish_connection :adapter => adapter, :database => "groupdate_test", :username => adapter == "mysql2" ? "root" : nil
36
36
  User.delete_all
37
37
  end
38
38
 
39
39
  it "works!" do
40
40
  [
41
- {name: "Andrew", score: 1, created_at: Time.parse("2013-04-01 00:00:00 UTC")},
42
- {name: "Jordan", score: 2, created_at: Time.parse("2013-04-01 00:00:00 UTC")},
43
- {name: "Nick", score: 3, created_at: Time.parse("2013-04-02 00:00:00 UTC")}
41
+ {:name => "Andrew", :score => 1, :created_at => Time.parse("2013-04-01 00:00:00 UTC")},
42
+ {:name => "Jordan", :score => 2, :created_at => Time.parse("2013-04-01 00:00:00 UTC")},
43
+ {:name => "Nick", :score => 3, :created_at => Time.parse("2013-04-02 00:00:00 UTC")}
44
44
  ].each{|u| User.create!(u) }
45
45
 
46
46
  assert_equal(
47
- {
47
+ ordered_hash({
48
48
  time_key("2013-04-01 00:00:00 UTC") => 1,
49
49
  time_key("2013-04-02 00:00:00 UTC") => 1
50
- },
50
+ }),
51
51
  User.where("score > 1").group_by_day(:created_at).count
52
52
  )
53
53
  end
@@ -58,6 +58,10 @@ describe Groupdate do
58
58
  assert_equal({}, User.group_by_hour_of_day(:created_at).order("hour_of_day desc").count)
59
59
  end
60
60
 
61
+ it "allows for table name" do
62
+ assert_equal({}, User.group_by_day("users.created_at").count)
63
+ end
64
+
61
65
  it "group_by_second" do
62
66
  assert_group :second, "2013-04-01 00:00:01 UTC", "2013-04-01 00:00:01 UTC"
63
67
  end
@@ -124,7 +128,7 @@ describe Groupdate do
124
128
 
125
129
  def assert_group(method, created_at, key, time_zone = nil)
126
130
  create_user created_at
127
- assert_equal({time_key(key) => 1}, User.send(:"group_by_#{method}", :created_at, time_zone).count)
131
+ assert_equal(ordered_hash({time_key(key) => 1}), User.send(:"group_by_#{method}", :created_at, time_zone).count)
128
132
  end
129
133
 
130
134
  def assert_group_tz(method, created_at, key)
@@ -133,7 +137,7 @@ describe Groupdate do
133
137
 
134
138
  def assert_group_number(method, created_at, key, time_zone = nil)
135
139
  create_user created_at
136
- assert_equal({number_key(key) => 1}, User.send(:"group_by_#{method}", :created_at, time_zone).count)
140
+ assert_equal(ordered_hash({number_key(key) => 1}), User.send(:"group_by_#{method}", :created_at, time_zone).count)
137
141
  end
138
142
 
139
143
  def assert_group_number_tz(method, created_at, key)
@@ -144,7 +148,7 @@ describe Groupdate do
144
148
  if RUBY_PLATFORM == "java"
145
149
  User.connection.adapter_name == "PostgreSQL" ? Time.parse(key).strftime("%Y-%m-%d %H:%M:%S%z")[0..-3] : Time.parse(key).strftime("%Y-%m-%d %H:%M:%S").gsub(/ 00\:00\:00\z/, "")
146
150
  else
147
- User.connection.adapter_name == "PostgreSQL" && ActiveRecord::VERSION::MAJOR == 3 ? Time.parse(key).strftime("%Y-%m-%d %H:%M:%S%z")[0..-3] : Time.parse(key)
151
+ User.connection.adapter_name == "PostgreSQL" && ActiveRecord::VERSION::MAJOR == 3 ? Time.parse(key).strftime("%Y-%m-%d %H:%M:%S+00") : Time.parse(key)
148
152
  end
149
153
  end
150
154
 
@@ -156,8 +160,12 @@ describe Groupdate do
156
160
  end
157
161
  end
158
162
 
163
+ def ordered_hash(hash)
164
+ RUBY_VERSION =~ /1\.8/ ? hash.inject(ActiveSupport::OrderedHash.new){|h, (k, v)| h[k] = v; h } : hash
165
+ end
166
+
159
167
  def create_user(created_at)
160
- User.create!(name: "Andrew", score: 1, created_at: Time.parse(created_at))
168
+ User.create!(:name => "Andrew", :score => 1, :created_at => Time.parse(created_at))
161
169
  end
162
170
 
163
171
  end
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groupdate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Andrew Kane
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-25 00:00:00.000000000 Z
11
+ date: 2013-05-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,65 +41,57 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: minitest
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: pg
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: mysql2
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: The simplest way to group temporal data
@@ -127,28 +114,26 @@ files:
127
114
  homepage: ''
128
115
  licenses:
129
116
  - MIT
117
+ metadata: {}
130
118
  post_install_message:
131
119
  rdoc_options: []
132
120
  require_paths:
133
121
  - lib
134
122
  required_ruby_version: !ruby/object:Gem::Requirement
135
- none: false
136
123
  requirements:
137
- - - ! '>='
124
+ - - '>='
138
125
  - !ruby/object:Gem::Version
139
126
  version: '0'
140
127
  required_rubygems_version: !ruby/object:Gem::Requirement
141
- none: false
142
128
  requirements:
143
- - - ! '>='
129
+ - - '>='
144
130
  - !ruby/object:Gem::Version
145
131
  version: '0'
146
132
  requirements: []
147
133
  rubyforge_project:
148
- rubygems_version: 1.8.23
134
+ rubygems_version: 2.0.0
149
135
  signing_key:
150
- specification_version: 3
136
+ specification_version: 4
151
137
  summary: The simplest way to group temporal data
152
138
  test_files:
153
139
  - test/groupdate_test.rb
154
- has_rdoc: