active_record_survey 0.1.20 → 0.1.21

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: 36c2b2fd8de15c342720cd4da180be5ebf361d91
4
- data.tar.gz: 476f142713f229b16cb5156ea7d8120f81c8eeec
3
+ metadata.gz: 96acfdcb3022af01ad493de3970ded02d82e76ec
4
+ data.tar.gz: 77836f5cceb9598c7df0910446d72f022fac5b5d
5
5
  SHA512:
6
- metadata.gz: cae260e84326b7ecd9d20d36f548353fd57700f59426e731a53dff50b3a8987c2159147bee8100cc5817cc5757be03cdcd0a0f06e1aeb677789d3f92386bd343
7
- data.tar.gz: d8b145292eee0814beef6723de523938fa2ece558fa8fda76803b1fdd700a699990f1bad25fb2c0ae13119b873bde5d86d48c662b103ae4b2964d8c9290be3e1
6
+ metadata.gz: 61c26bc02c582db78f54379b961de73b3d91db7b8250c0e608c66734d00bdd32c7e3dd45a10b81dbd1eb47ed975472f38cad3e7321d7a76995c268f2d20bd4f4
7
+ data.tar.gz: f1a6e73f168e89abc61e0850a1f37f266a172907f1e044e0cc3adf642131b6137126f31194c5630e97bec448b56fee961dc0d8359b6c85b49521151edff512b9
data/README.md CHANGED
@@ -12,6 +12,12 @@ 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.20**
16
+ - answer#build_link now detects and throws an error when a infinite loop is added
17
+
18
+ **0.1.20**
19
+ - answer#remove_link wasn't correct. Fixed and added unit tests
20
+
15
21
  **0.1.15**
16
22
  - Don't consider instance_nodes marked for destruction when validating
17
23
 
@@ -138,7 +138,15 @@ module ActiveRecordSurvey
138
138
  end
139
139
  }
140
140
 
141
+ # TODO - check to make sure there is no path to itself
141
142
  end
143
+
144
+ self.node_maps.each { |node_map|
145
+ # There is a path from Q -> A that is a loop
146
+ if node_map.has_infinite_loop?
147
+ raise RuntimeError.new "Infinite loop detected"
148
+ end
149
+ }
142
150
  end
143
151
 
144
152
  # By default - answers build off the original question node
@@ -46,5 +46,16 @@ module ActiveRecordSurvey
46
46
  i.children_until_node_not_ancestor_of(klass)
47
47
  }
48
48
  end
49
+
50
+ # Check to see whether there is an infinite loop from this node_map
51
+ def has_infinite_loop?(path = [])
52
+ self.children.each { |i|
53
+ # Detect infinite loop
54
+ if path.include?(self.node) || i.has_infinite_loop?(path.clone.push(self.node))
55
+ return true
56
+ end
57
+ }
58
+ false
59
+ end
49
60
  end
50
61
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordSurvey
2
- VERSION = "0.1.20"
2
+ VERSION = "0.1.21"
3
3
  end
@@ -7,9 +7,33 @@ describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
7
7
  @survey.save
8
8
  end
9
9
 
10
- describe '#remove_link', :focus => true do
10
+ describe '#build_link', :focus => true do
11
+ it 'should throw error when build_link creates an infinite loop' do
12
+ survey = ActiveRecordSurvey::Survey.new()
13
+
14
+ q1 = ActiveRecordSurvey::Node::Question.new(:text => "Q1")
15
+ survey.build_question(q1)
16
+ q1_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q1 A1")
17
+ q1.build_answer(q1_a1)
18
+
19
+ q2 = ActiveRecordSurvey::Node::Question.new(:text => "Q2")
20
+ survey.build_question(q2)
21
+ q2_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q2 A1")
22
+ q2.build_answer(q2_a1)
23
+
24
+ q3 = ActiveRecordSurvey::Node::Question.new(:text => "Q3")
25
+ survey.build_question(q3)
26
+ q3_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Q3 A1")
27
+ q3.build_answer(q3_a1)
28
+
29
+ q1_a1.build_link(q2)
30
+ q2_a1.build_link(q3)
31
+ expect{q3_a1.build_link(q1)}.to raise_error(RuntimeError) # This should throw exception
32
+ end
33
+ end
34
+
35
+ describe '#remove_link' do
11
36
  it 'should only unlink the specified answer' do
12
-
13
37
  q4 = nil
14
38
  q4_a1 = nil
15
39
  q4_a2 = nil
@@ -22,7 +46,7 @@ describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
22
46
  q5 = i if i.text == "Q5 Boolean"
23
47
  q6 = i if i.text == "Q6"
24
48
  }
25
-
49
+
26
50
  q4.answers.each { |i|
27
51
  q4_a1 = i if i.text == "Q4 A1"
28
52
  q4_a2 = i if i.text == "Q4 A2"
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.20
4
+ version: 0.1.21
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-30 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord