active_record_survey 0.1.34 → 0.1.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26eecc198f8c314ac2a23e3f746dcc823acb9720
4
- data.tar.gz: 1e7076165aff517190a7e0f45b804d6b0fa0e93d
3
+ metadata.gz: e024c72de4b41b4e3937d465726d0110cadbcf83
4
+ data.tar.gz: 41352a433cb8b8a6b8f0d8779c7ce8ced446cc4a
5
5
  SHA512:
6
- metadata.gz: e4a76741e270ffcec64140526bf6467f40a82e55126c73796f357936a1e7a4a7085f07c662b71a24b4dc5dfcd340cdde9b61bff721aebe2b8a6f17496dcc4554
7
- data.tar.gz: ae0b50818d46601fce209a7452b311bfcbd962e27c4ebbd4213254bb3b2b0a5b2504d9b54b80c0073a3db5116bf2be17686e6fe9c765083400637fed1cdbdce0
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
- node_map.children << self.survey.node_maps.build(:node => self, :survey => self.survey)
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,3 +1,3 @@
1
1
  module ActiveRecordSurvey
2
- VERSION = "0.1.34"
2
+ VERSION = "0.1.35"
3
3
  end
@@ -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()
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.34
4
+ version: 0.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Butch Marshall