active_record_survey 0.1.32 → 0.1.34
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26eecc198f8c314ac2a23e3f746dcc823acb9720
|
4
|
+
data.tar.gz: 1e7076165aff517190a7e0f45b804d6b0fa0e93d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4a76741e270ffcec64140526bf6467f40a82e55126c73796f357936a1e7a4a7085f07c662b71a24b4dc5dfcd340cdde9b61bff721aebe2b8a6f17496dcc4554
|
7
|
+
data.tar.gz: ae0b50818d46601fce209a7452b311bfcbd962e27c4ebbd4213254bb3b2b0a5b2504d9b54b80c0073a3db5116bf2be17686e6fe9c765083400637fed1cdbdce0
|
data/README.md
CHANGED
@@ -12,6 +12,9 @@ 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.33**
|
16
|
+
- `ActiveRecordSurvey::Node::Answer#sibling_index` method for setting position as well
|
17
|
+
|
15
18
|
**0.1.32**
|
16
19
|
- `ActiveRecordSurvey::Node::Answer#sibling_index` for regular answers and chained answers
|
17
20
|
|
@@ -11,22 +11,6 @@ module ActiveRecordSurvey
|
|
11
11
|
}.include?(false)
|
12
12
|
end
|
13
13
|
|
14
|
-
# Gets index in sibling relationship
|
15
|
-
def sibling_index
|
16
|
-
if node_map = self.survey.node_maps.select { |i|
|
17
|
-
i.node == self
|
18
|
-
}.first
|
19
|
-
|
20
|
-
node_map.parent.children.each_with_index { |nm, i|
|
21
|
-
if nm == node_map
|
22
|
-
return i
|
23
|
-
end
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
return 0
|
28
|
-
end
|
29
|
-
|
30
14
|
# Returns the question that preceeds this answer
|
31
15
|
def question
|
32
16
|
self.survey.node_maps.select { |i|
|
@@ -151,9 +135,35 @@ module ActiveRecordSurvey
|
|
151
135
|
}
|
152
136
|
end
|
153
137
|
|
138
|
+
# Gets index in sibling relationship
|
139
|
+
def sibling_index
|
140
|
+
if node_map = self.survey.node_maps.select { |i|
|
141
|
+
i.node == self
|
142
|
+
}.first
|
143
|
+
|
144
|
+
node_map.parent.children.each_with_index { |nm, i|
|
145
|
+
if nm == node_map
|
146
|
+
return i
|
147
|
+
end
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
151
|
+
return 0
|
152
|
+
end
|
153
|
+
|
154
|
+
def sibling_index=index
|
155
|
+
current_index = self.sibling_index
|
156
|
+
|
157
|
+
offset = index - current_index
|
158
|
+
|
159
|
+
(1..offset.abs).each { |i|
|
160
|
+
self.send(((offset > 0)? "move_down" : "move_up"))
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
154
164
|
# Moves answer up relative to other answers
|
155
165
|
def move_up
|
156
|
-
|
166
|
+
self.survey.node_maps.select { |i|
|
157
167
|
i.node == self
|
158
168
|
}.collect { |node_map|
|
159
169
|
begin
|
@@ -165,7 +175,7 @@ module ActiveRecordSurvey
|
|
165
175
|
|
166
176
|
# Moves answer down relative to other answers
|
167
177
|
def move_down
|
168
|
-
|
178
|
+
self.survey.node_maps.select { |i|
|
169
179
|
i.node == self
|
170
180
|
}.collect { |node_map|
|
171
181
|
begin
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveRecordSurvey::Node::Answer::Boolean, :boolean_spec => true do
|
4
|
-
describe '#sibling_index'
|
4
|
+
describe '#sibling_index' do
|
5
5
|
before(:each) do
|
6
6
|
@survey = ActiveRecordSurvey::Survey.new()
|
7
7
|
@q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => @survey)
|
@@ -34,6 +34,22 @@ describe ActiveRecordSurvey::Node::Answer::Boolean, :boolean_spec => true do
|
|
34
34
|
@survey.save
|
35
35
|
end
|
36
36
|
|
37
|
+
describe '#sibling_index' do
|
38
|
+
it 'should go higher if possible' do
|
39
|
+
@q1_a3.sibling_index = 0
|
40
|
+
|
41
|
+
@survey.reload
|
42
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}])
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should go lower if possible' do
|
46
|
+
@q1_a1.sibling_index = 2
|
47
|
+
|
48
|
+
@survey.reload
|
49
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
37
53
|
describe '#move_up' do
|
38
54
|
it 'should go higher of possible' do
|
39
55
|
@q1_a2.move_up
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
|
4
4
|
|
5
|
-
describe '#sibling_index'
|
5
|
+
describe '#sibling_index' do
|
6
6
|
before(:each) do
|
7
7
|
@survey = ActiveRecordSurvey::Survey.new()
|
8
8
|
@q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => @survey)
|
@@ -35,8 +35,41 @@ describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
|
|
35
35
|
@survey.save
|
36
36
|
end
|
37
37
|
|
38
|
+
describe '#sibling_index' do
|
39
|
+
it 'should go higher if possible' do
|
40
|
+
@q1_a3.sibling_index = 0
|
41
|
+
|
42
|
+
@survey.reload
|
43
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
|
44
|
+
|
45
|
+
@survey.save
|
46
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
|
47
|
+
|
48
|
+
@survey.reload
|
49
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should go lower by one' do
|
53
|
+
@q1_a1.sibling_index = 1
|
54
|
+
@survey.reload
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should go lower if possible' do
|
58
|
+
@q1_a1.sibling_index = 2
|
59
|
+
|
60
|
+
@survey.reload
|
61
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
|
62
|
+
|
63
|
+
@survey.save
|
64
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
|
65
|
+
|
66
|
+
@survey.reload
|
67
|
+
expect(@survey.as_map(no_ids: true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
38
71
|
describe '#move_up' do
|
39
|
-
it 'should go higher
|
72
|
+
it 'should go higher if possible' do
|
40
73
|
@q1_a2.move_up
|
41
74
|
|
42
75
|
@survey.reload
|
@@ -52,7 +85,7 @@ describe ActiveRecordSurvey::Node::Answer, :answer_spec => true do
|
|
52
85
|
end
|
53
86
|
|
54
87
|
describe '#move_down' do
|
55
|
-
it 'should go lower
|
88
|
+
it 'should go lower if possible' do
|
56
89
|
@q1_a2.move_down
|
57
90
|
|
58
91
|
@survey.reload
|