surveyor_gui 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +44 -0
  3. data/.travis.yml +17 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE +21 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +159 -0
  8. data/Rakefile +66 -0
  9. data/app/controllers/answers_controller.rb +3 -0
  10. data/app/controllers/application_controller.rb +3 -0
  11. data/app/controllers/dependencys_controller.rb +286 -0
  12. data/app/controllers/question_groups_controller.rb +84 -0
  13. data/app/controllers/questions_controller.rb +187 -0
  14. data/app/controllers/survey_sections_controller.rb +80 -0
  15. data/app/controllers/surveyforms_controller.rb +4 -0
  16. data/app/controllers/surveyor_controller.rb +89 -0
  17. data/app/controllers/surveyor_gui/reports_controller.rb +339 -0
  18. data/app/controllers/surveyor_gui/responses_controller.rb +39 -0
  19. data/app/controllers/surveyor_gui/survey_controller.rb +16 -0
  20. data/app/facades/report_formatter.rb +44 -0
  21. data/app/facades/report_preview_wrapper.rb +11 -0
  22. data/app/facades/report_response_generator.rb +147 -0
  23. data/app/helpers/application_helper.rb +2 -0
  24. data/app/helpers/dependency_helper.rb +5 -0
  25. data/app/helpers/question_helper.rb +22 -0
  26. data/app/helpers/surveyform_helper.rb +179 -0
  27. data/app/helpers/surveyor_gui/report_helper.rb +19 -0
  28. data/app/helpers/surveyor_helper.rb +4 -0
  29. data/app/inputs/currency_input.rb +5 -0
  30. data/app/inputs/date_picker_input.rb +7 -0
  31. data/app/inputs/datetime_picker_input.rb +5 -0
  32. data/app/inputs/percent_input.rb +5 -0
  33. data/app/inputs/time_picker_input.rb +5 -0
  34. data/app/mailers/.gitkeep +0 -0
  35. data/app/models/.gitkeep +0 -0
  36. data/app/models/answer.rb +4 -0
  37. data/app/models/column.rb +3 -0
  38. data/app/models/dependency.rb +4 -0
  39. data/app/models/dependency_condition.rb +4 -0
  40. data/app/models/permitted_params_decorator.rb +80 -0
  41. data/app/models/question.rb +4 -0
  42. data/app/models/question_group.rb +4 -0
  43. data/app/models/question_type.rb +7 -0
  44. data/app/models/response.rb +4 -0
  45. data/app/models/response_set.rb +4 -0
  46. data/app/models/row.rb +3 -0
  47. data/app/models/survey.rb +4 -0
  48. data/app/models/survey_section.rb +4 -0
  49. data/app/models/surveyform.rb +103 -0
  50. data/app/uploaders/blob_uploader.rb +48 -0
  51. data/app/views/dependencys/_column.html.erb +1 -0
  52. data/app/views/dependencys/_dependency.html.erb +22 -0
  53. data/app/views/dependencys/_dependency_condition_fields.html.erb +48 -0
  54. data/app/views/dependencys/_form.html.erb +20 -0
  55. data/app/views/dependencys/blank.html.erb +0 -0
  56. data/app/views/dependencys/edit.html.erb +1 -0
  57. data/app/views/dependencys/new.html.erb +1 -0
  58. data/app/views/layouts/application.html.erb +14 -0
  59. data/app/views/layouts/surveyor_gui_blank.html.erb +12 -0
  60. data/app/views/layouts/surveyor_gui_default.html.erb +16 -0
  61. data/app/views/layouts/surveyor_modified.html.erb +14 -0
  62. data/app/views/partials/_answer.html.haml +33 -0
  63. data/app/views/partials/_question.html.haml +33 -0
  64. data/app/views/partials/_question_group.html.haml +73 -0
  65. data/app/views/partials/_section.html.haml +13 -0
  66. data/app/views/question_groups/_form.html.erb +56 -0
  67. data/app/views/question_groups/_group_inline_field.html.erb +21 -0
  68. data/app/views/question_groups/_group_inline_fields.html.erb +25 -0
  69. data/app/views/question_groups/blank.html.erb +0 -0
  70. data/app/views/question_groups/edit.html.erb +1 -0
  71. data/app/views/question_groups/new.html.erb +1 -0
  72. data/app/views/questions/_answer_fields.html.erb +23 -0
  73. data/app/views/questions/_answer_options.html.erb +28 -0
  74. data/app/views/questions/_form.html.erb +65 -0
  75. data/app/views/questions/_grid_dropdown_columns.html.erb +10 -0
  76. data/app/views/questions/_grid_dropdown_fields.html.erb +42 -0
  77. data/app/views/questions/_grid_fields.html.erb +9 -0
  78. data/app/views/questions/_no_picks.html.erb +29 -0
  79. data/app/views/questions/_pick.html +21 -0
  80. data/app/views/questions/_picks.html.erb +12 -0
  81. data/app/views/questions/blank.html.erb +0 -0
  82. data/app/views/questions/edit.html.erb +1 -0
  83. data/app/views/questions/new.html.erb +1 -0
  84. data/app/views/survey_sections/_form.html.erb +13 -0
  85. data/app/views/survey_sections/blank.html.erb +0 -0
  86. data/app/views/survey_sections/edit.html.erb +1 -0
  87. data/app/views/survey_sections/new.html.erb +1 -0
  88. data/app/views/surveyforms/_form.html.erb +50 -0
  89. data/app/views/surveyforms/_question_field.html.erb +148 -0
  90. data/app/views/surveyforms/_question_group.html.erb +116 -0
  91. data/app/views/surveyforms/_question_group_fields.html.erb +3 -0
  92. data/app/views/surveyforms/_question_name_and_number.html.erb +6 -0
  93. data/app/views/surveyforms/_question_section.html.erb +15 -0
  94. data/app/views/surveyforms/_question_wrapper.html.erb +109 -0
  95. data/app/views/surveyforms/_survey_section_fields.html.erb +138 -0
  96. data/app/views/surveyforms/clone_survey.html.erb +13 -0
  97. data/app/views/surveyforms/edit.html.erb +5 -0
  98. data/app/views/surveyforms/index.html.erb +40 -0
  99. data/app/views/surveyforms/new.html.erb +1 -0
  100. data/app/views/surveyforms/show.html.erb +5 -0
  101. data/app/views/surveyor_gui/reports/_graphs.html.haml +21 -0
  102. data/app/views/surveyor_gui/reports/_grid.html.haml +42 -0
  103. data/app/views/surveyor_gui/reports/_grid_dropdown.html.haml +56 -0
  104. data/app/views/surveyor_gui/reports/_repeater.html.haml +28 -0
  105. data/app/views/surveyor_gui/reports/_show_report.html.haml +33 -0
  106. data/app/views/surveyor_gui/reports/_single_question.html.haml +70 -0
  107. data/app/views/surveyor_gui/reports/show.html.erb +14 -0
  108. data/app/views/surveyor_gui/responses/_grid.html.haml +20 -0
  109. data/app/views/surveyor_gui/responses/_grid_dropdown.html.haml +20 -0
  110. data/app/views/surveyor_gui/responses/_repeater.html.haml +22 -0
  111. data/app/views/surveyor_gui/responses/_survey_results.html.haml +40 -0
  112. data/app/views/surveyor_gui/responses/index.html.haml +24 -0
  113. data/app/views/surveyor_gui/responses/show.html.haml +42 -0
  114. data/app/views/surveyor_gui/shared/_grid_comments.html.haml +10 -0
  115. data/app/views/surveyor_gui/shared/_new_line.html.haml +2 -0
  116. data/app/views/surveyor_gui/shared/_pick_comments.html.haml +15 -0
  117. data/app/views/surveyor_gui/shared/_question_number.html.haml +9 -0
  118. data/app/views/surveyor_gui/shared/_report_data.html.haml +24 -0
  119. data/app/views/surveyor_gui/shared/_stars_report_data.html.haml +14 -0
  120. data/config.ru +4 -0
  121. data/config/environment.rb +0 -0
  122. data/config/routes.rb +71 -0
  123. data/db/migrate/20140307204049_add_template_to_surveys.rb +5 -0
  124. data/db/migrate/20140307235607_add_test_data_to_response_sets.rb +5 -0
  125. data/db/migrate/20140308171947_add_original_choice_to_answers.rb +5 -0
  126. data/db/migrate/20140308172118_add_blob_to_responses.rb +5 -0
  127. data/db/migrate/20140308172417_add_modifiable_to_survey_section.rb +5 -0
  128. data/db/migrate/20140308174532_add_modifiable_to_question.rb +5 -0
  129. data/db/migrate/20140308175305_add_dynamically_generate_to_questions.rb +5 -0
  130. data/db/migrate/20140311032923_add_dummy_blob_to_questions.rb +5 -0
  131. data/db/migrate/20140311160609_add_dynamic_source_to_questions.rb +5 -0
  132. data/db/migrate/20140311161714_add_report_code_to_questions.rb +5 -0
  133. data/db/migrate/20140530181134_add_is_comment_to_questions.rb +5 -0
  134. data/db/migrate/20140531012006_add_is_comment_to_answers.rb +5 -0
  135. data/db/migrate/20140531225529_create_rows.rb +9 -0
  136. data/db/migrate/20140601011151_create_columns.rb +11 -0
  137. data/db/migrate/20140602030330_add_column_id_to_answers.rb +5 -0
  138. data/db/migrate/20140603155606_add_column_id_to_responses.rb +5 -0
  139. data/db/migrate/20140606023527_add_column_id_to_dependency_conditions.rb +5 -0
  140. data/db/migrate/20140815165307_add_user_id_to_survey.rb +5 -0
  141. data/lib/assets/.gitkeep +0 -0
  142. data/lib/assets/images/addicon.png +0 -0
  143. data/lib/assets/images/datepicker.gif +0 -0
  144. data/lib/assets/images/delete.gif +0 -0
  145. data/lib/assets/images/delete.png +0 -0
  146. data/lib/assets/images/images/border.png +0 -0
  147. data/lib/assets/images/images/controls.png +0 -0
  148. data/lib/assets/images/images/loading.gif +0 -0
  149. data/lib/assets/images/images/loading_background.png +0 -0
  150. data/lib/assets/images/images/overlay.png +0 -0
  151. data/lib/assets/images/rails.png +0 -0
  152. data/lib/assets/images/star.gif +0 -0
  153. data/lib/assets/javascripts/.gitkeep +0 -0
  154. data/lib/assets/javascripts/surveyor_gui/jquery.MetaData.js +121 -0
  155. data/lib/assets/javascripts/surveyor_gui/jquery.blockUI.js +619 -0
  156. data/lib/assets/javascripts/surveyor_gui/jquery.rating.js +377 -0
  157. data/lib/assets/javascripts/surveyor_gui/jquery.validate.js +1188 -0
  158. data/lib/assets/javascripts/surveyor_gui/surveyor_add_ons.js +10 -0
  159. data/lib/assets/javascripts/surveyor_gui/surveyor_gui.js +1417 -0
  160. data/lib/assets/stylesheets/.gitkeep +0 -0
  161. data/lib/assets/stylesheets/surveyor_gui/jquery.rating.css +12 -0
  162. data/lib/assets/stylesheets/surveyor_gui/surveyor_add_ons.css +3 -0
  163. data/lib/assets/stylesheets/surveyor_gui/surveyor_gui.sass +650 -0
  164. data/lib/enumerable_extenders.rb +31 -0
  165. data/lib/generators/surveyor_gui/install_generator.rb +57 -0
  166. data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_add_ons.js +2 -0
  167. data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_gui_all.js +24 -0
  168. data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_add_ons.css.sass +1 -0
  169. data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_gui_all.css.sass +8 -0
  170. data/lib/generators/surveyor_gui/templates/app/helpers/surveyor_helper.rb +4 -0
  171. data/lib/generators/surveyor_gui/templates/app/models/response_set_user.rb +13 -0
  172. data/lib/generators/surveyor_gui/templates/app/views/layouts/surveyor_gui_default.html.erb +16 -0
  173. data/lib/generators/surveyor_gui/templates/config/initializers/simple_form.rb +140 -0
  174. data/lib/generators/surveyor_gui/templates/config/locales/en.yml +5 -0
  175. data/lib/surveyor_gui.rb +17 -0
  176. data/lib/surveyor_gui/engine.rb +30 -0
  177. data/lib/surveyor_gui/helpers/surveyor_helper_methods.rb +19 -0
  178. data/lib/surveyor_gui/models/answer_methods.rb +24 -0
  179. data/lib/surveyor_gui/models/column_methods.rb +43 -0
  180. data/lib/surveyor_gui/models/dependency_condition_methods.rb +53 -0
  181. data/lib/surveyor_gui/models/dependency_methods.rb +83 -0
  182. data/lib/surveyor_gui/models/question_and_group_shared_methods.rb +11 -0
  183. data/lib/surveyor_gui/models/question_group_methods.rb +55 -0
  184. data/lib/surveyor_gui/models/question_methods.rb +435 -0
  185. data/lib/surveyor_gui/models/question_type_methods.rb +493 -0
  186. data/lib/surveyor_gui/models/response_methods.rb +67 -0
  187. data/lib/surveyor_gui/models/response_set_methods.rb +54 -0
  188. data/lib/surveyor_gui/models/row_methods.rb +11 -0
  189. data/lib/surveyor_gui/models/survey_methods.rb +32 -0
  190. data/lib/surveyor_gui/models/survey_section_methods.rb +32 -0
  191. data/lib/surveyor_gui/surveyforms_controller_methods.rb +258 -0
  192. data/lib/surveyor_gui/version.rb +3 -0
  193. data/lib/tasks/.gitkeep +0 -0
  194. data/lib/tasks/surveyor_gui_tasks.rake +4 -0
  195. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  196. data/spec/controllers/surveyforms_controller_spec.rb +361 -0
  197. data/spec/controllers/surveyor_controller_spec.rb +303 -0
  198. data/spec/factories.rb +181 -0
  199. data/spec/features/create_survey_spec.rb +418 -0
  200. data/spec/features/dependencies_spec.rb +61 -0
  201. data/spec/features/rearrange_survey_spec.rb +118 -0
  202. data/spec/features/ui_spec.rb +469 -0
  203. data/spec/fixtures/REDCapDemoDatabase_DataDictionary.csv +127 -0
  204. data/spec/fixtures/chinese_survey.rb +14 -0
  205. data/spec/fixtures/everything.rb +215 -0
  206. data/spec/fixtures/favorites-ish.rb +22 -0
  207. data/spec/fixtures/favorites.rb +22 -0
  208. data/spec/fixtures/feelings.rb +38 -0
  209. data/spec/fixtures/lifestyle.rb +55 -0
  210. data/spec/fixtures/numbers.rb +21 -0
  211. data/spec/fixtures/redcap_new_headers.csv +1 -0
  212. data/spec/fixtures/redcap_siblings.csv +1 -0
  213. data/spec/fixtures/redcap_whitespace.csv +1 -0
  214. data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
  215. data/spec/helpers/surveyor_helper_spec.rb +116 -0
  216. data/spec/lib/common_spec.rb +37 -0
  217. data/spec/lib/parser_spec.rb +393 -0
  218. data/spec/lib/rake_kitchen_sink.rb +42 -0
  219. data/spec/lib/redcap_parser_spec.rb +129 -0
  220. data/spec/lib/unparser_spec.rb +126 -0
  221. data/spec/models/answer_spec.rb +144 -0
  222. data/spec/models/dependency_condition_spec.rb +428 -0
  223. data/spec/models/dependency_spec.rb +90 -0
  224. data/spec/models/question_group_spec.rb +66 -0
  225. data/spec/models/question_spec.rb +176 -0
  226. data/spec/models/response_set_spec.rb +452 -0
  227. data/spec/models/response_spec.rb +208 -0
  228. data/spec/models/survey_section_spec.rb +58 -0
  229. data/spec/models/survey_spec.rb +155 -0
  230. data/spec/models/surveyor_gui/question_spec.rb +60 -0
  231. data/spec/models/surveyor_gui/question_type_spec.rb +268 -0
  232. data/spec/models/validation_condition_spec.rb +98 -0
  233. data/spec/models/validation_spec.rb +64 -0
  234. data/spec/spec.opts +4 -0
  235. data/spec/spec_helper.rb +119 -0
  236. data/spec/support/scenario_outline_helper.rb +39 -0
  237. data/spec/support/shared.rb +10 -0
  238. data/spec/support/surveyforms_creation_helpers.rb +312 -0
  239. data/spec/support/surveyforms_rearrangement_helpers.rb +170 -0
  240. data/spec/support/surveyor_api_helpers.rb +15 -0
  241. data/spec/support/surveyor_ui_helpers.rb +108 -0
  242. data/spec/support/wait_for_ajax.rb +11 -0
  243. data/spec/views/questions/edit.html.erb_spec.rb +73 -0
  244. data/spec/views/surveyforms/edit.html.erb_spec.rb +126 -0
  245. data/surveyor_gui.gemspec +52 -0
  246. data/test/dummy/README.rdoc +261 -0
  247. data/test/dummy/Rakefile +7 -0
  248. data/test/dummy/app/assets/javascripts/application.js +15 -0
  249. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  250. data/test/dummy/app/controllers/application_controller.rb +3 -0
  251. data/test/dummy/app/helpers/application_helper.rb +2 -0
  252. data/test/dummy/app/mailers/.gitkeep +0 -0
  253. data/test/dummy/app/models/.gitkeep +0 -0
  254. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  255. data/test/dummy/config.ru +4 -0
  256. data/test/dummy/config/application.rb +59 -0
  257. data/test/dummy/config/boot.rb +10 -0
  258. data/test/dummy/config/database.yml +25 -0
  259. data/test/dummy/config/environment.rb +5 -0
  260. data/test/dummy/config/environments/development.rb +37 -0
  261. data/test/dummy/config/environments/production.rb +67 -0
  262. data/test/dummy/config/environments/test.rb +37 -0
  263. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  264. data/test/dummy/config/initializers/inflections.rb +15 -0
  265. data/test/dummy/config/initializers/mime_types.rb +5 -0
  266. data/test/dummy/config/initializers/secret_token.rb +7 -0
  267. data/test/dummy/config/initializers/session_store.rb +8 -0
  268. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  269. data/test/dummy/config/locales/en.yml +5 -0
  270. data/test/dummy/config/routes.rb +58 -0
  271. data/test/dummy/lib/assets/.gitkeep +0 -0
  272. data/test/dummy/log/.gitkeep +0 -0
  273. data/test/dummy/public/404.html +26 -0
  274. data/test/dummy/public/422.html +26 -0
  275. data/test/dummy/public/500.html +25 -0
  276. data/test/dummy/public/favicon.ico +0 -0
  277. data/test/dummy/script/rails +6 -0
  278. data/test/surveyor-gui_test.rb +7 -0
  279. data/test/test_helper.rb +15 -0
  280. data/vendor/assets/stylesheets/.gitkeep +0 -0
  281. data/vendor/assets/stylesheets/custom.sass +5 -0
  282. data/vendor/plugins/.gitkeep +0 -0
  283. metadata +664 -0
@@ -0,0 +1,181 @@
1
+ # encoding: utf-8
2
+ # http://github.com/thoughtbot/factory_girl/tree/master
3
+ require 'rubygems'
4
+ require 'factory_girl'
5
+
6
+ FactoryGirl.define do
7
+ sequence(:unique_survey_access_code){|n| "simple survey #{UUIDTools::UUID.random_create.to_s}" }
8
+
9
+ factory :survey do |s|
10
+ s.title "Simple survey"
11
+ s.description "A simple survey for testing"
12
+ s.access_code { FactoryGirl.generate :unique_survey_access_code }
13
+ s.survey_version 0
14
+ end
15
+
16
+ factory :surveyform do |s|
17
+ s.title "Simple survey"
18
+ s.description "A simple survey for testing"
19
+ s.access_code { FactoryGirl.generate :unique_survey_access_code }
20
+ s.survey_version 0
21
+ end
22
+
23
+ factory :template, parent: :surveyform do |s|
24
+ s.template true
25
+ end
26
+
27
+ factory :survey_translation do |t|
28
+ t.locale "es"
29
+ t.translation %(title: "Un idioma nunca es suficiente"
30
+ survey_sections:
31
+ one:
32
+ title: "Uno"
33
+ questions:
34
+ hello:
35
+ text: "¡Hola!"
36
+ name:
37
+ text: "¿Cómo se llama Usted?"
38
+ answers:
39
+ name:
40
+ help_text: "Mi nombre es...")
41
+ end
42
+
43
+ sequence(:survey_section_display_order){|n| n }
44
+
45
+ factory :survey_section do |s|
46
+ s.association :survey # s.survey_id {}
47
+ s.title {"Demographics"}
48
+ s.description {"Asking you about your personal data"}
49
+ s.display_order {FactoryGirl.generate :survey_section_display_order}
50
+ s.reference_identifier {"demographics"}
51
+ s.data_export_identifier {"demographics"}
52
+ end
53
+
54
+ sequence(:question_display_order){|n| n }
55
+
56
+ factory :question do |q|
57
+ q.association :survey_section # s.survey_section_id {}
58
+ # q.question_group_id {}
59
+ q.text "What is your favorite color?"
60
+ q.short_text "favorite_color"
61
+ q.help_text "just write it in the box"
62
+ q.pick :none
63
+ q.reference_identifier {|me| "q_#{me.object_id}"}
64
+ # q.data_export_identifier {}
65
+ # q.common_namespace {}
66
+ # q.common_identifier {}
67
+ q.display_order {FactoryGirl.generate :question_display_order}
68
+ # q.display_type {} # nil is default
69
+ q.is_mandatory false
70
+ # q.display_width {}
71
+ q.correct_answer_id nil
72
+ end
73
+
74
+ factory :question_group do |g|
75
+ g.text {"Describe your family"}
76
+ g.help_text {}
77
+ g.reference_identifier {|me| "g_#{me.object_id}"}
78
+ g.data_export_identifier {}
79
+ g.common_namespace {}
80
+ g.common_identifier {}
81
+ g.display_type {}
82
+ g.custom_class {}
83
+ g.custom_renderer {}
84
+ end
85
+
86
+ sequence(:answer_display_order){|n| n }
87
+
88
+ factory :answer do |a|
89
+ a.association :question # a.question_id {}
90
+ a.text "My favorite color is clear"
91
+ a.short_text "clear"
92
+ a.help_text "Clear is the absense of color"
93
+ # a.weight
94
+ a.response_class "string"
95
+ # a.reference_identifier {}
96
+ # a.data_export_identifier {}
97
+ # a.common_namespace {}
98
+ # a.common_identifier {}
99
+ a.display_order {FactoryGirl.generate :answer_display_order}
100
+ # a.is_exclusive {}
101
+ a.display_type "default"
102
+ # a.display_length {}
103
+ # a.custom_class {}
104
+ # a.custom_renderer {}
105
+ end
106
+
107
+ factory :dependency do |d|
108
+ # the dependent question
109
+ d.association :question # d.question_id {}
110
+ d.question_group_id {}
111
+ d.rule {"A"}
112
+ end
113
+
114
+ factory :dependency_condition do |d|
115
+ d.association :dependency # d.dependency_id {}
116
+ d.rule_key {"A"}
117
+ # the conditional question
118
+ d.question_id {}
119
+ d.operator {"=="}
120
+ d.answer_id {}
121
+ d.datetime_value {}
122
+ d.integer_value {}
123
+ d.float_value {}
124
+ d.unit {}
125
+ d.text_value {}
126
+ d.string_value {}
127
+ d.response_other {}
128
+ end
129
+
130
+ factory :response_set do |r|
131
+ r.user_id {}
132
+ r.association :survey # r.survey_id {}
133
+ r.access_code {Surveyor::Common.make_tiny_code}
134
+ r.started_at {Time.now}
135
+ r.completed_at {}
136
+ r.test_data {false}
137
+ end
138
+
139
+ factory :response do |r|
140
+ r.association :response_set # r.response_set_id {}
141
+ r.survey_section_id {}
142
+ r.question_id {}
143
+ r.answer_id {}
144
+ r.datetime_value {}
145
+ r.integer_value {}
146
+ r.float_value {}
147
+ r.unit {}
148
+ r.text_value {}
149
+ r.string_value {}
150
+ r.response_other {}
151
+ r.response_group {}
152
+ end
153
+
154
+ factory :validation do |v|
155
+ v.association :answer # v.answer_id {}
156
+ v.rule {"A"}
157
+ v.message {}
158
+ end
159
+
160
+ factory :validation_condition do |v|
161
+ v.association :validation # v.validation_id {}
162
+ v.rule_key {"A"}
163
+ v.question_id {}
164
+ v.operator {"=="}
165
+ v.answer_id {}
166
+ v.datetime_value {}
167
+ v.integer_value {}
168
+ v.float_value {}
169
+ v.unit {}
170
+ v.text_value {}
171
+ v.string_value {}
172
+ v.response_other {}
173
+ v.regexp {}
174
+ end
175
+
176
+ factory :column do |c|
177
+ c.association :question_group
178
+ c.text {}
179
+ c.answers_textbox {}
180
+ end
181
+ end
@@ -0,0 +1,418 @@
1
+ require 'spec_helper'
2
+
3
+ #from spec/support/surveyforms_helpers.rb
4
+ include SurveyFormsCreationHelpers::CreateSurvey
5
+ include SurveyFormsCreationHelpers::BuildASurvey
6
+
7
+ feature "User creates a new survey using a browser", %q{
8
+ As a user
9
+ I want to create a new survey using a browser
10
+ So that I don't have to learn the Surveyor DSL or dive into technical weeds} do
11
+
12
+ #force a cr/lf to make the output look better
13
+ scenario " " do
14
+ end
15
+
16
+ context "User has not yet started a new survey" do
17
+ scenario "User starts a new survey" do
18
+ #Given I'm on the surveyform web page
19
+ visit surveyforms_path
20
+
21
+ #When I click "New Survey"
22
+ click_link "New Survey"
23
+
24
+ #Then I see the "Create New Survey" page
25
+ expect(page).to have_content("Create New Survey")
26
+ end
27
+
28
+ scenario "User gives the survey a title" do
29
+ #Given I'm on the "Create New Survey" page
30
+ visit new_surveyform_path
31
+
32
+ #When I fill in a title
33
+ fill_in "Title", with: "How was Boston?"
34
+
35
+ #And I save the survey
36
+ click_button "Save Changes"
37
+
38
+ #Then I can start entering more details, like sections
39
+ expect(page).to have_button "Add Section"
40
+
41
+ #And questions
42
+ expect(page).to have_button "Add Question"
43
+ end
44
+ end
45
+
46
+ context "User started a new survey" do
47
+ before :each do
48
+ start_a_new_survey
49
+ end
50
+
51
+ scenario "User gives the section a title", :js=>true do
52
+ #Given I've started a new survey
53
+ #When I click the "Edit Section Title" button
54
+ click_button "Edit Section Title"
55
+
56
+ #Then I see a window pop-up
57
+ expect(page).to have_css('iframe')
58
+ within_frame 0 do
59
+
60
+ #And I see a new form for "Edit Survey Section"
61
+ find('form')
62
+ expect(find('h1')).to have_content("Edit Survey Section")
63
+
64
+ #And I enter a title
65
+ fill_in "Title", with: "Accommodations"
66
+
67
+ #And I save the title
68
+ click_button "Save Changes"
69
+
70
+ #Then the window goes away
71
+ end
72
+
73
+ #And I can see the correctly titled section in my survey
74
+ expect(first_section_title).to have_content("Accommodations")
75
+ end
76
+
77
+ scenario "User adds a text question", :js=>true do
78
+ #Given I've started a new survey
79
+ #When I click the "Add Question" button
80
+ click_button "Add Question"
81
+
82
+ #Then I see a window pop-up
83
+ expect(page).to have_css('iframe')
84
+ within_frame 0 do
85
+
86
+ #And I see a new form for "Add Question"
87
+ find('form')
88
+ expect(find('h1')).to have_content("Add Question")
89
+
90
+ #And I frame the question
91
+ fill_in "question_text", with: "Where did you stay?"
92
+
93
+ #And I select the "text" question type
94
+ select_question_type "Text"
95
+
96
+ #And I save the question
97
+ click_button "Save Changes"
98
+
99
+ #Then the window goes away
100
+ end
101
+
102
+ #And I can see the question in my survey
103
+ expect(first_question).to have_content("1) Where did you stay?")
104
+ expect(page).to have_css("input[type='text']")
105
+ end
106
+
107
+ context "User adds questions of each type to the survey" do
108
+ before :each do
109
+ start_a_new_survey
110
+ end
111
+ scenario "User adds a number question", :js=>true do
112
+ #Given I've added a new question
113
+ add_question do
114
+
115
+ #Then I select the "number" question type
116
+ select_question_type "Number"
117
+
118
+ #And I frame the question
119
+ fill_in "question_text", with: "How many days did you stay?"
120
+
121
+ #And I add the suffix, "Stayed"
122
+ fill_in "question_prefix", with: "Stayed"
123
+
124
+ #And I add the suffix, "days"
125
+ fill_in "question_suffix", with: "days at hotel"
126
+
127
+ #And I sav the question
128
+ click_button "Save Changes"
129
+
130
+ #Then the window goes away
131
+ end
132
+
133
+ #And I can see the question in my survey
134
+ expect(first_question).to have_content("1) How many days did you stay?")
135
+ expect(page).to have_css("input[type='text']")
136
+ expect(page).to have_content(/Stayed.*days at hotel/)
137
+ end
138
+
139
+
140
+ scenario "User adds a multiple choice question", :js=>true do
141
+ #Given I've added a new question
142
+ add_question do
143
+
144
+ #Then I select the "multiple choice" question type
145
+ select_question_type "Multiple Choice (only one answer)"
146
+
147
+ #And I frame the question
148
+ fill_in "question_text", with: "What type of room did you get?"
149
+
150
+ #And I add some choices"
151
+ fill_in "question_answers_textbox", with: """Deluxe King
152
+ Standard Queen
153
+ Standard Double"""
154
+
155
+ #And I save the question
156
+ click_button "Save Changes"
157
+
158
+ #Then the window goes away
159
+ end
160
+
161
+ #And I can see the question in my survey
162
+ expect(first_question).to have_content("1) What type of room did you get?")
163
+ expect(page).to have_css("input[type='radio'][value='Deluxe King']")
164
+ expect(page).to have_css("input[type='radio'][value='Standard Queen']")
165
+ expect(page).to have_css("input[type='radio'][value='Standard Double']")
166
+ end
167
+
168
+
169
+ scenario "User adds a choose any question", :js=>true do
170
+ #Given I've added a new question
171
+ add_question do
172
+
173
+ #Then I select the "multiple choice, multiple answers" question type
174
+ select_question_type "Multiple Choice (multiple answers)"
175
+
176
+ #And I frame the question
177
+ fill_in "question_text", with: "What did you order from the minibar?"
178
+
179
+ #And I add some choices"
180
+ fill_in "question_answers_textbox", with: """Bottled Water
181
+ Kit Kats
182
+ Scotch"""
183
+
184
+ #And I save the question
185
+ click_button "Save Changes"
186
+
187
+ #Then the window goes away
188
+ end
189
+
190
+ #And I can see the question in my survey
191
+ expect(first_question).to have_content("1) What did you order from the minibar?")
192
+ expect(page).to have_css("input[type='checkbox'][value='Bottled Water']")
193
+ expect(page).to have_css("input[type='checkbox'][value='Kit Kats']")
194
+ expect(page).to have_css("input[type='checkbox'][value='Scotch']")
195
+ end
196
+
197
+
198
+ scenario "User adds a dropdown list", :js=>true do
199
+ #Given I've added a new question
200
+ add_question do
201
+
202
+ #Then I select the "Dropdown" question type
203
+ select_question_type "Dropdown List"
204
+
205
+ #And I frame the question
206
+ fill_in "question_text", with: "1) What neighborhood were you in?"
207
+
208
+ #And I add some choices"
209
+ fill_in "question_answers_textbox", with: """ Financial District
210
+ Back Bay
211
+ North End"""
212
+
213
+ #And I save the question
214
+ click_button "Save Changes"
215
+
216
+ #Then the window goes away
217
+ end
218
+
219
+ #And I can see the question in my survey
220
+ expect(first_question).to have_content("1) What neighborhood were you in?")
221
+ expect(page).to have_css("option[value='Financial District']")
222
+ expect(page).to have_css("option[value='Back Bay']")
223
+ expect(page).to have_css("option[value='North End']")
224
+ end
225
+
226
+
227
+ scenario "User adds a date question", :js=>true do
228
+ #Given I've added a new question
229
+ add_question do
230
+
231
+ #Then I select the "Date" question type
232
+ select_question_type "Date"
233
+
234
+ #And I frame the question
235
+ fill_in "question_text", with: "When did you checkout?"
236
+
237
+ #And I save the question
238
+ click_button "Save Changes"
239
+
240
+ #Then the window goes away
241
+ end
242
+
243
+ #And I can see the question in my survey
244
+ expect(first_question).to have_content("1) When did you checkout?")
245
+ expect(page).to have_css("div.ui-datepicker",:visible=>false)
246
+
247
+ #Then I click on the question
248
+ 1.times {page.execute_script "$('input.date_picker').trigger('focus')"}
249
+
250
+ #And I see a datepicker popup
251
+ expect(page).to have_css("div.ui-datepicker", :visible=>true)
252
+ end
253
+
254
+ scenario "User adds a label", :js=>true do
255
+ #Given I've added a new question
256
+ add_question do
257
+
258
+ #Then I select the "Label" question type
259
+ select_question_type "Label"
260
+
261
+ #And I frame the question
262
+ fill_in "question_text", with: "You don't need to answer the following questions if you are not comfortable."
263
+
264
+ #And I save the question
265
+ click_button "Save Changes"
266
+
267
+ #Then the window goes away
268
+ end
269
+
270
+ #And I can see the label in my survey and it has no question number
271
+ expect(page).to have_content(/(?<!1\)\s)You don't need to answer the following questions if you are not comfortable./)
272
+ end
273
+
274
+ scenario "User adds a text box question", :js=>true do
275
+ #Given I've added a new question
276
+ add_question do
277
+
278
+ #Then I select the "Text Box" question type
279
+ select_question_type "Text Box (for extended text, like notes, etc.)"
280
+
281
+ #And I frame the question
282
+ fill_in "question_text", with: "What did you think of the staff?"
283
+
284
+ #And I save the question
285
+ click_button "Save Changes"
286
+
287
+ #Then the window goes away
288
+ end
289
+
290
+ #And I can see the question in my survey
291
+ expect(first_question).to have_content("1) What did you think of the staff?")
292
+ expect(page).to have_css("textarea")
293
+ end
294
+
295
+ scenario "User adds a slider question", :js=>true do
296
+ #Given I've added a new question
297
+ add_question do
298
+
299
+ #Then I select the "Slider" question type
300
+ select_question_type "Slider"
301
+
302
+ #And I frame the question
303
+ fill_in "question_text", with: "What did you think of the food?"
304
+
305
+ #And I add some choices"
306
+ fill_in "question_answers_textbox", with: """Sucked!
307
+ Meh
308
+ Good
309
+ Wicked good!"""
310
+
311
+
312
+ #And I save the question
313
+ click_button "Save Changes"
314
+
315
+ #Then the window goes away
316
+ end
317
+
318
+ #And I can see the slider in my survey
319
+ expect(first_question).to have_content("1) What did you think of the food?")
320
+ expect(page).to have_css(".ui-slider")
321
+
322
+ #And I can see the text for both ends of the slider (but not the middle)
323
+ expect(page).to have_content("Sucked!")
324
+ expect(page).not_to have_content("Meh")
325
+ expect(page).not_to have_content("Good")
326
+ expect(page).to have_content("Wicked good!")
327
+ end
328
+
329
+ scenario "User adds a star question", :js=>true do
330
+ #Given I've added a new question
331
+ add_question do
332
+
333
+ #Then I select the "Star" question type
334
+ select_question_type "Star"
335
+
336
+ #And I frame the question
337
+ fill_in "question_text", with: "How would you rate your stay?"
338
+
339
+ #And I save the question
340
+ click_button "Save Changes"
341
+
342
+ #Then the window goes away
343
+ end
344
+
345
+ #And I can see the question in my survey
346
+ expect(first_question).to have_content("1) How would you rate your stay?")
347
+
348
+ #And I see stars!
349
+ expect(page).to have_css('div.star-rating a')
350
+ end
351
+
352
+
353
+ scenario "User includes a file upload in the survey", :js=>true do
354
+ #Given I've added a new question
355
+ add_question do
356
+ #Then I select the "Star" question type
357
+ select_question_type "File Upload"
358
+
359
+ #And I frame the question
360
+ fill_in "question_text", with: "Please upload a copy of your bill."
361
+
362
+ #And I save the question
363
+ click_button "Save Changes"
364
+
365
+ #Then the window goes away
366
+ end
367
+
368
+ #And I can see the question in my survey
369
+ expect(first_question).to have_content("1) Please upload a copy of your bill.")
370
+
371
+ #And I can browse my files
372
+ expect(page).to have_css("input[type='file']")
373
+ end
374
+
375
+ scenario "User adds a grid - pick one question", :js=>true do
376
+ #Given I've added a new question
377
+ add_question do
378
+
379
+ #And I frame the question
380
+ fill_in "question_text", with: "Rate the service:"
381
+
382
+ #Then I select the "Star" question type
383
+ select_question_type "Grid (pick one)"
384
+
385
+ #And I add columns to the grid
386
+ expect(page).to have_css("#question_grid_columns_textbox")
387
+ fill_in "question_grid_columns_textbox", with: "Poor\nOk\nGood\nOutstanding"
388
+
389
+ #And I add columns to the grid
390
+ fill_in "question_grid_rows_textbox", with: "Front Desk\nConcierge\nRoom Service\nValet"
391
+
392
+ #And I save the question
393
+ click_button "Save Changes"
394
+
395
+ #Then the window goes away
396
+ end
397
+
398
+ #And I can see the question in my survey
399
+ expect(first_question).to have_content("1) Rate the service:")
400
+
401
+ #And I see a nice grid of radio buttons
402
+ expect(page).to have_content(/1\) Rate the service.*Poor.*Ok.*Good.*Outstanding.*(?<!\d\)\s)Front Desk.*(?<!\d\)\s)Concierge.*(?<!\d\)\s)Room Service.*(?<!\d\)\s)Valet/m)
403
+
404
+ expect(page).to have_css("input[type='radio'][value='Poor']")
405
+ expect(page).to have_css("input[type='radio'][value='Ok']")
406
+ expect(page).to have_css("input[type='radio'][value='Good']")
407
+ expect(page).to have_css("input[type='radio'][value='Outstanding']")
408
+ end
409
+ end
410
+ end #end context "user has started a new survey"
411
+
412
+ scenario "User saves a survey with all the different question types", :js=>true do
413
+ build_a_survey
414
+ click_button "Save Changes"
415
+ expect(page).to have_content(/[Ss]uccessfully update/)
416
+ expect(page).to have_content("How was Boston?")
417
+ end
418
+ end #end feature