by_star 3.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/mysql.yml +92 -0
  3. data/.github/workflows/postgresql.yml +99 -0
  4. data/.gitignore +6 -5
  5. data/.travis.yml +92 -61
  6. data/CHANGELOG.md +63 -44
  7. data/Gemfile +18 -18
  8. data/MIT-LICENSE +20 -20
  9. data/README.md +616 -577
  10. data/Rakefile +18 -18
  11. data/UPGRADING +4 -6
  12. data/by_star.gemspec +34 -34
  13. data/cleaner.rb +24 -24
  14. data/lib/by_star/base.rb +69 -68
  15. data/lib/by_star/between.rb +185 -156
  16. data/lib/by_star/directional.rb +35 -37
  17. data/lib/by_star/kernel/date.rb +41 -50
  18. data/lib/by_star/kernel/in_time_zone.rb +20 -0
  19. data/lib/by_star/kernel/time.rb +41 -41
  20. data/lib/by_star/normalization.rb +156 -127
  21. data/lib/by_star/orm/active_record/by_star.rb +75 -61
  22. data/lib/by_star/orm/mongoid/by_star.rb +90 -76
  23. data/lib/by_star/orm/mongoid/reorder.rb +23 -23
  24. data/lib/by_star/version.rb +3 -3
  25. data/lib/by_star.rb +18 -17
  26. data/spec/database.yml +15 -15
  27. data/spec/fixtures/active_record/models.rb +12 -12
  28. data/spec/fixtures/active_record/schema.rb +19 -19
  29. data/spec/fixtures/mongoid/models.rb +31 -31
  30. data/spec/fixtures/shared/seeds.rb +36 -26
  31. data/spec/gemfiles/Gemfile.rails +5 -0
  32. data/spec/gemfiles/Gemfile.rails32 +7 -0
  33. data/spec/gemfiles/Gemfile.rails40 +7 -7
  34. data/spec/gemfiles/Gemfile.rails41 +7 -7
  35. data/spec/gemfiles/Gemfile.rails42 +7 -7
  36. data/spec/gemfiles/Gemfile.rails50 +7 -10
  37. data/spec/gemfiles/Gemfile.rails51 +7 -10
  38. data/spec/gemfiles/Gemfile.rails52 +7 -0
  39. data/spec/gemfiles/Gemfile.rails60 +7 -0
  40. data/spec/gemfiles/Gemfile.rails61 +7 -0
  41. data/spec/integration/active_record/active_record_spec.rb +41 -38
  42. data/spec/integration/mongoid/mongoid_spec.rb +39 -37
  43. data/spec/integration/shared/at_time.rb +53 -0
  44. data/spec/integration/shared/between_dates.rb +99 -0
  45. data/spec/integration/shared/between_times.rb +99 -82
  46. data/spec/integration/shared/by_calendar_month.rb +55 -55
  47. data/spec/integration/shared/by_cweek.rb +54 -54
  48. data/spec/integration/shared/by_day.rb +120 -96
  49. data/spec/integration/shared/by_direction.rb +126 -172
  50. data/spec/integration/shared/by_fortnight.rb +48 -48
  51. data/spec/integration/shared/by_month.rb +50 -50
  52. data/spec/integration/shared/by_quarter.rb +49 -49
  53. data/spec/integration/shared/by_week.rb +54 -54
  54. data/spec/integration/shared/by_weekend.rb +49 -49
  55. data/spec/integration/shared/by_year.rb +48 -48
  56. data/spec/integration/shared/index_scope_parameter.rb +111 -0
  57. data/spec/integration/shared/offset_parameter.rb +32 -32
  58. data/spec/integration/shared/order_parameter.rb +36 -36
  59. data/spec/integration/shared/relative.rb +174 -174
  60. data/spec/spec_helper.rb +33 -29
  61. data/spec/unit/kernel_date_spec.rb +113 -113
  62. data/spec/unit/kernel_time_spec.rb +57 -57
  63. data/spec/unit/normalization_spec.rb +384 -305
  64. data/tmp/.gitignore +1 -1
  65. metadata +33 -21
  66. data/spec/gemfiles/Gemfile.master +0 -6
  67. data/spec/integration/shared/scope_parameter.rb +0 -73
