active_record_survey 0.1.29 → 0.1.30

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: d2afb9c3325db53de73001c5d6f59325c1358857
4
- data.tar.gz: 79c0edcfa55069372786f9aec408e679f4216752
3
+ metadata.gz: 600d9499d8cde5f959faf9af9775f35c84f965c2
4
+ data.tar.gz: 54c5136528e2ea561f2e0bb1fcfc875d21683a9d
5
5
  SHA512:
6
- metadata.gz: 1b82564a960e98748f511fe5aa26b8b76b1b1a71c6b993f18bdf979631cce2dcf714f008b5da9a1cd7176bb03088bca5ad6c17842df6f494ab225f5f4dea357a
7
- data.tar.gz: 7ab230a31470113797bd349e784e24a500562ae4cd651e35b4e476f79c39712bcb30ab029cc8b66cfbade0320025593eb4436ef36516c64429ac2fe1180f77be
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,3 +1,3 @@
1
1
  module ActiveRecordSurvey
2
- VERSION = "0.1.29"
2
+ VERSION = "0.1.30"
3
3
  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', :focus => true do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_survey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.29
4
+ version: 0.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Butch Marshall