active_record_survey 0.1.37 → 0.1.38

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: 1e48bc1f74ce11bb6285537bb34e00fb614b1e33
4
- data.tar.gz: 1528b2c91f64d66e4cf543b37f2b933e356efa5d
3
+ metadata.gz: 241fd16207e3dbcd096b90623040aa4142152663
4
+ data.tar.gz: 6ccfd912a9438462a86152a38e4b783c3088d85d
5
5
  SHA512:
6
- metadata.gz: d5ed3484bfcac51667d8243b31e187b9b1a372faab368e85d23477ec675b1cfa68ec75e147d3fde56acb57e6a04ca03ce5a740ecf843bde15034ec30959d16bf
7
- data.tar.gz: 5ff5d9269c791274f92c6538d0f5559080367b1866ef4929b2363d29dbe244fd877fea29283747624ec480a6df0de940b3e848a882f54d20657da9a6a8c25339
6
+ metadata.gz: e30a4dda78ec1c903d70100db1a83dc6fdbbf0a93d213b329a389a02f5beadad0cefdcff43e02d1b790ce053e924345beabd502da3c89bd54369a36a7a6efb1c
7
+ data.tar.gz: a80ed53f9f0261fe74ef34537b28451d3291fd9d72ff5cf04a26b72a26cd2a3ee9bdccb3c399970e21f5570bb95f67acd00937c3661fcd42a2bed2ef642ccf76
@@ -86,5 +86,24 @@ module ActiveRecordSurvey
86
86
 
87
87
  list.compact.uniq
88
88
  end
89
+
90
+ private
91
+ # Before a node is destroyed, will re-build the node_map links from parent to child if they exist
92
+ # If a question is being destroyed and it has answers - don't link its answers - only parent questions that follow it
93
+ def before_destroy_rebuild_node_map
94
+
95
+ self.survey.node_maps.select { |i|
96
+ i.node == self
97
+ }.each { |node_map|
98
+ # Remap all of this nodes children to the parent
99
+ node_map.children.each { |child|
100
+ if !child.node.class.ancestors.include?(::ActiveRecordSurvey::Node::Answer)
101
+ node_map.parent.children << child
102
+ end
103
+ }
104
+ }
105
+
106
+ true
107
+ end
89
108
  end
90
109
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordSurvey
2
- VERSION = "0.1.37"
2
+ VERSION = "0.1.38"
3
3
  end
@@ -1,8 +1,58 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveRecordSurvey::Node::Question, :question_spec => true do
4
+ describe "#before_destroy_rebuild_node_map" do
5
+ it 'should not relink any following questions' do
6
+ @survey = ActiveRecordSurvey::Survey.new()
7
+ @survey.save
8
+
9
+ @q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => @survey)
10
+ @q1_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Answer #1a")
11
+ @q1.build_answer(@q1_a1)
12
+
13
+ @q2 = ActiveRecordSurvey::Node::Question.new(:text => "Question #2", :survey => @survey)
14
+ @q2_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Answer #1b")
15
+ @q2.build_answer(@q2_a1)
16
+
17
+ @q3 = ActiveRecordSurvey::Node::Question.new(:text => "Question #3", :survey => @survey)
18
+ @q3_a1 = ActiveRecordSurvey::Node::Answer.new(:text => "Answer #1c")
19
+ @q3.build_answer(@q3_a1)
20
+
21
+ @q1_a1.build_link(@q2)
22
+ @q2_a1.build_link(@q3)
23
+
24
+ @survey.save
25
+
26
+ @q2.destroy
27
+ @survey.reload
28
+
29
+ expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Answer #1a", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
30
+ end
31
+
32
+ it 'should relink any following questions' do
33
+ @survey = ActiveRecordSurvey::Survey.new()
34
+
35
+ @q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => @survey)
36
+ @q2 = ActiveRecordSurvey::Node::Question.new(:text => "Question #2", :survey => @survey)
37
+ @q3 = ActiveRecordSurvey::Node::Question.new(:text => "Question #3", :survey => @survey)
38
+
39
+ @survey.build_first_question(@q1)
40
+ @q1.build_link(@q2)
41
+ @q2.build_link(@q3)
42
+
43
+ @survey.save
44
+
45
+ expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}]}])
46
+
47
+ @q2.destroy
48
+ @survey.reload
49
+
50
+ expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[]}]}])
51
+ end
52
+ end
53
+
4
54
  describe "#remove_link" do
5
- it 'should remove the link between the question and child questions or answers child questions', :focus => true do
55
+ it 'should remove the link between the question and child questions or answers child questions' do
6
56
  @survey = ActiveRecordSurvey::Survey.new()
7
57
  @survey.save
8
58
 
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.37
4
+ version: 0.1.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Butch Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-31 00:00:00.000000000 Z
11
+ date: 2016-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord