surveyor 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -2
- data/VERSION +1 -1
- data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +2 -8
- data/lib/surveyor/models/answer_methods.rb +5 -3
- data/lib/surveyor/models/question_group_methods.rb +4 -0
- data/lib/surveyor/models/question_methods.rb +5 -0
- data/lib/surveyor/models/survey_section_methods.rb +2 -1
- data/lib/surveyor/parser.rb +5 -11
- data/lib/surveyor/unparser.rb +146 -0
- data/lib/tasks/surveyor_tasks.rake +23 -2
- data/spec/lib/unparser_spec.rb +126 -0
- data/spec/models/question_spec.rb +8 -0
- data/surveyor.gemspec +4 -1
- metadata +6 -3
data/README.md
CHANGED
@@ -89,8 +89,12 @@ After you have run them start up your app and go to:
|
|
89
89
|
|
90
90
|
http://localhost:3000/surveys
|
91
91
|
|
92
|
-
Try taking the survey and compare it to the contents of the DSL file kitchen\_sink\_survey.rb. See how each type of
|
93
|
-
|
92
|
+
Try taking the survey and compare it to the contents of the DSL file kitchen\_sink\_survey.rb. See how each type of DSL question maps to the resulting rendered view of the question.
|
93
|
+
|
94
|
+
There are two other useful rake tasks for removing (only surveys without responses) and un-parsing (from db to DSL file) surveys:
|
95
|
+
|
96
|
+
rake surveyor:remove
|
97
|
+
rake surveyor:unparse
|
94
98
|
|
95
99
|
# Customizing surveyor
|
96
100
|
|
@@ -110,6 +114,13 @@ To work on the plugin code (for enhancements, and bug fixes, etc...) fork this g
|
|
110
114
|
|
111
115
|
# Changes
|
112
116
|
|
117
|
+
0.16.0
|
118
|
+
|
119
|
+
* minor fixes to unparsing
|
120
|
+
* refining unparser. added rake task to unparse survey. closes #79
|
121
|
+
* unparsing for groups, dependencies, validations
|
122
|
+
* starting work on unparser for basic survey, section and question.
|
123
|
+
|
113
124
|
0.15.0
|
114
125
|
|
115
126
|
* prevent duplicate survey titles by appending incrementing numbers
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.16.0
|
@@ -73,7 +73,7 @@ survey "“Kitchen Sink” survey" do
|
|
73
73
|
a :text, :custom_class => 'mapper'
|
74
74
|
# validations can use regexp values
|
75
75
|
validation :rule => "A"
|
76
|
-
condition_A "=~", :regexp =>
|
76
|
+
condition_A "=~", :regexp => "[0-9a-zA-z\. #]"
|
77
77
|
|
78
78
|
# Questions, groups, and answers take a custom renderer (a partial in the application's views dir)
|
79
79
|
# defaults are "/partials/question_group", "/partials/question", "/partials/answer", so the custom renderers should have a different name
|
@@ -82,13 +82,7 @@ survey "“Kitchen Sink” survey" do
|
|
82
82
|
|
83
83
|
q_time_lunch "What time do you usually take a lunch break?"
|
84
84
|
a_1 :time
|
85
|
-
|
86
|
-
# # validation conditions can look up the response to another question/answer pair
|
87
|
-
# q_time_dinner "What time do you usually take a dinner break?"
|
88
|
-
# a :time
|
89
|
-
# validation :rule => "A"
|
90
|
-
# condition_A ">=", :question_reference => "time_lunch", :answer_reference => "1"
|
91
|
-
|
85
|
+
|
92
86
|
q "When would you like to meet for dinner?"
|
93
87
|
a :date
|
94
88
|
|
@@ -24,9 +24,11 @@ module Surveyor
|
|
24
24
|
|
25
25
|
def default_args
|
26
26
|
self.display_order ||= self.question ? self.question.answers.count : 0
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
self.is_exclusive ||= false
|
28
|
+
self.hide_label ||= false
|
29
|
+
self.response_class ||= "answer"
|
30
|
+
self.short_text ||= text
|
31
|
+
self.data_export_identifier ||= Surveyor::Common.normalize(text)
|
30
32
|
end
|
31
33
|
|
32
34
|
def renderer(q = question)
|
@@ -29,6 +29,8 @@ module Surveyor
|
|
29
29
|
self.display_type ||= "default"
|
30
30
|
self.pick ||= "none"
|
31
31
|
self.display_order ||= self.survey_section ? self.survey_section.questions.count : 0
|
32
|
+
self.data_export_identifier ||= Surveyor::Common.normalize(text)
|
33
|
+
self.short_text ||= text
|
32
34
|
end
|
33
35
|
|
34
36
|
def pick=(val)
|
@@ -55,6 +57,9 @@ module Surveyor
|
|
55
57
|
def part_of_group?
|
56
58
|
!self.question_group.nil?
|
57
59
|
end
|
60
|
+
def solo?
|
61
|
+
self.question_group.nil?
|
62
|
+
end
|
58
63
|
|
59
64
|
def renderer(g = question_group)
|
60
65
|
r = [g ? g.renderer.to_s : nil, display_type].compact.join("_")
|
@@ -23,7 +23,8 @@ module Surveyor
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def default_args
|
26
|
-
self.display_order ||=
|
26
|
+
self.display_order ||= survey ? survey.sections.count : 0
|
27
|
+
self.data_export_identifier ||= Surveyor::Common.normalize(title)
|
27
28
|
end
|
28
29
|
|
29
30
|
end
|
data/lib/surveyor/parser.rb
CHANGED
@@ -95,8 +95,7 @@ class SurveySection < ActiveRecord::Base
|
|
95
95
|
|
96
96
|
# build and set context
|
97
97
|
title = args[0]
|
98
|
-
context[:survey_section] = context[:survey].sections.build({ :title => title
|
99
|
-
:data_export_identifier => Surveyor::Common.normalize(title)}.merge(args[1] || {}))
|
98
|
+
context[:survey_section] = context[:survey].sections.build({ :title => title }.merge(args[1] || {}))
|
100
99
|
end
|
101
100
|
def clear(context)
|
102
101
|
context.delete_if{|k,v| k != :survey && k != :question_references && k != :answer_references}
|
@@ -133,9 +132,7 @@ class Question < ActiveRecord::Base
|
|
133
132
|
:question_group => context[:question_group],
|
134
133
|
:reference_identifier => reference_identifier,
|
135
134
|
:text => text,
|
136
|
-
:
|
137
|
-
:display_type => (original_method =~ /label|image/ ? original_method : "default"),
|
138
|
-
:data_export_identifier => Surveyor::Common.normalize(text)}.merge(args[1] || {}))
|
135
|
+
:display_type => (original_method =~ /label|image/ ? original_method : "default")}.merge(args[1] || {}))
|
139
136
|
|
140
137
|
# keep reference for dependencies
|
141
138
|
context[:question_references][reference_identifier] = context[:question] unless reference_identifier.blank?
|
@@ -196,12 +193,9 @@ class Answer < ActiveRecord::Base
|
|
196
193
|
|
197
194
|
def self.parse_and_build(context, args, original_method, reference_identifier)
|
198
195
|
# clear context
|
199
|
-
context.delete_if{|k,v| %w(answer validation validation_condition).map(&:to_sym).include? k}
|
196
|
+
context.delete_if{|k,v| %w(answer validation validation_condition reference_identifier).map(&:to_sym).include? k}
|
200
197
|
|
201
|
-
attrs = { :reference_identifier => reference_identifier
|
202
|
-
:is_exclusive => false,
|
203
|
-
:hide_label => false,
|
204
|
-
:response_class => "answer"}.merge(self.parse_args(args))
|
198
|
+
attrs = { :reference_identifier => reference_identifier}.merge(self.parse_args(args))
|
205
199
|
|
206
200
|
# add answers to grid
|
207
201
|
if context[:question_group] && context[:question_group].display_type == "grid"
|
@@ -227,7 +221,7 @@ class Answer < ActiveRecord::Base
|
|
227
221
|
end
|
228
222
|
end
|
229
223
|
def self.text_args(text = "Answer")
|
230
|
-
{:text => text.to_s
|
224
|
+
{:text => text.to_s}
|
231
225
|
end
|
232
226
|
def self.hash_from(arg)
|
233
227
|
arg.is_a?(Symbol) ? {:response_class => arg.to_s} : arg.is_a?(Hash) ? arg : {}
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Surveyor
|
2
|
+
class Unparser
|
3
|
+
# Class methods
|
4
|
+
def self.unparse(survey)
|
5
|
+
survey.unparse(dsl = "")
|
6
|
+
dsl
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Surveyor models with extra parsing methods
|
12
|
+
class Survey < ActiveRecord::Base
|
13
|
+
# block
|
14
|
+
include Surveyor::Models::SurveyMethods
|
15
|
+
def unparse(dsl)
|
16
|
+
attrs = (self.attributes.diff Survey.new(:title => title).attributes).delete_if{|k,v| %w(created_at updated_at inactive_at id title access_code).include? k}.symbolize_keys!
|
17
|
+
dsl << "survey \"#{title}\""
|
18
|
+
dsl << (attrs.blank? ? " do\n" : ", #{attrs.inspect.gsub(/\{|\}/, "")} do\n")
|
19
|
+
sections.each{|section| section.unparse(dsl)}
|
20
|
+
dsl << "end\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
class SurveySection < ActiveRecord::Base
|
24
|
+
# block
|
25
|
+
include Surveyor::Models::SurveySectionMethods
|
26
|
+
def unparse(dsl)
|
27
|
+
attrs = (self.attributes.diff SurveySection.new(:title => title).attributes).delete_if{|k,v| %w(created_at updated_at id survey_id).include? k}.symbolize_keys!
|
28
|
+
group_questions = []
|
29
|
+
dsl << " section \"#{title}\""
|
30
|
+
dsl << (attrs.blank? ? " do\n" : ", #{attrs.inspect.gsub(/\{|\}/, "")} do\n")
|
31
|
+
questions.each_with_index do |question, index|
|
32
|
+
if question.solo?
|
33
|
+
question.unparse(dsl)
|
34
|
+
else # gather up the group questions
|
35
|
+
group_questions << question
|
36
|
+
if (index + 1 >= questions.size) or (question.question_group != questions[index + 1].question_group)
|
37
|
+
# this is the last question of the section, or the group
|
38
|
+
question.question_group.unparse(dsl)
|
39
|
+
end
|
40
|
+
group_questions = []
|
41
|
+
end
|
42
|
+
end
|
43
|
+
dsl << " end\n"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
class QuestionGroup < ActiveRecord::Base
|
47
|
+
# block
|
48
|
+
include Surveyor::Models::QuestionGroupMethods
|
49
|
+
def unparse(dsl)
|
50
|
+
attrs = (self.attributes.diff QuestionGroup.new(:text => text).attributes).delete_if{|k,v| %w(created_at updated_at id).include?(k) or (k == "display_type" && %w(grid repeater default).include?(v))}.symbolize_keys!
|
51
|
+
method = (%w(grid repeater).include?(display_type) ? display_type : "group")
|
52
|
+
dsl << "\n"
|
53
|
+
dsl << " #{method} \"#{text}\""
|
54
|
+
dsl << (attrs.blank? ? " do\n" : ", #{attrs.inspect.gsub(/\{|\}/, "")} do\n")
|
55
|
+
questions.first.answers.each{|answer| answer.unparse(dsl)} if display_type == "grid"
|
56
|
+
questions.each{|question| question.unparse(dsl)}
|
57
|
+
dsl << " end\n"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
class Question < ActiveRecord::Base
|
61
|
+
# nonblock
|
62
|
+
include Surveyor::Models::QuestionMethods
|
63
|
+
def unparse(dsl)
|
64
|
+
attrs = (self.attributes.diff Question.new(:text => text).attributes).delete_if{|k,v| %w(created_at updated_at reference_identifier id survey_section_id question_group_id).include?(k) or (k == "display_type" && v == "label")}.symbolize_keys!
|
65
|
+
dsl << (solo? ? "\n" : " ")
|
66
|
+
if display_type == "label"
|
67
|
+
dsl << " label"
|
68
|
+
else
|
69
|
+
dsl << " q"
|
70
|
+
end
|
71
|
+
dsl << "_#{reference_identifier}" unless reference_identifier.blank?
|
72
|
+
dsl << " \"#{text}\""
|
73
|
+
dsl << (attrs.blank? ? "\n" : ", #{attrs.inspect.gsub(/\{|\}/, "")}\n")
|
74
|
+
if solo? or question_group.display_type != "grid"
|
75
|
+
answers.each{|answer| answer.unparse(dsl)}
|
76
|
+
end
|
77
|
+
dependency.unparse(dsl) if dependency
|
78
|
+
end
|
79
|
+
end
|
80
|
+
class Dependency < ActiveRecord::Base
|
81
|
+
# nonblock
|
82
|
+
include Surveyor::Models::DependencyMethods
|
83
|
+
def unparse(dsl)
|
84
|
+
attrs = (self.attributes.diff Dependency.new.attributes).delete_if{|k,v| %w(created_at updated_at id question_id).include?(k) }.symbolize_keys!
|
85
|
+
dsl << " " if question.part_of_group?
|
86
|
+
dsl << " dependency"
|
87
|
+
dsl << (attrs.blank? ? "\n" : " #{attrs.inspect.gsub(/\{|\}/, "")}\n")
|
88
|
+
dependency_conditions.each{|dependency_condition| dependency_condition.unparse(dsl)}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
class DependencyCondition < ActiveRecord::Base
|
92
|
+
# nonblock
|
93
|
+
include Surveyor::Models::DependencyConditionMethods
|
94
|
+
def unparse(dsl)
|
95
|
+
attrs = (self.attributes.diff Dependency.new.attributes).delete_if{|k,v| %w(created_at updated_at question_id question_group_id rule_key rule operator id dependency_id answer_id).include? k}.symbolize_keys!
|
96
|
+
dsl << " " if dependency.question.part_of_group?
|
97
|
+
dsl << " condition"
|
98
|
+
dsl << "_#{rule_key}" unless rule_key.blank?
|
99
|
+
dsl << " :q_#{question.reference_identifier}, \"#{operator}\""
|
100
|
+
dsl << (attrs.blank? ? ", {:answer_reference=>\"#{answer.reference_identifier}\"}\n" : ", {#{attrs.inspect.gsub(/\{|\}/, "")}, :answer_reference=>\"#{answer.reference_identifier}\"}\n")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
class Answer < ActiveRecord::Base
|
104
|
+
# nonblock
|
105
|
+
include Surveyor::Models::AnswerMethods
|
106
|
+
def unparse(dsl)
|
107
|
+
attrs = (self.attributes.diff Answer.new(:text => text).attributes).delete_if{|k,v| %w(created_at updated_at reference_identifier response_class id question_id).include? k}.symbolize_keys!
|
108
|
+
attrs.delete(:is_exclusive) if text == "Omit" && is_exclusive == true
|
109
|
+
attrs.merge!({:is_exclusive => false}) if text == "Omit" && is_exclusive == false
|
110
|
+
dsl << " " if question.part_of_group?
|
111
|
+
dsl << " a"
|
112
|
+
dsl << "_#{reference_identifier}" unless reference_identifier.blank?
|
113
|
+
if response_class.to_s.titlecase == text && attrs == {:hide_label => true}
|
114
|
+
dsl << " :#{response_class}"
|
115
|
+
else
|
116
|
+
dsl << [ text.blank? ? nil : text == "Other" ? " :other" : text == "Omit" ? " :omit" : " \"#{text}\"",
|
117
|
+
(response_class.blank? or response_class == "answer") ? nil : " #{response_class.to_sym.inspect}",
|
118
|
+
attrs.blank? ? nil : " #{attrs.inspect.gsub(/\{|\}/, "")}\n"].compact.join(",")
|
119
|
+
end
|
120
|
+
dsl << "\n"
|
121
|
+
validations.each{|validation| validation.unparse(dsl)}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
class Validation < ActiveRecord::Base
|
125
|
+
# nonblock
|
126
|
+
include Surveyor::Models::ValidationMethods
|
127
|
+
def unparse(dsl)
|
128
|
+
attrs = (self.attributes.diff Validation.new.attributes).delete_if{|k,v| %w(created_at updated_at id answer_id).include?(k) }.symbolize_keys!
|
129
|
+
dsl << " " if answer.question.part_of_group?
|
130
|
+
dsl << " validation"
|
131
|
+
dsl << (attrs.blank? ? "\n" : " #{attrs.inspect.gsub(/\{|\}/, "")}\n")
|
132
|
+
validation_conditions.each{|validation_condition| validation_condition.unparse(dsl)}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
class ValidationCondition < ActiveRecord::Base
|
136
|
+
# nonblock
|
137
|
+
include Surveyor::Models::ValidationConditionMethods
|
138
|
+
def unparse(dsl)
|
139
|
+
attrs = (self.attributes.diff ValidationCondition.new.attributes).delete_if{|k,v| %w(created_at updated_at operator rule_key id validation_id).include? k}.symbolize_keys!
|
140
|
+
dsl << " " if validation.answer.question.part_of_group?
|
141
|
+
dsl << " condition"
|
142
|
+
dsl << "_#{rule_key}" unless rule_key.blank?
|
143
|
+
dsl << " \"#{operator}\""
|
144
|
+
dsl << (attrs.blank? ? "\n" : ", #{attrs.inspect.gsub(/\{|\}/, "")}\n")
|
145
|
+
end
|
146
|
+
end
|
@@ -10,6 +10,27 @@ namespace :surveyor do
|
|
10
10
|
Surveyor::Parser.parse File.read(file)
|
11
11
|
puts "--- Done #{file} ---"
|
12
12
|
end
|
13
|
+
desc "generate a surveyor DSL file from a survey"
|
14
|
+
task :unparse => :environment do
|
15
|
+
surveys = Survey.all
|
16
|
+
if surveys
|
17
|
+
puts "The following surveys are available"
|
18
|
+
surveys.each do |survey|
|
19
|
+
puts "#{survey.id} #{survey.title}"
|
20
|
+
end
|
21
|
+
print "Which survey would you like to unparse? "
|
22
|
+
id = $stdin.gets.to_i
|
23
|
+
if survey_to_unparse = surveys.detect{|s| s.id == id}
|
24
|
+
filename = "surveys/#{survey_to_unparse.access_code}_#{Date.today.to_s(:db)}.rb"
|
25
|
+
puts "unparsing #{survey_to_unparse.title} to #{filename}"
|
26
|
+
File.open(filename, 'w') {|f| f.write(Surveyor::Unparser.unparse(survey_to_unparse))}
|
27
|
+
else
|
28
|
+
puts "not found"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
puts "There are no surveys available"
|
32
|
+
end
|
33
|
+
end
|
13
34
|
desc "remove surveys (that don't have response sets)"
|
14
35
|
task :remove => :environment do
|
15
36
|
surveys = Survey.all.delete_if{|s| !s.response_sets.blank?}
|
@@ -18,7 +39,7 @@ namespace :surveyor do
|
|
18
39
|
surveys.each do |survey|
|
19
40
|
puts "#{survey.id} #{survey.title}"
|
20
41
|
end
|
21
|
-
|
42
|
+
print "Which survey would you like to remove? "
|
22
43
|
id = $stdin.gets.to_i
|
23
44
|
if survey_to_delete = surveys.detect{|s| s.id == id}
|
24
45
|
puts "removing #{survey_to_delete.title}"
|
@@ -27,7 +48,7 @@ namespace :surveyor do
|
|
27
48
|
put "not found"
|
28
49
|
end
|
29
50
|
else
|
30
|
-
puts "There are no surveys
|
51
|
+
puts "There are no surveys without response sets"
|
31
52
|
end
|
32
53
|
end
|
33
54
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Surveyor::Unparser do
|
4
|
+
before(:each) do
|
5
|
+
@survey = Survey.new(:title => "Simple survey", :description => "very simple")
|
6
|
+
@section = @survey.sections.build(:title => "Simple section")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should unparse a basic survey, section, and question" do
|
10
|
+
q1 = @section.questions.build(:text => "What is your favorite color?", :reference_identifier => 1, :pick => :one)
|
11
|
+
a11 = q1.answers.build(:text => "red", :response_class => "answer", :reference_identifier => 1, :question => q1)
|
12
|
+
a12 = q1.answers.build(:text => "green", :response_class => "answer", :reference_identifier => 2, :question => q1)
|
13
|
+
a13 = q1.answers.build(:text => "blue", :response_class => "answer", :reference_identifier => 3, :question => q1)
|
14
|
+
a14 = q1.answers.build(:text => "Other", :response_class => "string", :reference_identifier => 4, :question => q1)
|
15
|
+
a15 = q1.answers.build(:text => "Omit", :reference_identifier => 5, :question => q1, :is_exclusive => true)
|
16
|
+
q2 = @section.questions.build(:text => "What is your name?", :reference_identifier => 2, :pick => :none)
|
17
|
+
a21 = q2.answers.build(:response_class => "string", :reference_identifier => 1, :question => q2)
|
18
|
+
Surveyor::Unparser.unparse(@survey).should ==
|
19
|
+
<<-dsl
|
20
|
+
survey "Simple survey", :description=>"very simple" do
|
21
|
+
section "Simple section" do
|
22
|
+
|
23
|
+
q_1 "What is your favorite color?", :pick=>"one"
|
24
|
+
a_1 "red"
|
25
|
+
a_2 "green"
|
26
|
+
a_3 "blue"
|
27
|
+
a_4 :other, :string
|
28
|
+
a_5 :omit
|
29
|
+
|
30
|
+
q_2 "What is your name?"
|
31
|
+
a_1 :string
|
32
|
+
end
|
33
|
+
end
|
34
|
+
dsl
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should unparse groups" do
|
38
|
+
q3 = @section.questions.build(:text => "Happy?")
|
39
|
+
a31 = q3.answers.build(:text => "Yes", :question => q3)
|
40
|
+
a32 = q3.answers.build(:text => "Maybe", :question => q3)
|
41
|
+
a33 = q3.answers.build(:text => "No", :question => q3)
|
42
|
+
|
43
|
+
q4 = @section.questions.build(:text => "Energized?")
|
44
|
+
a41 = q4.answers.build(:text => "Yes", :question => q4)
|
45
|
+
a42 = q4.answers.build(:text => "Maybe", :question => q4)
|
46
|
+
a43 = q4.answers.build(:text => "No", :question => q4)
|
47
|
+
|
48
|
+
g1 = q3.build_question_group(:text => "How are you feeling?", :display_type => "grid")
|
49
|
+
q4.question_group = g1
|
50
|
+
g1.questions = [q3, q4]
|
51
|
+
|
52
|
+
q5 = @section.questions.build(:text => "Model")
|
53
|
+
a51 = q5.answers.build(:response_class => "string", :question => q3)
|
54
|
+
|
55
|
+
g2 = q5.build_question_group(:text => "Tell us about the cars you own", :display_type => "repeater")
|
56
|
+
g2.questions = [q5]
|
57
|
+
|
58
|
+
Surveyor::Unparser.unparse(@survey).should ==
|
59
|
+
<<-dsl
|
60
|
+
survey "Simple survey", :description=>"very simple" do
|
61
|
+
section "Simple section" do
|
62
|
+
|
63
|
+
grid "How are you feeling?" do
|
64
|
+
a "Yes"
|
65
|
+
a "Maybe"
|
66
|
+
a "No"
|
67
|
+
q "Happy?"
|
68
|
+
q "Energized?"
|
69
|
+
end
|
70
|
+
|
71
|
+
repeater "Tell us about the cars you own" do
|
72
|
+
q "Model"
|
73
|
+
a :string
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
dsl
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should unparse a basic survey, section, and question" do
|
81
|
+
q6 = @section.questions.build(:text => "What... is your name? (e.g. It is 'Arthur', King of the Britons)", :reference_identifier => "montypython3")
|
82
|
+
a61 = q6.answers.build(:response_class => "string", :reference_identifier => 1, :question => q6)
|
83
|
+
|
84
|
+
q7 = @section.questions.build(:text => "What... is your quest? (e.g. To seek the Holy Grail)", :display_type => "label")
|
85
|
+
d1 = q7.build_dependency(:rule => "A", :question => q7)
|
86
|
+
dc1 = d1.dependency_conditions.build(:dependency => d1, :question => q6, :answer => a61, :operator => "==", :string_value => "It is 'Arthur', King of the Britons", :rule_key => "A")
|
87
|
+
|
88
|
+
q8 = @section.questions.build(:text => "How many pets do you own?")
|
89
|
+
a81 = q8.answers.build(:response_class => "integer", :question => q8)
|
90
|
+
v1 = a81.validations.build(:rule => "A", :answer => a81)
|
91
|
+
vc1 = v1.validation_conditions.build(:operator => ">=", :integer_value => 0, :validation => v1, :rule_key => "A")
|
92
|
+
|
93
|
+
q9 = @section.questions.build(:text => "Pick your favorite date AND time", :custom_renderer => "/partials/custom_question")
|
94
|
+
a91 = q9.answers.build(:response_class => "datetime", :question => q9)
|
95
|
+
|
96
|
+
q10 = @section.questions.build(:text => "What time do you usually take a lunch break?", :reference_identifier => "time_lunch")
|
97
|
+
a101 = q10.answers.build(:response_class => "time", :reference_identifier => 1, :question => q10)
|
98
|
+
|
99
|
+
Surveyor::Unparser.unparse(@survey).should ==
|
100
|
+
<<-dsl
|
101
|
+
survey "Simple survey", :description=>"very simple" do
|
102
|
+
section "Simple section" do
|
103
|
+
|
104
|
+
q_montypython3 "What... is your name? (e.g. It is 'Arthur', King of the Britons)"
|
105
|
+
a_1 :string
|
106
|
+
|
107
|
+
label "What... is your quest? (e.g. To seek the Holy Grail)"
|
108
|
+
dependency :rule=>"A"
|
109
|
+
condition_A :q_montypython3, "==", {:string_value=>"It is 'Arthur', King of the Britons", :answer_reference=>"1"}
|
110
|
+
|
111
|
+
q "How many pets do you own?"
|
112
|
+
a :integer
|
113
|
+
validation :rule=>"A"
|
114
|
+
condition_A ">=", :integer_value=>0
|
115
|
+
|
116
|
+
q "Pick your favorite date AND time", :custom_renderer=>"/partials/custom_question"
|
117
|
+
a :datetime
|
118
|
+
|
119
|
+
q_time_lunch "What time do you usually take a lunch break?"
|
120
|
+
a_1 :time
|
121
|
+
end
|
122
|
+
end
|
123
|
+
dsl
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
@@ -59,6 +59,14 @@ describe Question, "when interacting with an instance" do
|
|
59
59
|
@question.renderer.should == :default
|
60
60
|
end
|
61
61
|
|
62
|
+
it "should let you know if it is part of a group" do
|
63
|
+
@question.question_group = Factory(:question_group)
|
64
|
+
@question.solo?.should be_false
|
65
|
+
@question.part_of_group?.should be_true
|
66
|
+
@question.question_group = nil
|
67
|
+
@question.solo?.should be_true
|
68
|
+
@question.part_of_group?.should be_false
|
69
|
+
end
|
62
70
|
end
|
63
71
|
|
64
72
|
describe Question, "with dependencies" do
|
data/surveyor.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{surveyor}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.16.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Chamberlain", "Mark Yoon"]
|
@@ -154,12 +154,14 @@ Gem::Specification.new do |s|
|
|
154
154
|
"lib/surveyor/models/validation_methods.rb",
|
155
155
|
"lib/surveyor/parser.rb",
|
156
156
|
"lib/surveyor/surveyor_controller_methods.rb",
|
157
|
+
"lib/surveyor/unparser.rb",
|
157
158
|
"lib/tasks/surveyor_tasks.rake",
|
158
159
|
"rails/init.rb",
|
159
160
|
"spec/controllers/surveyor_controller_spec.rb",
|
160
161
|
"spec/factories.rb",
|
161
162
|
"spec/lib/common_spec.rb",
|
162
163
|
"spec/lib/parser_spec.rb",
|
164
|
+
"spec/lib/unparser_spec.rb",
|
163
165
|
"spec/models/answer_spec.rb",
|
164
166
|
"spec/models/dependency_condition_spec.rb",
|
165
167
|
"spec/models/dependency_spec.rb",
|
@@ -188,6 +190,7 @@ Gem::Specification.new do |s|
|
|
188
190
|
"spec/factories.rb",
|
189
191
|
"spec/lib/common_spec.rb",
|
190
192
|
"spec/lib/parser_spec.rb",
|
193
|
+
"spec/lib/unparser_spec.rb",
|
191
194
|
"spec/models/answer_spec.rb",
|
192
195
|
"spec/models/dependency_condition_spec.rb",
|
193
196
|
"spec/models/dependency_spec.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surveyor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 95
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 16
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.16.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Chamberlain
|
@@ -195,12 +195,14 @@ files:
|
|
195
195
|
- lib/surveyor/models/validation_methods.rb
|
196
196
|
- lib/surveyor/parser.rb
|
197
197
|
- lib/surveyor/surveyor_controller_methods.rb
|
198
|
+
- lib/surveyor/unparser.rb
|
198
199
|
- lib/tasks/surveyor_tasks.rake
|
199
200
|
- rails/init.rb
|
200
201
|
- spec/controllers/surveyor_controller_spec.rb
|
201
202
|
- spec/factories.rb
|
202
203
|
- spec/lib/common_spec.rb
|
203
204
|
- spec/lib/parser_spec.rb
|
205
|
+
- spec/lib/unparser_spec.rb
|
204
206
|
- spec/models/answer_spec.rb
|
205
207
|
- spec/models/dependency_condition_spec.rb
|
206
208
|
- spec/models/dependency_spec.rb
|
@@ -257,6 +259,7 @@ test_files:
|
|
257
259
|
- spec/factories.rb
|
258
260
|
- spec/lib/common_spec.rb
|
259
261
|
- spec/lib/parser_spec.rb
|
262
|
+
- spec/lib/unparser_spec.rb
|
260
263
|
- spec/models/answer_spec.rb
|
261
264
|
- spec/models/dependency_condition_spec.rb
|
262
265
|
- spec/models/dependency_spec.rb
|