active_record_survey 0.1.6 → 0.1.7
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/lib/active_record_survey/instance_node.rb +5 -5
- data/lib/active_record_survey/node/answer/rank.rb +8 -0
- data/lib/active_record_survey/node/answer/scale.rb +10 -0
- data/lib/active_record_survey/node/answer/text.rb +7 -0
- data/lib/active_record_survey/node.rb +5 -4
- data/lib/active_record_survey/node_validation/maximum_answer.rb +1 -4
- data/lib/active_record_survey/node_validation/minimum_answer.rb +0 -3
- data/lib/active_record_survey/node_validation.rb +3 -2
- data/lib/active_record_survey/version.rb +1 -1
- data/spec/active_record_survey/node/answer/boolean_spec.rb +130 -120
- data/spec/active_record_survey/node/answer/rank_spec.rb +125 -1
- data/spec/active_record_survey/node/answer/scale_spec.rb +150 -52
- data/spec/active_record_survey/node/answer/text_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07f6faab384d06f3ef40dd8786143e54b36bc195
|
4
|
+
data.tar.gz: 47f1f3bc3f2a8319d3978cc94388ebbfdde81f82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 502f9da2618cd7e84441668135c5d1678f49fc382e729e04e8fd1eeba374a8049049b6ec2a012205d69cff2352865d217e890a3da85fcb26f8bb82c74c4e4ac7
|
7
|
+
data.tar.gz: 552fc36dfacb68835174cc6e8f53151b2def44c6f0a789befee1aa49225f5bb3409084e8f88363632620a4849cee5a81c08b25428ec57df85f956f85ca658914
|
@@ -12,18 +12,18 @@ module ActiveRecordSurvey
|
|
12
12
|
instance_node.errors[:base] << "NO_PATH"
|
13
13
|
end
|
14
14
|
|
15
|
+
parent_nodes = self.node.node_maps.collect { |j| j.parent }
|
16
|
+
|
15
17
|
# Two instance_nodes on the same node for this instance
|
16
18
|
if self.instance.instance_nodes.select { |i|
|
19
|
+
# And the two arrays
|
17
20
|
# Two votes share a parent (this means a question has two answers for this instance)
|
18
|
-
(i.node.node_maps.collect { |j|
|
19
|
-
j.parent
|
20
|
-
} & self.node.node_maps.collect { |j|
|
21
|
-
j.parent
|
22
|
-
}).length > 0
|
21
|
+
(i.node.node_maps.collect { |j| j.parent } & parent_nodes).length > 0
|
23
22
|
}.length > 1
|
24
23
|
instance_node.errors[:base] << "DUPLICATE_PATH"
|
25
24
|
end
|
26
25
|
|
26
|
+
# Validate against the associated node
|
27
27
|
if !self.node.validate_instance_node(self)
|
28
28
|
instance_node.errors[:base] << "INVALID"
|
29
29
|
end
|
@@ -11,6 +11,14 @@ module ActiveRecordSurvey
|
|
11
11
|
instance_node.value.to_i <= self.max_rank
|
12
12
|
end
|
13
13
|
|
14
|
+
# Rank answers are considered answered if they have a value of greater than "0"
|
15
|
+
def is_answered_for_instance?(instance)
|
16
|
+
if instance_node = self.instance_node_for_instance(instance)
|
17
|
+
# Answered if > 0
|
18
|
+
instance_node.value.to_i > 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
protected
|
15
23
|
|
16
24
|
# Calculate the number of Rank nodes above this one
|
@@ -7,5 +7,15 @@ module ActiveRecordSurvey
|
|
7
7
|
super &&
|
8
8
|
(instance_node.value.to_s.empty? || !instance_node.value.to_s.match(/^(\d+(\.\d+)?)$/).nil?)
|
9
9
|
end
|
10
|
+
|
11
|
+
# Scale answers are considered answered if they have a value of greater than "0"
|
12
|
+
def is_answered_for_instance?(instance)
|
13
|
+
if instance_node = self.instance_node_for_instance(instance)
|
14
|
+
# Answered if not empty and > 0
|
15
|
+
!instance_node.value.to_s.empty? && instance_node.value.to_i >= 0
|
16
|
+
else
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
@@ -1,5 +1,12 @@
|
|
1
1
|
module ActiveRecordSurvey
|
2
2
|
# Text answers are... text answers
|
3
3
|
class Node::Answer::Text < Node::Answer
|
4
|
+
# Text answers are considered answered if they have text entered
|
5
|
+
def is_answered_for_instance?(instance)
|
6
|
+
if instance_node = self.instance_node_for_instance(instance)
|
7
|
+
# Answered if has text
|
8
|
+
instance_node.value.to_s.strip.length > 0
|
9
|
+
end
|
10
|
+
end
|
4
11
|
end
|
5
12
|
end
|
@@ -32,12 +32,13 @@ module ActiveRecordSurvey
|
|
32
32
|
|
33
33
|
# Run all validations applied to this node
|
34
34
|
def validate_instance_node(instance_node)
|
35
|
-
#
|
36
|
-
#
|
35
|
+
# Basically this cache is messed up? Why? TODO.
|
36
|
+
# Reloading in the spec seems to fix this... but... this could be a booby trap for others
|
37
|
+
#self.node_validations(true)
|
38
|
+
|
37
39
|
!self.node_validations.collect { |node_validation|
|
38
40
|
node_validation.validate_instance_node(instance_node, self)
|
39
|
-
}.include?(false) &&
|
40
|
-
!self.node_maps.collect { |node_map|
|
41
|
+
}.include?(false) && !self.node_maps.collect { |node_map|
|
41
42
|
if node_map.parent
|
42
43
|
node_map.parent.node.validate_instance_node(instance_node)
|
43
44
|
# Hit top node
|
@@ -3,10 +3,7 @@ module ActiveRecordSurvey
|
|
3
3
|
class NodeValidation::MaximumAnswer < NodeValidation
|
4
4
|
# Validate the instance_node to ensure a maximum number of answers are made
|
5
5
|
def validate_instance_node(instance_node, question_node = nil)
|
6
|
-
#
|
7
|
-
#puts "runnin min answer validation"
|
8
|
-
|
9
|
-
# Only makes sense for questions to have minimum answers
|
6
|
+
# Only makes sense for questions to have maximum answers
|
10
7
|
if !question_node.class.ancestors.include?(::ActiveRecordSurvey::Node::Question)
|
11
8
|
return false
|
12
9
|
end
|
@@ -3,9 +3,6 @@ module ActiveRecordSurvey
|
|
3
3
|
class NodeValidation::MinimumAnswer < NodeValidation
|
4
4
|
# Validate the instance_node to ensure a minimum number of answers are made
|
5
5
|
def validate_instance_node(instance_node, question_node = nil)
|
6
|
-
#puts "-------------------------------------------"
|
7
|
-
#puts "runnin min answer validation"
|
8
|
-
|
9
6
|
# Only makes sense for questions to have minimum answers
|
10
7
|
if !question_node.class.ancestors.include?(::ActiveRecordSurvey::Node::Question)
|
11
8
|
return false
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRecordSurvey::Node::Answer::Boolean, :
|
3
|
+
describe ActiveRecordSurvey::Node::Answer::Boolean, :boolean_spec => true do
|
4
4
|
describe 'a boolean survey is' do
|
5
5
|
before(:all) do
|
6
6
|
@survey = ActiveRecordSurvey::Survey.new
|
@@ -18,15 +18,6 @@ describe ActiveRecordSurvey::Node::Answer::Boolean, :focus => true do
|
|
18
18
|
nodes = @survey.build_question(@q1_a4, [], nodes[0])
|
19
19
|
nodes = @survey.build_question(@q1_a5, [], nodes[0])
|
20
20
|
|
21
|
-
@q1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumAnswer.new(
|
22
|
-
:node => @q1,
|
23
|
-
:value => 1 # min 1 of the 3 answers must be "answered"
|
24
|
-
)
|
25
|
-
@q1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumAnswer.new(
|
26
|
-
:node => @q1,
|
27
|
-
:value => 3 # max 2 of the 3 answers must be "answered"
|
28
|
-
)
|
29
|
-
|
30
21
|
@survey.save
|
31
22
|
end
|
32
23
|
|
@@ -109,123 +100,142 @@ describe ActiveRecordSurvey::Node::Answer::Boolean, :focus => true do
|
|
109
100
|
end
|
110
101
|
end
|
111
102
|
|
112
|
-
describe ActiveRecordSurvey::NodeValidation
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
)
|
126
|
-
instance.instance_nodes.build(
|
127
|
-
:instance => instance,
|
128
|
-
:node => @q1_a3,
|
129
|
-
:value => 1,
|
130
|
-
)
|
131
|
-
instance.save
|
132
|
-
|
133
|
-
expect(instance.valid?).to be(true)
|
134
|
-
end
|
135
|
-
end
|
103
|
+
describe ActiveRecordSurvey::NodeValidation do
|
104
|
+
before(:all) do
|
105
|
+
@q1.node_validations.build(
|
106
|
+
:type => 'ActiveRecordSurvey::NodeValidation::MinimumAnswer',
|
107
|
+
:node => @q1,
|
108
|
+
:value => 1 # min 1 of the 3 answers must be "answered"
|
109
|
+
)
|
110
|
+
@q1.node_validations.build(
|
111
|
+
:type => 'ActiveRecordSurvey::NodeValidation::MaximumAnswer',
|
112
|
+
:node => @q1,
|
113
|
+
:value => 3 # max 2 of the 3 answers must be "answered"
|
114
|
+
)
|
115
|
+
@q1.save
|
136
116
|
|
137
|
-
|
138
|
-
|
139
|
-
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
140
|
-
instance.instance_nodes.build(
|
141
|
-
:instance => instance,
|
142
|
-
:node => @q1_a1,
|
143
|
-
:value => 0,
|
144
|
-
)
|
145
|
-
instance.instance_nodes.build(
|
146
|
-
:instance => instance,
|
147
|
-
:node => @q1_a2,
|
148
|
-
:value => 0,
|
149
|
-
)
|
150
|
-
instance.instance_nodes.build(
|
151
|
-
:instance => instance,
|
152
|
-
:node => @q1_a3,
|
153
|
-
:value => 0,
|
154
|
-
)
|
155
|
-
instance.save
|
156
|
-
|
157
|
-
expect(instance.valid?).to be(false)
|
158
|
-
end
|
117
|
+
# Weird caching is happening
|
118
|
+
@q1_a1.reload
|
159
119
|
end
|
160
|
-
end
|
161
120
|
|
121
|
+
describe ActiveRecordSurvey::NodeValidation::MinimumAnswer do
|
122
|
+
describe 'valid when' do
|
123
|
+
it 'has a value greater than the minimum' do
|
124
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
125
|
+
instance.instance_nodes.build(
|
126
|
+
:instance => instance,
|
127
|
+
:node => @q1_a1,
|
128
|
+
:value => 1,
|
129
|
+
)
|
130
|
+
instance.instance_nodes.build(
|
131
|
+
:instance => instance,
|
132
|
+
:node => @q1_a2,
|
133
|
+
:value => 0,
|
134
|
+
)
|
135
|
+
instance.instance_nodes.build(
|
136
|
+
:instance => instance,
|
137
|
+
:node => @q1_a3,
|
138
|
+
:value => 1,
|
139
|
+
)
|
140
|
+
instance.save
|
141
|
+
|
142
|
+
expect(instance.valid?).to be(true)
|
143
|
+
end
|
144
|
+
end
|
162
145
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
)
|
187
|
-
instance.instance_nodes.build(
|
188
|
-
:instance => instance,
|
189
|
-
:node => @q1_a5,
|
190
|
-
:value => 0,
|
191
|
-
)
|
192
|
-
instance.save
|
193
|
-
|
194
|
-
expect(instance.valid?).to be(true)
|
146
|
+
describe 'invalid when' do
|
147
|
+
it 'has a value less than the minimum' do
|
148
|
+
@q1.node_validations(true)
|
149
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
150
|
+
instance.instance_nodes.build(
|
151
|
+
:instance => instance,
|
152
|
+
:node => @q1_a1,
|
153
|
+
:value => 0,
|
154
|
+
)
|
155
|
+
instance.instance_nodes.build(
|
156
|
+
:instance => instance,
|
157
|
+
:node => @q1_a2,
|
158
|
+
:value => 0,
|
159
|
+
)
|
160
|
+
instance.instance_nodes.build(
|
161
|
+
:instance => instance,
|
162
|
+
:node => @q1_a3,
|
163
|
+
:value => 0,
|
164
|
+
)
|
165
|
+
instance.save
|
166
|
+
|
167
|
+
expect(instance.valid?).to be(false)
|
168
|
+
end
|
195
169
|
end
|
196
170
|
end
|
197
171
|
|
198
|
-
describe
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
172
|
+
describe ActiveRecordSurvey::NodeValidation::MaximumAnswer do
|
173
|
+
describe 'valid when' do
|
174
|
+
it 'has a value less than the maximum' do
|
175
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
176
|
+
instance.instance_nodes.build(
|
177
|
+
:instance => instance,
|
178
|
+
:node => @q1_a1,
|
179
|
+
:value => 1,
|
180
|
+
)
|
181
|
+
instance.instance_nodes.build(
|
182
|
+
:instance => instance,
|
183
|
+
:node => @q1_a2,
|
184
|
+
:value => 0,
|
185
|
+
)
|
186
|
+
instance.instance_nodes.build(
|
187
|
+
:instance => instance,
|
188
|
+
:node => @q1_a3,
|
189
|
+
:value => 1,
|
190
|
+
)
|
191
|
+
instance.instance_nodes.build(
|
192
|
+
:instance => instance,
|
193
|
+
:node => @q1_a4,
|
194
|
+
:value => 1,
|
195
|
+
)
|
196
|
+
instance.instance_nodes.build(
|
197
|
+
:instance => instance,
|
198
|
+
:node => @q1_a5,
|
199
|
+
:value => 0,
|
200
|
+
)
|
201
|
+
instance.save
|
202
|
+
|
203
|
+
expect(instance.valid?).to be(true)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe 'invalid when' do
|
208
|
+
it 'has a value greater than the maximum' do
|
209
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
210
|
+
instance.instance_nodes.build(
|
211
|
+
:instance => instance,
|
212
|
+
:node => @q1_a1,
|
213
|
+
:value => 1,
|
214
|
+
)
|
215
|
+
instance.instance_nodes.build(
|
216
|
+
:instance => instance,
|
217
|
+
:node => @q1_a2,
|
218
|
+
:value => 1,
|
219
|
+
)
|
220
|
+
instance.instance_nodes.build(
|
221
|
+
:instance => instance,
|
222
|
+
:node => @q1_a3,
|
223
|
+
:value => 1,
|
224
|
+
)
|
225
|
+
instance.instance_nodes.build(
|
226
|
+
:instance => instance,
|
227
|
+
:node => @q1_a4,
|
228
|
+
:value => 1,
|
229
|
+
)
|
230
|
+
instance.instance_nodes.build(
|
231
|
+
:instance => instance,
|
232
|
+
:node => @q1_a5,
|
233
|
+
:value => 1,
|
234
|
+
)
|
235
|
+
instance.save
|
236
|
+
|
237
|
+
expect(instance.valid?).to be(false)
|
238
|
+
end
|
229
239
|
end
|
230
240
|
end
|
231
241
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRecordSurvey::Node::Answer::Rank do
|
3
|
+
describe ActiveRecordSurvey::Node::Answer::Rank, :rank_spec => true do
|
4
4
|
describe 'survey is' do
|
5
5
|
before(:all) do
|
6
6
|
@survey = ActiveRecordSurvey::Survey.new
|
@@ -217,5 +217,129 @@ describe ActiveRecordSurvey::Node::Answer::Rank do
|
|
217
217
|
expect(instance.valid?).to be(false)
|
218
218
|
end
|
219
219
|
end
|
220
|
+
|
221
|
+
describe ActiveRecordSurvey::NodeValidation do
|
222
|
+
before(:all) do
|
223
|
+
@q1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumAnswer.new(
|
224
|
+
:node => @q1,
|
225
|
+
:value => 2 # min 1 of the 3 answers must be "answered"
|
226
|
+
)
|
227
|
+
@q1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumAnswer.new(
|
228
|
+
:node => @q1,
|
229
|
+
:value => 3 # max 2 of the 3 answers must be "answered"
|
230
|
+
)
|
231
|
+
|
232
|
+
# Weird caching is happening
|
233
|
+
@q1_a1.reload
|
234
|
+
end
|
235
|
+
|
236
|
+
describe ActiveRecordSurvey::NodeValidation::MinimumAnswer do
|
237
|
+
describe 'valid when' do
|
238
|
+
it 'has a value greater than the minimum' do
|
239
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
240
|
+
instance.instance_nodes.build(
|
241
|
+
:instance => instance,
|
242
|
+
:node => @q1_a1,
|
243
|
+
:value => 1,
|
244
|
+
)
|
245
|
+
instance.instance_nodes.build(
|
246
|
+
:instance => instance,
|
247
|
+
:node => @q1_a2,
|
248
|
+
:value => 2,
|
249
|
+
)
|
250
|
+
instance.instance_nodes.build(
|
251
|
+
:instance => instance,
|
252
|
+
:node => @q1_a3,
|
253
|
+
:value => 3,
|
254
|
+
)
|
255
|
+
instance.save
|
256
|
+
|
257
|
+
expect(instance.valid?).to be(true)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe 'invalid when' do
|
262
|
+
it 'has a value less than the minimum' do
|
263
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
264
|
+
instance.instance_nodes.build(
|
265
|
+
:instance => instance,
|
266
|
+
:node => @q1_a1,
|
267
|
+
:value => 1,
|
268
|
+
)
|
269
|
+
instance.save
|
270
|
+
|
271
|
+
expect(instance.valid?).to be(false)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
describe ActiveRecordSurvey::NodeValidation::MaximumAnswer do
|
277
|
+
describe 'valid when' do
|
278
|
+
it 'has a value less than the maximum' do
|
279
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
280
|
+
instance.instance_nodes.build(
|
281
|
+
:instance => instance,
|
282
|
+
:node => @q1_a1,
|
283
|
+
:value => 1,
|
284
|
+
)
|
285
|
+
instance.instance_nodes.build(
|
286
|
+
:instance => instance,
|
287
|
+
:node => @q1_a2,
|
288
|
+
:value => 2,
|
289
|
+
)
|
290
|
+
instance.instance_nodes.build(
|
291
|
+
:instance => instance,
|
292
|
+
:node => @q1_a3,
|
293
|
+
)
|
294
|
+
instance.instance_nodes.build(
|
295
|
+
:instance => instance,
|
296
|
+
:node => @q1_a4,
|
297
|
+
)
|
298
|
+
instance.instance_nodes.build(
|
299
|
+
:instance => instance,
|
300
|
+
:node => @q1_a5,
|
301
|
+
:value => 3,
|
302
|
+
)
|
303
|
+
instance.save
|
304
|
+
|
305
|
+
expect(instance.valid?).to be(true)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
describe 'invalid when' do
|
310
|
+
it 'has a value greater than the maximum' do
|
311
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
312
|
+
instance.instance_nodes.build(
|
313
|
+
:instance => instance,
|
314
|
+
:node => @q1_a1,
|
315
|
+
:value => 1,
|
316
|
+
)
|
317
|
+
instance.instance_nodes.build(
|
318
|
+
:instance => instance,
|
319
|
+
:node => @q1_a2,
|
320
|
+
:value => 2,
|
321
|
+
)
|
322
|
+
instance.instance_nodes.build(
|
323
|
+
:instance => instance,
|
324
|
+
:node => @q1_a3,
|
325
|
+
:value => 3,
|
326
|
+
)
|
327
|
+
instance.instance_nodes.build(
|
328
|
+
:instance => instance,
|
329
|
+
:node => @q1_a4,
|
330
|
+
:value => 4,
|
331
|
+
)
|
332
|
+
instance.instance_nodes.build(
|
333
|
+
:instance => instance,
|
334
|
+
:node => @q1_a5,
|
335
|
+
:value => 5,
|
336
|
+
)
|
337
|
+
instance.save
|
338
|
+
|
339
|
+
expect(instance.valid?).to be(false)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
220
344
|
end
|
221
345
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRecordSurvey::Node::Answer::Scale do
|
3
|
+
describe ActiveRecordSurvey::Node::Answer::Scale, :scale_spec => true do
|
4
4
|
describe 'survey is' do
|
5
5
|
before(:all) do
|
6
6
|
@survey = ActiveRecordSurvey::Survey.new
|
@@ -80,78 +80,176 @@ describe ActiveRecordSurvey::Node::Answer::Scale do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
describe ActiveRecordSurvey::NodeValidation
|
84
|
-
describe
|
85
|
-
|
86
|
-
@
|
87
|
-
:node => @
|
88
|
-
:value =>
|
89
|
-
)
|
90
|
-
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
91
|
-
instance.instance_nodes.build(
|
92
|
-
:instance => instance,
|
93
|
-
:node => @q1_a1,
|
94
|
-
:value => 5,
|
83
|
+
describe ActiveRecordSurvey::NodeValidation do
|
84
|
+
describe ActiveRecordSurvey::NodeValidation::MinimumAnswer do
|
85
|
+
before(:all) do
|
86
|
+
@q1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumAnswer.new(
|
87
|
+
:node => @q1,
|
88
|
+
:value => 1
|
95
89
|
)
|
96
|
-
|
90
|
+
|
91
|
+
# Weird caching is happening
|
92
|
+
@q1_a1.reload
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'valid when' do
|
96
|
+
it 'has a value greater than the minimum' do
|
97
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
98
|
+
instance.instance_nodes.build(
|
99
|
+
:instance => instance,
|
100
|
+
:node => @q1_a1,
|
101
|
+
:value => 5,
|
102
|
+
)
|
103
|
+
instance.save
|
104
|
+
|
105
|
+
expect(instance.valid?).to be(true)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'invalid when' do
|
110
|
+
it 'has a value less than the minimum' do
|
111
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
112
|
+
instance.instance_nodes.build(
|
113
|
+
:instance => instance,
|
114
|
+
:node => @q1_a1,
|
115
|
+
)
|
116
|
+
instance.save
|
97
117
|
|
98
|
-
|
118
|
+
expect(instance.valid?).to be(false)
|
119
|
+
end
|
99
120
|
end
|
100
121
|
end
|
101
122
|
|
102
|
-
describe
|
103
|
-
|
104
|
-
@
|
105
|
-
:node => @
|
106
|
-
:value =>
|
123
|
+
describe ActiveRecordSurvey::NodeValidation::MaximumAnswer do
|
124
|
+
before(:all) do
|
125
|
+
@q1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumAnswer.new(
|
126
|
+
:node => @q1,
|
127
|
+
:value => 2
|
107
128
|
)
|
108
|
-
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
109
|
-
instance.instance_nodes.build(
|
110
|
-
:instance => instance,
|
111
|
-
:node => @q1_a1,
|
112
|
-
:value => 5,
|
113
|
-
)
|
114
|
-
instance.save
|
115
129
|
|
116
|
-
|
130
|
+
# Weird caching is happening
|
131
|
+
@q1_a1.reload
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'valid when' do
|
135
|
+
it 'has a value less than the maximum' do
|
136
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
137
|
+
instance.instance_nodes.build(
|
138
|
+
:instance => instance,
|
139
|
+
:node => @q1_a1,
|
140
|
+
:value => 8,
|
141
|
+
)
|
142
|
+
instance.instance_nodes.build(
|
143
|
+
:instance => instance,
|
144
|
+
:node => @q1_a2,
|
145
|
+
:value => 9,
|
146
|
+
)
|
147
|
+
instance.instance_nodes.build(
|
148
|
+
:instance => instance,
|
149
|
+
:node => @q1_a3,
|
150
|
+
)
|
151
|
+
instance.save
|
152
|
+
|
153
|
+
expect(instance.valid?).to be(true)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'invalid when' do
|
158
|
+
it 'has a value greater than the maximum' do
|
159
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
160
|
+
instance.instance_nodes.build(
|
161
|
+
:instance => instance,
|
162
|
+
:node => @q1_a1,
|
163
|
+
:value => 8,
|
164
|
+
)
|
165
|
+
instance.instance_nodes.build(
|
166
|
+
:instance => instance,
|
167
|
+
:node => @q1_a2,
|
168
|
+
:value => 9,
|
169
|
+
)
|
170
|
+
instance.instance_nodes.build(
|
171
|
+
:instance => instance,
|
172
|
+
:node => @q1_a3,
|
173
|
+
:value => 10,
|
174
|
+
)
|
175
|
+
instance.save
|
176
|
+
|
177
|
+
expect(instance.valid?).to be(false)
|
178
|
+
end
|
117
179
|
end
|
118
180
|
end
|
119
|
-
end
|
120
181
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumValue.new(
|
125
|
-
:node => @q1_a1,
|
126
|
-
:value => 15
|
127
|
-
)
|
128
|
-
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
129
|
-
instance.instance_nodes.build(
|
130
|
-
:instance => instance,
|
182
|
+
describe ActiveRecordSurvey::NodeValidation::MinimumValue do
|
183
|
+
before(:all) do
|
184
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumValue.new(
|
131
185
|
:node => @q1_a1,
|
132
|
-
:value =>
|
186
|
+
:value => 4
|
133
187
|
)
|
134
|
-
|
188
|
+
end
|
135
189
|
|
136
|
-
|
190
|
+
describe 'valid when' do
|
191
|
+
it 'has a value greater than the minimum' do
|
192
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
193
|
+
instance.instance_nodes.build(
|
194
|
+
:instance => instance,
|
195
|
+
:node => @q1_a1,
|
196
|
+
:value => 5,
|
197
|
+
)
|
198
|
+
instance.save
|
199
|
+
|
200
|
+
expect(instance.valid?).to be(true)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe 'invalid when' do
|
205
|
+
it 'has a value less than the minimum' do
|
206
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
207
|
+
instance.instance_nodes.build(
|
208
|
+
:instance => instance,
|
209
|
+
:node => @q1_a1,
|
210
|
+
:value => 3,
|
211
|
+
)
|
212
|
+
instance.save
|
213
|
+
|
214
|
+
expect(instance.valid?).to be(false)
|
215
|
+
end
|
137
216
|
end
|
138
217
|
end
|
139
218
|
|
140
|
-
describe
|
141
|
-
|
219
|
+
describe ActiveRecordSurvey::NodeValidation::MaximumValue do
|
220
|
+
before(:all) do
|
142
221
|
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumValue.new(
|
143
222
|
:node => @q1_a1,
|
144
223
|
:value => 15
|
145
224
|
)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
:
|
151
|
-
|
152
|
-
|
225
|
+
end
|
226
|
+
|
227
|
+
describe 'valid when' do
|
228
|
+
it 'has a value less than the maximum' do
|
229
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
230
|
+
instance.instance_nodes.build(
|
231
|
+
:instance => instance,
|
232
|
+
:node => @q1_a1,
|
233
|
+
:value => 8,
|
234
|
+
)
|
235
|
+
instance.save
|
236
|
+
|
237
|
+
expect(instance.valid?).to be(true)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe 'invalid when' do
|
242
|
+
it 'has a value greater than the maximum' do
|
243
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
244
|
+
instance.instance_nodes.build(
|
245
|
+
:instance => instance,
|
246
|
+
:node => @q1_a1,
|
247
|
+
:value => 20,
|
248
|
+
)
|
249
|
+
instance.save
|
153
250
|
|
154
|
-
|
251
|
+
expect(instance.valid?).to be(false)
|
252
|
+
end
|
155
253
|
end
|
156
254
|
end
|
157
255
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_survey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Butch Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|