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.
- checksums.yaml +4 -4
- data/.github/workflows/mysql.yml +92 -0
- data/.github/workflows/postgresql.yml +99 -0
- data/.gitignore +6 -5
- data/.travis.yml +92 -61
- data/CHANGELOG.md +63 -44
- data/Gemfile +18 -18
- data/MIT-LICENSE +20 -20
- data/README.md +616 -577
- data/Rakefile +18 -18
- data/UPGRADING +4 -6
- data/by_star.gemspec +34 -34
- data/cleaner.rb +24 -24
- data/lib/by_star/base.rb +69 -68
- data/lib/by_star/between.rb +185 -156
- data/lib/by_star/directional.rb +35 -37
- data/lib/by_star/kernel/date.rb +41 -50
- data/lib/by_star/kernel/in_time_zone.rb +20 -0
- data/lib/by_star/kernel/time.rb +41 -41
- data/lib/by_star/normalization.rb +156 -127
- data/lib/by_star/orm/active_record/by_star.rb +75 -61
- data/lib/by_star/orm/mongoid/by_star.rb +90 -76
- data/lib/by_star/orm/mongoid/reorder.rb +23 -23
- data/lib/by_star/version.rb +3 -3
- data/lib/by_star.rb +18 -17
- data/spec/database.yml +15 -15
- data/spec/fixtures/active_record/models.rb +12 -12
- data/spec/fixtures/active_record/schema.rb +19 -19
- data/spec/fixtures/mongoid/models.rb +31 -31
- data/spec/fixtures/shared/seeds.rb +36 -26
- data/spec/gemfiles/Gemfile.rails +5 -0
- data/spec/gemfiles/Gemfile.rails32 +7 -0
- data/spec/gemfiles/Gemfile.rails40 +7 -7
- data/spec/gemfiles/Gemfile.rails41 +7 -7
- data/spec/gemfiles/Gemfile.rails42 +7 -7
- data/spec/gemfiles/Gemfile.rails50 +7 -10
- data/spec/gemfiles/Gemfile.rails51 +7 -10
- data/spec/gemfiles/Gemfile.rails52 +7 -0
- data/spec/gemfiles/Gemfile.rails60 +7 -0
- data/spec/gemfiles/Gemfile.rails61 +7 -0
- data/spec/integration/active_record/active_record_spec.rb +41 -38
- data/spec/integration/mongoid/mongoid_spec.rb +39 -37
- data/spec/integration/shared/at_time.rb +53 -0
- data/spec/integration/shared/between_dates.rb +99 -0
- data/spec/integration/shared/between_times.rb +99 -82
- data/spec/integration/shared/by_calendar_month.rb +55 -55
- data/spec/integration/shared/by_cweek.rb +54 -54
- data/spec/integration/shared/by_day.rb +120 -96
- data/spec/integration/shared/by_direction.rb +126 -172
- data/spec/integration/shared/by_fortnight.rb +48 -48
- data/spec/integration/shared/by_month.rb +50 -50
- data/spec/integration/shared/by_quarter.rb +49 -49
- data/spec/integration/shared/by_week.rb +54 -54
- data/spec/integration/shared/by_weekend.rb +49 -49
- data/spec/integration/shared/by_year.rb +48 -48
- data/spec/integration/shared/index_scope_parameter.rb +111 -0
- data/spec/integration/shared/offset_parameter.rb +32 -32
- data/spec/integration/shared/order_parameter.rb +36 -36
- data/spec/integration/shared/relative.rb +174 -174
- data/spec/spec_helper.rb +33 -29
- data/spec/unit/kernel_date_spec.rb +113 -113
- data/spec/unit/kernel_time_spec.rb +57 -57
- data/spec/unit/normalization_spec.rb +384 -305
- data/tmp/.gitignore +1 -1
- metadata +33 -21
- data/spec/gemfiles/Gemfile.master +0 -6
- 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 '
|
6
|
-
gem 'pg', '~> 0.15'
|
7
|
-
gem '
|
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'
|
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'
|
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'
|
@@ -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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ActiveRecord::Base.
|
16
|
-
|
17
|
-
load File.dirname(__FILE__) + '/../../fixtures/active_record/
|
18
|
-
load File.dirname(__FILE__) + '/../../fixtures/
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
it_behaves_like '
|
25
|
-
it_behaves_like '
|
26
|
-
it_behaves_like '
|
27
|
-
it_behaves_like '
|
28
|
-
it_behaves_like '
|
29
|
-
it_behaves_like '
|
30
|
-
it_behaves_like 'by
|
31
|
-
it_behaves_like 'by
|
32
|
-
it_behaves_like 'by
|
33
|
-
it_behaves_like 'by
|
34
|
-
it_behaves_like 'by
|
35
|
-
it_behaves_like 'by
|
36
|
-
it_behaves_like 'by
|
37
|
-
it_behaves_like '
|
38
|
-
|
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 '
|
24
|
-
it_behaves_like '
|
25
|
-
it_behaves_like '
|
26
|
-
it_behaves_like '
|
27
|
-
it_behaves_like '
|
28
|
-
it_behaves_like 'by
|
29
|
-
it_behaves_like 'by
|
30
|
-
it_behaves_like 'by
|
31
|
-
it_behaves_like 'by
|
32
|
-
it_behaves_like 'by
|
33
|
-
it_behaves_like 'by
|
34
|
-
it_behaves_like 'by
|
35
|
-
it_behaves_like 'by
|
36
|
-
it_behaves_like '
|
37
|
-
|
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(
|
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(
|
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(
|
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(
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|