active_record_survey 0.1.29 → 0.1.30
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: 600d9499d8cde5f959faf9af9775f35c84f965c2
|
4
|
+
data.tar.gz: 54c5136528e2ea561f2e0bb1fcfc875d21683a9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 830b35f1da8d9af17142c1a77061b62ec2dadcd104afbd4033f6ef277d58ee946acc91a704025b01bc0691f3c9988be9976bf1c81bcbbfed98c1633fdfe8b764
|
7
|
+
data.tar.gz: 82f5041bf2c60cc07c674e0f6217092465da5dfed2dfd3bcaa261d2106d21a52e00fae8a4fd4ab9b1a09ef00bc976560daa662d812e645c05fccdba3a43d6ff4
|
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.30**
|
16
|
+
- `ActiveRecordSurvey::Node::Question` now throws ArgumentError if answers of different types are added to it
|
17
|
+
|
15
18
|
**0.1.29**
|
16
19
|
- `ActiveRecordSurvey::Node::Answer` now cleans up associated node_maps on destruction
|
17
20
|
- extending/including `ActiveRecordSurvey::Answer::Chained` now rebuilds broken links in the parent<->child node_maps if a middle node_map is destroyed
|
@@ -11,11 +11,19 @@ module ActiveRecordSurvey
|
|
11
11
|
def build_answer(answer_node)
|
12
12
|
# A survey must either be passed or already present in self.node_maps
|
13
13
|
if self.survey.nil?
|
14
|
-
raise ArgumentError.new "A survey must be passed if Question is not yet added to a survey"
|
14
|
+
raise ArgumentError.new "A survey must be passed if ActiveRecordSurvey::Node::Question is not yet added to a survey"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Cannot mix answer types
|
18
|
+
# Check if not match existing - throw error
|
19
|
+
if !self.answers.select { |answer|
|
20
|
+
answer.class != answer_node.class
|
21
|
+
}.empty?
|
22
|
+
raise ArgumentError.new "Cannot mix answer types on question"
|
15
23
|
end
|
16
24
|
|
17
25
|
# Answers actually define how they're built off the parent node
|
18
26
|
answer_node.send(:build_answer, self)
|
19
27
|
end
|
20
28
|
end
|
21
|
-
end
|
29
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveRecordSurvey::Node::Answer::Boolean, :boolean_spec => true do
|
4
|
-
describe '#destroy'
|
4
|
+
describe '#destroy' do
|
5
5
|
it 'should re-link broken chains' do
|
6
6
|
survey = ActiveRecordSurvey::Survey.new()
|
7
7
|
q1 = ActiveRecordSurvey::Node::Question.new(:text => "Question #1", :survey => survey)
|
@@ -13,6 +13,13 @@ describe ActiveRecordSurvey::Node::Question, :question_spec => true do
|
|
13
13
|
it 'should raise ArgumentError if survey not linked to question' do
|
14
14
|
expect{@q.build_answer(@a1)}.to raise_error(ArgumentError)
|
15
15
|
end
|
16
|
+
it 'should raise ArgumentError if answers of different types added' do
|
17
|
+
@q.survey = @survey
|
18
|
+
a1 = ActiveRecordSurvey::Node::Answer::Boolean.new(:text => "A1")
|
19
|
+
a2 = ActiveRecordSurvey::Node::Answer::Text.new(:text => "A2")
|
20
|
+
@q.build_answer(a1)
|
21
|
+
expect{@q.build_answer(a2)}.to raise_error(ArgumentError)
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
describe 'when valid' do
|