active_record_survey 0.1.25 → 0.1.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,15 +5,14 @@ describe ActiveRecordSurvey::Node::Answer::Scale, :scale_spec => true do
5
5
  before(:all) do
6
6
  @survey = ActiveRecordSurvey::Survey.new
7
7
 
8
- @q1 = ActiveRecordSurvey::Node::Question.new()
8
+ @q1 = ActiveRecordSurvey::Node::Question.new(:survey => @survey)
9
9
  @q1_a1 = ActiveRecordSurvey::Node::Answer::Scale.new()
10
10
  @q1_a2 = ActiveRecordSurvey::Node::Answer::Scale.new()
11
11
  @q1_a3 = ActiveRecordSurvey::Node::Answer::Scale.new()
12
12
 
13
- @survey.build_question(@q1)
14
- @q1.build_answer(@q1_a1, @survey)
15
- @q1.build_answer(@q1_a2, @survey)
16
- @q1.build_answer(@q1_a3, @survey)
13
+ @q1.build_answer(@q1_a1)
14
+ @q1.build_answer(@q1_a2)
15
+ @q1.build_answer(@q1_a3)
17
16
 
18
17
  @survey.save
19
18
  end
@@ -5,11 +5,10 @@ describe ActiveRecordSurvey::Node::Answer::Text, :text_spec => true do
5
5
  before(:all) do
6
6
  @survey = ActiveRecordSurvey::Survey.new
7
7
 
8
- @q1 = ActiveRecordSurvey::Node::Question.new()
8
+ @q1 = ActiveRecordSurvey::Node::Question.new(:survey => @survey)
9
9
  @q1_a1 = ActiveRecordSurvey::Node::Answer::Text.new()
10
10
  @q1_a2 = ActiveRecordSurvey::Node::Answer::Text.new()
11
11
 
12
- @survey.build_question(@q1)
13
12
  @q1.build_answer(@q1_a1)
14
13
  @q1.build_answer(@q1_a2)
15
14
 
@@ -1,6 +1,61 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
4
+ describe "#build_link" do
5
+ it 'should not have to be saved to produce a valid #as_map' do
6
+ survey = ActiveRecordSurvey::Survey.new()
7
+ q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => survey)
8
+ q1_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #1")
9
+ q1_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #2")
10
+ q1_a3 = ActiveRecordSurvey::Node::Answer.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.new(:text => "Q2 Answer #1")
17
+ q2_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 Answer #2")
18
+ q2.build_answer(q2_a1)
19
+ q2.build_answer(q2_a2)
20
+
21
+ q1_a1.build_link(q2)
22
+
23
+ expect(survey.node_maps.length).to eq(7)
24
+ expect(survey.as_map).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"=>"Q2 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=>[]}]}])
25
+
26
+ q3 = ActiveRecordSurvey::Node::Question.new(:text => "Q3", :survey => survey)
27
+ q3_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 A1")
28
+ q3_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 A2")
29
+ q3.build_answer(q3_a1)
30
+ q3.build_answer(q3_a2)
31
+
32
+ q1_a2.build_link(q3)
33
+
34
+ expect(survey.node_maps.length).to eq(10)
35
+ expect(survey.as_map).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"=>"Q2 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"=>"Q3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q3 A2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q1 Answer #3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
36
+
37
+ q4 = ActiveRecordSurvey::Node::Question.new(:text => "Q4", :survey => survey)
38
+ q4_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q4 A1")
39
+ q4_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q4 A2")
40
+ q4.build_answer(q4_a1)
41
+ q4.build_answer(q4_a2)
42
+
43
+ # Link up Q1
44
+ q1_a3.build_link(q4)
45
+ expect(survey.node_maps.length).to eq(13)
46
+ expect(survey.as_map).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"=>"Q2 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"=>"Q3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q3 A2", :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"=>"Q4", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 A2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}])
47
+
48
+ # Link up Q2
49
+ q2_a1.build_link(q4)
50
+ q2_a2.build_link(q3)
51
+
52
+ # Link up Q3
53
+ q3_a1.build_link(q4)
54
+ q3_a2.build_link(q4)
55
+ expect(survey.as_map).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"=>"Q4", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 A2", :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"=>"Q3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q4", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 A2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 A2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q4", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 A2", :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"=>"Q3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q4", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 A2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 A2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q4", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 A2", :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"=>"Q4", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 A2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}])
56
+ end
57
+ end
58
+
4
59
  describe 'a survey' do
