acts_as_span 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -3
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +0 -3
- data/README.rdoc +4 -16
- data/Rakefile +5 -1
- data/acts_as_span.gemspec +21 -5
- data/lib/acts_as_span.rb +55 -98
- data/lib/acts_as_span/no_overlap_validator.rb +51 -0
- data/lib/acts_as_span/span_instance.rb +17 -33
- data/lib/acts_as_span/span_instance/status.rb +12 -27
- data/lib/acts_as_span/span_instance/validations.rb +5 -53
- data/lib/acts_as_span/span_klass.rb +11 -19
- data/lib/acts_as_span/span_klass/status.rb +33 -12
- data/lib/acts_as_span/version.rb +2 -2
- data/lib/acts_as_span/within_parent_date_span_validator.rb +42 -0
- data/spec/lib/acts_as_span_spec.rb +18 -36
- data/spec/lib/delegation_spec.rb +45 -78
- data/spec/lib/no_overlap_validator_spec.rb +96 -0
- data/spec/lib/span_instance/named_scopes_on_spec.rb +193 -193
- data/spec/lib/span_instance/named_scopes_spec.rb +193 -191
- data/spec/lib/span_instance/overlap_spec.rb +193 -253
- data/spec/lib/span_instance/status_spec.rb +22 -35
- data/spec/lib/span_instance/validations_spec.rb +8 -44
- data/spec/lib/span_instance_spec.rb +5 -30
- data/spec/lib/within_parent_date_span_validator_spec.rb +115 -0
- data/spec/spec_helper.rb +19 -6
- data/spec/spec_models.rb +69 -0
- metadata +158 -58
- data/Gemfile.lock +0 -47
- data/lib/acts_as_span/span_instance/overlap.rb +0 -17
- data/lib/acts_as_span/span_klass/overlap.rb +0 -21
- data/spec/lib/negative_spec.rb +0 -30
- data/spec/spec.opts +0 -1
@@ -1,302 +1,304 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "a basic model using acts_as_span" do
|
4
|
-
before(:all) do
|
5
|
-
build_model :span_model do
|
6
|
-
string :description
|
7
|
-
date :start_date
|
8
|
-
date :end_date
|
9
|
-
|
10
|
-
acts_as_span
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
3
|
+
RSpec.describe "a basic model using acts_as_span" do
|
14
4
|
context "named_scopes and current?, expired?, and future?" do
|
15
5
|
# -2 -1 T +1 +2 C F E
|
16
6
|
# A |---| E
|
17
|
-
# B |-------| C
|
18
|
-
# C |--------------| C
|
19
|
-
# D | C
|
20
|
-
# E |------| C
|
21
|
-
# F |--| F
|
22
|
-
# G |-> C
|
23
|
-
# H |-> C
|
24
|
-
# I |-> F
|
7
|
+
# B |-------| C
|
8
|
+
# C |--------------| C
|
9
|
+
# D | C
|
10
|
+
# E |------| C
|
11
|
+
# F |--| F
|
12
|
+
# G |-> C
|
13
|
+
# H |-> C
|
14
|
+
# I |-> F
|
25
15
|
# J <-| E
|
26
|
-
# K <-| C
|
27
|
-
# L <-| C
|
28
|
-
# M <-> C
|
16
|
+
# K <-| C
|
17
|
+
# L <-| C
|
18
|
+
# M <-> C
|
19
|
+
let(:span_a) {[ - 2.days, - 1.day ]}
|
20
|
+
let(:span_b) {[ - 2.days, 0.days ]}
|
21
|
+
let(:span_c) {[ - 2.days, 2.days ]}
|
22
|
+
let(:span_d) {[ 0.days, 0.days ]}
|
23
|
+
let(:span_e) {[ 0.days, 2.days ]}
|
24
|
+
let(:span_f) {[ 1.day, 2.days ]}
|
25
|
+
let(:span_g) {[ - 2.days, nil ]}
|
26
|
+
let(:span_h) {[ 0.days, nil ]}
|
27
|
+
let(:span_i) {[ 1.day, nil ]}
|
28
|
+
let(:span_j) {[ nil, - 1.day ]}
|
29
|
+
let(:span_k) {[ nil, 0.days ]}
|
30
|
+
let(:span_l) {[ nil, 2.days ]}
|
31
|
+
let(:span_m) {[ nil, nil ]}
|
32
|
+
|
33
|
+
let(:query_date) { Date.current }
|
34
|
+
|
35
|
+
let!(:span_model) do
|
36
|
+
current_start_date = start_date.nil? ? nil : query_date + start_date
|
37
|
+
current_end_date = end_date.nil? ? nil : query_date + end_date
|
38
|
+
|
39
|
+
SpanModel.create!(
|
40
|
+
start_date: current_start_date,
|
41
|
+
end_date: current_end_date)
|
42
|
+
end
|
43
|
+
|
29
44
|
context "A) start_date < today & end_date < today" do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
45
|
+
let(:start_date) { span_a[0] }
|
46
|
+
let(:end_date) { span_a[1] }
|
47
|
+
|
34
48
|
it "should NOT be included in #current" do
|
35
|
-
SpanModel.current.
|
36
|
-
|
49
|
+
expect(SpanModel.current).not_to include(span_model)
|
50
|
+
expect(span_model.current?).to be_falsey
|
37
51
|
end
|
38
|
-
|
52
|
+
|
39
53
|
it "should NOT be included in #future" do
|
40
|
-
SpanModel.future.
|
41
|
-
|
54
|
+
expect(SpanModel.future).not_to include(span_model)
|
55
|
+
expect(span_model.future?).to be_falsey
|
42
56
|
end
|
43
|
-
|
57
|
+
|
44
58
|
it "should be included in #expired" do
|
45
|
-
SpanModel.expired.
|
46
|
-
|
59
|
+
expect(SpanModel.expired).to include(span_model)
|
60
|
+
expect(span_model.expired?).to be_truthy
|
47
61
|
end
|
48
62
|
end
|
49
|
-
|
63
|
+
|
50
64
|
context "B) start_date < today & end_date == today" do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
65
|
+
let(:start_date) { span_b[0] }
|
66
|
+
let(:end_date) { span_b[1] }
|
67
|
+
|
55
68
|
it "should be included in #current" do
|
56
|
-
SpanModel.current.
|
57
|
-
|
69
|
+
expect(SpanModel.current).to include(span_model)
|
70
|
+
expect(span_model.current?).to be_truthy
|
58
71
|
end
|
59
|
-
|
72
|
+
|
60
73
|
it "should NOT be included in #future" do
|
61
|
-
SpanModel.future.
|
62
|
-
|
74
|
+
expect(SpanModel.future).not_to include(span_model)
|
75
|
+
expect(span_model.future?).to be_falsey
|
63
76
|
end
|
64
|
-
|
77
|
+
|
65
78
|
it "should NOT be included in #expired" do
|
66
|
-
SpanModel.expired.
|
67
|
-
|
79
|
+
expect(SpanModel.expired).not_to include(span_model)
|
80
|
+
expect(span_model.expired?).to be_falsey
|
68
81
|
end
|
69
82
|
end
|
70
|
-
|
83
|
+
|
71
84
|
context "C) start_date < today & end_date > today" do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
85
|
+
let(:start_date) { span_c[0] }
|
86
|
+
let(:end_date) { span_c[1] }
|
87
|
+
|
76
88
|
it "should be included in #current" do
|
77
|
-
SpanModel.current.
|
78
|
-
|
89
|
+
expect(SpanModel.current).to include(span_model)
|
90
|
+
expect(span_model.current?).to be_truthy
|
79
91
|
end
|
80
|
-
|
92
|
+
|
81
93
|
it "should NOT be included in #future" do
|
82
|
-
SpanModel.future.
|
83
|
-
|
94
|
+
expect(SpanModel.future).not_to include(span_model)
|
95
|
+
expect(span_model.future?).to be_falsey
|
84
96
|
end
|
85
|
-
|
97
|
+
|
86
98
|
it "should NOT be included in #expired" do
|
87
|
-
SpanModel.expired.
|
88
|
-
|
99
|
+
expect(SpanModel.expired).not_to include(span_model)
|
100
|
+
expect(span_model.expired?).to be_falsey
|
89
101
|
end
|
90
102
|
end
|
91
|
-
|
103
|
+
|
92
104
|
context "D) start_date == today & end_date == today" do
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
105
|
+
let(:start_date) { span_d[0] }
|
106
|
+
let(:end_date) { span_d[1] }
|
107
|
+
|
97
108
|
it "should be included in #current" do
|
98
|
-
SpanModel.current.
|
99
|
-
|
109
|
+
expect(SpanModel.current).to include(span_model)
|
110
|
+
expect(span_model.current?).to be_truthy
|
100
111
|
end
|
101
|
-
|
112
|
+
|
102
113
|
it "should NOT be included in #future" do
|
103
|
-
SpanModel.future.
|
104
|
-
|
114
|
+
expect(SpanModel.future).not_to include(span_model)
|
115
|
+
expect(span_model.future?).to be_falsey
|
105
116
|
end
|
106
|
-
|
117
|
+
|
107
118
|
it "should NOT be included in #expired" do
|
108
|
-
SpanModel.expired.
|
109
|
-
|
119
|
+
expect(SpanModel.expired).not_to include(span_model)
|
120
|
+
expect(span_model.expired?).to be_falsey
|
110
121
|
end
|
111
122
|
end
|
112
|
-
|
123
|
+
|
113
124
|
context "E) start_date == today & end_date > today" do
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
125
|
+
let(:start_date) { span_e[0] }
|
126
|
+
let(:end_date) { span_e[1] }
|
127
|
+
|
118
128
|
it "should be included in #current" do
|
119
|
-
SpanModel.current.
|
120
|
-
|
129
|
+
expect(SpanModel.current).to include(span_model)
|
130
|
+
expect(span_model.current?).to be_truthy
|
121
131
|
end
|
122
|
-
|
132
|
+
|
123
133
|
it "should NOT be included in #future" do
|
124
|
-
SpanModel.future.
|
125
|
-
|
134
|
+
expect(SpanModel.future).not_to include(span_model)
|
135
|
+
expect(span_model.future?).to be_falsey
|
126
136
|
end
|
127
|
-
|
137
|
+
|
128
138
|
it "should NOT be included in #expired" do
|
129
|
-
SpanModel.expired.
|
130
|
-
|
139
|
+
expect(SpanModel.expired).not_to include(span_model)
|
140
|
+
expect(span_model.expired?).to be_falsey
|
131
141
|
end
|
132
142
|
end
|
133
|
-
|
143
|
+
|
134
144
|
context "F) start_date > today & end_date > today" do
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
145
|
+
let(:start_date) { span_f[0] }
|
146
|
+
let(:end_date) { span_f[1] }
|
147
|
+
|
139
148
|
it "should NOT be included in #current" do
|
140
|
-
SpanModel.current.
|
141
|
-
|
149
|
+
expect(SpanModel.current).not_to include(span_model)
|
150
|
+
expect(span_model.current?).to be_falsey
|
142
151
|
end
|
143
|
-
|
152
|
+
|
144
153
|
it "should be included in #future" do
|
145
|
-
SpanModel.future.
|
146
|
-
|
154
|
+
expect(SpanModel.future).to include(span_model)
|
155
|
+
expect(span_model.future?).to be_truthy
|
147
156
|
end
|
148
|
-
|
157
|
+
|
149
158
|
it "should NOT be included in #expired" do
|
150
|
-
SpanModel.expired.
|
151
|
-
|
159
|
+
expect(SpanModel.expired).not_to include(span_model)
|
160
|
+
expect(span_model.expired?).to be_falsey
|
152
161
|
end
|
153
162
|
end
|
154
|
-
|
163
|
+
|
155
164
|
context "G) start_date < today & end_date == nil" do
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
165
|
+
let(:start_date) { span_g[0] }
|
166
|
+
let(:end_date) { span_g[1] }
|
167
|
+
|
160
168
|
it "should be included in #current" do
|
161
|
-
SpanModel.current.
|
162
|
-
|
169
|
+
expect(SpanModel.current).to include(span_model)
|
170
|
+
expect(span_model.current?).to be_truthy
|
163
171
|
end
|
164
|
-
|
172
|
+
|
165
173
|
it "should NOT be included in #future" do
|
166
|
-
SpanModel.future.
|
167
|
-
|
174
|
+
expect(SpanModel.future).not_to include(span_model)
|
175
|
+
expect(span_model.future?).to be_falsey
|
168
176
|
end
|
169
|
-
|
177
|
+
|
170
178
|
it "should NOT be included in #expired" do
|
171
|
-
SpanModel.expired.
|
172
|
-
|
179
|
+
expect(SpanModel.expired).not_to include(span_model)
|
180
|
+
expect(span_model.expired?).to be_falsey
|
173
181
|
end
|
174
182
|
end
|
175
|
-
|
183
|
+
|
176
184
|
context "H) start_date == today & end_date == nil" do
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
185
|
+
let(:start_date) { span_h[0] }
|
186
|
+
let(:end_date) { span_h[1] }
|
187
|
+
|
181
188
|
it "should be included in #current" do
|
182
|
-
SpanModel.current.
|
183
|
-
|
189
|
+
expect(SpanModel.current).to include(span_model)
|
190
|
+
expect(span_model.current?).to be_truthy
|
184
191
|
end
|
185
|
-
|
192
|
+
|
186
193
|
it "should NOT be included in #future" do
|
187
|
-
SpanModel.future.
|
188
|
-
|
194
|
+
expect(SpanModel.future).not_to include(span_model)
|
195
|
+
expect(span_model.future?).to be_falsey
|
189
196
|
end
|
190
|
-
|
197
|
+
|
191
198
|
it "should NOT be included in #expired" do
|
192
|
-
SpanModel.expired.
|
193
|
-
|
199
|
+
expect(SpanModel.expired).not_to include(span_model)
|
200
|
+
expect(span_model.expired?).to be_falsey
|
194
201
|
end
|
195
202
|
end
|
196
|
-
|
203
|
+
|
197
204
|
context "I) start_date > today & end_date == nil" do
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
205
|
+
let(:start_date) { span_i[0] }
|
206
|
+
let(:end_date) { span_i[1] }
|
207
|
+
|
202
208
|
it "should NOT be included in #current" do
|
203
|
-
SpanModel.current.
|
204
|
-
|
209
|
+
expect(SpanModel.current).not_to include(span_model)
|
210
|
+
expect(span_model.current?).to be_falsey
|
205
211
|
end
|
206
|
-
|
212
|
+
|
207
213
|
it "should be included in #future" do
|
208
|
-
SpanModel.future.
|
209
|
-
|
214
|
+
expect(SpanModel.future).to include(span_model)
|
215
|
+
expect(span_model.future?).to be_truthy
|
210
216
|
end
|
211
|
-
|
217
|
+
|
212
218
|
it "should NOT be included in #expired" do
|
213
|
-
SpanModel.expired.
|
214
|
-
|
219
|
+
expect(SpanModel.expired).not_to include(span_model)
|
220
|
+
expect(span_model.expired?).to be_falsey
|
215
221
|
end
|
216
222
|
end
|
217
|
-
|
223
|
+
|
218
224
|
context "J) start_date == nil & end_date < today" do
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
225
|
+
let(:start_date) { span_j[0] }
|
226
|
+
let(:end_date) { span_j[1] }
|
227
|
+
|
223
228
|
it "should NOT be included in #current" do
|
224
|
-
SpanModel.current.
|
225
|
-
|
229
|
+
expect(SpanModel.current).not_to include(span_model)
|
230
|
+
expect(span_model.current?).to be_falsey
|
226
231
|
end
|
227
|
-
|
232
|
+
|
228
233
|
it "should NOT be included in #future" do
|
229
|
-
SpanModel.future.
|
230
|
-
|
234
|
+
expect(SpanModel.future).not_to include(span_model)
|
235
|
+
expect(span_model.future?).to be_falsey
|
231
236
|
end
|
232
|
-
|
237
|
+
|
233
238
|
it "should be included in #expired" do
|
234
|
-
SpanModel.expired.
|
235
|
-
|
239
|
+
expect(SpanModel.expired).to include(span_model)
|
240
|
+
expect(span_model.expired?).to be_truthy
|
236
241
|
end
|
237
242
|
end
|
238
|
-
|
243
|
+
|
239
244
|
context "K) start_date == nil & end_date == today" do
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
245
|
+
let(:start_date) { span_k[0] }
|
246
|
+
let(:end_date) { span_k[1] }
|
247
|
+
|
244
248
|
it "should be included in #current" do
|
245
|
-
SpanModel.current.
|
246
|
-
|
249
|
+
expect(SpanModel.current).to include(span_model)
|
250
|
+
expect(span_model.current?).to be_truthy
|
247
251
|
end
|
248
|
-
|
252
|
+
|
249
253
|
it "should NOT be included in #future" do
|
250
|
-
SpanModel.future.
|
251
|
-
|
254
|
+
expect(SpanModel.future).not_to include(span_model)
|
255
|
+
expect(span_model.future?).to be_falsey
|
252
256
|
end
|
253
|
-
|
257
|
+
|
254
258
|
it "should NOT be included in #expired" do
|
255
|
-
SpanModel.expired.
|
256
|
-
|
259
|
+
expect(SpanModel.expired).not_to include(span_model)
|
260
|
+
expect(span_model.expired?).to be_falsey
|
257
261
|
end
|
258
262
|
end
|
259
|
-
|
263
|
+
|
260
264
|
context "L) start_date == nil & end_date > today" do
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
+
let(:start_date) { span_l[0] }
|
266
|
+
let(:end_date) { span_l[1] }
|
267
|
+
|
265
268
|
it "should be included in #current" do
|
266
|
-
SpanModel.current.
|
267
|
-
|
269
|
+
expect(SpanModel.current).to include(span_model)
|
270
|
+
expect(span_model.current?).to be_truthy
|
268
271
|
end
|
269
|
-
|
272
|
+
|
270
273
|
it "should NOT be included in #future" do
|
271
|
-
SpanModel.future.
|
272
|
-
|
274
|
+
expect(SpanModel.future).not_to include(span_model)
|
275
|
+
expect(span_model.future?).to be_falsey
|
273
276
|
end
|
274
|
-
|
277
|
+
|
275
278
|
it "should NOT be included in #expired" do
|
276
|
-
SpanModel.expired.
|
277
|
-
|
279
|
+
expect(SpanModel.expired).not_to include(span_model)
|
280
|
+
expect(span_model.expired?).to be_falsey
|
278
281
|
end
|
279
282
|
end
|
280
|
-
|
283
|
+
|
281
284
|
context "M) start_date == nil & end_date == nil" do
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
285
|
+
let(:start_date) { span_m[0] }
|
286
|
+
let(:end_date) { span_m[1] }
|
287
|
+
|
286
288
|
it "should be included in #current" do
|
287
|
-
SpanModel.current.
|
288
|
-
|
289
|
+
expect(SpanModel.current).to include(span_model)
|
290
|
+
expect(span_model.current?).to be_truthy
|
289
291
|
end
|
290
|
-
|
292
|
+
|
291
293
|
it "should NOT be included in #future" do
|
292
|
-
SpanModel.future.
|
293
|
-
|
294
|
+
expect(SpanModel.future).not_to include(span_model)
|
295
|
+
expect(span_model.future?).to be_falsey
|
294
296
|
end
|
295
|
-
|
297
|
+
|
296
298
|
it "should NOT be included in #expired" do
|
297
|
-
SpanModel.expired.
|
298
|
-
|
299
|
+
expect(SpanModel.expired).not_to include(span_model)
|
300
|
+
expect(span_model.expired?).to be_falsey
|
299
301
|
end
|
300
302
|
end
|
301
303
|
end
|
302
|
-
end
|
304
|
+
end
|