active_record_survey 0.1.22 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +106 -9
- data/lib/active_record_survey/node/answer/chain/boolean.rb +19 -0
- data/lib/active_record_survey/node/answer/{rank.rb → chain/rank.rb} +2 -21
- data/lib/active_record_survey/node/answer/chain/scale.rb +21 -0
- data/lib/active_record_survey/node/answer/chain/text.rb +14 -0
- data/lib/active_record_survey/node/answer/{text.rb → chain.rb} +7 -9
- data/lib/active_record_survey/version.rb +1 -1
- data/lib/active_record_survey.rb +5 -4
- data/spec/active_record_survey/node/answer/boolean_spec.rb +6 -6
- data/spec/active_record_survey/node/answer/rank_spec.rb +6 -6
- data/spec/active_record_survey/node/answer/scale_spec.rb +4 -4
- data/spec/active_record_survey/node/answer/text_spec.rb +3 -3
- data/spec/active_record_survey/node/question_spec.rb +8 -8
- data/spec/factories/active_record_survey/survey.rb +2 -2
- metadata +6 -5
- data/lib/active_record_survey/node/answer/boolean.rb +0 -38
- data/lib/active_record_survey/node/answer/scale.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af6f4cb30e84b3fe9429b0d1c3c61ddb9f489947
|
4
|
+
data.tar.gz: 024880ac8b4f3a09bb5aef167ee60c1ffdcebc6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f34d9376211feb9217986b500dc6182b57e173f110966b360556d13a303c5c1446161c17cf4a87df8c9588edcecef56cddf7044b63234f30d24d877c659a0216
|
7
|
+
data.tar.gz: 29a73df91e68016693270265364569f3cc03a181cea2552dc5c984c5efe80749acdb950041a1c7113f37ab9c40daca34cd15e429bad6f5587a87449a9c38580d
|
data/README.md
CHANGED
@@ -12,6 +12,9 @@ The goal is to give a simple interface for creating surveys and validating the a
|
|
12
12
|
Release Notes
|
13
13
|
============
|
14
14
|
|
15
|
+
**0.1.23**
|
16
|
+
- Added `ActiveRecordSurvey::Node::Answer::Chain` for common chainable interface for answers
|
17
|
+
|
15
18
|
**0.1.22**
|
16
19
|
- answer#remove_link cleaned up so it can be understood
|
17
20
|
|
@@ -124,39 +127,133 @@ A number of different answer types are implemented by default.
|
|
124
127
|
- [Scale](#answer_scale)
|
125
128
|
- [Text](#answer_text)
|
126
129
|
|
127
|
-
|
130
|
+
<a id="answer_default"></a>
|
131
|
+
#### Default
|
128
132
|
|
129
133
|
```ruby
|
130
134
|
ActiveRecordSurvey::Node::Answer
|
131
135
|
```
|
132
136
|
|
133
|
-
|
137
|
+
The default answer type (think of it like a radio question) - this is currently the only answer type you can attach to a question so that depending on the answer given you can branch to a different question.
|
138
|
+
|
139
|
+
<a id="answer_checkbox"></a>
|
140
|
+
#### Boolean
|
134
141
|
|
135
142
|
```ruby
|
136
|
-
ActiveRecordSurvey::Node::Answer::Boolean
|
143
|
+
ActiveRecordSurvey::Node::Answer::Chain::Boolean
|
137
144
|
```
|
138
145
|
|
139
|
-
|
146
|
+
True/False (0/1 actually... think of it like a checkbox) answer types.
|
147
|
+
|
148
|
+
<a id="answer_rank"></a>
|
149
|
+
#### Rank
|
140
150
|
|
141
151
|
```ruby
|
142
|
-
ActiveRecordSurvey::Node::Answer::Rank
|
152
|
+
ActiveRecordSurvey::Node::Answer::Chain::Rank
|
143
153
|
```
|
144
154
|
|
145
|
-
|
155
|
+
Rankable (answer value is 1..NUM_ANSWERS) to rank the answers in relation to one another.
|
156
|
+
|
157
|
+
<a id="answer_scale"></a>
|
158
|
+
#### Scale
|
146
159
|
|
147
160
|
```ruby
|
148
|
-
ActiveRecordSurvey::Node::Answer::Scale
|
161
|
+
ActiveRecordSurvey::Node::Answer::Chain::Scale
|
149
162
|
```
|
150
163
|
|
151
|
-
|
164
|
+
Scale (answer value is a min/max on a scale of A->B) where you can specificy each answer on a scale
|
165
|
+
|
166
|
+
<a id="answer_text"></a>
|
167
|
+
#### Text
|
152
168
|
|
153
169
|
```ruby
|
154
|
-
ActiveRecordSurvey::Node::Answer::Text
|
170
|
+
ActiveRecordSurvey::Node::Answer::Chain::Text
|
155
171
|
```
|
156
172
|
|
173
|
+
Textual answer to a question (e.g. please tell us what you thinik...)
|
174
|
+
|
157
175
|
### Answer Validation
|
158
176
|
|
177
|
+
Enforcing answer criteria is accomplished by attaching validation nodes to `ActiveRecordSurvey::Node` records.
|
178
|
+
|
179
|
+
When a survey is taken validations are automatically run and their criteria is enforced.
|
180
|
+
|
181
|
+
A number of validations are already implemented by default.
|
182
|
+
|
183
|
+
You can implement your own validation by extending the `ActiveRecordSurvey::ValidationNode` class.
|
184
|
+
|
185
|
+
- [MaximumAnswer](#answer_maximum_answer)
|
186
|
+
- [MinimumAnswer](#answer_minimum_answer)
|
187
|
+
- [MaximumValue](#answer_maximum_value)
|
188
|
+
- [MinimumValue](#answer_minimum_value)
|
189
|
+
- [MaximumLength](#answer_maximum_length)
|
190
|
+
- [MinimumLength](#answer_minimum_length)
|
191
|
+
|
192
|
+
<a id="answer_maximum_answer"></a>
|
193
|
+
#### MaximumAnswer
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
ActiveRecordSurvey::ValidationNode::MaximumAnswer
|
197
|
+
```
|
198
|
+
|
199
|
+
These nodes should only be attached to nodes which extend `ActiveRecordSurvey::Node::Question` nodes.
|
200
|
+
|
201
|
+
Ensures that a maximum numer of answers have been selected. For chained answer nodes such as `ActiveRecordSurvey::Node::Answer::Chain::Boolean`,`ActiveRecordSurvey::Node::Answer::Chain::Rank`, and `ActiveRecordSurvey::Node::Answer::Chain::Scale` it enforces a maximum amount that be answered.
|
202
|
+
|
203
|
+
<a id=answer_minimum_answer""></a>
|
204
|
+
#### MinimumAnswer
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
ActiveRecordSurvey::ValidationNode::MinimumAnswer
|
208
|
+
```
|
209
|
+
|
210
|
+
These nodes should only be attached to nodes which extend `ActiveRecordSurvey::Node::Question` nodes.
|
211
|
+
|
212
|
+
Ensures that a minimum numer of answers have been selected. For chained answer nodes such as `ActiveRecordSurvey::Node::Answer::Chain::Boolean`,`ActiveRecordSurvey::Node::Answer::Chain::Rank`, and `ActiveRecordSurvey::Node::Answer::Chain::Scale` it enforces a minimum amount that can be answered.
|
213
|
+
|
214
|
+
<a id="answer_maximum_value"></a>
|
215
|
+
#### MaximumValue
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
ActiveRecordSurvey::ValidationNode::MaximumValue
|
219
|
+
```
|
220
|
+
|
221
|
+
These nodes should only be attached to nodes which extend `ActiveRecordSurvey::Node::Answer` nodes which record an scalar answer value such as `ActiveRecordSurvey::Node::Answer::Chain::Scale`.
|
222
|
+
|
223
|
+
Ensures that a minimum scalar value has been entered.
|
224
|
+
|
225
|
+
<a id="answer_minimum_value"></a>
|
226
|
+
#### MinimumValue
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
ActiveRecordSurvey::ValidationNode::MinimumValue
|
230
|
+
```
|
231
|
+
|
232
|
+
These nodes should only be attached to nodes which extend `ActiveRecordSurvey::Node::Answer` nodes which record an scalar answer value such as `ActiveRecordSurvey::Node::Answer::Chain::Scale`.
|
233
|
+
|
234
|
+
Ensures that a maximum scalar value has been entered.
|
235
|
+
|
236
|
+
<a id="answer_maximum_length"></a>
|
237
|
+
#### MaximumLength
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
ActiveRecordSurvey::ValidationNode::MaximumLength
|
241
|
+
```
|
242
|
+
|
243
|
+
These nodes should only be attached to nodes which extend `ActiveRecordSurvey::Node::Answer` nodes nodes which record a text value such as `ActiveRecordSurvey::Node::Answer::Chain::Text`.
|
244
|
+
|
245
|
+
Ensures that a maximum amount of text has been answered.
|
246
|
+
|
247
|
+
<a id="answer_minimum_length"></a>
|
248
|
+
#### MinimumLength
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
ActiveRecordSurvey::ValidationNode::MinimumLength
|
252
|
+
```
|
253
|
+
|
254
|
+
These nodes should only be attached to nodes which extend `ActiveRecordSurvey::Node::Answer` nodes nodes which record a text value such as `ActiveRecordSurvey::Node::Answer::Chain::Text`.
|
159
255
|
|
256
|
+
Ensures that a minimum amount of text has been answered.
|
160
257
|
|
161
258
|
## Development
|
162
259
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ActiveRecordSurvey
|
2
|
+
# Boolean answers can have values 0|1
|
3
|
+
class Node::Answer::Chain::Boolean < Node::Answer::Chain
|
4
|
+
# Only boolean values
|
5
|
+
def validate_instance_node(instance_node)
|
6
|
+
# super - all validations on this node pass
|
7
|
+
super &&
|
8
|
+
!instance_node.value.to_s.match(/^[0|1]$/).nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
# Boolean answers are considered answered if they have a value of "1"
|
12
|
+
def is_answered_for_instance?(instance)
|
13
|
+
if instance_node = self.instance_node_for_instance(instance)
|
14
|
+
# Instance node is answered "1"
|
15
|
+
(instance_node.value.to_i === 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveRecordSurvey
|
2
|
-
# Rank in relation to parent/children of ActiveRecordSurvey::Node::Answer::Rank
|
3
|
-
class Node::Answer::Rank < Node::Answer
|
2
|
+
# Rank in relation to parent/children of ActiveRecordSurvey::Node::Answer::Chain::Rank
|
3
|
+
class Node::Answer::Chain::Rank < Node::Answer::Chain
|
4
4
|
# Accept integer or empty values
|
5
5
|
# Must be within range of the number of ranking nodes
|
6
6
|
def validate_instance_node(instance_node)
|
@@ -19,25 +19,6 @@ module ActiveRecordSurvey
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
# Rank nodes are different - they must find the final rank node added and add to it
|
23
|
-
def build_answer(question_node, survey)
|
24
|
-
# No node_maps exist yet from this question
|
25
|
-
if question_node.node_maps.length === 0
|
26
|
-
# Build our first node-map
|
27
|
-
question_node.node_maps.build(:node => question_node, :survey => survey)
|
28
|
-
end
|
29
|
-
|
30
|
-
last_in_chain = question_node.answers.last || question_node
|
31
|
-
|
32
|
-
# Each instance of this question needs the answer hung from it
|
33
|
-
last_in_chain.node_maps.each { |node_map|
|
34
|
-
answer_node_map = self.node_maps.build(:node => self, :survey => survey)
|
35
|
-
node_map.children << answer_node_map
|
36
|
-
}
|
37
|
-
|
38
|
-
true
|
39
|
-
end
|
40
|
-
|
41
22
|
protected
|
42
23
|
|
43
24
|
# Calculate the number of Rank nodes above this one
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveRecordSurvey
|
2
|
+
# Can hold a value on a scale (e.g. from 0-10)
|
3
|
+
class Node::Answer::Chain::Scale < Node::Answer::Chain
|
4
|
+
# Accept integer, float, or empty values
|
5
|
+
def validate_instance_node(instance_node)
|
6
|
+
# super - all validations on this node pass
|
7
|
+
super &&
|
8
|
+
(instance_node.value.to_s.empty? || !instance_node.value.to_s.match(/^(\d+(\.\d+)?)$/).nil?)
|
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
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActiveRecordSurvey
|
2
|
+
# Text answers are... text answers
|
3
|
+
class Node::Answer::Chain::Text < Node::Answer::Chain
|
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
|
+
else
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,17 +1,15 @@
|
|
1
1
|
module ActiveRecordSurvey
|
2
|
-
#
|
3
|
-
class Node::Answer::
|
4
|
-
|
2
|
+
# Boolean answers can have values 0|1
|
3
|
+
class Node::Answer::Chain < Node::Answer
|
4
|
+
|
5
5
|
def is_answered_for_instance?(instance)
|
6
6
|
if instance_node = self.instance_node_for_instance(instance)
|
7
|
-
#
|
8
|
-
instance_node.value.
|
9
|
-
else
|
10
|
-
false
|
7
|
+
# Instance node is answered "1"
|
8
|
+
(instance_node.value.to_i === 1)
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
14
|
-
#
|
12
|
+
# Chain nodes are different - they must find the final answer node added and add to it
|
15
13
|
def build_answer(question_node, survey)
|
16
14
|
# No node_maps exist yet from this question
|
17
15
|
if question_node.node_maps.length === 0
|
@@ -30,4 +28,4 @@ module ActiveRecordSurvey
|
|
30
28
|
true
|
31
29
|
end
|
32
30
|
end
|
33
|
-
end
|
31
|
+
end
|
data/lib/active_record_survey.rb
CHANGED
@@ -12,10 +12,11 @@ require "active_record_survey/survey"
|
|
12
12
|
require "active_record_survey/node"
|
13
13
|
require "active_record_survey/node/question"
|
14
14
|
require "active_record_survey/node/answer"
|
15
|
-
require "active_record_survey/node/answer/
|
16
|
-
require "active_record_survey/node/answer/
|
17
|
-
require "active_record_survey/node/answer/
|
18
|
-
require "active_record_survey/node/answer/
|
15
|
+
require "active_record_survey/node/answer/chain"
|
16
|
+
require "active_record_survey/node/answer/chain/text"
|
17
|
+
require "active_record_survey/node/answer/chain/rank"
|
18
|
+
require "active_record_survey/node/answer/chain/scale"
|
19
|
+
require "active_record_survey/node/answer/chain/boolean"
|
19
20
|
|
20
21
|
require "active_record_survey/node_map"
|
21
22
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRecordSurvey::Node::Answer::Boolean, :boolean_spec => true do
|
3
|
+
describe ActiveRecordSurvey::Node::Answer::Chain::Boolean, :boolean_spec => true do
|
4
4
|
describe 'a boolean survey is' do
|
5
5
|
before(:all) do
|
6
6
|
@survey = ActiveRecordSurvey::Survey.new
|
7
7
|
|
8
8
|
@q1 = ActiveRecordSurvey::Node::Question.new()
|
9
|
-
@q1_a1 = ActiveRecordSurvey::Node::Answer::Boolean.new()
|
10
|
-
@q1_a2 = ActiveRecordSurvey::Node::Answer::Boolean.new()
|
11
|
-
@q1_a3 = ActiveRecordSurvey::Node::Answer::Boolean.new()
|
12
|
-
@q1_a4 = ActiveRecordSurvey::Node::Answer::Boolean.new()
|
13
|
-
@q1_a5 = ActiveRecordSurvey::Node::Answer::Boolean.new()
|
9
|
+
@q1_a1 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new()
|
10
|
+
@q1_a2 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new()
|
11
|
+
@q1_a3 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new()
|
12
|
+
@q1_a4 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new()
|
13
|
+
@q1_a5 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new()
|
14
14
|
|
15
15
|
@survey.build_question(@q1)
|
16
16
|
@q1.build_answer(@q1_a1, @survey)
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRecordSurvey::Node::Answer::Rank, :rank_spec => true do
|
3
|
+
describe ActiveRecordSurvey::Node::Answer::Chain::Rank, :rank_spec => true do
|
4
4
|
describe 'survey is' do
|
5
5
|
before(:all) do
|
6
6
|
@survey = ActiveRecordSurvey::Survey.new
|
7
7
|
|
8
8
|
@q1 = ActiveRecordSurvey::Node::Question.new()
|
9
|
-
@q1_a1 = ActiveRecordSurvey::Node::Answer::Rank.new()
|
10
|
-
@q1_a2 = ActiveRecordSurvey::Node::Answer::Rank.new()
|
11
|
-
@q1_a3 = ActiveRecordSurvey::Node::Answer::Rank.new()
|
12
|
-
@q1_a4 = ActiveRecordSurvey::Node::Answer::Rank.new()
|
13
|
-
@q1_a5 = ActiveRecordSurvey::Node::Answer::Rank.new()
|
9
|
+
@q1_a1 = ActiveRecordSurvey::Node::Answer::Chain::Rank.new()
|
10
|
+
@q1_a2 = ActiveRecordSurvey::Node::Answer::Chain::Rank.new()
|
11
|
+
@q1_a3 = ActiveRecordSurvey::Node::Answer::Chain::Rank.new()
|
12
|
+
@q1_a4 = ActiveRecordSurvey::Node::Answer::Chain::Rank.new()
|
13
|
+
@q1_a5 = ActiveRecordSurvey::Node::Answer::Chain::Rank.new()
|
14
14
|
|
15
15
|
@survey.build_question(@q1)
|
16
16
|
@q1.build_answer(@q1_a1, @survey)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRecordSurvey::Node::Answer::Scale, :scale_spec => true do
|
3
|
+
describe ActiveRecordSurvey::Node::Answer::Chain::Scale, :scale_spec => true do
|
4
4
|
describe 'survey is' do
|
5
5
|
before(:all) do
|
6
6
|
@survey = ActiveRecordSurvey::Survey.new
|
7
7
|
|
8
8
|
@q1 = ActiveRecordSurvey::Node::Question.new()
|
9
|
-
@q1_a1 = ActiveRecordSurvey::Node::Answer::Scale.new()
|
10
|
-
@q1_a2 = ActiveRecordSurvey::Node::Answer::Scale.new()
|
11
|
-
@q1_a3 = ActiveRecordSurvey::Node::Answer::Scale.new()
|
9
|
+
@q1_a1 = ActiveRecordSurvey::Node::Answer::Chain::Scale.new()
|
10
|
+
@q1_a2 = ActiveRecordSurvey::Node::Answer::Chain::Scale.new()
|
11
|
+
@q1_a3 = ActiveRecordSurvey::Node::Answer::Chain::Scale.new()
|
12
12
|
|
13
13
|
@survey.build_question(@q1)
|
14
14
|
@q1.build_answer(@q1_a1, @survey)
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveRecordSurvey::Node::Answer::Text, :text_spec => true do
|
3
|
+
describe ActiveRecordSurvey::Node::Answer::Chain::Text, :text_spec => true do
|
4
4
|
describe 'a text survey is' do
|
5
5
|
before(:all) do
|
6
6
|
@survey = ActiveRecordSurvey::Survey.new
|
7
7
|
|
8
8
|
@q1 = ActiveRecordSurvey::Node::Question.new()
|
9
|
-
@q1_a1 = ActiveRecordSurvey::Node::Answer::Text.new()
|
10
|
-
@q1_a2 = ActiveRecordSurvey::Node::Answer::Text.new()
|
9
|
+
@q1_a1 = ActiveRecordSurvey::Node::Answer::Chain::Text.new()
|
10
|
+
@q1_a2 = ActiveRecordSurvey::Node::Answer::Chain::Text.new()
|
11
11
|
|
12
12
|
@survey.build_question(@q1)
|
13
13
|
@q1.build_answer(@q1_a1)
|
@@ -109,11 +109,11 @@ describe ActiveRecordSurvey::Node::Question, :question_spec => true do
|
|
109
109
|
expect(@survey.node_maps.length).to eq(31)
|
110
110
|
|
111
111
|
@q5 = ActiveRecordSurvey::Node::Question.new(:text => "Question #5")
|
112
|
-
@q5_a1 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #1")
|
113
|
-
@q5_a2 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #2")
|
114
|
-
@q5_a3 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #3")
|
115
|
-
@q5_a4 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #4")
|
116
|
-
@q5_a5 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #5")
|
112
|
+
@q5_a1 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new(:text => "Q5 Answer #1")
|
113
|
+
@q5_a2 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new(:text => "Q5 Answer #2")
|
114
|
+
@q5_a3 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new(:text => "Q5 Answer #3")
|
115
|
+
@q5_a4 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new(:text => "Q5 Answer #4")
|
116
|
+
@q5_a5 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new(:text => "Q5 Answer #5")
|
117
117
|
# Boolean builds the links differently! - it chains them so there is no branching choice
|
118
118
|
@q5.build_answer(@q5_a1, @survey)
|
119
119
|
@q5.build_answer(@q5_a2, @survey)
|
@@ -135,7 +135,7 @@ describe ActiveRecordSurvey::Node::Question, :question_spec => true do
|
|
135
135
|
|
136
136
|
expect(@survey.node_maps.length).to eq(74)
|
137
137
|
|
138
|
-
expect(@survey.as_map.as_json).to eq([{"text"=>"Question #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q1 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q2 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q2 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}, {"text"=>"Q1 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q1 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}]}])
|
138
|
+
expect(@survey.as_map.as_json).to eq([{"text"=>"Question #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q1 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q2 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q2 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}, {"text"=>"Q1 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q1 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}]}])
|
139
139
|
|
140
140
|
# Cannot build a link when a link already exists
|
141
141
|
expect { @q1_a2.build_link(@q2) }.to raise_error RuntimeError
|
@@ -143,11 +143,11 @@ describe ActiveRecordSurvey::Node::Question, :question_spec => true do
|
|
143
143
|
# Remove the link
|
144
144
|
@q1_a2.remove_link
|
145
145
|
|
146
|
-
expect(@survey.as_map.as_json).to eq([{"text"=>"Question #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q1 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q2 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q2 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}, {"text"=>"Q1 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q1 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}]}, {"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}])
|
146
|
+
expect(@survey.as_map.as_json).to eq([{"text"=>"Question #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q1 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q2 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q2 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}, {"text"=>"Q1 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q1 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}]}, {"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}])
|
147
147
|
|
148
148
|
@q1_a2.build_link(@q3)
|
149
149
|
|
150
|
-
expect(@survey.as_map.as_json).to eq([{"text"=>"Question #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q1 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q2 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q2 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}, {"text"=>"Q1 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q1 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Boolean", "children"=>[]}]}]}]}]}]}]}]}])
|
150
|
+
expect(@survey.as_map.as_json).to eq([{"text"=>"Question #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q1 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q2 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q2 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q3 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q3 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}]}]}, {"text"=>"Q1 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q4 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}, {"text"=>"Q4 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[]}]}]}, {"text"=>"Q1 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer", "children"=>[{"text"=>"Question #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Question", "children"=>[{"text"=>"Q5 Answer #1", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #2", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #3", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #4", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[{"text"=>"Q5 Answer #5", "id"=>nil, "node_id"=>nil, "type"=>"ActiveRecordSurvey::Node::Answer::Chain::Boolean", "children"=>[]}]}]}]}]}]}]}]}])
|
151
151
|
end
|
152
152
|
end
|
153
153
|
end
|
@@ -33,8 +33,8 @@ module FactoryGirlSurveyHelpers
|
|
33
33
|
|
34
34
|
q5 = ActiveRecordSurvey::Node::Question.new(:text => "Q5 Boolean")
|
35
35
|
survey.build_question(q5)
|
36
|
-
q5_a1 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 A1")
|
37
|
-
q5_a2 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 A2")
|
36
|
+
q5_a1 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new(:text => "Q5 A1")
|
37
|
+
q5_a2 = ActiveRecordSurvey::Node::Answer::Chain::Boolean.new(:text => "Q5 A2")
|
38
38
|
q5.build_answer(q5_a1)
|
39
39
|
q5.build_answer(q5_a2)
|
40
40
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Butch Marshall
|
@@ -145,10 +145,11 @@ files:
|
|
145
145
|
- lib/active_record_survey/instance_node.rb
|
146
146
|
- lib/active_record_survey/node.rb
|
147
147
|
- lib/active_record_survey/node/answer.rb
|
148
|
-
- lib/active_record_survey/node/answer/
|
149
|
-
- lib/active_record_survey/node/answer/
|
150
|
-
- lib/active_record_survey/node/answer/
|
151
|
-
- lib/active_record_survey/node/answer/
|
148
|
+
- lib/active_record_survey/node/answer/chain.rb
|
149
|
+
- lib/active_record_survey/node/answer/chain/boolean.rb
|
150
|
+
- lib/active_record_survey/node/answer/chain/rank.rb
|
151
|
+
- lib/active_record_survey/node/answer/chain/scale.rb
|
152
|
+
- lib/active_record_survey/node/answer/chain/text.rb
|
152
153
|
- lib/active_record_survey/node/question.rb
|
153
154
|
- lib/active_record_survey/node_map.rb
|
154
155
|
- lib/active_record_survey/node_validation.rb
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module ActiveRecordSurvey
|
2
|
-
# Boolean answers can have values 0|1
|
3
|
-
class Node::Answer::Boolean < Node::Answer
|
4
|
-
# Only boolean values
|
5
|
-
def validate_instance_node(instance_node)
|
6
|
-
# super - all validations on this node pass
|
7
|
-
super &&
|
8
|
-
!instance_node.value.to_s.match(/^[0|1]$/).nil?
|
9
|
-
end
|
10
|
-
|
11
|
-
# Boolean answers are considered answered if they have a value of "1"
|
12
|
-
def is_answered_for_instance?(instance)
|
13
|
-
if instance_node = self.instance_node_for_instance(instance)
|
14
|
-
# Instance node is answered "1"
|
15
|
-
(instance_node.value.to_i === 1)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Boolean nodes are different - they must find the final boolean node added and add to it
|
20
|
-
def build_answer(question_node, survey)
|
21
|
-
# No node_maps exist yet from this question
|
22
|
-
if question_node.node_maps.length === 0
|
23
|
-
# Build our first node-map
|
24
|
-
question_node.node_maps.build(:node => question_node, :survey => survey)
|
25
|
-
end
|
26
|
-
|
27
|
-
last_in_chain = question_node.answers.last || question_node
|
28
|
-
|
29
|
-
# Each instance of this question needs the answer hung from it
|
30
|
-
last_in_chain.node_maps.each { |node_map|
|
31
|
-
answer_node_map = self.node_maps.build(:node => self, :survey => survey)
|
32
|
-
node_map.children << answer_node_map
|
33
|
-
}
|
34
|
-
|
35
|
-
true
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module ActiveRecordSurvey
|
2
|
-
# Can hold a value on a scale (e.g. from 0-10)
|
3
|
-
class Node::Answer::Scale < Node::Answer
|
4
|
-
# Accept integer, float, or empty values
|
5
|
-
def validate_instance_node(instance_node)
|
6
|
-
# super - all validations on this node pass
|
7
|
-
super &&
|
8
|
-
(instance_node.value.to_s.empty? || !instance_node.value.to_s.match(/^(\d+(\.\d+)?)$/).nil?)
|
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
|
20
|
-
|
21
|
-
# Scale nodes are different - they must find the final scale node added and add to it
|
22
|
-
def build_answer(question_node, survey)
|
23
|
-
# No node_maps exist yet from this question
|
24
|
-
if question_node.node_maps.length === 0
|
25
|
-
# Build our first node-map
|
26
|
-
question_node.node_maps.build(:node => question_node, :survey => survey)
|
27
|
-
end
|
28
|
-
|
29
|
-
last_in_chain = question_node.answers.last || question_node
|
30
|
-
|
31
|
-
# Each instance of this question needs the answer hung from it
|
32
|
-
last_in_chain.node_maps.each { |node_map|
|
33
|
-
answer_node_map = self.node_maps.build(:node => self, :survey => survey)
|
34
|
-
node_map.children << answer_node_map
|
35
|
-
}
|
36
|
-
|
37
|
-
true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|