by_star 3.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,54 +1,54 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'by week' do
|
4
|
-
|
5
|
-
describe '#by_week' do
|
6
|
-
|
7
|
-
context 'point-in-time' do
|
8
|
-
subject { Post.by_week('2014-01-02') }
|
9
|
-
it { expect(subject.count).to eql(4) }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_week(0) }
|
14
|
-
it { expect(subject.count).to eql(7) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_week(Date.parse('2014-01-01'), strict: true) }
|
19
|
-
it { expect(subject.count).to eql(0) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with :year option' do
|
23
|
-
|
24
|
-
context 'point-in-time' do
|
25
|
-
subject { Post.by_week(52, year: 2013) }
|
26
|
-
it { expect(subject.count).to eql(4) }
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_week(52, year: 2013) }
|
31
|
-
it { expect(subject.count).to eql(7) }
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_week(52, year: 2013, strict: true) }
|
36
|
-
it { expect(subject.count).to eql(0) }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise an error when given an invalid argument' do
|
41
|
-
expect { Post.by_week(-1) }.to raise_error(ByStar::ParseError, 'Week number must be between 0 and 52')
|
42
|
-
expect { Post.by_week(53) }.to raise_error(ByStar::ParseError, 'Week number must be between 0 and 52')
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should be able to use an alternative field' do
|
46
|
-
expect(Event.by_week(field: 'end_time').count).to eq 3
|
47
|
-
end
|
48
|
-
|
49
|
-
context ':start_day option' do
|
50
|
-
subject { Post.by_week('2014-01-02', start_day: :thursday) }
|
51
|
-
it { expect(subject.count).to eql(1) }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'by week' do
|
4
|
+
|
5
|
+
describe '#by_week' do
|
6
|
+
|
7
|
+
context 'point-in-time' do
|
8
|
+
subject { Post.by_week('2014-01-02') }
|
9
|
+
it { expect(subject.count).to eql(4) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'timespan' do
|
13
|
+
subject { Event.by_week(0) }
|
14
|
+
it { expect(subject.count).to eql(7) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'timespan strict' do
|
18
|
+
subject { Event.by_week(Date.parse('2014-01-01'), strict: true) }
|
19
|
+
it { expect(subject.count).to eql(0) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with :year option' do
|
23
|
+
|
24
|
+
context 'point-in-time' do
|
25
|
+
subject { Post.by_week(52, year: 2013) }
|
26
|
+
it { expect(subject.count).to eql(4) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'timespan' do
|
30
|
+
subject { Event.by_week(52, year: 2013) }
|
31
|
+
it { expect(subject.count).to eql(7) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'timespan strict' do
|
35
|
+
subject { Event.by_week(52, year: 2013, strict: true) }
|
36
|
+
it { expect(subject.count).to eql(0) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise an error when given an invalid argument' do
|
41
|
+
expect { Post.by_week(-1) }.to raise_error(ByStar::ParseError, 'Week number must be between 0 and 52')
|
42
|
+
expect { Post.by_week(53) }.to raise_error(ByStar::ParseError, 'Week number must be between 0 and 52')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should be able to use an alternative field' do
|
46
|
+
expect(Event.by_week(field: 'end_time').count).to eq 3
|
47
|
+
end
|
48
|
+
|
49
|
+
context ':start_day option' do
|
50
|
+
subject { Post.by_week('2014-01-02', start_day: :thursday) }
|
51
|
+
it { expect(subject.count).to eql(1) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'by weekend' do
|
4
|
-
|
5
|
-
describe '#by_weekend' do
|
6
|
-
|
7
|
-
context 'point-in-time' do
|
8
|
-
subject { Post.by_weekend('2014-01-01') }
|
9
|
-
it { expect(subject.count).to eql(1) }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_weekend(0) }
|
14
|
-
it { expect(subject.count).to eql(5) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_weekend(Date.parse('2014-01-01'), strict: true) }
|
19
|
-
it { expect(subject.count).to eql(0) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with :year option' do
|
23
|
-
|
24
|
-
context 'point-in-time' do
|
25
|
-
subject { Post.by_weekend(52, year: 2013) }
|
26
|
-
it { expect(subject.count).to eql(1) }
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_weekend(52, year: 2013) }
|
31
|
-
it { expect(subject.count).to eql(5) }
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_weekend(52, year: 2013, strict: true) }
|
36
|
-
it { expect(subject.count).to eql(0) }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise an error when given an invalid argument' do
|
41
|
-
expect { Post.by_weekend(-1) }.to raise_error(ByStar::ParseError, 'Week number must be between 0 and 52')
|
42
|
-
expect { Post.by_weekend(53) }.to raise_error(ByStar::ParseError, 'Week number must be between 0 and 52')
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should be able to use an alternative field' do
|
46
|
-
expect(Event.by_weekend(field: 'end_time').count).to eq 1
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'by weekend' do
|
4
|
+
|
5
|
+
describe '#by_weekend' do
|
6
|
+
|
7
|
+
context 'point-in-time' do
|
8
|
+
subject { Post.by_weekend('2014-01-01') }
|
9
|
+
it { expect(subject.count).to eql(1) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'timespan' do
|
13
|
+
subject { Event.by_weekend(0) }
|
14
|
+
it { expect(subject.count).to eql(5) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'timespan strict' do
|
18
|
+
subject { Event.by_weekend(Date.parse('2014-01-01'), strict: true) }
|
19
|
+
it { expect(subject.count).to eql(0) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with :year option' do
|
23
|
+
|
24
|
+
context 'point-in-time' do
|
25
|
+
subject { Post.by_weekend(52, year: 2013) }
|
26
|
+
it { expect(subject.count).to eql(1) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'timespan' do
|
30
|
+
subject { Event.by_weekend(52, year: 2013) }
|
31
|
+
it { expect(subject.count).to eql(5) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'timespan strict' do
|
35
|
+
subject { Event.by_weekend(52, year: 2013, strict: true) }
|
36
|
+
it { expect(subject.count).to eql(0) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise an error when given an invalid argument' do
|
41
|
+
expect { Post.by_weekend(-1) }.to raise_error(ByStar::ParseError, 'Week number must be between 0 and 52')
|
42
|
+
expect { Post.by_weekend(53) }.to raise_error(ByStar::ParseError, 'Week number must be between 0 and 52')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should be able to use an alternative field' do
|
46
|
+
expect(Event.by_weekend(field: 'end_time').count).to eq 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'by year' do
|
4
|
-
|
5
|
-
describe '#by_year' do
|
6
|
-
|
7
|
-
context 'point-in-time' do
|
8
|
-
subject { Post.by_year('2014') }
|
9
|
-
it { expect(subject.count).to eql(12) }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_year(13) }
|
14
|
-
it { expect(subject.count).to eql(13) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_year(Date.parse('2014-02-01'), strict: true) }
|
19
|
-
it { expect(subject.count).to eql(9) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'integer' do
|
23
|
-
|
24
|
-
context 'point-in-time' do
|
25
|
-
subject { Post.by_year(2013) }
|
26
|
-
it { expect(subject.count).to eql(10) }
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_year(2014) }
|
31
|
-
it { expect(subject.count).to eql(14) }
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_year(2013, strict: true) }
|
36
|
-
it { expect(subject.count).to eql(8) }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should be able to use an alternative field' do
|
41
|
-
expect(Event.by_year(field: 'end_time').count).to eq 14
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'can use a 2-digit year' do
|
45
|
-
expect(Post.by_year(13).count).to eq 10
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'by year' do
|
4
|
+
|
5
|
+
describe '#by_year' do
|
6
|
+
|
7
|
+
context 'point-in-time' do
|
8
|
+
subject { Post.by_year('2014') }
|
9
|
+
it { expect(subject.count).to eql(12) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'timespan' do
|
13
|
+
subject { Event.by_year(13) }
|
14
|
+
it { expect(subject.count).to eql(13) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'timespan strict' do
|
18
|
+
subject { Event.by_year(Date.parse('2014-02-01'), strict: true) }
|
19
|
+
it { expect(subject.count).to eql(9) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'integer' do
|
23
|
+
|
24
|
+
context 'point-in-time' do
|
25
|
+
subject { Post.by_year(2013) }
|
26
|
+
it { expect(subject.count).to eql(10) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'timespan' do
|
30
|
+
subject { Event.by_year(2014) }
|
31
|
+
it { expect(subject.count).to eql(14) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'timespan strict' do
|
35
|
+
subject { Event.by_year(2013, strict: true) }
|
36
|
+
it { expect(subject.count).to eql(8) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should be able to use an alternative field' do
|
41
|
+
expect(Event.by_year(field: 'end_time').count).to eq 14
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'can use a 2-digit year' do
|
45
|
+
expect(Post.by_year(13).count).to eq 10
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'index_scope parameter' do
|
4
|
+
|
5
|
+
describe ':scope' do
|
6
|
+
|
7
|
+
it 'should memoize the scope variable' do
|
8
|
+
expect(Event.instance_variable_get(:@by_star_index_scope)).to be_nil
|
9
|
+
expect(Post.instance_variable_get(:@by_star_index_scope)).to be_nil
|
10
|
+
expect(Appointment.instance_variable_get(:@by_star_index_scope)).to be_a Proc
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'between_times with index_scope' do
|
14
|
+
|
15
|
+
context 'nil' do
|
16
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: nil) }
|
17
|
+
it { expect(subject.count).to eql(16) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'false' do
|
21
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: false) }
|
22
|
+
it { expect(subject.count).to eql(16) }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'Time' do
|
26
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: Time.zone.parse('2013-11-30 17:00:00')) }
|
27
|
+
it { expect(subject.count).to eql(14) }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'DateTime' do
|
31
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: Time.zone.parse('2013-11-30 17:00:00').to_datetime) }
|
32
|
+
it { expect(subject.count).to eql(14) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'Date' do
|
36
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: Date.parse('2013-11-30')) }
|
37
|
+
it { expect(subject.count).to eql(14) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'ActiveSupport::Duration' do
|
41
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: 3.hours) }
|
42
|
+
it { expect(subject.count).to eql(13) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'Numeric' do
|
46
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: 3600) }
|
47
|
+
it { expect(subject.count).to eql(13) }
|
48
|
+
end
|
49
|
+
|
50
|
+
context ':beginning_of_day' do
|
51
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: :beginning_of_day) }
|
52
|
+
it { expect(subject.count).to eql(13) }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'unsupported type' do
|
56
|
+
subject { Event.between_times(Date.parse('2013-12-01'), Date.parse('2014-01-31'), index_scope: Integer) }
|
57
|
+
it { expect{subject.count}.to raise_error(RuntimeError) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'at_time with index_scope' do
|
62
|
+
|
63
|
+
context 'nil' do
|
64
|
+
subject { Event.at_time(Time.zone.parse('2013-12-01 14:00'), index_scope: nil) }
|
65
|
+
it { expect(subject.count).to eql(3) }
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'false' do
|
69
|
+
subject { Event.at_time(Time.zone.parse('2013-12-01 14:00'), index_scope: false) }
|
70
|
+
it { expect(subject.count).to eql(3) }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'Time' do
|
74
|
+
subject { Event.at_time(Time.zone.parse('2013-12-01 14:00'), index_scope: Time.zone.parse('2013-10-30 17:00:00')) }
|
75
|
+
it { expect(subject.count).to eql(3) }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'DateTime' do
|
79
|
+
subject { Event.at_time(Time.zone.parse('2013-12-01 14:00'), index_scope: Time.zone.parse('2013-11-30 17:00:00').to_datetime) }
|
80
|
+
it { expect(subject.count).to eql(1) }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'Date' do
|
84
|
+
subject { Event.at_time(Time.zone.parse('2013-12-01 14:00'), index_scope: Date.parse('2013-11-30')) }
|
85
|
+
it { expect(subject.count).to eql(1) }
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'ActiveSupport::Duration' do
|
89
|
+
subject { Event.at_time(Time.zone.parse('2013-12-01 14:00'), index_scope: 100.hours) }
|
90
|
+
it { expect(subject.count).to eql(1) }
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'Numeric' do
|
94
|
+
subject { Event.at_time(Time.zone.parse('2013-12-01 14:00'), index_scope: 60 * 60 * 1000) }
|
95
|
+
it { expect(subject.count).to eql(3) }
|
96
|
+
end
|
97
|
+
|
98
|
+
context ':beginning_of_day' do
|
99
|
+
let!(:custom_event){ t = Time.zone.parse('2013-12-30 17:00'); Event.create!(start_time: t - 1.hour, end_time: t + 1.hour) }
|
100
|
+
subject { Event.at_time(Time.zone.parse('2013-12-30 16:00'), index_scope: :beginning_of_day) }
|
101
|
+
it { expect(subject.count).to eql(1) }
|
102
|
+
after { custom_event.delete }
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'unsupported type' do
|
106
|
+
subject { Event.at_time(Time.zone.parse('2013-12-01 14:00'), index_scope: Integer) }
|
107
|
+
it { expect{subject.count}.to raise_error(RuntimeError) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'offset parameter' do
|
4
|
-
|
5
|
-
describe ':offset' do
|
6
|
-
|
7
|
-
it 'should memoize the offset variable' do
|
8
|
-
expect(Event.instance_variable_get(:@by_star_offset)).to eq 3.hours
|
9
|
-
expect(Post.instance_variable_get(:@by_star_offset)).to be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'between_times with default offset' do
|
13
|
-
subject { Event.between_times(Time.zone.parse('2014-01-01'), Time.zone.parse('2014-01-10')) }
|
14
|
-
it { expect(subject.count).to eql(7) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'between_times with offset override' do
|
18
|
-
subject { Event.between_times(Time.zone.parse('2014-01-01')..Time.zone.parse('2014-01-10'), offset: 16.hours) }
|
19
|
-
it { expect(subject.count).to eql(7) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'by_day with default offset' do
|
23
|
-
subject { Event.by_day(Time.zone.parse('2014-01-01')) }
|
24
|
-
it { expect(subject.count).to eql(5) }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'by_day with offset override' do
|
28
|
-
subject { Event.by_day(Time.zone.parse('2014-12-26'), field: :start_time, offset: 5.hours) }
|
29
|
-
it { expect(subject.count).to eql(0) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'offset parameter' do
|
4
|
+
|
5
|
+
describe ':offset' do
|
6
|
+
|
7
|
+
it 'should memoize the offset variable' do
|
8
|
+
expect(Event.instance_variable_get(:@by_star_offset)).to eq 3.hours
|
9
|
+
expect(Post.instance_variable_get(:@by_star_offset)).to be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'between_times with default offset' do
|
13
|
+
subject { Event.between_times(Time.zone.parse('2014-01-01'), Time.zone.parse('2014-01-10')) }
|
14
|
+
it { expect(subject.count).to eql(7) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'between_times with offset override' do
|
18
|
+
subject { Event.between_times(Time.zone.parse('2014-01-01')..Time.zone.parse('2014-01-10'), offset: 16.hours) }
|
19
|
+
it { expect(subject.count).to eql(7) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'by_day with default offset' do
|
23
|
+
subject { Event.by_day(Time.zone.parse('2014-01-01')) }
|
24
|
+
it { expect(subject.count).to eql(5) }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'by_day with offset override' do
|
28
|
+
subject { Event.by_day(Time.zone.parse('2014-12-26'), field: :start_time, offset: 5.hours) }
|
29
|
+
it { expect(subject.count).to eql(0) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'order parameter' do
|
4
|
-
|
5
|
-
describe ':order' do
|
6
|
-
|
7
|
-
if testing_active_record?
|
8
|
-
|
9
|
-
it 'should be able to order the result set asc' do
|
10
|
-
scope = Post.by_year(Time.zone.now.year, order: 'created_at ASC')
|
11
|
-
expect(scope.order_values).to eq ['created_at ASC']
|
12
|
-
expect(scope.first.created_at).to eq Time.zone.parse('2014-01-01 17:00:00')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should be able to order the result set desc' do
|
16
|
-
scope = Post.by_year(Time.zone.now.year, order: 'created_at DESC')
|
17
|
-
expect(scope.order_values).to eq ['created_at DESC']
|
18
|
-
expect(scope.first.created_at).to eq Time.zone.parse('2014-04-15 17:00:00')
|
19
|
-
end
|
20
|
-
|
21
|
-
elsif testing_mongoid?
|
22
|
-
|
23
|
-
it 'should be able to order the result set asc' do
|
24
|
-
scope = Post.by_year(Time.zone.now.year, order: {created_at: :asc})
|
25
|
-
expect(scope.options[:sort]).to eq({'created_at' => 1})
|
26
|
-
expect(scope.first.created_at).to eq Time.zone.parse('2014-01-01 17:00:00')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should be able to order the result set desc' do
|
30
|
-
scope = Post.by_year(Time.zone.now.year, order: {created_at: :desc})
|
31
|
-
expect(scope.options[:sort]).to eq({'created_at' => -1})
|
32
|
-
expect(scope.first.created_at).to eq Time.zone.parse('2014-04-15 17:00:00')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'order parameter' do
|
4
|
+
|
5
|
+
describe ':order' do
|
6
|
+
|
7
|
+
if testing_active_record?
|
8
|
+
|
9
|
+
it 'should be able to order the result set asc' do
|
10
|
+
scope = Post.by_year(Time.zone.now.year, order: 'created_at ASC')
|
11
|
+
expect(scope.order_values).to eq ['created_at ASC']
|
12
|
+
expect(scope.first.created_at).to eq Time.zone.parse('2014-01-01 17:00:00')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should be able to order the result set desc' do
|
16
|
+
scope = Post.by_year(Time.zone.now.year, order: 'created_at DESC')
|
17
|
+
expect(scope.order_values).to eq ['created_at DESC']
|
18
|
+
expect(scope.first.created_at).to eq Time.zone.parse('2014-04-15 17:00:00')
|
19
|
+
end
|
20
|
+
|
21
|
+
elsif testing_mongoid?
|
22
|
+
|
23
|
+
it 'should be able to order the result set asc' do
|
24
|
+
scope = Post.by_year(Time.zone.now.year, order: {created_at: :asc})
|
25
|
+
expect(scope.options[:sort]).to eq({'created_at' => 1})
|
26
|
+
expect(scope.first.created_at).to eq Time.zone.parse('2014-01-01 17:00:00')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should be able to order the result set desc' do
|
30
|
+
scope = Post.by_year(Time.zone.now.year, order: {created_at: :desc})
|
31
|
+
expect(scope.options[:sort]).to eq({'created_at' => -1})
|
32
|
+
expect(scope.first.created_at).to eq Time.zone.parse('2014-04-15 17:00:00')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|