active_record_survey 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record_survey.rb +2 -0
- data/lib/active_record_survey/node_validation/maximum_answer.rb +10 -0
- data/lib/active_record_survey/node_validation/maximum_length.rb +1 -1
- data/lib/active_record_survey/node_validation/minimum_answer.rb +10 -0
- data/lib/active_record_survey/version.rb +1 -1
- data/spec/active_record_survey/node/answer/boolean_spec.rb +39 -0
- data/spec/active_record_survey/node/answer/rank_spec.rb +1 -1
- data/spec/active_record_survey/node/answer/scale_spec.rb +76 -76
- data/spec/active_record_survey/node/answer/text_spec.rb +129 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89488bc6129619788df343d2782e6e5789b63ea9
|
4
|
+
data.tar.gz: 734de7ad575ef2049f491cc289ddfc798e7f4c30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c5dd82b54caf2511537e2b3261ff0f90329241500fa4ebe3c83830486e5b3a626ae149a5d59cc9477dbb3a97cde32072f48e85258dc3ff76dd95e284b7dc424
|
7
|
+
data.tar.gz: bbd6dd35bd48ba070e2379ee38a1360fbbaf5e7e027f73c6f10607104d3b2b9886966d423e31ed9772fd84013d1f0794c5a7a504fa184fc996d58c6ed0e71d09
|
data/lib/active_record_survey.rb
CHANGED
@@ -24,6 +24,8 @@ require "active_record_survey/node_validation/minimum_value"
|
|
24
24
|
require "active_record_survey/node_validation/maximum_value"
|
25
25
|
require "active_record_survey/node_validation/maximum_length"
|
26
26
|
require "active_record_survey/node_validation/minimum_length"
|
27
|
+
require "active_record_survey/node_validation/minimum_answer"
|
28
|
+
require "active_record_survey/node_validation/maximum_answer"
|
27
29
|
|
28
30
|
require "active_record_survey/instance"
|
29
31
|
require "active_record_survey/instance_node"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActiveRecordSurvey
|
2
|
+
# Ensure the a maximum number of answers are made
|
3
|
+
class NodeValidation::MaximumAnswer < NodeValidation
|
4
|
+
# Validate the instance_node to ensure a maximum number of answers are made
|
5
|
+
def validate_instance_node(instance_node, node = nil)
|
6
|
+
!instance_node.value.to_s.empty? &&
|
7
|
+
instance_node.value.to_f >= self.value.to_f
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -3,7 +3,7 @@ module ActiveRecordSurvey
|
|
3
3
|
class NodeValidation::MaximumLength < NodeValidation
|
4
4
|
# Validate the instance_node value
|
5
5
|
def validate_instance_node(instance_node, node = nil)
|
6
|
-
instance_node.value.to_s.length
|
6
|
+
(self.value.to_i >= instance_node.value.to_s.length.to_i)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActiveRecordSurvey
|
2
|
+
# Ensure the a minimum number of answers are made
|
3
|
+
class NodeValidation::MinimumAnswer < NodeValidation
|
4
|
+
# Validate the instance_node to ensure a minimum number of answers are made
|
5
|
+
def validate_instance_node(instance_node, node = nil)
|
6
|
+
!instance_node.value.to_s.empty? &&
|
7
|
+
instance_node.value.to_f >= self.value.to_f
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -90,5 +90,44 @@ describe ActiveRecordSurvey::Node::Answer::Boolean do
|
|
90
90
|
expect(instance.valid?).to be(false)
|
91
91
|
end
|
92
92
|
end
|
93
|
+
|
94
|
+
describe ActiveRecordSurvey::NodeValidation::MinimumAnswer do
|
95
|
+
describe 'valid when' do
|
96
|
+
it 'has a value greater than the minimum' do
|
97
|
+
@q1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumAnswer.new(
|
98
|
+
:node => @q1,
|
99
|
+
:value => 2 # 2 of the 3 answers must be "answered"
|
100
|
+
)
|
101
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
102
|
+
instance.instance_nodes.build(
|
103
|
+
:instance => instance,
|
104
|
+
:node => @q1_a1,
|
105
|
+
:value => "this is greater than minimum length",
|
106
|
+
)
|
107
|
+
instance.save
|
108
|
+
|
109
|
+
#expect(instance.valid?).to be(true)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
=begin
|
113
|
+
describe 'invalid when' do
|
114
|
+
it 'has a value less than the minimum' do
|
115
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumLength.new(
|
116
|
+
:node => @q1_a1,
|
117
|
+
:value => 3
|
118
|
+
)
|
119
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
120
|
+
instance.instance_nodes.build(
|
121
|
+
:instance => instance,
|
122
|
+
:node => @q1_a1,
|
123
|
+
:value => "12",
|
124
|
+
)
|
125
|
+
instance.save
|
126
|
+
|
127
|
+
expect(instance.valid?).to be(false)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
=end
|
131
|
+
end
|
93
132
|
end
|
94
133
|
end
|
@@ -52,82 +52,6 @@ describe ActiveRecordSurvey::Node::Answer::Scale do
|
|
52
52
|
|
53
53
|
expect(instance.valid?).to be(true)
|
54
54
|
end
|
55
|
-
|
56
|
-
describe ActiveRecordSurvey::NodeValidation::MinimumValue do
|
57
|
-
describe 'valid when' do
|
58
|
-
it 'has a value greater than the minimum' do
|
59
|
-
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumValue.new(
|
60
|
-
:node => @q1_a1,
|
61
|
-
:value => 4
|
62
|
-
)
|
63
|
-
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
64
|
-
instance.instance_nodes.build(
|
65
|
-
:instance => instance,
|
66
|
-
:node => @q1_a1,
|
67
|
-
:value => 5,
|
68
|
-
)
|
69
|
-
instance.save
|
70
|
-
|
71
|
-
expect(instance.valid?).to be(true)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'invalid when' do
|
76
|
-
it 'has a value less than the minimum' do
|
77
|
-
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumValue.new(
|
78
|
-
:node => @q1_a1,
|
79
|
-
:value => 6
|
80
|
-
)
|
81
|
-
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
82
|
-
instance.instance_nodes.build(
|
83
|
-
:instance => instance,
|
84
|
-
:node => @q1_a1,
|
85
|
-
:value => 5,
|
86
|
-
)
|
87
|
-
instance.save
|
88
|
-
|
89
|
-
expect(instance.valid?).to be(false)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe ActiveRecordSurvey::NodeValidation::MaximumValue do
|
95
|
-
describe 'valid when' do
|
96
|
-
it 'has a value less than the maximum' do
|
97
|
-
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumValue.new(
|
98
|
-
:node => @q1_a1,
|
99
|
-
:value => 15
|
100
|
-
)
|
101
|
-
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
102
|
-
instance.instance_nodes.build(
|
103
|
-
:instance => instance,
|
104
|
-
:node => @q1_a1,
|
105
|
-
:value => 8,
|
106
|
-
)
|
107
|
-
instance.save
|
108
|
-
|
109
|
-
expect(instance.valid?).to be(true)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe 'invalid when' do
|
114
|
-
it 'has a value greater than the maximum' do
|
115
|
-
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumValue.new(
|
116
|
-
:node => @q1_a1,
|
117
|
-
:value => 15
|
118
|
-
)
|
119
|
-
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
120
|
-
instance.instance_nodes.build(
|
121
|
-
:instance => instance,
|
122
|
-
:node => @q1_a1,
|
123
|
-
:value => 20,
|
124
|
-
)
|
125
|
-
instance.save
|
126
|
-
|
127
|
-
expect(instance.valid?).to be(false)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
55
|
end
|
132
56
|
|
133
57
|
describe 'invalid when' do
|
@@ -155,5 +79,81 @@ describe ActiveRecordSurvey::Node::Answer::Scale do
|
|
155
79
|
expect(instance.valid?).to be(false)
|
156
80
|
end
|
157
81
|
end
|
82
|
+
|
83
|
+
describe ActiveRecordSurvey::NodeValidation::MinimumValue do
|
84
|
+
describe 'valid when' do
|
85
|
+
it 'has a value greater than the minimum' do
|
86
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumValue.new(
|
87
|
+
:node => @q1_a1,
|
88
|
+
:value => 4
|
89
|
+
)
|
90
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
91
|
+
instance.instance_nodes.build(
|
92
|
+
:instance => instance,
|
93
|
+
:node => @q1_a1,
|
94
|
+
:value => 5,
|
95
|
+
)
|
96
|
+
instance.save
|
97
|
+
|
98
|
+
expect(instance.valid?).to be(true)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'invalid when' do
|
103
|
+
it 'has a value less than the minimum' do
|
104
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumValue.new(
|
105
|
+
:node => @q1_a1,
|
106
|
+
:value => 6
|
107
|
+
)
|
108
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
109
|
+
instance.instance_nodes.build(
|
110
|
+
:instance => instance,
|
111
|
+
:node => @q1_a1,
|
112
|
+
:value => 5,
|
113
|
+
)
|
114
|
+
instance.save
|
115
|
+
|
116
|
+
expect(instance.valid?).to be(false)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe ActiveRecordSurvey::NodeValidation::MaximumValue do
|
122
|
+
describe 'valid when' do
|
123
|
+
it 'has a value less than the maximum' do
|
124
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumValue.new(
|
125
|
+
:node => @q1_a1,
|
126
|
+
:value => 15
|
127
|
+
)
|
128
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
129
|
+
instance.instance_nodes.build(
|
130
|
+
:instance => instance,
|
131
|
+
:node => @q1_a1,
|
132
|
+
:value => 8,
|
133
|
+
)
|
134
|
+
instance.save
|
135
|
+
|
136
|
+
expect(instance.valid?).to be(true)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe 'invalid when' do
|
141
|
+
it 'has a value greater than the maximum' do
|
142
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumValue.new(
|
143
|
+
:node => @q1_a1,
|
144
|
+
:value => 15
|
145
|
+
)
|
146
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
147
|
+
instance.instance_nodes.build(
|
148
|
+
:instance => instance,
|
149
|
+
:node => @q1_a1,
|
150
|
+
:value => 20,
|
151
|
+
)
|
152
|
+
instance.save
|
153
|
+
|
154
|
+
expect(instance.valid?).to be(false)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
158
|
end
|
159
159
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveRecordSurvey::Node::Answer::Text, :test => true do
|
4
|
+
describe 'a text survey is' do
|
5
|
+
before(:all) do
|
6
|
+
@survey = ActiveRecordSurvey::Survey.new
|
7
|
+
|
8
|
+
@q1 = ActiveRecordSurvey::Node::Question.new(:text => "What... what do you think?")
|
9
|
+
@q1_a1 = ActiveRecordSurvey::Node::Answer::Text.new()
|
10
|
+
|
11
|
+
@survey.build_question(@q1, [@q1_a1])
|
12
|
+
|
13
|
+
@survey.save
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'valid' do
|
17
|
+
it 'when empty' do
|
18
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
19
|
+
instance.instance_nodes.build(
|
20
|
+
:instance => instance,
|
21
|
+
:node => @q1_a1,
|
22
|
+
:value => ""
|
23
|
+
)
|
24
|
+
instance.save
|
25
|
+
|
26
|
+
expect(instance.valid?).to be(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'when not specified' do
|
30
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
31
|
+
instance.instance_nodes.build(
|
32
|
+
:instance => instance,
|
33
|
+
:node => @q1_a1,
|
34
|
+
)
|
35
|
+
instance.save
|
36
|
+
|
37
|
+
expect(instance.valid?).to be(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'when has content' do
|
41
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
42
|
+
instance.instance_nodes.build(
|
43
|
+
:instance => instance,
|
44
|
+
:node => @q1_a1,
|
45
|
+
:value => "We have some content here!",
|
46
|
+
)
|
47
|
+
instance.save
|
48
|
+
|
49
|
+
expect(instance.valid?).to be(true)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ActiveRecordSurvey::NodeValidation::MinimumLength do
|
54
|
+
describe 'valid when' do
|
55
|
+
it 'has a value greater than the minimum' do
|
56
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumLength.new(
|
57
|
+
:node => @q1_a1,
|
58
|
+
:value => 3
|
59
|
+
)
|
60
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
61
|
+
instance.instance_nodes.build(
|
62
|
+
:instance => instance,
|
63
|
+
:node => @q1_a1,
|
64
|
+
:value => "this is greater than minimum length",
|
65
|
+
)
|
66
|
+
instance.save
|
67
|
+
|
68
|
+
expect(instance.valid?).to be(true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'invalid when' do
|
73
|
+
it 'has a value less than the minimum' do
|
74
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MinimumLength.new(
|
75
|
+
:node => @q1_a1,
|
76
|
+
:value => 3
|
77
|
+
)
|
78
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
79
|
+
instance.instance_nodes.build(
|
80
|
+
:instance => instance,
|
81
|
+
:node => @q1_a1,
|
82
|
+
:value => "12",
|
83
|
+
)
|
84
|
+
instance.save
|
85
|
+
|
86
|
+
expect(instance.valid?).to be(false)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe ActiveRecordSurvey::NodeValidation::MaximumLength do
|
92
|
+
describe 'invalid when' do
|
93
|
+
it 'has a value greater than the maximum' do
|
94
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumLength.new(
|
95
|
+
:node => @q1_a1,
|
96
|
+
:value => 15
|
97
|
+
)
|
98
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
99
|
+
instance.instance_nodes.build(
|
100
|
+
:instance => instance,
|
101
|
+
:node => @q1_a1,
|
102
|
+
:value => "123456789111213141516",
|
103
|
+
)
|
104
|
+
instance.save
|
105
|
+
|
106
|
+
expect(instance.valid?).to be(false)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'valid when' do
|
111
|
+
it 'has a value less than the maximum' do
|
112
|
+
@q1_a1.node_validations << ActiveRecordSurvey::NodeValidation::MaximumLength.new(
|
113
|
+
:node => @q1_a1,
|
114
|
+
:value => 15
|
115
|
+
)
|
116
|
+
instance = ActiveRecordSurvey::Instance.new(:survey => @survey)
|
117
|
+
instance.instance_nodes.build(
|
118
|
+
:instance => instance,
|
119
|
+
:node => @q1_a1,
|
120
|
+
:value => "test",
|
121
|
+
)
|
122
|
+
instance.save
|
123
|
+
|
124
|
+
expect(instance.valid?).to be(true)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
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.
|
4
|
+
version: 0.1.5
|
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-09-
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -132,8 +132,10 @@ files:
|
|
132
132
|
- lib/active_record_survey/node/question.rb
|
133
133
|
- lib/active_record_survey/node_map.rb
|
134
134
|
- lib/active_record_survey/node_validation.rb
|
135
|
+
- lib/active_record_survey/node_validation/maximum_answer.rb
|
135
136
|
- lib/active_record_survey/node_validation/maximum_length.rb
|
136
137
|
- lib/active_record_survey/node_validation/maximum_value.rb
|
138
|
+
- lib/active_record_survey/node_validation/minimum_answer.rb
|
137
139
|
- lib/active_record_survey/node_validation/minimum_length.rb
|
138
140
|
- lib/active_record_survey/node_validation/minimum_value.rb
|
139
141
|
- lib/active_record_survey/survey.rb
|
@@ -146,6 +148,7 @@ files:
|
|
146
148
|
- spec/active_record_survey/node/answer/boolean_spec.rb
|
147
149
|
- spec/active_record_survey/node/answer/rank_spec.rb
|
148
150
|
- spec/active_record_survey/node/answer/scale_spec.rb
|
151
|
+
- spec/active_record_survey/node/answer/text_spec.rb
|
149
152
|
- spec/active_record_survey/survey_spec.rb
|
150
153
|
- spec/active_record_survey_spec.rb
|
151
154
|
- spec/spec_helper.rb
|
@@ -177,6 +180,7 @@ test_files:
|
|
177
180
|
- spec/active_record_survey/node/answer/boolean_spec.rb
|
178
181
|
- spec/active_record_survey/node/answer/rank_spec.rb
|
179
182
|
- spec/active_record_survey/node/answer/scale_spec.rb
|
183
|
+
- spec/active_record_survey/node/answer/text_spec.rb
|
180
184
|
- spec/active_record_survey/survey_spec.rb
|
181
185
|
- spec/active_record_survey_spec.rb
|
182
186
|
- spec/spec_helper.rb
|