5
60
  before(:each) do
6
61
  @survey = FactoryGirl.build(:basic_survey)
@@ -11,18 +66,15 @@ describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
11
66
  it 'should throw error when build_link creates an infinite loop' do
12
67
  survey = ActiveRecordSurvey::Survey.new()
13
68
 
14
- q1 = ActiveRecordSurvey::Node::Question.new(:text => "Q1")
15
- survey.build_question(q1)
69
+ q1 = ActiveRecordSurvey::Node::Question.new(:text => "Q1", :survey => survey)
16
70
  q1_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 A1")
17
71
  q1.build_answer(q1_a1)
18
72
 
19
- q2 = ActiveRecordSurvey::Node::Question.new(:text => "Q2")
20
- survey.build_question(q2)
73
+ q2 = ActiveRecordSurvey::Node::Question.new(:text => "Q2", :survey => survey)
21
74
  q2_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 A1")
22
75
  q2.build_answer(q2_a1)
23
76
 
24
- q3 = ActiveRecordSurvey::Node::Question.new(:text => "Q3")
25
- survey.build_question(q3)
77
+ q3 = ActiveRecordSurvey::Node::Question.new(:text => "Q3", :survey => survey)
26
78
  q3_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 A1")
27
79
  q3.build_answer(q3_a1)
28
80
 
@@ -34,16 +86,20 @@ describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
34
86
  it 'should keep consistent number of nodes after calling #remove_link and #build_link', :focus => true do
35
87
  survey = FactoryGirl.build(:simple_survey)
36
88
  survey.save
37
- q = ActiveRecordSurvey::Node::Question.new(:text => "Question Linkable")
38
- survey.build_question(q)
89
+
90
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(31)
91
+
92
+ q = survey.questions.build(:type => "ActiveRecordSurvey::Node::Question", :text => "Question Linkable", :survey => survey)
39
93
  q_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Question Linkable Answer #1")
40
94
  q_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Question Linkable Answer #2")
41
95
  q.build_answer(q_a1)
42
96
  q.build_answer(q_a2)
43
- survey.save
97
+
98
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(34)
44
99
 
45
100
  # Find Q4 Answer #2
46
101
  q4_a2 = nil
102
+
47
103
  survey.questions.each { |q|
48
104
  if q.text == "Question #4"
49
105
  q.answers.each { |a|
@@ -52,58 +108,71 @@ describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
52
108
  end
53
109
  }
54
110
 
55
- survey.reload
56
- expect(survey.node_maps.length).to eq(34)
57
-
111
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(34)
58
112
  q4_a2.build_link(q)
59
- q4_a2.save
113
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(49)
114
+ 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", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}])
115
+
116
+ survey.save
117
+ 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", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}])
118
+
119
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(49)
60
120
  survey.reload
61
- expect(survey.node_maps.length).to eq(49)
121
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(49)
122
+ 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", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}])
62
123
 
63
124
  q4_a2.remove_link
64
- q4_a2.save
125
+
126
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(34)
127
+ 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", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}, {"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
128
+
129
+ survey.save
65
130
  survey.reload
66
- expect(survey.node_maps.length).to eq(34)
67
131
 
68
- q.reload # This is needed - won't build properly... its wierd... gotta fix this
132
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(34)
133
+ 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", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}, {"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
134
+
69
135
  q4_a2.build_link(q)
136
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(49)
137
+ 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", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}])
70
138
 
71
- q4_a2.save
139
+ survey.save
72
140
  survey.reload
73
- expect(survey.node_maps.length).to eq(49)
141
+
142
+ expect(survey.node_maps.select { |i| !i.marked_for_destruction? }.length).to eq(49)
143
+ 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", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question Linkable", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question Linkable Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Question Linkable Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}])
74
144
  end
75
145
 
76
146
  it 'should be allowed before saving after calling #remove_link' do
77
147
  survey = ActiveRecordSurvey::Survey.new()