@@ -1,7 +1,7 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'mongoid', '~> 4.0.0'
6
- gem 'pg', '~> 0.15'
7
- gem 'activerecord', '~> 4.2.0'
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec path: '../../'
4
+
5
+ gem 'activerecord', '~> 4.2.0'
6
+ gem 'pg', '~> 0.15'
7
+ gem 'mongoid'
@@ -1,10 +1,7 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'activerecord', '~> 5.0.0'
6
- gem 'pg', '~> 0.18'
7
- gem 'mongoid', '~> 6.0'
8
- # Due to weird connection issues in 2.5.0
9
- # TODO: double check this for non 2.5.0 versions
10
- gem 'mongo', '~> 2.4.3'
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec path: '../../'
4
+
5
+ gem 'activerecord', '~> 5.0.0'
6
+ gem 'pg', '~> 0.18'
7
+ gem 'mongoid'
@@ -1,10 +1,7 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec path: '../../'
4
-
5
- gem 'activerecord', '~> 5.1.0'
6
- gem 'pg', '~> 0.18'
7
- gem 'mongoid', '~> 6.0'
8
- # Due to weird connection issues in 2.5.0
9
- # TODO: double check this for non 2.5.0 versions
10
- gem 'mongo', '~> 2.4.3'
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec path: '../../'
4
+
5
+ gem 'activerecord', '~> 5.1.0'
6
+ gem 'pg', '~> 0.18'
7
+ gem 'mongoid'
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec path: '../../'
4
+
5
+ gem 'activerecord', '~> 5.2.0'
6
+ gem 'pg', '~> 0.18'
7
+ gem 'mongoid'
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec path: '../../'
4
+
5
+ gem 'activerecord', '~> 6.0'
6
+ gem 'pg'
7
+ gem 'mongoid'
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec path: '../../'
4
+
5
+ gem 'activerecord', '~> 6.1'
6
+ gem 'pg'
7
+ gem 'mongoid'
@@ -1,38 +1,41 @@
1
- require 'spec_helper'
2
- Dir[File.dirname(__FILE__) + '/../shared/*.rb'].each {|file| require file }
3
-
4
- describe ActiveRecord do
5
- before(:all) do
6
- ActiveRecord::Base.default_timezone = :utc
7
- # ActiveRecord::Base.logger = Logger.new(STDOUT)
8
-
9
- db_config = YAML::load_file(File.dirname(__FILE__) + '/../../database.yml')
10
- if db_config.has_key?('sqlite') && db_config['sqlite'].has_key?('database')
11
- db_config['sqlite']['database'] = File.dirname(__FILE__) + '/../../tmp/' + db_config['sqlite']['database']
12
- end
13
-
14
- ActiveRecord::Base.configurations = db_config
15
- ActiveRecord::Base.establish_connection(ENV['DB'].try(:to_sym) || :sqlite)
16
- load File.dirname(__FILE__) + '/../../fixtures/active_record/schema.rb'
17
- load File.dirname(__FILE__) + '/../../fixtures/active_record/models.rb'
18
- load File.dirname(__FILE__) + '/../../fixtures/shared/seeds.rb'
19
-
20
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/../../tmp/activerecord.log')
21
- end
22
-
23
- it_behaves_like 'between_times'
24
- it_behaves_like 'offset parameter'
25
- it_behaves_like 'order parameter'
26
- it_behaves_like 'scope parameter'
27
- it_behaves_like 'by day'
28
- it_behaves_like 'by direction'
29
- it_behaves_like 'by fortnight'
30
- it_behaves_like 'by month'
31
- it_behaves_like 'by calendar month'
32
- it_behaves_like 'by quarter'
33
- it_behaves_like 'by week'
34
- it_behaves_like 'by cweek'
35
- it_behaves_like 'by weekend'
36
- it_behaves_like 'by year'
37
- it_behaves_like 'relative'
38
- end if testing_active_record?
1
+ require 'spec_helper'
2
+ Dir[File.dirname(__FILE__) + '/../shared/*.rb'].each {|file| require file }
3
+
4
+ describe ActiveRecord do
5
+ before(:all) do
6
+ ActiveRecord::Base.default_timezone = :utc
7
+ # ActiveRecord::Base.logger = Logger.new(STDOUT)
8
+ database_file = File.dirname(__FILE__) + '/../../database.yml'
9
+ parsed_config = ERB.new(File.read(database_file)).result
10
+ db_config = YAML.safe_load(parsed_config)
11
+ if db_config.has_key?('sqlite') && db_config['sqlite'].has_key?('database')
12
+ db_config['sqlite']['database'] = File.dirname(__FILE__) + '/../../tmp/' + db_config['sqlite']['database']
13
+ end
14
+
15
+ ActiveRecord::Base.configurations = db_config
16
+ ActiveRecord::Base.establish_connection(ENV['DB'].try(:to_sym) || :sqlite)
17
+ load File.dirname(__FILE__) + '/../../fixtures/active_record/schema.rb'
18
+ load File.dirname(__FILE__) + '/../../fixtures/active_record/models.rb'
19
+ load File.dirname(__FILE__) + '/../../fixtures/shared/seeds.rb'
20
+
21
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/../../tmp/activerecord.log')
22
+ end
23
+
24
+ it_behaves_like 'between_times'
25
+ it_behaves_like 'between_dates'
26
+ it_behaves_like 'at_time'
27
+ it_behaves_like 'offset parameter'
28
+ it_behaves_like 'order parameter'
29
+ it_behaves_like 'index_scope parameter'
30
+ it_behaves_like 'by day'
31
+ it_behaves_like 'by direction'
32
+ it_behaves_like 'by fortnight'
33
+ it_behaves_like 'by month'
34
+ it_behaves_like 'by calendar month'
35
+ it_behaves_like 'by quarter'
36
+ it_behaves_like 'by week'
37
+ it_behaves_like 'by cweek'
38
+ it_behaves_like 'by weekend'
39
+ it_behaves_like 'by year'
40
+ it_behaves_like 'relative'
41
+ end if testing_active_record?
@@ -1,37 +1,39 @@
1
- require 'spec_helper'
2
- Dir[File.dirname(__FILE__) + '/../shared/*.rb'].each {|file| require file }
3
-
4
- describe 'Mongoid' do
5
-
6
- before(:all) do
7
- DATABASE_NAME = "mongoid_#{Process.pid}"
8
- # Moped.logger = Logger.new(STDOUT)
9
-
10
- Mongoid.configure do |config|
11
- config.connect_to DATABASE_NAME
12
- end
13
-
14
- load File.dirname(__FILE__) + '/../../fixtures/mongoid/models.rb'
15
- load File.dirname(__FILE__) + '/../../fixtures/shared/seeds.rb'
16
- end
17
-
18
- after(:all) do
19
- Mongoid.purge!
20
- end
21
-
22
- it_behaves_like 'between_times'
23
- it_behaves_like 'offset parameter'
24
- it_behaves_like 'order parameter'
25
- it_behaves_like 'scope parameter'
26
- it_behaves_like 'by day'
27
- it_behaves_like 'by direction'
28
- it_behaves_like 'by fortnight'
29
- it_behaves_like 'by month'
30
- it_behaves_like 'by calendar month'
31
- it_behaves_like 'by quarter'
32
- it_behaves_like 'by week'
33
- it_behaves_like 'by cweek'
34
- it_behaves_like 'by weekend'
35
- it_behaves_like 'by year'
36
- it_behaves_like 'relative'
37
- end if testing_mongoid?
1
+ require 'spec_helper'
2
+ Dir[File.dirname(__FILE__) + '/../shared/*.rb'].each {|file| require file }
3
+
4
+ describe 'Mongoid' do
5
+
6
+ before(:all) do
7
+ DATABASE_NAME = "mongoid_#{Process.pid}"
8
+ # Moped.logger = Logger.new(STDOUT)
9
+
10
+ Mongoid.configure do |config|
11
+ config.connect_to DATABASE_NAME
12
+ end
13
+
14
+ load File.dirname(__FILE__) + '/../../fixtures/mongoid/models.rb'
15
+ load File.dirname(__FILE__) + '/../../fixtures/shared/seeds.rb'
16
+ end
17
+
18
+ after(:all) do
19
+ Mongoid.purge!
20
+ end
21
+
22
+ it_behaves_like 'between_times'
23
+ it_behaves_like 'between_dates'
24
+ it_behaves_like 'at_time'
25
+ it_behaves_like 'offset parameter'
26
+ it_behaves_like 'order parameter'
27
+ it_behaves_like 'index_scope parameter'
28
+ it_behaves_like 'by day'
29
+ it_behaves_like 'by direction'
30
+ it_behaves_like 'by fortnight'
31
+ it_behaves_like 'by month'
32
+ it_behaves_like 'by calendar month'
33
+ it_behaves_like 'by quarter'
34
+ it_behaves_like 'by week'
35
+ it_behaves_like 'by cweek'
36
+ it_behaves_like 'by weekend'
37
+ it_behaves_like 'by year'
38
+ it_behaves_like 'relative'
39
+ end if testing_mongoid?
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'at_time' do
4
+
5
+ describe '#at_time' do
6
+
7
+ context 'point object' do
8
+
9
+ context 'exactly equal' do
10
+ subject { Post.at_time(Time.zone.parse('2013-12-28 17:00:00')) }
11
+ it { expect(subject.count).to eql(1) }
12
+ end
13
+
14
+ context 'not exactly equal' do
15
+ subject { Post.at_time(Time.zone.parse('2013-12-28 17:00:01')) }
16
+ it { expect(subject.count).to eql(0) }
17
+ end
18
+ end
19
+
20
+ context 'timespan object' do
21
+
22
+ context 'before start time' do
23
+ subject { Event.at_time(Time.zone.parse('2013-12-23 16:59:59')) }
24
+ it { expect(subject.count).to eql(2) }
25
+ end
26
+
27
+ context 'at start time' do
28
+ subject { Event.at_time(Time.zone.parse('2013-12-23 17:00:00')) }
29
+ it { expect(subject.count).to eql(3) }
30
+ end
31
+
32
+ context 'after start time' do
33
+ subject { Event.at_time(Time.zone.parse('2013-12-23 17:00:01')) }
34
+ it { expect(subject.count).to eql(3) }
35
+ end
36
+
37
+ context 'before end time' do
38
+ subject { Event.at_time(Time.zone.parse('2013-11-06 16:59:59')) }
39
+ it { expect(subject.count).to eql(1) }
40
+ end
41
+
42
+ context 'at end time' do
43
+ subject { Event.at_time(Time.zone.parse('2013-11-06 17:00:00')) }
44
+ it { expect(subject.count).to eql(0) }
45
+ end
46
+
47
+ context 'after end time' do
48
+ subject { Event.at_time(Time.zone.parse('2013-11-06 17:00:01')) }
49
+ it { expect(subject.count).to eql(0) }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'between_dates' do
4
+
5
+ describe '#between_dates' do
6
+ subject { Post.between_dates(Time.zone.parse('2014-01-01'), Time.zone.parse('2014-01-06')) }
7
+
8
+ if testing_active_record?
9
+ it { is_expected.to be_a(ActiveRecord::Relation) }
10
+ else testing_mongoid?
11
+ it { is_expected.to be_a(Mongoid::Criteria) }
12
+ end
13
+
14
+ it { expect(subject.count).to eql(3) }
15
+
16
+ context 'one-sided query' do
17
+
18
+ context 'point query' do
19
+
20
+ context 'only start time' do
21
+ subject { Post.between_dates(Time.zone.parse('2014-01-01'), nil) }
22
+ it { expect(subject.count).to eql(12) }
23
+ end
24
+
25
+ context 'only end time' do
26
+ subject { Post.between_dates(nil, Time.zone.parse('2014-01-01')) }
27
+ it { expect(subject.count).to eql(12) }
28
+
29
+ context 'neither start nor end time' do
30
+ subject { Post.between_dates(nil, nil) }
31
+ it { expect(subject.count).to eql(22) }
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'timespan loose query' do
37
+
38
+ context 'only start time' do
39
+ subject { Event.between_dates(Time.zone.parse('2014-01-01'), nil, strict: false) }
40
+ it { expect(subject.count).to eql(17) }
41
+ end
42
+
43
+ context 'only end time' do
44
+ subject { Event.between_dates(nil, Time.zone.parse('2014-01-01'), strict: false) }
45
+ it { expect(subject.count).to eql(13) }
46
+
47
+ context 'neither start nor end time' do
48
+ subject { Event.between_dates(nil, nil) }
49
+ it { expect(subject.count).to eql(30) }
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'timespan strict query' do
55
+
56
+ context 'only start time' do
57
+ subject { Event.between_dates(Time.zone.parse('2014-01-01'), nil) }
58
+ it { expect(subject.count).to eql(17) }
59
+ end
60
+
61
+ context 'only end time' do
62
+ subject { Event.between_dates(nil, Time.zone.parse('2014-01-01')) }
63
+ it { expect(subject.count).to eql(13) }
64
+
65
+ context 'neither start nor end time' do
66
+ subject { Event.between_dates(nil, nil) }
67
+ it { expect(subject.count).to eql(30) }
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'two-sided query' do
74
+ context 'DST starts (Sydney)', sydney: true do
75
+ context 'day before' do
76
+ subject { Event.between_dates(Date.parse('2020-04-04'), Date.parse('2020-04-04'), offset: 5.hours) }
77
+ it { expect(subject.count).to eql(3) }
78
+ end
79
+
80
+ context 'same day' do
81
+ subject { Event.between_dates(Date.parse('2020-04-05'), Date.parse('2020-04-05'), offset: 5.hours) }
82
+ it { expect(subject.count).to eql(1) }
83
+ end
84
+ end
85
+
86
+ context 'when DST ends (Sydney)', sydney: true do
87
+ context 'day before' do
88
+ subject { Event.between_dates(Date.parse('2020-10-03'), Date.parse('2020-10-03'), offset: 5.hours) }
89
+ it { expect(subject.count).to eql(1) }
90
+ end
91
+
92
+ context 'same day' do
93
+ subject { Event.between_dates(Date.parse('2020-10-04'), Date.parse('2020-10-04'), offset: 5.hours) }
94
+ it { expect(subject.count).to eql(3) }
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,82 +1,99 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for 'between_times' do
4
-
5
- describe '#between_times' do
6
- subject { Post.between_times(Time.zone.parse('2014-01-01'), Time.zone.parse('2014-01-06')) }
7
-
8
- if testing_active_record?
9
- it { is_expected.to be_a(ActiveRecord::Relation) }
10
- else testing_mongoid?
11
- it { is_expected.to be_a(Mongoid::Criteria) }
12
- end
13
-
14
- it { expect(subject.count).to eql(3) }
15
-
16
- context 'one-sided query' do
17
-
18
- context 'point query' do
19
-
20
- context 'only start time' do
21
- subject { Post.between_times(Time.zone.parse('2014-01-01'), nil) }
22
- it { expect(subject.count).to eql(12) }
23
- end
24
-
25
- context 'only end time' do
26
- subject { Post.between_times(nil, Time.zone.parse('2014-01-01')) }
27
- it { expect(subject.count).to eql(10) }
28
-
29
- context 'neither start nor end time' do
30
- subject { Post.between_times(nil, nil) }
31
- it { expect(subject.count).to eql(22) }
32
- end
33
- end
34
- end
35
-
36
- context 'timespan loose query' do
37
-
38
- context 'only start time' do
39
- subject { Event.between_times(Time.zone.parse('2014-01-01'), nil, strict: false) }
40
- it { expect(subject.count).to eql(9) }
41
- end
42
-
43
- context 'only end time' do
44
- subject { Event.between_times(nil, Time.zone.parse('2014-01-01'), strict: false) }
45
- it { expect(subject.count).to eql(13) }
46
-
47
- context 'neither start nor end time' do
48
- subject { Event.between_times(nil, nil) }
49
- it { expect(subject.count).to eql(22) }
50
- end
51
- end
52
- end
53
-
54
- context 'timespan strict query' do
55
-
56
- context 'only start time' do
57
- subject { Event.between_times(Time.zone.parse('2014-01-01'), nil) }
58
- it { expect(subject.count).to eql(9) }
59
- end
60
-
61
- context 'only end time' do
62
- subject { Event.between_times(nil, Time.zone.parse('2014-01-01')) }
63
- it { expect(subject.count).to eql(13) }
64
-
65
- context 'neither start nor end time' do
66
- subject { Event.between_times(nil, nil) }
67
- it { expect(subject.count).to eql(22) }
68
- end
69
- end
70
- end
71
- end
72
- end
73
-
74
- if testing_mongoid?
75
- describe '#between' do
76
- it 'should not override Mongoid between method' do
77
- posts = Post.between(created_at: Time.zone.parse('2014-01-01')..Time.zone.parse('2014-01-06'))
78
- expect(posts.count).to eql(3)
79
- end
80
- end
81
- end
82
- end
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'between_times' do
4
+
5
+ describe '#between_times' do
6
+ subject { Post.between_times(Time.zone.parse('2014-01-01'), Time.zone.parse('2014-01-06')) }
7
+
8
+ if testing_active_record?
9
+ it { is_expected.to be_a(ActiveRecord::Relation) }
10
+ else testing_mongoid?
11
+ it { is_expected.to be_a(Mongoid::Criteria) }
12
+ end
13
+
14
+ it { expect(subject.count).to eql(3) }
15
+
16
+ context 'one-sided query' do
17
+
18
+ context 'point query' do
19
+
20
+ context 'only start time' do
21
+ subject { Post.between_times(Time.zone.parse('2014-01-01'), nil) }
22
+ it { expect(subject.count).to eql(12) }
23
+ end
24
+
25
+ context 'only end time' do
26
+ subject { Post.between_times(nil, Time.zone.parse('2014-01-01')) }
27
+ it { expect(subject.count).to eql(10) }
28
+
29
+ context 'neither start nor end time' do
30
+ subject { Post.between_times(nil, nil) }
31
+ it { expect(subject.count).to eql(22) }
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'timespan loose query' do
37
+
38
+ context 'only start time' do
39
+ subject { Event.between_times(Time.zone.parse('2014-01-01'), nil, strict: false) }
40
+ it { expect(subject.count).to eql(17) }
41
+ end
42
+
43
+ context 'only end time' do
44
+ subject { Event.between_times(nil, Time.zone.parse('2014-01-01'), strict: false) }
45
+ it { expect(subject.count).to eql(13) }
46
+
47
+ context 'neither start nor end time' do
48
+ subject { Event.between_times(nil, nil) }
49
+ it { expect(subject.count).to eql(30) }
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'timespan strict query' do
55
+
56
+ context 'only start time' do
57
+ subject { Event.between_times(Time.zone.parse('2014-01-01'), nil) }
58
+ it { expect(subject.count).to eql(17) }
59
+ end
60
+
61
+ context 'only end time' do
62
+ subject { Event.between_times(nil, Time.zone.parse('2014-01-01')) }
63
+ it { expect(subject.count).to eql(13) }
64
+
65
+ context 'neither start nor end time' do
66
+ subject { Event.between_times(nil, nil) }
67
+ it { expect(subject.count).to eql(30) }
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'two-sided query' do
74
+ context 'DST starts (Sydney)', sydney: true do
75
+ context 'day before' do
76
+ subject { Event.between_times(Date.parse('2020-04-04'), Date.parse('2020-04-04'), offset: 5.hours) }
77
+ it { expect(subject.count).to eql(3) }
78
+ end
79
+
80
+ context 'same day' do
81
+ subject { Event.between_times(Date.parse('2020-04-05'), Date.parse('2020-04-05'), offset: 5.hours) }
82
+ it { expect(subject.count).to eql(1) }
83
+ end
84
+ end
85
+
86
+ context 'when DST ends (Sydney)', sydney: true do
87
+ context 'day before' do
88
+ subject { Event.between_times(Date.parse('2020-10-03'), Date.parse('2020-10-03'), offset: 5.hours) }
89
+ it { expect(subject.count).to eql(1) }
90
+ end
91
+
92
+ context 'same day' do
93
+ subject { Event.between_times(Date.parse('2020-10-04'), Date.parse('2020-10-04'), offset: 5.hours) }
94
+ it { expect(subject.count).to eql(3) }
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end