Skip to content

Commit 2c0a350

Browse files
authored
fix(dependency): ensure that project with a groupdate dependency >= 5 can install forest-rails (#454)
1 parent e00a16f commit 2c0a350

File tree

8 files changed

+78
-9
lines changed

8 files changed

+78
-9
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ gem 'rails', '6.0.3.6'
2626
gem 'jsonapi-serializers', '1.0.1'
2727
gem 'rack-cors'
2828
gem 'arel-helpers', '2.11.0'
29-
gem 'groupdate', '2.5.2'
29+
gem 'groupdate', '5.2.2'
3030
gem 'useragent'
3131
gem 'jwt'
3232
gem 'bcrypt'

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PATH
44
forest_liana (6.3.3)
55
arel-helpers
66
bcrypt
7-
groupdate (= 2.5.2)
7+
groupdate (>= 5.0.0)
88
httparty
99
ipaddress
1010
json
@@ -89,8 +89,8 @@ GEM
8989
erubi (1.10.0)
9090
globalid (0.4.2)
9191
activesupport (>= 4.2.0)
92-
groupdate (2.5.2)
93-
activesupport (>= 3)
92+
groupdate (5.2.2)
93+
activesupport (>= 5)
9494
httparty (0.18.1)
9595
mime-types (~> 3.0)
9696
multi_xml (>= 0.5.2)
@@ -235,7 +235,7 @@ DEPENDENCIES
235235
bcrypt
236236
byebug
237237
forest_liana!
238-
groupdate (= 2.5.2)
238+
groupdate (= 5.2.2)
239239
httparty (= 0.18.1)
240240
ipaddress (= 0.8.3)
241241
json

app/services/forest_liana/line_stat_getter.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ class LineStatGetter < StatGetter
33
attr_accessor :record
44

55
def client_timezone
6+
# As stated here https://github.com/ankane/groupdate#for-sqlite
7+
# groupdate does not handle timezone for SQLite
8+
return nil if 'SQLite' == ActiveRecord::Base.connection.adapter_name
69
@params[:timezone]
710
end
811

@@ -26,9 +29,10 @@ def perform
2629
value = FiltersParser.new(@params[:filters], value, @params[:timezone]).apply_filters
2730
end
2831

32+
Groupdate.week_start = :monday
33+
2934
value = value.send(time_range, group_by_date_field, {
30-
time_zone: client_timezone,
31-
week_start: :mon
35+
time_zone: client_timezone
3236
})
3337

3438
value = value.send(@params[:aggregate].downcase, @params[:aggregate_field])

forest_liana.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
2222
s.add_runtime_dependency "jwt"
2323
s.add_runtime_dependency "rack-cors"
2424
s.add_runtime_dependency "arel-helpers"
25-
s.add_runtime_dependency "groupdate", "2.5.2"
25+
s.add_runtime_dependency "groupdate", ">= 5.0.0"
2626
s.add_runtime_dependency "useragent"
2727
s.add_runtime_dependency "bcrypt"
2828
s.add_runtime_dependency "httparty"

spec/dummy/app/models/owner.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Owner < ActiveRecord::Base
2+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class CreateOwners < ActiveRecord::Migration[6.0]
2+
def change
3+
create_table :owners do |t|
4+
t.string :name
5+
t.datetime :hired_at
6+
end
7+
end
8+
end

spec/dummy/db/schema.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2021_03_26_140855) do
13+
ActiveRecord::Schema.define(version: 2021_05_11_141752) do
1414

1515
create_table "isle", force: :cascade do |t|
1616
t.string "name"
@@ -27,6 +27,11 @@
2727
t.index ["island_id"], name: "index_locations_on_island_id"
2828
end
2929

30+
create_table "owners", force: :cascade do |t|
31+
t.string "name"
32+
t.datetime "hired_at"
33+
end
34+
3035
create_table "references", force: :cascade do |t|
3136
t.datetime "created_at", precision: 6, null: false
3237
t.datetime "updated_at", precision: 6, null: false
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module ForestLiana
2+
describe LineStatGetter do
3+
describe 'Check client_timezone function' do
4+
describe 'with a SQLite database' do
5+
it 'should return nil' do
6+
expect(LineStatGetter.new(Owner, {
7+
timezone: "Europe/Paris",
8+
aggregate: "Count",
9+
}).client_timezone).to eq(nil)
10+
end
11+
end
12+
13+
describe 'with a non-SQLite database' do
14+
it 'should return the timezone' do
15+
ActiveRecord::Base.connection.stub(:adapter_name) { 'NotSQLite' }
16+
expect(LineStatGetter.new(Owner, {
17+
timezone: "Europe/Paris",
18+
aggregate: "Count",
19+
}).client_timezone).to eq('Europe/Paris')
20+
end
21+
end
22+
end
23+
24+
describe 'Check perform function' do
25+
describe 'Using a Count aggregation' do
26+
describe 'Using a Week time range' do
27+
it 'should return consistent data based on monday as week_start ' do
28+
29+
# Week should start on monday
30+
# 08-05-2021 was a Saturday
31+
Owner.create(name: 'Michel', hired_at: Date.parse('08-05-2021'));
32+
Owner.create(name: 'Robert', hired_at: Date.parse('09-05-2021'));
33+
Owner.create(name: 'José', hired_at: Date.parse('10-05-2021'));
34+
Owner.create(name: 'Yves', hired_at: Date.parse('11-05-2021'));
35+
36+
stat = LineStatGetter.new(Owner, {
37+
timezone: "Europe/Paris",
38+
aggregate: "Count",
39+
time_range: "Week",
40+
group_by_date_field: "hired_at",
41+
}).perform
42+
43+
expect(stat.value.find { |item| item[:label] == "W18-2021" }[:values][:value]).to eq(2)
44+
expect(stat.value.find { |item| item[:label] == "W19-2021" }[:values][:value]).to eq(2)
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end

0 commit comments

Comments
 (0)