78
148
 
79
- q1 = ActiveRecordSurvey::Node::Question.new(:text => "Q1")
80
- survey.build_question(q1)
149
+ q1 = ActiveRecordSurvey::Node::Question.new(:text => "Q1", :survey => survey)
81
150
  q1_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 A1")
82
151
  q1.build_answer(q1_a1)
83
152
 
84
- q2 = ActiveRecordSurvey::Node::Question.new(:text => "Q2")
85
- survey.build_question(q2)
86
- q3 = ActiveRecordSurvey::Node::Question.new(:text => "Q3")
87
- survey.build_question(q3)
153
+ q2 = ActiveRecordSurvey::Node::Question.new(:text => "Q2", :survey => survey)
154
+ q3 = ActiveRecordSurvey::Node::Question.new(:text => "Q3", :survey => survey)
88
155
 
89
- expect(survey.as_map).to eq([{"text"=>"Q1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}, {"text"=>"Q2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}, {"text"=>"Q3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
156
+ expect(survey.as_map).to eq([{"text"=>"Q1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
90
157
 
91
158
  q1_a1.build_link(q2)
92
159
  expect(q1_a1.next_question).to eq(q2)
93
- expect(survey.as_map).to eq([{"text"=>"Q1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}]}, {"text"=>"Q3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
160
+
161
+ expect(survey.as_map).to eq([{"text"=>"Q1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}]}])
94
162
 
95
163
  q1_a1.remove_link
96
164
  expect(q1_a1.next_question).to eq(nil)
97
- expect(survey.as_map).to eq([{"text"=>"Q1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}, {"text"=>"Q2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}, {"text"=>"Q3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
165
+
166
+ expect(survey.as_map).to eq([{"text"=>"Q1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}, {"text"=>"Q2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
98
167
 
99
168
  q1_a1.build_link(q3)
100
169
  expect(q1_a1.next_question).to eq(q3)
101
170
  expect(survey.as_map).to eq([{"text"=>"Q1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q3", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}]}, {"text"=>"Q2", :id=>nil, :node_id=>nil, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
102
171
 
103
172
  survey.save
104
- expect(survey.as_map).to eq([{"text"=>"Q1", :id=>339, :node_id=>93, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>340, :node_id=>94, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q3", :id=>341, :node_id=>95, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}]}, {"text"=>"Q2", :id=>342, :node_id=>96, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
173
+ expect(survey.as_map(:no_ids => true)).to eq([{"text"=>"Q1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}]}, {"text"=>"Q2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
105
174
  survey.reload
106
- expect(survey.as_map).to eq([{"text"=>"Q1", :id=>339, :node_id=>93, :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :id=>340, :node_id=>94, :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q3", :id=>341, :node_id=>95, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}]}, {"text"=>"Q2", :id=>342, :node_id=>96, :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
175
+ expect(survey.as_map(:no_ids => true)).to eq([{"text"=>"Q1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 A1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Q3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}]}, {"text"=>"Q2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}])
107
176
  end
108
177
  end
109
178
 
@@ -153,20 +222,39 @@ describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
153
222
 
154
223
  describe '#next_question' do
155
224
  it 'should get the next question' do
156
- expected = [
157
- ["Q1 A1 -> Q2", "Q1 A2 -> Q3", "Q1 A3 -> Q4"],
158
- ["Q2 A1 -> Q4", "Q2 A2 -> Q3"],
159
- ["Q4 A1 -> Q6", "Q4 A2 -> Q5 Boolean"],
160
- ["Q6 A1 -> ", "Q6 A2 -> "],
161
- ["Q3 A1 -> Q4", "Q3 A2 -> Q4"],
162
- ["Q5 A1 -> Q6", "Q5 A2 -> Q6"],
163
- ]
225
+ expected = {
226
+ "Q1" => {
227
+ "Q1 A1" => "Q2",
228
+ "Q1 A2" => "Q3",
229
+ "Q1 A3" => "Q4",
230
+ },
231
+ "Q2" => {
232
+ "Q2 A1" => "Q4",
233
+ "Q2 A2" => "Q3",
234
+ },
235
+ "Q3" => {
236
+ "Q3 A1" => "Q4",
237
+ "Q3 A2" => "Q4",
238
+ },
239
+ "Q4" => {
240
+ "Q4 A1" => "Q6",
241
+ "Q4 A2" => "Q5 Boolean",
242
+ },
243
+ "Q5 Boolean" => {
244
+ "Q5 A1" => "Q6",
245
+ "Q5 A2" => "Q6",
246
+ },
247
+ "Q6" => {
248
+ "Q6 A1" => "",
249
+ "Q6 A2" => ""
250
+ }
251
+ }
164
252
 
165
253
  @survey.questions.each_with_index { |question, question_index|
166
254
  question.answers.each_with_index { |answer, answer_index|
167
- actual = "#{answer.text} -> #{((answer.next_question)? answer.next_question.text : '')}"
255
+ next_question_text = "#{((answer.next_question)? answer.next_question.text : '')}"
168
256
 
169
- expect(actual).to eq(expected[question_index][answer_index])
257
+ expect(next_question_text).to eq(expected[question.text][answer.text.to_s])
170
258
  }
171
259
  }
172
260
  end
@@ -1,35 +1,80 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveRecordSurvey::Node::Question, :question_spec => true do
4
+ describe "#build_answer" do
5
+ before(:each) do
6
+ @survey = ActiveRecordSurvey::Survey.new()
7
+ @q = ActiveRecordSurvey::Node::Question.new(:text => "Q")
8
+ @a1 = ActiveRecordSurvey::Node::Answer.new(:text => "A1")
9
+ @a2 = ActiveRecordSurvey::Node::Answer.new(:text => "A2")
10
+ end
11
+
12
+ describe 'when invalid' do
13
+ it 'should raise ArgumentError if survey not linked to question' do
14
+ expect{@q.build_answer(@a1)}.to raise_error(ArgumentError)
15
+ end
16
+ end
17
+
18
+ describe 'when valid' do
19
+ before(:each) do
20
+ @q.survey = @survey
21
+ end
22
+ it 'should return true if successful' do
23
+ expect(@q.build_answer(@a1)).to eq(true)
24
+ end
25
+ it 'should link the question to the answer' do
26
+ expect(@q.answers.length).to eq(0)
27
+ @q.build_answer(@a1)
28
+ expect(@q.answers.length).to eq(1)
29
+ expect(@q.answers.first).to eq(@a1)
30
+
31
+ expect(@survey.node_maps.length).to eq(2)
32
+ end
33
+ it 'should work for multiple answers' do
34
+ expect(@q.answers.length).to eq(0)
35
+
36
+ @q.build_answer(@a1)
37
+ expect(@q.answers.length).to eq(1)
38
+ expect(@q.answers.first).to eq(@a1)
39
+
40
+ @q.build_answer(@a2)
41
+ expect(@q.answers.length).to eq(2)
42
+ expect(@q.answers.last).to eq(@a2)
43
+
44
+ expect(@survey.node_maps.length).to eq(3)
45
+ end
46
+ end
47
+ end
48
+
4
49
  describe 'a survey' do
5
50
  before(:all) do
6
51
  @survey = ActiveRecordSurvey::Survey.new()
7
52
 
8
- @q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1")
53
+ @q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => @survey)
9
54
  @q1_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #1")
10
55
  @q1_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #2")
11
56
  @q1_a3 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #3")
12
- @q1.build_answer(@q1_a1, @survey)
13
- @q1.build_answer(@q1_a2, @survey)
14
- @q1.build_answer(@q1_a3, @survey)
57
+ @q1.build_answer(@q1_a1)
58
+ @q1.build_answer(@q1_a2)
59
+ @q1.build_answer(@q1_a3)
15
60
 
16
- @q2 = ActiveRecordSurvey::Node::Question.new(:text => "Question #2")
61
+ @q2 = ActiveRecordSurvey::Node::Question.new(:text => "Question #2", :survey => @survey)
17
62
  @q2_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 Answer #1")
18
63
  @q2_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 Answer #2")
19
- @q2.build_answer(@q2_a1, @survey)
20
- @q2.build_answer(@q2_a2, @survey)
64
+ @q2.build_answer(@q2_a1)
65
+ @q2.build_answer(@q2_a2)
21
66
 
22
- @q3 = ActiveRecordSurvey::Node::Question.new(:text => "Question #3")
67
+ @q3 = ActiveRecordSurvey::Node::Question.new(:text => "Question #3", :survey => @survey)
23
68
  @q3_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 Answer #1")
24
69
  @q3_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 Answer #2")
25
- @q3.build_answer(@q3_a1, @survey)
26
- @q3.build_answer(@q3_a2, @survey)
70
+ @q3.build_answer(@q3_a1)
71
+ @q3.build_answer(@q3_a2)
27
72
 
28
- @q4 = ActiveRecordSurvey::Node::Question.new(:text => "Question #4")
73
+ @q4 = ActiveRecordSurvey::Node::Question.new(:text => "Question #4", :survey => @survey)
29
74
  @q4_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q4 Answer #1")
30
75
  @q4_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q4 Answer #2")
31
- @q4.build_answer(@q4_a1, @survey)
32
- @q4.build_answer(@q4_a2, @survey)
76
+ @q4.build_answer(@q4_a1)
77
+ @q4.build_answer(@q4_a2)
33
78
 
34
79
  # Link up Q1
35
80
  @q1_a1.build_link(@q2)
@@ -61,31 +106,31 @@ describe ActiveRecordSurvey::Node::Question, :question_spec => true do
61
106
  it 'should have the right number of node maps' do
62
107
  @survey = ActiveRecordSurvey::Survey.new()
63
108
 
64
- @q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1")
109
+ @q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => @survey)
65
110
  @q1_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #1")
66
111
  @q1_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #2")
67
112
  @q1_a3 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #3")
68
- @q1.build_answer(@q1_a1, @survey)
69
- @q1.build_answer(@q1_a2, @survey)
70
- @q1.build_answer(@q1_a3, @survey)
113
+ @q1.build_answer(@q1_a1)
114
+ @q1.build_answer(@q1_a2)
115
+ @q1.build_answer(@q1_a3)
71
116
 
72
- @q2 = ActiveRecordSurvey::Node::Question.new(:text => "Question #2")
117
+ @q2 = ActiveRecordSurvey::Node::Question.new(:text => "Question #2", :survey => @survey)
73
118
  @q2_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 Answer #1")
74
119
  @q2_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 Answer #2")
75
- @q2.build_answer(@q2_a1, @survey)
76
- @q2.build_answer(@q2_a2, @survey)
120
+ @q2.build_answer(@q2_a1)
121
+ @q2.build_answer(@q2_a2)
77
122
 
78
- @q3 = ActiveRecordSurvey::Node::Question.new(:text => "Question #3")
123
+ @q3 = ActiveRecordSurvey::Node::Question.new(:text => "Question #3", :survey => @survey)
79
124
  @q3_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 Answer #1")
80
125
  @q3_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 Answer #2")
81
- @q3.build_answer(@q3_a1, @survey)
82
- @q3.build_answer(@q3_a2, @survey)
126
+ @q3.build_answer(@q3_a1)
127
+ @q3.build_answer(@q3_a2)
83
128
 
84
- @q4 = ActiveRecordSurvey::Node::Question.new(:text => "Question #4")
129
+ @q4 = ActiveRecordSurvey::Node::Question.new(:text => "Question #4", :survey => @survey)
85
130
  @q4_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q4 Answer #1")
86
131
  @q4_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q4 Answer #2")
87
- @q4.build_answer(@q4_a1, @survey)
88
- @q4.build_answer(@q4_a2, @survey)
132
+ @q4.build_answer(@q4_a1)
133
+ @q4.build_answer(@q4_a2)
89
134
 
90
135
  expect(@survey.node_maps.length).to eq(13)
91
136
 
@@ -108,26 +153,26 @@ describe ActiveRecordSurvey::Node::Question, :question_spec => true do
108
153
 
109
154
  expect(@survey.node_maps.length).to eq(31)
110
155
 
111
- @q5 = ActiveRecordSurvey::Node::Question.new(:text => "Question #5")
156
+ @q5 = ActiveRecordSurvey::Node::Question.new(:text => "Question #5", :survey => @survey)
112
157
  @q5_a1 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #1")
113
158
  @q5_a2 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #2")
114
159
  @q5_a3 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #3")
115
160
  @q5_a4 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #4")
116
161
  @q5_a5 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "Q5 Answer #5")
117
162
  # Boolean builds the links differently! - it chains them so there is no branching choice
118
- @q5.build_answer(@q5_a1, @survey)
119
- @q5.build_answer(@q5_a2, @survey)
120
- @q5.build_answer(@q5_a3, @survey)
121
- @q5.build_answer(@q5_a4, @survey)
122
- @q5.build_answer(@q5_a5, @survey)
163
+ @q5.build_answer(@q5_a1)
164
+ @q5.build_answer(@q5_a2)
165
+ @q5.build_answer(@q5_a3)
166
+ @q5.build_answer(@q5_a4)
167
+ @q5.build_answer(@q5_a5)
123
168
 
124
169
  @q4_a1.build_link(@q5)
125
170
 
126
171
  expect(@survey.node_maps.length).to eq(67)
127
172
 
128
173
  # Now - add an extra answer to Q1
129
- @q1_a4 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #4")
130
- @q1.build_answer(@q1_a4, @survey)
174
+ @q1_a4 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #4", :survey => @survey)
175
+ @q1.build_answer(@q1_a4)
131
176
 
132
177
  expect(@survey.node_maps.length).to eq(68)
133
178
 
@@ -5,31 +5,31 @@ describe ActiveRecordSurvey::Survey, :survey_spec => true do
5
5
  before(:all) do
6
6
  @survey = ActiveRecordSurvey::Survey.new()
7
7
 
8
- @q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1")
8
+ @q1 = @survey.questions.build(:type => "ActiveRecordSurvey::Node::Question", :text => "Question #1", :survey => @survey)
9
9
  @q1_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #1")
10
10
  @q1_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #2")
11
11
  @q1_a3 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 Answer #3")
12
- @q1.build_answer(@q1_a1, @survey)
13
- @q1.build_answer(@q1_a2, @survey)
14
- @q1.build_answer(@q1_a3, @survey)
12
+ @q1.build_answer(@q1_a1)
13
+ @q1.build_answer(@q1_a2)
14
+ @q1.build_answer(@q1_a3)
15
15
 
16
- @q2 = ActiveRecordSurvey::Node::Question.new(:text => "Question #2")
16
+ @q2 = @survey.questions.build(:type => "ActiveRecordSurvey::Node::Question", :text => "Question #2", :survey => @survey)
17
17
  @q2_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 Answer #1")
18
18
  @q2_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 Answer #2")
19
- @q2.build_answer(@q2_a1, @survey)
20
- @q2.build_answer(@q2_a2, @survey)
19
+ @q2.build_answer(@q2_a1)
20
+ @q2.build_answer(@q2_a2)
21
21
 
22
- @q3 = ActiveRecordSurvey::Node::Question.new(:text => "Question #3")
22
+ @q3 = @survey.questions.build(:type => "ActiveRecordSurvey::Node::Question", :text => "Question #3", :survey => @survey)
23
23
  @q3_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 Answer #1")
24
24
  @q3_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 Answer #2")
25
- @q3.build_answer(@q3_a1, @survey)
26
- @q3.build_answer(@q3_a2, @survey)
25
+ @q3.build_answer(@q3_a1)
26
+ @q3.build_answer(@q3_a2)
27
27
 
28
- @q4 = ActiveRecordSurvey::Node::Question.new(:text => "Question #4")
28
+ @q4 = @survey.questions.build(:type => "ActiveRecordSurvey::Node::Question", :text => "Question #4", :survey => @survey)
29
29
  @q4_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q4 Answer #1")
30
30
  @q4_a2 = ActiveRecordSurvey::Node::Answer.new(:text => "Q4 Answer #2")
31
- @q4.build_answer(@q4_a1, @survey)
32
- @q4.build_answer(@q4_a2, @survey)
31
+ @q4.build_answer(@q4_a1)
32
+ @q4.build_answer(@q4_a2)
33
33
 
34
34
  # Link up Q1
35
35
  @q1_a1.build_link(@q2)