by_star 2.2.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +5 -5
- data/.travis.yml +61 -35
- data/CHANGELOG.md +44 -35
- data/Gemfile +18 -25
- data/MIT-LICENSE +20 -20
- data/README.md +577 -540
- data/Rakefile +18 -18
- data/UPGRADING +6 -12
- data/by_star.gemspec +34 -32
- data/cleaner.rb +24 -24
- data/lib/by_star.rb +17 -16
- data/lib/by_star/base.rb +68 -70
- data/lib/by_star/between.rb +156 -120
- data/lib/by_star/directional.rb +37 -33
- data/lib/by_star/kernel/date.rb +50 -19
- data/lib/by_star/kernel/time.rb +41 -41
- data/lib/by_star/normalization.rb +127 -118
- data/lib/by_star/orm/active_record/by_star.rb +61 -69
- data/lib/by_star/orm/mongoid/by_star.rb +76 -73
- data/lib/by_star/orm/mongoid/reorder.rb +23 -0
- data/lib/by_star/version.rb +3 -3
- data/spec/database.yml +15 -15
- data/spec/fixtures/active_record/models.rb +12 -10
- data/spec/fixtures/active_record/schema.rb +19 -19
- data/spec/fixtures/mongoid/models.rb +31 -29
- data/spec/fixtures/shared/seeds.rb +26 -26
- data/spec/gemfiles/Gemfile.master +6 -0
- data/spec/gemfiles/Gemfile.rails40 +7 -0
- data/spec/gemfiles/Gemfile.rails41 +7 -0
- data/spec/gemfiles/Gemfile.rails42 +7 -0
- data/spec/gemfiles/Gemfile.rails50 +10 -0
- data/spec/gemfiles/Gemfile.rails51 +10 -0
- data/spec/integration/active_record/active_record_spec.rb +38 -53
- data/spec/integration/mongoid/mongoid_spec.rb +37 -46
- data/spec/integration/shared/between_times.rb +82 -0
- data/spec/integration/shared/by_calendar_month.rb +55 -55
- data/spec/integration/shared/by_cweek.rb +54 -0
- data/spec/integration/shared/by_day.rb +96 -108
- data/spec/integration/shared/by_direction.rb +172 -153
- 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/offset_parameter.rb +32 -31
- data/spec/integration/shared/order_parameter.rb +36 -0
- data/spec/integration/shared/relative.rb +174 -174
- data/spec/integration/shared/scope_parameter.rb +73 -72
- data/spec/spec_helper.rb +29 -29
- data/spec/unit/kernel_date_spec.rb +113 -60
- data/spec/unit/kernel_time_spec.rb +57 -57
- data/spec/unit/normalization_spec.rb +305 -255
- metadata +61 -62
@@ -1,48 +1,48 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'by fortnight' do
|
4
|
-
|
5
|
-
describe '#by_fortnight' do
|
6
|
-
|
7
|
-
context 'point-in-time' do
|
8
|
-
subject { Post.by_fortnight('2014-01-01') }
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_fortnight(0) }
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_fortnight(Date.parse('2014-01-01'), strict: true) }
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with :year option' do
|
23
|
-
|
24
|
-
context 'point-in-time' do
|
25
|
-
subject { Post.by_fortnight(26, year: 2013) }
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_fortnight(26, year: 2013) }
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_fortnight(26, year: 2013, strict: true) }
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise an error when given an invalid argument' do
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should be able to use an alternative field' do
|
45
|
-
Event.by_fortnight(:
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'by fortnight' do
|
4
|
+
|
5
|
+
describe '#by_fortnight' do
|
6
|
+
|
7
|
+
context 'point-in-time' do
|
8
|
+
subject { Post.by_fortnight('2014-01-01') }
|
9
|
+
it { expect(subject.count).to eql(5) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'timespan' do
|
13
|
+
subject { Event.by_fortnight(0) }
|
14
|
+
it { expect(subject.count).to eql(7) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'timespan strict' do
|
18
|
+
subject { Event.by_fortnight(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_fortnight(26, year: 2013) }
|
26
|
+
it { expect(subject.count).to eql(6) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'timespan' do
|
30
|
+
subject { Event.by_fortnight(26, year: 2013) }
|
31
|
+
it { expect(subject.count).to eql(7) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'timespan strict' do
|
35
|
+
subject { Event.by_fortnight(26, year: 2013, strict: true) }
|
36
|
+
it { expect(subject.count).to eql(1) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise an error when given an invalid argument' do
|
41
|
+
expect { Post.by_fortnight(27) }.to raise_error(ByStar::ParseError, 'Fortnight number must be between 0 and 26')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should be able to use an alternative field' do
|
45
|
+
expect(Event.by_fortnight(field: 'end_time').count).to eq 5
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'by month' do
|
4
|
-
|
5
|
-
describe '#by_month' do
|
6
|
-
|
7
|
-
context 'point-in-time' do
|
8
|
-
subject { Post.by_month('Feb') }
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_month(1) }
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_month(Date.parse('2014-02-01'), strict: true) }
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with :year option' do
|
23
|
-
|
24
|
-
context 'point-in-time' do
|
25
|
-
subject { Post.by_month(12, year: 2013) }
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_month('December', year: 2013) }
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_month('Dec', year: 2013, strict: true) }
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise an error when given an invalid argument' do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should be able to use an alternative field' do
|
47
|
-
Event.by_month(:
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'by month' do
|
4
|
+
|
5
|
+
describe '#by_month' do
|
6
|
+
|
7
|
+
context 'point-in-time' do
|
8
|
+
subject { Post.by_month('Feb') }
|
9
|
+
it { expect(subject.count).to eql(2) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'timespan' do
|
13
|
+
subject { Event.by_month(1) }
|
14
|
+
it { expect(subject.count).to eql(9) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'timespan strict' do
|
18
|
+
subject { Event.by_month(Date.parse('2014-02-01'), strict: true) }
|
19
|
+
it { expect(subject.count).to eql(1) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with :year option' do
|
23
|
+
|
24
|
+
context 'point-in-time' do
|
25
|
+
subject { Post.by_month(12, year: 2013) }
|
26
|
+
it { expect(subject.count).to eql(8) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'timespan' do
|
30
|
+
subject { Event.by_month('December', year: 2013) }
|
31
|
+
it { expect(subject.count).to eql(12) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'timespan strict' do
|
35
|
+
subject { Event.by_month('Dec', year: 2013, strict: true) }
|
36
|
+
it { expect(subject.count).to eql(4) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise an error when given an invalid argument' do
|
41
|
+
expect{ Post.by_month(0) }.to raise_error(ByStar::ParseError, 'Month must be a number between 1 and 12 or a month name')
|
42
|
+
expect{ Post.by_month(13) }.to raise_error(ByStar::ParseError, 'Month must be a number between 1 and 12 or a month name')
|
43
|
+
expect{ Post.by_month('foobar') }.to raise_error(ByStar::ParseError, 'Month must be a number between 1 and 12 or a month name')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should be able to use an alternative field' do
|
47
|
+
expect(Event.by_month(field: 'end_time').count).to eq 8
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for 'by quarter' do
|
4
|
-
|
5
|
-
describe '#by_quarter' do
|
6
|
-
|
7
|
-
context 'point-in-time' do
|
8
|
-
subject { Post.by_quarter(2) }
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_quarter(1) }
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_quarter(Date.parse('2014-02-01'), strict: true) }
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with :year option' do
|
23
|
-
|
24
|
-
context 'point-in-time' do
|
25
|
-
subject { Post.by_quarter(4, year: 2013) }
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_quarter(4, year: 2013) }
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_quarter(4, year: 2013, strict: true) }
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise an error when given an invalid argument' do
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should be able to use an alternative field' do
|
46
|
-
Event.by_quarter(1, :
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for 'by quarter' do
|
4
|
+
|
5
|
+
describe '#by_quarter' do
|
6
|
+
|
7
|
+
context 'point-in-time' do
|
8
|
+
subject { Post.by_quarter(2) }
|
9
|
+
it { expect(subject.count).to eql(2) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'timespan' do
|
13
|
+
subject { Event.by_quarter(1) }
|
14
|
+
it { expect(subject.count).to eql(13) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'timespan strict' do
|
18
|
+
subject { Event.by_quarter(Date.parse('2014-02-01'), strict: true) }
|
19
|
+
it { expect(subject.count).to eql(7) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with :year option' do
|
23
|
+
|
24
|
+
context 'point-in-time' do
|
25
|
+
subject { Post.by_quarter(4, year: 2013) }
|
26
|
+
it { expect(subject.count).to eql(10) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'timespan' do
|
30
|
+
subject { Event.by_quarter(4, year: 2013) }
|
31
|
+
it { expect(subject.count).to eql(13) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'timespan strict' do
|
35
|
+
subject { Event.by_quarter(4, year: 2013, strict: true) }
|
36
|
+
it { expect(subject.count).to eql(8) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise an error when given an invalid argument' do
|
41
|
+
expect{ Post.by_quarter(0) }.to raise_error(ByStar::ParseError, 'Quarter number must be between 1 and 4')
|
42
|
+
expect{ Post.by_quarter(5) }.to raise_error(ByStar::ParseError, 'Quarter number must be between 1 and 4')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should be able to use an alternative field' do
|
46
|
+
expect(Event.by_quarter(1, field: 'end_time').count).to eq 12
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -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
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_week(0) }
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_week(Date.parse('2014-01-01'), strict: true) }
|
19
|
-
|
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
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_week(52, year: 2013) }
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_week(52, year: 2013, strict: true) }
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise an error when given an invalid argument' do
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should be able to use an alternative field' do
|
46
|
-
Event.by_week(:
|
47
|
-
end
|
48
|
-
|
49
|
-
context ':start_day option' do
|
50
|
-
subject { Post.by_week('2014-01-02', :
|
51
|
-
|
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
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'timespan' do
|
13
|
-
subject { Event.by_weekend(0) }
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'timespan strict' do
|
18
|
-
subject { Event.by_weekend(Date.parse('2014-01-01'), strict: true) }
|
19
|
-
|
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
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'timespan' do
|
30
|
-
subject { Event.by_weekend(52, year: 2013) }
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'timespan strict' do
|
35
|
-
subject { Event.by_weekend(52, year: 2013, strict: true) }
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise an error when given an invalid argument' do
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should be able to use an alternative field' do
|
46
|
-
Event.by_weekend(:
|
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
|