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.
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,172 +1,126 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for 'by direction' do
4
-
5
- describe '#before' do
6
-
7
- context 'point-in-time' do
8
- subject { Post.before(Date.parse '2014-01-05') }
9
- it { expect(subject.count).to eql(12) }
10
- end
11
-
12
- context 'timespan default' do
13
- subject { Event.before(Time.zone.parse '2014-01-05') }
14
- it { expect(subject.count).to eql(13) }
15
- end
16
-
17
- context 'timespan strict' do
18
- subject { Event.before('2014-01-05', strict: true) }
19
- it { expect(subject.count).to eql(13) }
20
- end
21
-
22
- context 'timespan not strict' do
23
- subject { Event.before('2014-01-05', strict: false) }
24
- it { expect(subject.count).to eql(13) }
25
- end
26
-
27
- context 'alternative field' do
28
- subject { Event.before('2014-01-05', field: 'created_at') }
29
- it { expect(subject.count).to eql(12) }
30
- end
31
-
32
- context 'with default scope' do
33
- subject { Appointment.before('2014-01-05', field: 'created_at') }
34
- it { expect(subject.count).to eql(4) }
35
- end
36
-
37
- context 'with scope as a query criteria' do
38
- subject { Post.before('2014-01-05', field: 'created_at', scope: Post.where(day_of_month: 5)) }
39
- it { expect(subject.count).to eql(1) }
40
- end
41
-
42
- context 'with scope as a proc' do
43
- subject { Post.before('2014-01-05', field: 'created_at', scope: ->{ where(day_of_month: 5) }) }
44
- it { expect(subject.count).to eql(1) }
45
- end
46
- end
47
-
48
- describe '#after' do
49
-
50
- context 'point-in-time' do
51
- subject { Post.after('2014-01-05') }
52
- it { expect(subject.count).to eql(10) }
53
- end
54
-
55
- context 'timespan default' do
56
- subject { Event.after(Date.parse '2014-01-05') }
57
- it { expect(subject.count).to eql(9) }
58
- end
59
-
60
- context 'timespan strict' do
61
- subject { Event.after('2014-01-05', strict: true) }
62
- it { expect(subject.count).to eql(9) }
63
- end
64
-
65
- context 'timespan not strict' do
66
- subject { Event.after('2014-01-05', strict: false) }
67
- it { expect(subject.count).to eql(9) }
68
- end
69
-
70
- context 'alternative field' do
71
- subject { Event.after('2014-01-05', field: 'created_at') }
72
- it { expect(subject.count).to eql(10) }
73
- end
74
-
75
- context 'with default scope' do
76
- subject { Appointment.after('2014-01-05', field: 'created_at') }
77
- it { expect(subject.count).to eql(3) }
78
- end
79
-
80
- context 'with scope as a query criteria' do
81
- subject { Post.after('2014-01-05', field: 'created_at', scope: Post.where(day_of_month: 5)) }
82
- it { expect(subject.count).to eql(1) }
83
- end
84
-
85
- context 'with scope as a proc' do
86
- subject { Post.after('2014-01-05', field: 'created_at', scope: ->{ where(day_of_month: 5) }) }
87
- it { expect(subject.count).to eql(1) }
88
- end
89
- end
90
-
91
- describe '#oldest and #newest' do
92
-
93
- context 'point-in-time' do
94
- it { expect(Post.newest.created_at).to eq Time.zone.parse('2014-04-15 17:00:00') }
95
- it { expect(Post.oldest.created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
96
- end
97
-
98
- context 'timespan' do
99
- it { expect(Event.newest.created_at).to eq Time.zone.parse('2014-04-15 17:00:00') }
100
- it { expect(Event.oldest.created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
101
- end
102
-
103
- context 'timespan strict' do
104
- it { expect(Event.newest(strict: true).created_at).to eq Time.zone.parse('2014-04-15 17:00:00') }
105
- it { expect(Event.oldest(strict: true).created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
106
- end
107
-
108
- context 'alternative field' do
109
- it { expect(Event.newest(field: 'created_at').created_at).to eq Time.zone.parse('2014-04-15 17:00:00') }
110
- it { expect(Event.oldest(field: 'created_at').created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
111
- end
112
-
113
- context 'with default scope' do
114
- it { expect(Appointment.newest(field: 'created_at').created_at).to eq Time.zone.parse('2014-04-01 17:00:00') }
115
- it { expect(Appointment.oldest(field: 'created_at').created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
116
- end
117
-
118
- context 'with scope as a query criteria' do
119
- it { expect(Post.newest(field: 'created_at', scope: Post.where(day_of_month: 5)).created_at).to eq Time.zone.parse('2014-01-05 17:00:00') }
120
- it { expect(Post.oldest(field: 'created_at', scope: Post.where(day_of_month: 5)).created_at).to eq Time.zone.parse('2013-12-05 17:00:00') }
121
- end
122
-
123
- context 'with scope as a proc' do
124
- it { expect(Post.newest(field: 'created_at', scope: ->{ where(day_of_month: 5) }).created_at).to eq Time.zone.parse('2014-01-05 17:00:00') }
125
- it { expect(Post.oldest(field: 'created_at', scope: ->{ where(day_of_month: 5) }).created_at).to eq Time.zone.parse('2013-12-05 17:00:00') }
126
- end
127
- end
128
-
129
- describe '#previous and #next' do
130
-
131
- context 'point-in-time' do
132
- subject { Post.where(created_at: Time.zone.parse('2014-01-10 17:00:00')).first }
133
- it{ expect(subject.previous.created_at).to eq Time.zone.parse('2014-01-05 17:00:00') }
134
- it{ expect(subject.next.created_at).to eq Time.zone.parse('2014-01-12 17:00:00') }
135
- end
136
-
137
- context 'timespan' do
138
- subject { Event.where(start_time: Time.zone.parse('2014-01-05 17:00:00')).first }
139
- it{ expect(subject.previous.start_time).to eq Time.zone.parse('2013-12-31 17:00:00') }
140
- it{ expect(subject.next.start_time).to eq Time.zone.parse('2014-01-07 17:00:00') }
141
- end
142
-
143
- context 'with default scope' do
144
- subject { Appointment.where(created_at: Time.zone.parse('2014-01-05 17:00:00')).first }
145
- it{ expect(subject.previous.created_at).to eq Time.zone.parse('2014-01-01 17:00:00') }
146
- it{ expect(subject.next.created_at).to eq Time.zone.parse('2014-02-01 17:00:00') }
147
- end
148
-
149
- context 'with scope as a query criteria' do
150
- subject { Post.where(created_at: Time.zone.parse('2014-01-05 17:00:00')).first }
151
- it{ expect(subject.previous({ scope: Post.where(day_of_month: 5) }).created_at).to eq Time.zone.parse('2013-12-05 17:00:00') }
152
- it{ expect(subject.next({ scope: Post.where(day_of_month: 1) }).created_at).to eq Time.zone.parse('2014-02-01 17:00:00') }
153
- end
154
-
155
- context 'with scope as a proc' do
156
- subject { Post.where(created_at: Time.zone.parse('2014-01-05 17:00:00')).first }
157
- it{ expect(subject.previous({ scope: Proc.new{ where(day_of_month: 5) } }).created_at).to eq Time.zone.parse('2013-12-05 17:00:00') }
158
- it{ expect(subject.previous({ scope: Proc.new{|record| where(day_of_month: record.day_of_month) } }).created_at).to eq Time.zone.parse('2013-12-05 17:00:00') }
159
- it{ expect(subject.next({ scope: ->{ where(day_of_month: 1) } }).created_at).to eq Time.zone.parse('2014-02-01 17:00:00') }
160
- it{ expect(subject.next({ scope: ->(record){ where(day_of_month: record.day_of_month - 4) } }).created_at).to eq Time.zone.parse('2014-02-01 17:00:00') }
161
- end
162
-
163
- context 'specify a field' do
164
- subject { Post.where(created_at: Time.zone.parse('2014-01-01 17:00:00')).first }
165
- it{ expect(subject.previous.created_at).to eq Time.zone.parse('2013-12-31 17:00:00') }
166
- it{ expect(subject.next.created_at).to eq Time.zone.parse('2014-01-05 17:00:00') }
167
- it{ expect(subject.previous(field: 'updated_at').created_at).to eq Time.zone.parse('2013-12-31 17:00:00') }
168
- it{ expect(subject.next(field: 'updated_at').created_at).to eq Time.zone.parse('2014-01-01 17:00:00') }
169
- end
170
-
171
- end
172
- end
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'by direction' do
4
+
5
+ describe '#before' do
6
+
7
+ context 'point-in-time' do
8
+ subject { Post.before(Date.parse '2014-01-05') }
9
+ it { expect(subject.count).to eql(12) }
10
+ end
11
+
12
+ context 'timespan default' do
13
+ subject { Event.before(Time.zone.parse '2014-01-05') }
14
+ it { expect(subject.count).to eql(13) }
15
+ end
16
+
17
+ context 'timespan strict' do
18
+ subject { Event.before('2014-01-05', strict: true) }
19
+ it { expect(subject.count).to eql(13) }
20
+ end
21
+
22
+ context 'timespan not strict' do
23
+ subject { Event.before('2014-01-05', strict: false) }
24
+ it { expect(subject.count).to eql(13) }
25
+ end
26
+
27
+ context 'alternative field' do
28
+ subject { Event.before('2014-01-05', field: 'created_at') }
29
+ it { expect(subject.count).to eql(20) }
30
+ end
31
+
32
+ context 'with default scope' do
33
+ subject { Appointment.before('2014-01-05', field: 'created_at') }
34
+ it { expect(subject.count).to eql(12) }
35
+ end
36
+ end
37
+
38
+ describe '#after' do
39
+
40
+ context 'point-in-time' do
41
+ subject { Post.after('2014-01-05') }
42
+ it { expect(subject.count).to eql(10) }
43
+ end
44
+
45
+ context 'timespan default' do
46
+ subject { Event.after(Date.parse '2014-01-05') }
47
+ it { expect(subject.count).to eql(17) }
48
+ end
49
+
50
+ context 'timespan strict' do
51
+ subject { Event.after('2014-01-05', strict: true) }
52
+ it { expect(subject.count).to eql(17) }
53
+ end
54
+
55
+ context 'timespan not strict' do
56
+ subject { Event.after('2014-01-05', strict: false) }
57
+ it { expect(subject.count).to eql(17) }
58
+ end
59
+
60
+ context 'alternative field' do
61
+ subject { Event.after('2014-01-05', field: 'created_at') }
62
+ it { expect(subject.count).to eql(10) }
63
+ end
64
+
65
+ context 'with default scope' do
66
+ subject { Appointment.after('2014-01-05', field: 'created_at') }
67
+ it { expect(subject.count).to eql(10) }
68
+ end
69
+ end
70
+
71
+ describe '#oldest and #newest' do
72
+ context 'point-in-time' do
73
+ it { expect(Post.newest.created_at).to eq Time.zone.parse('2014-04-15 17:00:00') }
74
+ it { expect(Post.oldest.created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
75
+ end
76
+
77
+ context 'timespan' do
78
+ it { expect(Event.newest.created_at).to eq Time.zone.parse('2011-01-01 00:00:00') }
79
+ it { expect(Event.oldest.created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
80
+ end
81
+
82
+ context 'timespan strict' do
83
+ it { expect(Event.newest(strict: true).created_at).to eq Time.zone.parse('2011-01-01 00:00:00') }
84
+ it { expect(Event.oldest(strict: true).created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
85
+ end
86
+
87
+ context 'alternative field' do
88
+ it { expect(Event.newest(field: 'created_at').created_at).to eq Time.zone.parse('2014-04-15 17:00:00') }
89
+ it { expect(Event.oldest(field: 'created_at').created_at).to eq Time.zone.parse('2011-01-01 00:00:00') }
90
+ end
91
+
92
+ context 'with default scope' do
93
+ it { expect(Appointment.newest(field: 'created_at').created_at).to eq Time.zone.parse('2014-04-15 17:00:00') }
94
+ it { expect(Appointment.oldest(field: 'created_at').created_at).to eq Time.zone.parse('2013-11-01 17:00:00') }
95
+ end
96
+ end
97
+
98
+ describe '#previous and #next' do
99
+
100
+ context 'point-in-time' do
101
+ subject { Post.where(created_at: Time.zone.parse('2014-01-10 17:00:00')).first }
102
+ it{ expect(subject.previous.created_at).to eq Time.zone.parse('2014-01-05 17:00:00') }
103
+ it{ expect(subject.next.created_at).to eq Time.zone.parse('2014-01-12 17:00:00') }
104
+ end
105
+
106
+ context 'timespan' do
107
+ subject { Event.where(start_time: Time.zone.parse('2014-01-05 17:00:00')).first }
108
+ it{ expect(subject.previous.start_time).to eq Time.zone.parse('2013-12-31 17:00:00') }
109
+ it{ expect(subject.next.start_time).to eq Time.zone.parse('2014-01-07 17:00:00') }
110
+ end
111
+
112
+ context 'with default scope' do
113
+ subject { Appointment.where(created_at: Time.zone.parse('2014-01-05 17:00:00')).first }
114
+ it{ expect(subject.previous.created_at).to eq Time.zone.parse('2014-01-01 17:00:00') }
115
+ it{ expect(subject.next.created_at).to eq Time.zone.parse('2014-01-10 17:00:00') }
116
+ end
117
+
118
+ context 'specify a field' do
119
+ subject { Post.where(created_at: Time.zone.parse('2014-01-01 17:00:00')).first }
120
+ it{ expect(subject.previous.created_at).to eq Time.zone.parse('2013-12-31 17:00:00') }
121
+ it{ expect(subject.next.created_at).to eq Time.zone.parse('2014-01-05 17:00:00') }
122
+ it{ expect(subject.previous(field: 'updated_at').created_at).to eq Time.zone.parse('2013-12-31 17:00:00') }
123
+ it{ expect(subject.next(field: 'updated_at').created_at).to eq Time.zone.parse('2014-01-01 17:00:00') }
124
+ end
125
+ end
126
+ end
@@ -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
- 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
+ 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
- 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
+ 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
- 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
+ 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