active_record_survey 0.1.34 → 0.1.35
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e024c72de4b41b4e3937d465726d0110cadbcf83
|
4
|
+
data.tar.gz: 41352a433cb8b8a6b8f0d8779c7ce8ced446cc4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f70aea6ac4dd79b3ff9e6b6b97096ca52ea839d6241b39aaef8740ad5ec91d1f9ce18fa7acd5fe5ce7ff5db1657b10586b2effa4fa1a1c7a0f8fca3d89b65a5
|
7
|
+
data.tar.gz: 77f86f2a2b516981e85cff63cd97bd2fb570cf7014c241894774c6c5a7ff0330fcbcbf226d93b1b02215e40b4b54ffc1c9f26450134c55b46843b93addcfb789
|
@@ -20,6 +20,7 @@ module ActiveRecordSurvey
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# Chain nodes are different - they must find the final answer node added and add to it
|
23
|
+
# They must also see if the final answer node then points somewhere else - and fix the links on that
|
23
24
|
def build_answer(question_node)
|
24
25
|
self.survey = question_node.survey
|
25
26
|
|
@@ -37,7 +38,17 @@ module ActiveRecordSurvey
|
|
37
38
|
self.survey.node_maps.select { |i|
|
38
39
|
i.node == last_answer_in_chain
|
39
40
|
}.each { |node_map|
|
40
|
-
|
41
|
+
curr_children = self.survey.node_maps.select { |j|
|
42
|
+
node_map.children.include?(j)
|
43
|
+
}
|
44
|
+
|
45
|
+
new_node_map = self.survey.node_maps.build(:node => self, :survey => self.survey)
|
46
|
+
|
47
|
+
node_map.children << new_node_map
|
48
|
+
|
49
|
+
curr_children.each { |c|
|
50
|
+
new_node_map.children << c
|
51
|
+
}
|
41
52
|
}
|
42
53
|
|
43
54
|
true
|
@@ -1,6 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveRecordSurvey::Node::Answer::Boolean, :boolean_spec => true do
|
4
|
+
describe '#build_answer' do
|
5
|
+
before(:each) do
|
6
|
+
@survey = ActiveRecordSurvey::Survey.new()
|
7
|
+
@q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => @survey)
|
8
|
+
@q1_a1 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q1 Answer #1")
|
9
|
+
@q1_a2 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q1 Answer #2")
|
10
|
+
@q1_a3 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q1 Answer #3")
|
11
|
+
@q1.build_answer(@q1_a1)
|
12
|
+
@q1.build_answer(@q1_a2)
|
13
|
+
@q1.build_answer(@q1_a3)
|
14
|
+
|
15
|
+
@q2 = ActiveRecordSurvey::Node::Question.new(:text => "Question #2", :survey => @survey)
|
16
|
+
@q2_a1 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q2 Answer #1")
|
17
|
+
@q2_a2 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q2 Answer #2")
|
18
|
+
@q2_a3 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q2 Answer #3")
|
19
|
+
@q2.build_answer(@q2_a1)
|
20
|
+
@q2.build_answer(@q2_a2)
|
21
|
+
@q2.build_answer(@q2_a3)
|
22
|
+
|
23
|
+
@q1_a3.build_link(@q2)
|
24
|
+
|
25
|
+
@survey.save
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should append to last answer and fix chain to next question' do
|
29
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q2 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}]}]}]}]}])
|
30
|
+
|
31
|
+
@q1_a4 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q2 Answer #4")
|
32
|
+
@q1.build_answer(@q1_a4)
|
33
|
+
|
34
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q2 Answer #4", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q2 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}]}]}]}]}]}])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
4
38
|
describe '#sibling_index' do
|
5
39
|
before(:each) do
|
6
40
|
@survey = ActiveRecordSurvey::Survey.new()
|