Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dependency): ensure that project with a groupdate dependency >= 5 can install forest-rails #454

Merged
merged 6 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ gem 'rails', '6.0.3.6'
gem 'jsonapi-serializers', '1.0.1'
gem 'rack-cors'
gem 'arel-helpers', '2.11.0'
gem 'groupdate', '2.5.2'
gem 'groupdate', '5.2.2'
gem 'useragent'
gem 'jwt'
gem 'bcrypt'
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PATH
forest_liana (6.3.2)
arel-helpers
bcrypt
groupdate (= 2.5.2)
groupdate (>= 5.0.0)
httparty
ipaddress
json
Expand Down Expand Up @@ -89,8 +89,8 @@ GEM
erubi (1.10.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
groupdate (2.5.2)
activesupport (>= 3)
groupdate (5.2.2)
activesupport (>= 5)
httparty (0.18.1)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
Expand Down Expand Up @@ -235,7 +235,7 @@ DEPENDENCIES
bcrypt
byebug
forest_liana!
groupdate (= 2.5.2)
groupdate (= 5.2.2)
httparty (= 0.18.1)
ipaddress (= 0.8.3)
json
Expand Down
8 changes: 6 additions & 2 deletions app/services/forest_liana/line_stat_getter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class LineStatGetter < StatGetter
attr_accessor :record

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

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

Groupdate.week_start = :monday

value = value.send(time_range, group_by_date_field, {
time_zone: client_timezone,
week_start: :mon
time_zone: client_timezone
})

value = value.send(@params[:aggregate].downcase, @params[:aggregate_field])
Expand Down
2 changes: 1 addition & 1 deletion forest_liana.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "jwt"
s.add_runtime_dependency "rack-cors"
s.add_runtime_dependency "arel-helpers"
s.add_runtime_dependency "groupdate", "2.5.2"
s.add_runtime_dependency "groupdate", ">= 5.0.0"
s.add_runtime_dependency "useragent"
s.add_runtime_dependency "bcrypt"
s.add_runtime_dependency "httparty"
Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/app/models/owner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Owner < ActiveRecord::Base
end
8 changes: 8 additions & 0 deletions spec/dummy/db/migrate/20210511141752_create_owners.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateOwners < ActiveRecord::Migration[6.0]
def change
create_table :owners do |t|
t.string :name
t.datetime :hired_at
end
end
end
7 changes: 6 additions & 1 deletion spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_03_26_140855) do
ActiveRecord::Schema.define(version: 2021_05_11_141752) do

create_table "isle", force: :cascade do |t|
t.string "name"
Expand All @@ -27,6 +27,11 @@
t.index ["island_id"], name: "index_locations_on_island_id"
end

create_table "owners", force: :cascade do |t|
t.string "name"
t.datetime "hired_at"
end

create_table "references", force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
Expand Down
50 changes: 50 additions & 0 deletions spec/services/forest_liana/line_stat_getter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module ForestLiana
describe LineStatGetter do
describe 'Check client_timezone function' do
describe 'with a SQLite database' do
it 'should return nil' do
expect(LineStatGetter.new(Owner, {
timezone: "Europe/Paris",
aggregate: "Count",
}).client_timezone).to eq(nil)
end
end

describe 'with a non-SQLite database' do
it 'should return the timezone' do
ActiveRecord::Base.connection.stub(:adapter_name) { 'NotSQLite' }
expect(LineStatGetter.new(Owner, {
timezone: "Europe/Paris",
aggregate: "Count",
}).client_timezone).to eq('Europe/Paris')
end
end
end

describe 'Check perform function' do
describe 'Using a Count aggregation' do
describe 'Using a Week time range' do
it 'should return consistent data based on monday as week_start ' do

# Week should start on monday
# 08-05-2021 was a Saturday
Owner.create(name: 'Michel', hired_at: Date.parse('08-05-2021'));
Owner.create(name: 'Robert', hired_at: Date.parse('09-05-2021'));
Owner.create(name: 'José', hired_at: Date.parse('10-05-2021'));
Owner.create(name: 'Yves', hired_at: Date.parse('11-05-2021'));

stat = LineStatGetter.new(Owner, {
timezone: "Europe/Paris",
aggregate: "Count",
time_range: "Week",
group_by_date_field: "hired_at",
}).perform

expect(stat.value.find { |item| item[:label] == "W18-2021" }[:values][:value]).to eq(2)
expect(stat.value.find { |item| item[:label] == "W19-2021" }[:values][:value]).to eq(2)
end
end
end
end
end
end