active_record_survey 0.1.19 → 0.1.20

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: 316776fa0f2de65dad54cffc746342a4177bd0f8
4
- data.tar.gz: da2a911ee4f3c17b012d6105b3d30514750934e2
3
+ metadata.gz: 36c2b2fd8de15c342720cd4da180be5ebf361d91
4
+ data.tar.gz: 476f142713f229b16cb5156ea7d8120f81c8eeec
5
5
  SHA512:
6
- metadata.gz: 1ea0702079cf83209dd6178b146d451eac4de35fc20eb9cc65f57c3fdc6129457c410bbcfbd323bfc2f20b9a9e31a47c90990f372668d64fdbecacb82223c089
7
- data.tar.gz: 65812f918dbc7061afff46083d6d419c18a0100ba7f98c1b58654bc8e11efe8b01a4d180860976f5f0beb1d365ee9060f8ede43bed37b71401817ebd11aa7919
6
+ metadata.gz: cae260e84326b7ecd9d20d36f548353fd57700f59426e731a53dff50b3a8987c2159147bee8100cc5817cc5757be03cdcd0a0f06e1aeb677789d3f92386bd343
7
+ data.tar.gz: d8b145292eee0814beef6723de523938fa2ece558fa8fda76803b1fdd700a699990f1bad25fb2c0ae13119b873bde5d86d48c662b103ae4b2964d8c9290be3e1
@@ -62,22 +62,33 @@ module ActiveRecordSurvey
62
62
  def remove_link
63
63
  @ancestor_marked_for_destruction ||= []
64
64
 
65
+ # Go through the answers node_maps
65
66
  self.node_maps.each_with_index { |answer_node_map, answer_node_map_index|
66
- answer_node_map.children.each_with_index { |child, child_index|
67
- # child.node == question this answer is pointing to
68
- child.node.node_maps.each_with_index { |i,ii|
67
+ # Go through all the node_maps this answers node map is linked to
68
+ # a.k.a all the questions node maps
69
+ answer_node_map.children = answer_node_map.children.select { |child|
70
+ node_map_removed = false
71
+ # TODO - clean up this logic to be easier to follow
72
+ # The question can be linked to from more than one answer!
73
+ # If this is the case, we *don'tz* want to leave one last node_map hanging out - we can destroy them all
74
+ linked_somewhere_else = !child.node.node_maps.select { |nm| nm.parent && nm.parent.node != self }.first.nil?
75
+
76
+ child.node.node_maps.select { |nm|
77
+ nm.parent && nm.parent.node == self
78
+ }.each_with_index { |nm,ii|
69
79
  # Cleans up all the excess node_maps from the old linkage
70
- if ii > 0
71
- i.mark_for_destruction
72
- @ancestor_marked_for_destruction << i if ii > 0
80
+ if linked_somewhere_else || nm.parent && nm.parent.node == self && ii > 0
81
+ nm.mark_for_destruction
82
+ @ancestor_marked_for_destruction << nm
83
+ node_map_removed = true
73
84
  end
74
85
  }
75
86
 
76
87
  # Should not know about parent
77
- child.parent = nil
88
+ child.parent = nil if node_map_removed
89
+
90
+ !node_map_removed
78
91
  }
79
- # Should not know about children
80
- answer_node_map.children = []
81
92
  }
82
93
  end
83
94
 
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordSurvey
2
- VERSION = "0.1.19"
2
+ VERSION = "0.1.20"
3
3
  end
@@ -2,11 +2,56 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
4
4
  describe 'a survey' do
5
- before(:all) do
5
+ before(:each) do
6
6
  @survey = FactoryGirl.build(:basic_survey)
7
7
  @survey.save
8
8
  end
9
9
 
10
+ describe '#remove_link', :focus => true do
11
+ it 'should only unlink the specified answer' do
12
+
13
+ q4 = nil
14
+ q4_a1 = nil
15
+ q4_a2 = nil
16
+ q5 = nil
17
+ q5_a1 = nil
18
+ q5_a2 = nil
19
+ q6 = nil
20
+ @survey.questions.each { |i|
21
+ q4 = i if i.text == "Q4"
22
+ q5 = i if i.text == "Q5 Boolean"
23
+ q6 = i if i.text == "Q6"
24
+ }
25
+
26
+ q4.answers.each { |i|
27
+ q4_a1 = i if i.text == "Q4 A1"
28
+ q4_a2 = i if i.text == "Q4 A2"
29
+ }
30
+ q5.answers.each { |i|
31
+ q5_a1 = i if i.text == "Q5 A1"
32
+ q5_a2 = i if i.text == "Q5 A2"
33
+ }
34
+
35
+ expect(q4_a1.next_question).to eq(q6)
36
+ expect(q5_a2.next_question).to eq(q6)
37
+
38
+ q5_a2.remove_link
39
+ q5_a2.save
40
+
41
+ # q5_a2 should now have no next question
42
+ expect(q5_a2.next_question).to eq(nil)
43
+
44
+ q5_a2.reload
45
+ expect(q5_a2.next_question).to eq(nil)
46
+
47
+ # q4_a1 should have been left alone
48
+ expect(q4_a1.next_question).to eq(q6)
49
+
50
+ q4_a1.reload
51
+ expect(q4_a1.next_question).to eq(q6)
52
+ end
53
+ end
54
+
10
55
  describe '#next_question' do
11
56
  it 'should get the next question' do
12
57
  expected = [
@@ -57,7 +57,7 @@ describe ActiveRecordSurvey::Node::Question, :question_spec => true do
57
57
  end
58
58
  end
59
59
 
60
- describe '#build_answer', :focus => true do
60
+ describe '#build_answer' do
61
61
  it 'should have the right number of node maps' do
62
62
  @survey = ActiveRecordSurvey::Survey.new()
63
63
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_survey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Butch Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-29 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord