surveyor 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/MIT-LICENSE +20 -0
- data/README.md +104 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/app/controllers/surveyor_controller.rb +117 -0
- data/app/helpers/survey_form_builder.rb +37 -0
- data/app/helpers/surveyor_helper.rb +66 -0
- data/app/models/answer.rb +21 -0
- data/app/models/dependency.rb +46 -0
- data/app/models/dependency_condition.rb +79 -0
- data/app/models/question.rb +54 -0
- data/app/models/question_group.rb +18 -0
- data/app/models/response.rb +47 -0
- data/app/models/response_set.rb +185 -0
- data/app/models/survey.rb +57 -0
- data/app/models/survey_section.rb +15 -0
- data/app/views/layouts/surveyor_default.html.erb +13 -0
- data/app/views/partials/_answer.html.haml +49 -0
- data/app/views/partials/_question.html.haml +73 -0
- data/app/views/partials/_question_group.html.haml +41 -0
- data/app/views/surveyor/edit.html.haml +32 -0
- data/app/views/surveyor/new.html.haml +17 -0
- data/app/views/surveyor/show.html.haml +12 -0
- data/config/routes.rb +10 -0
- data/generators/surveyor/EXTENDING_SURVEYOR +12 -0
- data/generators/surveyor/extend_surveyor_generator.rb +22 -0
- data/generators/surveyor/surveyor_generator.rb +60 -0
- data/generators/surveyor/templates/README +10 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_resize_se.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_35x9_colorpicker_indicator.gif.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/dadada_40x100_textures_02_glass_75.png +0 -0
- data/generators/surveyor/templates/assets/images/e6e6e6_40x100_textures_02_glass_75.png +0 -0
- data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_01_flat_0.png +0 -0
- data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_02_glass_65.png +0 -0
- data/generators/surveyor/templates/assets/javascripts/accessibleUISlider.jQuery.js +201 -0
- data/generators/surveyor/templates/assets/javascripts/jquery-1.2.6.js +3549 -0
- data/generators/surveyor/templates/assets/javascripts/jquery-ui-personalized-1.5.3.js +7616 -0
- data/generators/surveyor/templates/assets/javascripts/jquery.form.js +637 -0
- data/generators/surveyor/templates/assets/javascripts/surveyor.js +28 -0
- data/generators/surveyor/templates/assets/stylesheets/jquery-ui-slider-additions.css +71 -0
- data/generators/surveyor/templates/assets/stylesheets/reset.css +46 -0
- data/generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass +245 -0
- data/generators/surveyor/templates/assets/stylesheets/surveyor.css +231 -0
- data/generators/surveyor/templates/assets/stylesheets/ui.theme.css +851 -0
- data/generators/surveyor/templates/extensions/survey_extensions.rb +18 -0
- data/generators/surveyor/templates/extensions/surveyor_controller_extensions.rb +28 -0
- data/generators/surveyor/templates/extensions/surveyor_custom.html.erb +13 -0
- data/generators/surveyor/templates/extensions/surveyor_helper_extensions.rb +18 -0
- data/generators/surveyor/templates/initializers/haml.rb +8 -0
- data/generators/surveyor/templates/initializers/surveyor.rb +11 -0
- data/generators/surveyor/templates/migrate/create_answers.rb +45 -0
- data/generators/surveyor/templates/migrate/create_dependencies.rb +21 -0
- data/generators/surveyor/templates/migrate/create_dependency_conditions.rb +29 -0
- data/generators/surveyor/templates/migrate/create_question_groups.rb +18 -0
- data/generators/surveyor/templates/migrate/create_questions.rb +33 -0
- data/generators/surveyor/templates/migrate/create_response_sets.rb +22 -0
- data/generators/surveyor/templates/migrate/create_responses.rb +33 -0
- data/generators/surveyor/templates/migrate/create_survey_sections.rb +25 -0
- data/generators/surveyor/templates/migrate/create_surveys.rb +25 -0
- data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +201 -0
- data/generators/surveyor/templates/tasks/surveyor.rb +4 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/surveyor.rb +7 -0
- data/lib/surveyor/config.rb +45 -0
- data/lib/tasks/surveyor_tasks.rake +33 -0
- data/lib/tiny_code.rb +58 -0
- data/lib/xml_formatter.rb +12 -0
- data/script/surveyor/answer.rb +84 -0
- data/script/surveyor/columnizer.rb +36 -0
- data/script/surveyor/dependency.rb +43 -0
- data/script/surveyor/dependency_condition.rb +74 -0
- data/script/surveyor/question.rb +76 -0
- data/script/surveyor/question_group.rb +33 -0
- data/script/surveyor/specs/answer_spec.rb +66 -0
- data/script/surveyor/specs/question_dependency_spec.rb +46 -0
- data/script/surveyor/specs/question_group_spec.rb +9 -0
- data/script/surveyor/specs/question_spec.rb +111 -0
- data/script/surveyor/specs/section_spec.rb +58 -0
- data/script/surveyor/survey.rb +108 -0
- data/script/surveyor/survey_parser.rb +64 -0
- data/script/surveyor/survey_section.rb +153 -0
- data/script/surveyor/whr_dsl.tmproj +244 -0
- data/spec/controllers/surveyor_controller_spec.rb +328 -0
- data/spec/factories.rb +107 -0
- data/spec/models/answer_spec.rb +29 -0
- data/spec/models/dependency_condition_spec.rb +338 -0
- data/spec/models/dependency_spec.rb +82 -0
- data/spec/models/question_group_spec.rb +11 -0
- data/spec/models/question_spec.rb +75 -0
- data/spec/models/response_set_spec.rb +153 -0
- data/spec/models/response_spec.rb +94 -0
- data/spec/models/survey_section_spec.rb +34 -0
- data/spec/models/survey_spec.rb +72 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +14 -0
- data/surveyor.gemspec +187 -0
- data/uninstall.rb +1 -0
- metadata +211 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/question_group'
|
2
|
+
require File.dirname(__FILE__) + '/question'
|
3
|
+
require File.dirname(__FILE__) + '/answer'
|
4
|
+
require File.dirname(__FILE__) + '/dependency'
|
5
|
+
require File.dirname(__FILE__) + '/dependency_condition'
|
6
|
+
require File.dirname(__FILE__) + '/columnizer'
|
7
|
+
require 'activesupport'
|
8
|
+
#require 'activesupport/lib/active_support/core_ext/string/inflections'
|
9
|
+
|
10
|
+
class SurveySection
|
11
|
+
include Columnizer
|
12
|
+
|
13
|
+
# Context, Content, Display, Reference, Children, Placeholders
|
14
|
+
attr_accessor :id, :survey_id, :parser
|
15
|
+
attr_accessor :title, :description
|
16
|
+
attr_accessor :display_order
|
17
|
+
attr_accessor :reference_identifier, :data_export_identifier
|
18
|
+
attr_accessor :question_groups, :questions, :grid_answers
|
19
|
+
attr_accessor :current_question_group, :current_question, :current_dependency
|
20
|
+
|
21
|
+
|
22
|
+
# id, survey, and title required
|
23
|
+
def initialize(id, survey, title, options = {})
|
24
|
+
self.id = id
|
25
|
+
self.survey_id = survey.id
|
26
|
+
self.parser = survey.parser
|
27
|
+
self.title = title.strip
|
28
|
+
self.questions = []
|
29
|
+
self.question_groups = []
|
30
|
+
self.grid_answers = []
|
31
|
+
self.current_question_group = nil
|
32
|
+
self.current_question = nil
|
33
|
+
self.current_dependency = nil
|
34
|
+
self.default_options(title).merge(options).each{|key,value| self.instance_variable_set("@#{key}", value)}
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_options(title)
|
38
|
+
{ :data_export_identifier => Columnizer.to_normalized_column(title)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
# This method_missing magic does all the heavy lifting for the DSL
|
43
|
+
def method_missing(missing_method, *args, &block)
|
44
|
+
method_name, reference_identifier = missing_method.to_s.split("_")
|
45
|
+
|
46
|
+
case method_name
|
47
|
+
|
48
|
+
when "group", "g", "grid", "repeater"
|
49
|
+
puts " Group: #{reference_identifier}"
|
50
|
+
raise "Error: A question group cannot be empty" unless block_given?
|
51
|
+
|
52
|
+
options = {:reference_identifier => reference_identifier, :display_type => (method_name =~ /grid|repeater/)? method_name : nil }
|
53
|
+
self.question_groups << (self.current_question_group = QuestionGroup.new(self, args, options))
|
54
|
+
self.instance_eval(&block)
|
55
|
+
clear_current_question_group
|
56
|
+
|
57
|
+
when "question", "q", "label", "image"
|
58
|
+
puts " Question: #{reference_identifier}"
|
59
|
+
raise "Error: I'm dropping the block like it's hot" if block_given?
|
60
|
+
|
61
|
+
clear_current_question
|
62
|
+
options = {:reference_identifier => reference_identifier, :question_group_id => (current_question_group ? current_question_group.id : nil)}
|
63
|
+
options.merge!({:display_type => "label"}) if method_name == "label"
|
64
|
+
options.merge!({:display_type => "image"}) if method_name == "image"
|
65
|
+
self.questions << (self.current_question = Question.new(self, args, options))
|
66
|
+
add_grid_answers if self.current_question_group and self.current_question_group.display_type == "grid"
|
67
|
+
|
68
|
+
when "dependency", "d"
|
69
|
+
puts " Dependency: #{reference_identifier}"
|
70
|
+
raise "Error: I'm dropping the block like it's hot" if block_given?
|
71
|
+
raise "Error: " unless self.current_question
|
72
|
+
|
73
|
+
options = {:reference_identifier => reference_identifier}
|
74
|
+
self.current_question.dependency = (self.current_dependency = Dependency.new(current_question, args, options))
|
75
|
+
|
76
|
+
when "condition", "c"
|
77
|
+
puts " Condition: #{reference_identifier}"
|
78
|
+
raise "Error, I'm dropping the block like it's hot" if block_given?
|
79
|
+
raise "Error: No current dependency" unless self.current_dependency
|
80
|
+
|
81
|
+
options = {:reference_identifier => reference_identifier}
|
82
|
+
self.current_dependency.add_dependency_condition DependencyCondition.new(self, args, options)
|
83
|
+
|
84
|
+
when "answer", "a"
|
85
|
+
puts " Answer: #{reference_identifier}"
|
86
|
+
raise "Error, I'm dropping the block like it's hot" if block_given?
|
87
|
+
|
88
|
+
if self.current_question_group and self.current_question_group.display_type == "grid"
|
89
|
+
options = {:reference_identifier => reference_identifier, :display_order => self.grid_answers.size + 1}
|
90
|
+
self.grid_answers << Answer.new(nil, args, options)
|
91
|
+
else
|
92
|
+
raise "Error: No current question" unless self.current_question
|
93
|
+
options = {:reference_identifier => reference_identifier, :display_order => self.current_question.answers.size + 1}
|
94
|
+
self.current_question.answers << Answer.new(self.current_question, args, options)
|
95
|
+
end
|
96
|
+
|
97
|
+
else
|
98
|
+
raise " ERROR: '#{m_name}' not valid method_missing name"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def clear_current_question_group
|
103
|
+
self.current_question_group = nil
|
104
|
+
self.grid_answers = []
|
105
|
+
self.current_question = nil
|
106
|
+
end
|
107
|
+
|
108
|
+
def clear_current_question
|
109
|
+
self.current_question = nil
|
110
|
+
self.current_dependency = nil
|
111
|
+
end
|
112
|
+
|
113
|
+
def add_grid_answers
|
114
|
+
self.grid_answers.each do |grid_answer|
|
115
|
+
my_answer = grid_answer.dup
|
116
|
+
my_answer.id = self.parser.new_answer_id
|
117
|
+
my_answer.question_id = self.current_question.id
|
118
|
+
my_answer.parser = self.parser
|
119
|
+
self.current_question.answers << my_answer
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Used to find questions for dependency linking
|
124
|
+
def find_question_by_reference(ref_id)
|
125
|
+
question = nil
|
126
|
+
count = 0
|
127
|
+
while question.nil? and count < questions.size
|
128
|
+
question = self.questions[count] if self.questions[count].reference_identifier == ref_id
|
129
|
+
count +=1
|
130
|
+
end
|
131
|
+
question
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
def to_yml
|
136
|
+
out =[ %(#{@data_export_identifier}_#{@id}:) ]
|
137
|
+
out << %( id: #{@id})
|
138
|
+
out << %( survey_id: #{@survey_id})
|
139
|
+
out << %( title: "#{@title}")
|
140
|
+
out << %( description: "#{@description}")
|
141
|
+
out << %( display_order: #{display_order})
|
142
|
+
out << %( reference_identifier: #{@reference_identifier})
|
143
|
+
out << %( data_export_identifier: "#{@data_export_identifier}")
|
144
|
+
(out << nil ).join("\r\n")
|
145
|
+
end
|
146
|
+
|
147
|
+
def to_file
|
148
|
+
File.open(self.parser.survey_sections_yml, File::CREAT|File::APPEND|File::WRONLY) {|f| f << to_yml}
|
149
|
+
self.question_groups.compact.map(&:to_file)
|
150
|
+
self.questions.compact.map(&:to_file)
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>currentDocument</key>
|
6
|
+
<string>whrparse.rb</string>
|
7
|
+
<key>documents</key>
|
8
|
+
<array>
|
9
|
+
<dict>
|
10
|
+
<key>expanded</key>
|
11
|
+
<true/>
|
12
|
+
<key>name</key>
|
13
|
+
<string>whr_dsl</string>
|
14
|
+
<key>regexFolderFilter</key>
|
15
|
+
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
|
16
|
+
<key>sourceDirectory</key>
|
17
|
+
<string></string>
|
18
|
+
</dict>
|
19
|
+
</array>
|
20
|
+
<key>fileHierarchyDrawerWidth</key>
|
21
|
+
<integer>261</integer>
|
22
|
+
<key>metaData</key>
|
23
|
+
<dict>
|
24
|
+
<key>answer.rb</key>
|
25
|
+
<dict>
|
26
|
+
<key>caret</key>
|
27
|
+
<dict>
|
28
|
+
<key>column</key>
|
29
|
+
<integer>5</integer>
|
30
|
+
<key>line</key>
|
31
|
+
<integer>54</integer>
|
32
|
+
</dict>
|
33
|
+
<key>firstVisibleColumn</key>
|
34
|
+
<integer>0</integer>
|
35
|
+
<key>firstVisibleLine</key>
|
36
|
+
<integer>13</integer>
|
37
|
+
</dict>
|
38
|
+
<key>columnizer.rb</key>
|
39
|
+
<dict>
|
40
|
+
<key>caret</key>
|
41
|
+
<dict>
|
42
|
+
<key>column</key>
|
43
|
+
<integer>112</integer>
|
44
|
+
<key>line</key>
|
45
|
+
<integer>3</integer>
|
46
|
+
</dict>
|
47
|
+
<key>firstVisibleColumn</key>
|
48
|
+
<integer>0</integer>
|
49
|
+
<key>firstVisibleLine</key>
|
50
|
+
<integer>0</integer>
|
51
|
+
</dict>
|
52
|
+
<key>partials/_checkboxes.rhtml</key>
|
53
|
+
<dict>
|
54
|
+
<key>caret</key>
|
55
|
+
<dict>
|
56
|
+
<key>column</key>
|
57
|
+
<integer>0</integer>
|
58
|
+
<key>line</key>
|
59
|
+
<integer>0</integer>
|
60
|
+
</dict>
|
61
|
+
<key>firstVisibleColumn</key>
|
62
|
+
<integer>0</integer>
|
63
|
+
<key>firstVisibleLine</key>
|
64
|
+
<integer>0</integer>
|
65
|
+
</dict>
|
66
|
+
<key>partials/_date.rhtml</key>
|
67
|
+
<dict>
|
68
|
+
<key>caret</key>
|
69
|
+
<dict>
|
70
|
+
<key>column</key>
|
71
|
+
<integer>0</integer>
|
72
|
+
<key>line</key>
|
73
|
+
<integer>0</integer>
|
74
|
+
</dict>
|
75
|
+
<key>firstVisibleColumn</key>
|
76
|
+
<integer>0</integer>
|
77
|
+
<key>firstVisibleLine</key>
|
78
|
+
<integer>0</integer>
|
79
|
+
</dict>
|
80
|
+
<key>question.rb</key>
|
81
|
+
<dict>
|
82
|
+
<key>caret</key>
|
83
|
+
<dict>
|
84
|
+
<key>column</key>
|
85
|
+
<integer>68</integer>
|
86
|
+
<key>line</key>
|
87
|
+
<integer>68</integer>
|
88
|
+
</dict>
|
89
|
+
<key>firstVisibleColumn</key>
|
90
|
+
<integer>0</integer>
|
91
|
+
<key>firstVisibleLine</key>
|
92
|
+
<integer>46</integer>
|
93
|
+
</dict>
|
94
|
+
<key>registry_code.rb</key>
|
95
|
+
<dict>
|
96
|
+
<key>caret</key>
|
97
|
+
<dict>
|
98
|
+
<key>column</key>
|
99
|
+
<integer>49</integer>
|
100
|
+
<key>line</key>
|
101
|
+
<integer>19</integer>
|
102
|
+
</dict>
|
103
|
+
<key>firstVisibleColumn</key>
|
104
|
+
<integer>0</integer>
|
105
|
+
<key>firstVisibleLine</key>
|
106
|
+
<integer>0</integer>
|
107
|
+
</dict>
|
108
|
+
<key>section.rb</key>
|
109
|
+
<dict>
|
110
|
+
<key>caret</key>
|
111
|
+
<dict>
|
112
|
+
<key>column</key>
|
113
|
+
<integer>9</integer>
|
114
|
+
<key>line</key>
|
115
|
+
<integer>98</integer>
|
116
|
+
</dict>
|
117
|
+
<key>firstVisibleColumn</key>
|
118
|
+
<integer>0</integer>
|
119
|
+
<key>firstVisibleLine</key>
|
120
|
+
<integer>59</integer>
|
121
|
+
</dict>
|
122
|
+
<key>section_template.rhtml</key>
|
123
|
+
<dict>
|
124
|
+
<key>caret</key>
|
125
|
+
<dict>
|
126
|
+
<key>column</key>
|
127
|
+
<integer>134</integer>
|
128
|
+
<key>line</key>
|
129
|
+
<integer>3</integer>
|
130
|
+
</dict>
|
131
|
+
<key>firstVisibleColumn</key>
|
132
|
+
<integer>0</integer>
|
133
|
+
<key>firstVisibleLine</key>
|
134
|
+
<integer>0</integer>
|
135
|
+
</dict>
|
136
|
+
<key>specs/answer_spec.rb</key>
|
137
|
+
<dict>
|
138
|
+
<key>caret</key>
|
139
|
+
<dict>
|
140
|
+
<key>column</key>
|
141
|
+
<integer>50</integer>
|
142
|
+
<key>line</key>
|
143
|
+
<integer>24</integer>
|
144
|
+
</dict>
|
145
|
+
<key>columnSelection</key>
|
146
|
+
<false/>
|
147
|
+
<key>firstVisibleColumn</key>
|
148
|
+
<integer>0</integer>
|
149
|
+
<key>firstVisibleLine</key>
|
150
|
+
<integer>3</integer>
|
151
|
+
<key>selectFrom</key>
|
152
|
+
<dict>
|
153
|
+
<key>column</key>
|
154
|
+
<integer>60</integer>
|
155
|
+
<key>line</key>
|
156
|
+
<integer>24</integer>
|
157
|
+
</dict>
|
158
|
+
<key>selectTo</key>
|
159
|
+
<dict>
|
160
|
+
<key>column</key>
|
161
|
+
<integer>50</integer>
|
162
|
+
<key>line</key>
|
163
|
+
<integer>24</integer>
|
164
|
+
</dict>
|
165
|
+
</dict>
|
166
|
+
<key>specs/question_spec.rb</key>
|
167
|
+
<dict>
|
168
|
+
<key>caret</key>
|
169
|
+
<dict>
|
170
|
+
<key>column</key>
|
171
|
+
<integer>21</integer>
|
172
|
+
<key>line</key>
|
173
|
+
<integer>5</integer>
|
174
|
+
</dict>
|
175
|
+
<key>firstVisibleColumn</key>
|
176
|
+
<integer>0</integer>
|
177
|
+
<key>firstVisibleLine</key>
|
178
|
+
<integer>0</integer>
|
179
|
+
</dict>
|
180
|
+
<key>specs/section_spec.rb</key>
|
181
|
+
<dict>
|
182
|
+
<key>caret</key>
|
183
|
+
<dict>
|
184
|
+
<key>column</key>
|
185
|
+
<integer>43</integer>
|
186
|
+
<key>line</key>
|
187
|
+
<integer>43</integer>
|
188
|
+
</dict>
|
189
|
+
<key>firstVisibleColumn</key>
|
190
|
+
<integer>0</integer>
|
191
|
+
<key>firstVisibleLine</key>
|
192
|
+
<integer>0</integer>
|
193
|
+
</dict>
|
194
|
+
<key>specs/whrparse_spec.rb</key>
|
195
|
+
<dict>
|
196
|
+
<key>caret</key>
|
197
|
+
<dict>
|
198
|
+
<key>column</key>
|
199
|
+
<integer>5</integer>
|
200
|
+
<key>line</key>
|
201
|
+
<integer>6</integer>
|
202
|
+
</dict>
|
203
|
+
<key>firstVisibleColumn</key>
|
204
|
+
<integer>0</integer>
|
205
|
+
<key>firstVisibleLine</key>
|
206
|
+
<integer>0</integer>
|
207
|
+
</dict>
|
208
|
+
<key>whrparse.rb</key>
|
209
|
+
<dict>
|
210
|
+
<key>caret</key>
|
211
|
+
<dict>
|
212
|
+
<key>column</key>
|
213
|
+
<integer>9</integer>
|
214
|
+
<key>line</key>
|
215
|
+
<integer>20</integer>
|
216
|
+
</dict>
|
217
|
+
<key>firstVisibleColumn</key>
|
218
|
+
<integer>0</integer>
|
219
|
+
<key>firstVisibleLine</key>
|
220
|
+
<integer>0</integer>
|
221
|
+
</dict>
|
222
|
+
</dict>
|
223
|
+
<key>openDocuments</key>
|
224
|
+
<array>
|
225
|
+
<string>registry_code.rb</string>
|
226
|
+
<string>whrparse.rb</string>
|
227
|
+
<string>specs/answer_spec.rb</string>
|
228
|
+
<string>specs/question_spec.rb</string>
|
229
|
+
<string>specs/section_spec.rb</string>
|
230
|
+
<string>section.rb</string>
|
231
|
+
<string>section_template.rhtml</string>
|
232
|
+
<string>partials/_date.rhtml</string>
|
233
|
+
<string>partials/_checkboxes.rhtml</string>
|
234
|
+
<string>columnizer.rb</string>
|
235
|
+
<string>specs/whrparse_spec.rb</string>
|
236
|
+
<string>question.rb</string>
|
237
|
+
<string>answer.rb</string>
|
238
|
+
</array>
|
239
|
+
<key>showFileHierarchyDrawer</key>
|
240
|
+
<true/>
|
241
|
+
<key>windowFrame</key>
|
242
|
+
<string>{{282, 61}, {1119, 816}}</string>
|
243
|
+
</dict>
|
244
|
+
</plist>
|
@@ -0,0 +1,328 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe SurveyorController do
|
4
|
+
|
5
|
+
# map.available_surveys 'surveys', :conditions => {:method => :get}, :action => "new" # GET survey list
|
6
|
+
# map.take_survey 'surveys/:survey_code', :conditions => {:method => :post}, :action => "create" # Only POST of survey to create
|
7
|
+
# map.view_my_survey 'surveys/:survey_code/:response_set_code', :conditions => {:method => :get}, :action => "show" # GET viewable/printable? survey
|
8
|
+
# map.edit_my_survey 'surveys/:survey_code/:response_set_code/take', :conditions => {:method => :get}, :action => "edit" # GET editable survey
|
9
|
+
# map.update_my_survey 'surveys/:survey_code/:response_set_code', :conditions => {:method => :put}, :action => "update" # PUT edited survey
|
10
|
+
# map.finish_my_survey 'surveys/:survey_code/:response_set_code/finish', :conditions => {:method => :put}, :action => "finish" # PUT to close out the response_set
|
11
|
+
|
12
|
+
describe "handling GET /surveys (available_surveys)" do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@survey = mock_model(Survey)
|
16
|
+
Survey.stub!(:find).and_return([@survey])
|
17
|
+
end
|
18
|
+
|
19
|
+
def do_get
|
20
|
+
get :new
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be successful" do
|
24
|
+
do_get
|
25
|
+
response.should be_success
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should render index template" do
|
29
|
+
do_get
|
30
|
+
response.should render_template('new')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should find all surveys" do
|
34
|
+
Survey.should_receive(:find).with(:all).and_return([@survey])
|
35
|
+
do_get
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should assign the found surveys for the view" do
|
39
|
+
do_get
|
40
|
+
assigns[:surveys].should == [@survey]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "handling GET /surveys.xml (available_surveys)" do
|
45
|
+
before(:each) do
|
46
|
+
@surveys = mock("Array of Surveys", :to_xml => "XML")
|
47
|
+
Survey.stub!(:find).and_return(@surveys)
|
48
|
+
end
|
49
|
+
|
50
|
+
def do_get
|
51
|
+
@request.env["HTTP_ACCEPT"] = "application/xml"
|
52
|
+
get :new
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be successful" do
|
56
|
+
do_get
|
57
|
+
response.should be_success
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should find all surveys" do
|
61
|
+
Survey.should_receive(:find).with(:all).and_return(@surveys)
|
62
|
+
do_get
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should render the found surveys as xml" do
|
66
|
+
@surveys.should_receive(:to_xml).and_return("XML")
|
67
|
+
do_get
|
68
|
+
response.body.should == "XML"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "handling POST /surveys/XYZ (take_survey)" do
|
73
|
+
|
74
|
+
before(:each) do
|
75
|
+
@survey = mock_model(Survey, :access_code => "XYZ")
|
76
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
77
|
+
ResponseSet.stub!(:new).and_return(@response_set)
|
78
|
+
Survey.stub!(:find_by_access_code).and_return(@survey)
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "with successful save" do
|
82
|
+
|
83
|
+
def do_post
|
84
|
+
@response_set.should_receive(:save!).and_return(true)
|
85
|
+
post :create, :survey_code => "XYZ"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should look for the survey" do
|
89
|
+
Survey.should_receive(:find_by_access_code).with("XYZ").and_return(@survey)
|
90
|
+
do_post
|
91
|
+
end
|
92
|
+
it "should create a new response_set" do
|
93
|
+
ResponseSet.should_receive(:new).and_return(@response_set)
|
94
|
+
do_post
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should redirect to the new response_set" do
|
98
|
+
do_post
|
99
|
+
response.should redirect_to(edit_my_survey_url(:survey_code => "XYZ", :response_set_code => "PDQ"))
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "with failed save" do
|
105
|
+
|
106
|
+
def do_post
|
107
|
+
@response_set.should_receive(:save!).and_return(false)
|
108
|
+
post :create, :survey_code => "XYZ"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should re-redirect to 'new'" do
|
112
|
+
do_post
|
113
|
+
response.should redirect_to(available_surveys_url)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "with survey not found" do
|
119
|
+
|
120
|
+
def do_post
|
121
|
+
Survey.should_receive(:find_by_access_code).and_return(nil)
|
122
|
+
post :create, :survey_code => "XYZ"
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should re-redirect to 'new'" do
|
126
|
+
do_post
|
127
|
+
response.should redirect_to(available_surveys_url)
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "handling GET /surveys/XYZ/PDQ (view_my_survey)" do
|
134
|
+
|
135
|
+
before(:each) do
|
136
|
+
@survey = mock_model(Survey, :access_code => "XYZ", :sections => [mock_model(SurveySection)])
|
137
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
138
|
+
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
139
|
+
@response_set.stub!(:survey).and_return(@survey)
|
140
|
+
end
|
141
|
+
|
142
|
+
def do_get
|
143
|
+
get :show, :survey_code => "XYZ", :response_set_code => "PDQ"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should be successful" do
|
147
|
+
do_get
|
148
|
+
response.should be_success
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should render show template" do
|
152
|
+
do_get
|
153
|
+
response.should render_template('show')
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should find the response_set requested" do
|
157
|
+
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
158
|
+
do_get
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should assign the found response_set and survey for the view" do
|
162
|
+
do_get
|
163
|
+
assigns[:response_set].should equal(@response_set)
|
164
|
+
assigns[:survey].should equal(@survey)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should redirect if :response_code not found" do
|
168
|
+
get :show, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
169
|
+
response.should redirect_to(available_surveys_url)
|
170
|
+
end
|
171
|
+
|
172
|
+
# I'm not sure this is enterly neccessary since we look up the survey from the response_code in the url -BC
|
173
|
+
it "should redirect if :survey_code in url doesn't match response_set.survey.access_code" do
|
174
|
+
pending
|
175
|
+
get :show, :survey_code => "DIFFERENT", :response_set_code => "PDQ"
|
176
|
+
response.should redirect_to(available_surveys_url)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "handling GET /surveys/XYZ/PDQ/take (edit_my_survey)" do
|
181
|
+
|
182
|
+
before(:each) do
|
183
|
+
@survey = mock_model(Survey, :access_code => "XYZ")
|
184
|
+
@survey_section = mock_model(SurveySection)
|
185
|
+
@survey.stub!(:sections).and_return([@survey_section])
|
186
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
187
|
+
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
188
|
+
@response_set.stub!(:survey).and_return(@survey)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should be successful, render edit with the requested survey" do
|
192
|
+
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
193
|
+
|
194
|
+
get :edit, :survey_code => "XYZ", :response_set_code => "PDQ"
|
195
|
+
response.should be_success
|
196
|
+
response.should render_template('edit')
|
197
|
+
assigns[:response_set].should equal(@response_set)
|
198
|
+
assigns[:survey].should equal(@survey)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should redirect if :response_code not found" do
|
202
|
+
get :edit, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
203
|
+
response.should redirect_to(available_surveys_url)
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "handling PUT /surveys/XYZ/PDQ (update_my_survey)" do
|
209
|
+
|
210
|
+
before(:each) do
|
211
|
+
@survey = mock_model(Survey, :access_code => "XYZ", :sections => [mock_model(SurveySection)])
|
212
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
213
|
+
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
214
|
+
@response_set.stub!(:survey).and_return(@survey)
|
215
|
+
@response_set.stub!(:add_responses).and_return(true)
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "with no response_set in update" do
|
219
|
+
|
220
|
+
it "should find the response set requested" do
|
221
|
+
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
222
|
+
put :update, :survey_code => "XYZ", :response_set_code => "PDQ"
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "with a new response set" do
|
229
|
+
|
230
|
+
it "should accept properly formatted params and save the data" do
|
231
|
+
response_set_params = {"survey_code"=>"XYZ", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}]}}}
|
232
|
+
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
# describe "issue with posting data to an existing survey and the data not saving properly" do
|
237
|
+
# @survey = mock_model(Survey, :access_code => "XYZ")
|
238
|
+
# @response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
239
|
+
# ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
240
|
+
# @response_set.stub!(:survey).and_return(@survey)
|
241
|
+
# @response_set.stub!(:complete!).and_return(Time.now)
|
242
|
+
#
|
243
|
+
#
|
244
|
+
# end
|
245
|
+
|
246
|
+
# first post {"survey_code"=>"test_survey", "commit"=>"Next Section (Utensiles and you!) >>", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}, {"answer_id"=>"0", "string_value"=>""}], "2"=>[{"answer_id"=>"6"}], "3"=>[{"answer_id"=>"10"}], "4"=>[{"answer_id"=>"14"}], "5"=>[{"answer_id"=>"0"}, {"answer_id"=>"0"}]}, "existing_response_attributes"=>{"6"=>{"1"=>{"answer_id"=>"20", "string_value"=>"B"}}, "7"=>{"2"=>{"text_value"=>"foo", "answer_id"=>"21"}}, "5"=>{"7"=>{"answer_id"=>"17"}, "16"=>{"answer_id"=>"19", "string_value"=>"blah"}}}}, "authenticity_token"=>"d9ba68fe20a46703f3737b5cb0b7e17b7390de32", "_method"=>"put", "action"=>"update", "controller"=>"app", "response_set_code"=>"9VEsec1dK6", "section"=>"2"}
|
247
|
+
# second post {"survey_code"=>"test_survey", "commit"=>"Next Section (Utensiles and you!) >>", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}, {"answer_id"=>"0", "string_value"=>""}], "2"=>[{"answer_id"=>"6"}], "3"=>[{"answer_id"=>"10"}], "4"=>[{"answer_id"=>"14"}], "5"=>[{"answer_id"=>"0"}, {"answer_id"=>"0"}]}, "existing_response_attributes"=>{"6"=>{"1"=>{"answer_id"=>"20", "string_value"=>"B"}}, "7"=>{"2"=>{"text_value"=>"boooo", "answer_id"=>"21"}}, "5"=>{"7"=>{"answer_id"=>"17"}, "16"=>{"answer_id"=>"19", "string_value"=>"blahblahstink"}}}}, "authenticity_token"=>"d9ba68fe20a46703f3737b5cb0b7e17b7390de32", "_method"=>"put", "action"=>"update", "controller"=>"app", "response_set_code"=>"9VEsec1dK6", "section"=>"2"}
|
248
|
+
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
|
253
|
+
describe "with failed update" do
|
254
|
+
|
255
|
+
it "should re-render 'edit'" do
|
256
|
+
put :update, :survey_code => "XYZ", :response_set_code => "PDQ"
|
257
|
+
response.should be_success
|
258
|
+
response.should render_template('edit')
|
259
|
+
flash[:notice].should == "Unable to update survey"
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "handling PUT /surveys/XYZ/PDQ/finish (finish_my_survey)" do
|
266
|
+
|
267
|
+
before(:each) do
|
268
|
+
@survey = mock_model(Survey, :access_code => "XYZ", :sections => [mock_model(SurveySection)])
|
269
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
270
|
+
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
271
|
+
@response_set.stub!(:survey).and_return(@survey)
|
272
|
+
@response_set.stub!(:complete!).and_return(Time.now)
|
273
|
+
end
|
274
|
+
|
275
|
+
describe "with successful update" do
|
276
|
+
|
277
|
+
def do_put
|
278
|
+
put :finish, :survey_code => "XYZ", :response_set_code => "PDQ"
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should find the response_set requested" do
|
282
|
+
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
283
|
+
do_put
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should update the found response set" do
|
287
|
+
@response_set.should_receive(:complete!).and_return(Time.now)
|
288
|
+
do_put
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should assign the found response set and survey for the view" do
|
292
|
+
do_put
|
293
|
+
assigns(:response_set).should equal(@response_set)
|
294
|
+
assigns(:survey).should equal(@response_set.survey)
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should render the 'edit' template" do
|
298
|
+
do_put
|
299
|
+
response.should render_template('edit')
|
300
|
+
flash[:notice].should == "Completed survey"
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should redirect to available surveys if :response_code not found" do
|
304
|
+
put :update, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
305
|
+
response.should redirect_to(available_surveys_url)
|
306
|
+
flash[:notice].should == "Unable to find your responses to the survey"
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
describe "with failed update" do
|
312
|
+
|
313
|
+
def do_put
|
314
|
+
put :finish, :survey_code => "XYZ", :response_set_code => "PDQ"
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should re-render 'edit'" do
|
318
|
+
@response_set.should_receive(:complete!).and_return(false)
|
319
|
+
do_put
|
320
|
+
response.should render_template('edit')
|
321
|
+
flash[:notice].should == "Unable to complete survey"
|
322
|
+
end
|
323
|
+
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
|
328
|
+
end
|