upgrade_surveyor_gui 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +44 -0
  3. data/.travis.yml +17 -0
  4. data/CHANGELOG.md +46 -0
  5. data/Gemfile +8 -0
  6. data/LICENSE +21 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +244 -0
  9. data/Rakefile +66 -0
  10. data/app/controllers/surveyor_controller.rb +89 -0
  11. data/app/controllers/surveyor_gui/answers_controller.rb +3 -0
  12. data/app/controllers/surveyor_gui/application_controller.rb +3 -0
  13. data/app/controllers/surveyor_gui/dependencys_controller.rb +286 -0
  14. data/app/controllers/surveyor_gui/question_groups_controller.rb +90 -0
  15. data/app/controllers/surveyor_gui/questions_controller.rb +187 -0
  16. data/app/controllers/surveyor_gui/reports_controller.rb +339 -0
  17. data/app/controllers/surveyor_gui/responses_controller.rb +41 -0
  18. data/app/controllers/surveyor_gui/survey_controller.rb +16 -0
  19. data/app/controllers/surveyor_gui/survey_sections_controller.rb +80 -0
  20. data/app/controllers/surveyor_gui/surveyforms_controller.rb +4 -0
  21. data/app/facades/report_formatter.rb +46 -0
  22. data/app/facades/report_preview_wrapper.rb +11 -0
  23. data/app/facades/report_response_generator.rb +147 -0
  24. data/app/helpers/surveyor_gui/application_helper.rb +2 -0
  25. data/app/helpers/surveyor_gui/dependencys_helper.rb +5 -0
  26. data/app/helpers/surveyor_gui/question_groups_helper.rb +3 -0
  27. data/app/helpers/surveyor_gui/questions_helper.rb +22 -0
  28. data/app/helpers/surveyor_gui/reports_helper.rb +19 -0
  29. data/app/helpers/surveyor_gui/surveyforms_helper.rb +164 -0
  30. data/app/helpers/surveyor_helper.rb +4 -0
  31. data/app/inputs/currency_input.rb +5 -0
  32. data/app/inputs/date_picker_input.rb +7 -0
  33. data/app/inputs/datetime_picker_input.rb +5 -0
  34. data/app/inputs/percent_input.rb +5 -0
  35. data/app/inputs/time_picker_input.rb +5 -0
  36. data/app/mailers/.gitkeep +0 -0
  37. data/app/models/.gitkeep +0 -0
  38. data/app/models/answer.rb +4 -0
  39. data/app/models/column.rb +3 -0
  40. data/app/models/dependency.rb +4 -0
  41. data/app/models/dependency_condition.rb +4 -0
  42. data/app/models/permitted_params_decorator.rb +80 -0
  43. data/app/models/question.rb +4 -0
  44. data/app/models/question_group.rb +4 -0
  45. data/app/models/question_group_tracker.rb +19 -0
  46. data/app/models/question_type.rb +7 -0
  47. data/app/models/response.rb +4 -0
  48. data/app/models/response_set.rb +4 -0
  49. data/app/models/row.rb +3 -0
  50. data/app/models/survey.rb +4 -0
  51. data/app/models/survey_section.rb +4 -0
  52. data/app/models/surveyform.rb +103 -0
  53. data/app/uploaders/blob_uploader.rb +48 -0
  54. data/app/views/layouts/surveyor_gui/application.html.erb +14 -0
  55. data/app/views/layouts/surveyor_gui/surveyor_gui_blank.html.erb +13 -0
  56. data/app/views/layouts/surveyor_gui/surveyor_gui_default.html.erb +17 -0
  57. data/app/views/layouts/surveyor_gui/surveyor_modified.html.erb +14 -0
  58. data/app/views/partials/_answer.html.haml +33 -0
  59. data/app/views/partials/_question.html.haml +33 -0
  60. data/app/views/partials/_question_group.html.haml +73 -0
  61. data/app/views/partials/_section.html.haml +13 -0
  62. data/app/views/surveyor/edit.html.haml +21 -0
  63. data/app/views/surveyor_gui/dependencys/_column.html.erb +1 -0
  64. data/app/views/surveyor_gui/dependencys/_dependency.html.erb +22 -0
  65. data/app/views/surveyor_gui/dependencys/_dependency_condition_fields.html.erb +48 -0
  66. data/app/views/surveyor_gui/dependencys/_form.html.erb +20 -0
  67. data/app/views/surveyor_gui/dependencys/blank.html.erb +0 -0
  68. data/app/views/surveyor_gui/dependencys/edit.html.erb +1 -0
  69. data/app/views/surveyor_gui/dependencys/new.html.erb +1 -0
  70. data/app/views/surveyor_gui/partials/_url_helpers.html.erb +5 -0
  71. data/app/views/surveyor_gui/question_groups/_form.html.erb +57 -0
  72. data/app/views/surveyor_gui/question_groups/_group_inline_field.html.erb +21 -0
  73. data/app/views/surveyor_gui/question_groups/_group_inline_fields.html.erb +25 -0
  74. data/app/views/surveyor_gui/question_groups/blank.html.erb +0 -0
  75. data/app/views/surveyor_gui/question_groups/edit.html.erb +1 -0
  76. data/app/views/surveyor_gui/question_groups/new.html.erb +1 -0
  77. data/app/views/surveyor_gui/questions/_answer_fields.html.erb +23 -0
  78. data/app/views/surveyor_gui/questions/_answer_options.html.erb +28 -0
  79. data/app/views/surveyor_gui/questions/_form.html.erb +66 -0
  80. data/app/views/surveyor_gui/questions/_grid_dropdown_columns.html.erb +10 -0
  81. data/app/views/surveyor_gui/questions/_grid_dropdown_fields.html.erb +42 -0
  82. data/app/views/surveyor_gui/questions/_grid_fields.html.erb +9 -0
  83. data/app/views/surveyor_gui/questions/_no_picks.html.erb +29 -0
  84. data/app/views/surveyor_gui/questions/_pick.html +21 -0
  85. data/app/views/surveyor_gui/questions/_picks.html.erb +12 -0
  86. data/app/views/surveyor_gui/questions/blank.html.erb +0 -0
  87. data/app/views/surveyor_gui/questions/edit.html.erb +1 -0
  88. data/app/views/surveyor_gui/questions/new.html.erb +1 -0
  89. data/app/views/surveyor_gui/reports/_graphs.html.haml +21 -0
  90. data/app/views/surveyor_gui/reports/_grid.html.haml +42 -0
  91. data/app/views/surveyor_gui/reports/_grid_dropdown.html.haml +56 -0
  92. data/app/views/surveyor_gui/reports/_repeater.html.haml +27 -0
  93. data/app/views/surveyor_gui/reports/_show_report.html.haml +33 -0
  94. data/app/views/surveyor_gui/reports/_single_question.html.haml +70 -0
  95. data/app/views/surveyor_gui/reports/show.html.erb +14 -0
  96. data/app/views/surveyor_gui/responses/_grid.html.haml +20 -0
  97. data/app/views/surveyor_gui/responses/_grid_dropdown.html.haml +20 -0
  98. data/app/views/surveyor_gui/responses/_repeater.html.haml +22 -0
  99. data/app/views/surveyor_gui/responses/_survey_results.html.haml +40 -0
  100. data/app/views/surveyor_gui/responses/index.html.haml +24 -0
  101. data/app/views/surveyor_gui/responses/show.html.haml +42 -0
  102. data/app/views/surveyor_gui/shared/_grid_comments.html.haml +10 -0
  103. data/app/views/surveyor_gui/shared/_new_line.html.haml +2 -0
  104. data/app/views/surveyor_gui/shared/_pick_comments.html.haml +15 -0
  105. data/app/views/surveyor_gui/shared/_question_number.html.haml +11 -0
  106. data/app/views/surveyor_gui/shared/_report_data.html.haml +27 -0
  107. data/app/views/surveyor_gui/shared/_stars_report_data.html.haml +14 -0
  108. data/app/views/surveyor_gui/survey_sections/_form.html.erb +13 -0
  109. data/app/views/surveyor_gui/survey_sections/blank.html.erb +0 -0
  110. data/app/views/surveyor_gui/survey_sections/edit.html.erb +1 -0
  111. data/app/views/surveyor_gui/survey_sections/new.html.erb +1 -0
  112. data/app/views/surveyor_gui/surveyforms/_form.html.erb +50 -0
  113. data/app/views/surveyor_gui/surveyforms/_question_field.html.erb +148 -0
  114. data/app/views/surveyor_gui/surveyforms/_question_group.html.erb +116 -0
  115. data/app/views/surveyor_gui/surveyforms/_question_group_fields.html.erb +3 -0
  116. data/app/views/surveyor_gui/surveyforms/_question_name_and_number.html.erb +6 -0
  117. data/app/views/surveyor_gui/surveyforms/_question_section.html.erb +15 -0
  118. data/app/views/surveyor_gui/surveyforms/_question_wrapper.html.erb +108 -0
  119. data/app/views/surveyor_gui/surveyforms/_survey_section_fields.html.erb +137 -0
  120. data/app/views/surveyor_gui/surveyforms/clone_survey.html.erb +13 -0
  121. data/app/views/surveyor_gui/surveyforms/edit.html.erb +5 -0
  122. data/app/views/surveyor_gui/surveyforms/index.html.erb +40 -0
  123. data/app/views/surveyor_gui/surveyforms/new.html.erb +1 -0
  124. data/app/views/surveyor_gui/surveyforms/show.html.erb +5 -0
  125. data/config/environment.rb +0 -0
  126. data/config/routes.rb +71 -0
  127. data/config.ru +4 -0
  128. data/db/migrate/20140307204049_add_template_to_surveys.rb +5 -0
  129. data/db/migrate/20140307235607_add_test_data_to_response_sets.rb +5 -0
  130. data/db/migrate/20140308171947_add_original_choice_to_answers.rb +5 -0
  131. data/db/migrate/20140308172118_add_blob_to_responses.rb +5 -0
  132. data/db/migrate/20140308172417_add_modifiable_to_survey_section.rb +5 -0
  133. data/db/migrate/20140308174532_add_modifiable_to_question.rb +5 -0
  134. data/db/migrate/20140308175305_add_dynamically_generate_to_questions.rb +5 -0
  135. data/db/migrate/20140311032923_add_dummy_blob_to_questions.rb +5 -0
  136. data/db/migrate/20140311160609_add_dynamic_source_to_questions.rb +5 -0
  137. data/db/migrate/20140311161714_add_report_code_to_questions.rb +5 -0
  138. data/db/migrate/20140530181134_add_is_comment_to_questions.rb +5 -0
  139. data/db/migrate/20140531012006_add_is_comment_to_answers.rb +5 -0
  140. data/db/migrate/20140531225529_create_rows.rb +9 -0
  141. data/db/migrate/20140601011151_create_columns.rb +11 -0
  142. data/db/migrate/20140602030330_add_column_id_to_answers.rb +5 -0
  143. data/db/migrate/20140603155606_add_column_id_to_responses.rb +5 -0
  144. data/db/migrate/20140606023527_add_column_id_to_dependency_conditions.rb +5 -0
  145. data/db/migrate/20140815165307_add_user_id_to_survey.rb +5 -0
  146. data/lib/assets/.gitkeep +0 -0
  147. data/lib/assets/images/addicon.png +0 -0
  148. data/lib/assets/images/datepicker.gif +0 -0
  149. data/lib/assets/images/delete.gif +0 -0
  150. data/lib/assets/images/delete.png +0 -0
  151. data/lib/assets/images/images/border.png +0 -0
  152. data/lib/assets/images/images/controls.png +0 -0
  153. data/lib/assets/images/images/loading.gif +0 -0
  154. data/lib/assets/images/images/loading_background.png +0 -0
  155. data/lib/assets/images/images/overlay.png +0 -0
  156. data/lib/assets/images/rails.png +0 -0
  157. data/lib/assets/images/star.gif +0 -0
  158. data/lib/assets/javascripts/.gitkeep +0 -0
  159. data/lib/assets/javascripts/surveyor_gui/jquery.MetaData.js +121 -0
  160. data/lib/assets/javascripts/surveyor_gui/jquery.blockUI.js +619 -0
  161. data/lib/assets/javascripts/surveyor_gui/jquery.rating.js +377 -0
  162. data/lib/assets/javascripts/surveyor_gui/jquery.validate.js +1188 -0
  163. data/lib/assets/javascripts/surveyor_gui/surveyor_add_ons.js +10 -0
  164. data/lib/assets/javascripts/surveyor_gui/surveyor_gui.js +1428 -0
  165. data/lib/assets/stylesheets/.gitkeep +0 -0
  166. data/lib/assets/stylesheets/surveyor_gui/jquery.rating.css +12 -0
  167. data/lib/assets/stylesheets/surveyor_gui/surveyor_add_ons.css +3 -0
  168. data/lib/assets/stylesheets/surveyor_gui/surveyor_gui.sass +652 -0
  169. data/lib/enumerable_extenders.rb +31 -0
  170. data/lib/generators/surveyor_gui/install_generator.rb +57 -0
  171. data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_add_ons.js +2 -0
  172. data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_gui_all.js +24 -0
  173. data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_add_ons.css.sass +1 -0
  174. data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_gui_all.css.sass +8 -0
  175. data/lib/generators/surveyor_gui/templates/app/helpers/surveyor_helper.rb +4 -0
  176. data/lib/generators/surveyor_gui/templates/app/models/response_set_user.rb +13 -0
  177. data/lib/generators/surveyor_gui/templates/app/views/layouts/surveyor_gui/surveyor_gui_default.html.erb +17 -0
  178. data/lib/generators/surveyor_gui/templates/config/initializers/simple_form.rb +140 -0
  179. data/lib/generators/surveyor_gui/templates/config/locales/en.yml +5 -0
  180. data/lib/surveyor_gui/engine.rb +31 -0
  181. data/lib/surveyor_gui/helpers/surveyor_helper_methods.rb +19 -0
  182. data/lib/surveyor_gui/models/answer_methods.rb +24 -0
  183. data/lib/surveyor_gui/models/column_methods.rb +43 -0
  184. data/lib/surveyor_gui/models/dependency_condition_methods.rb +53 -0
  185. data/lib/surveyor_gui/models/dependency_methods.rb +83 -0
  186. data/lib/surveyor_gui/models/question_and_group_shared_methods.rb +11 -0
  187. data/lib/surveyor_gui/models/question_group_methods.rb +55 -0
  188. data/lib/surveyor_gui/models/question_methods.rb +435 -0
  189. data/lib/surveyor_gui/models/question_type_methods.rb +493 -0
  190. data/lib/surveyor_gui/models/response_methods.rb +71 -0
  191. data/lib/surveyor_gui/models/response_set_methods.rb +56 -0
  192. data/lib/surveyor_gui/models/row_methods.rb +11 -0
  193. data/lib/surveyor_gui/models/survey_methods.rb +32 -0
  194. data/lib/surveyor_gui/models/survey_section_methods.rb +32 -0
  195. data/lib/surveyor_gui/surveyforms_controller_methods.rb +258 -0
  196. data/lib/surveyor_gui/version.rb +3 -0
  197. data/lib/surveyor_gui.rb +17 -0
  198. data/lib/tasks/.gitkeep +0 -0
  199. data/lib/tasks/surveyor_gui_tasks.rake +4 -0
  200. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  201. data/spec/controllers/surveyforms_controller_spec.rb +362 -0
  202. data/spec/controllers/surveyor_controller_spec.rb +303 -0
  203. data/spec/factories.rb +181 -0
  204. data/spec/features/create_survey_spec.rb +417 -0
  205. data/spec/features/dependencies_spec.rb +65 -0
  206. data/spec/features/make_and_take_spec.rb +187 -0
  207. data/spec/features/rearrange_survey_spec.rb +118 -0
  208. data/spec/features/ui_spec.rb +469 -0
  209. data/spec/fixtures/REDCapDemoDatabase_DataDictionary.csv +127 -0
  210. data/spec/fixtures/chinese_survey.rb +14 -0
  211. data/spec/fixtures/everything.rb +215 -0
  212. data/spec/fixtures/favorites-ish.rb +22 -0
  213. data/spec/fixtures/favorites.rb +22 -0
  214. data/spec/fixtures/feelings.rb +38 -0
  215. data/spec/fixtures/lifestyle.rb +55 -0
  216. data/spec/fixtures/numbers.rb +21 -0
  217. data/spec/fixtures/redcap_new_headers.csv +1 -0
  218. data/spec/fixtures/redcap_siblings.csv +1 -0
  219. data/spec/fixtures/redcap_whitespace.csv +1 -0
  220. data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
  221. data/spec/helpers/surveyor_helper_spec.rb +116 -0
  222. data/spec/lib/common_spec.rb +37 -0
  223. data/spec/lib/parser_spec.rb +393 -0
  224. data/spec/lib/rake_kitchen_sink.rb +42 -0
  225. data/spec/lib/redcap_parser_spec.rb +129 -0
  226. data/spec/lib/unparser_spec.rb +126 -0
  227. data/spec/models/answer_spec.rb +144 -0
  228. data/spec/models/dependency_condition_spec.rb +428 -0
  229. data/spec/models/dependency_spec.rb +90 -0
  230. data/spec/models/question_group_spec.rb +66 -0
  231. data/spec/models/question_spec.rb +176 -0
  232. data/spec/models/response_set_spec.rb +452 -0
  233. data/spec/models/response_spec.rb +208 -0
  234. data/spec/models/survey_section_spec.rb +58 -0
  235. data/spec/models/survey_spec.rb +155 -0
  236. data/spec/models/surveyor_gui/question_spec.rb +60 -0
  237. data/spec/models/surveyor_gui/question_type_spec.rb +268 -0
  238. data/spec/models/validation_condition_spec.rb +98 -0
  239. data/spec/models/validation_spec.rb +64 -0
  240. data/spec/spec.opts +4 -0
  241. data/spec/spec_helper.rb +119 -0
  242. data/spec/support/scenario_outline_helper.rb +39 -0
  243. data/spec/support/shared.rb +10 -0
  244. data/spec/support/surveyforms_creation_helpers.rb +313 -0
  245. data/spec/support/surveyforms_rearrangement_helpers.rb +170 -0
  246. data/spec/support/surveyor_api_helpers.rb +15 -0
  247. data/spec/support/surveyor_ui_helpers.rb +108 -0
  248. data/spec/support/wait_for_ajax.rb +11 -0
  249. data/spec/views/questions/edit.html.erb_spec.rb +74 -0
  250. data/spec/views/surveyforms/edit.html.erb_spec.rb +126 -0
  251. data/surveyor_gui.gemspec +52 -0
  252. data/test/dummy/README.rdoc +261 -0
  253. data/test/dummy/Rakefile +7 -0
  254. data/test/dummy/app/assets/javascripts/application.js +15 -0
  255. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  256. data/test/dummy/app/controllers/application_controller.rb +3 -0
  257. data/test/dummy/app/helpers/application_helper.rb +2 -0
  258. data/test/dummy/app/mailers/.gitkeep +0 -0
  259. data/test/dummy/app/models/.gitkeep +0 -0
  260. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  261. data/test/dummy/config/application.rb +59 -0
  262. data/test/dummy/config/boot.rb +10 -0
  263. data/test/dummy/config/database.yml +25 -0
  264. data/test/dummy/config/environment.rb +5 -0
  265. data/test/dummy/config/environments/development.rb +37 -0
  266. data/test/dummy/config/environments/production.rb +67 -0
  267. data/test/dummy/config/environments/test.rb +37 -0
  268. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  269. data/test/dummy/config/initializers/inflections.rb +15 -0
  270. data/test/dummy/config/initializers/mime_types.rb +5 -0
  271. data/test/dummy/config/initializers/secret_token.rb +7 -0
  272. data/test/dummy/config/initializers/session_store.rb +8 -0
  273. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  274. data/test/dummy/config/locales/en.yml +5 -0
  275. data/test/dummy/config/routes.rb +58 -0
  276. data/test/dummy/config.ru +4 -0
  277. data/test/dummy/lib/assets/.gitkeep +0 -0
  278. data/test/dummy/log/.gitkeep +0 -0
  279. data/test/dummy/public/404.html +26 -0
  280. data/test/dummy/public/422.html +26 -0
  281. data/test/dummy/public/500.html +25 -0
  282. data/test/dummy/public/favicon.ico +0 -0
  283. data/test/dummy/script/rails +6 -0
  284. data/test/surveyor-gui_test.rb +7 -0
  285. data/test/test_helper.rb +15 -0
  286. data/tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016 +0 -0
  287. data/tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6 +0 -0
  288. data/vendor/assets/stylesheets/.gitkeep +0 -0
  289. data/vendor/assets/stylesheets/custom.sass +5 -0
  290. data/vendor/plugins/.gitkeep +0 -0
  291. metadata +600 -0
@@ -0,0 +1,3 @@
1
+ module SurveyorGui
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'surveyor'
2
+ module SurveyorGui
3
+ require 'surveyor_gui/engine' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
4
+ autoload :VERSION, 'surveyor_gui/version'
5
+ end
6
+ require 'jquery-rails'
7
+ require 'sass-rails'
8
+ require 'jquery-ui-sass-rails'
9
+
10
+ require 'will_paginate'
11
+ require 'simple_form'
12
+ require 'colorbox-rails'
13
+ require 'jquery-form-rails'
14
+ require 'carrierwave'
15
+ require 'dynamic_form'
16
+ require 'lazy_high_charts'
17
+ require 'enumerable_extenders'
File without changes
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :surveyor_gui do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,13 @@
1
+ <%%= simple_form_for(@<%= singular_name %>) do |f| %>
2
+ <%%= f.error_notification %>
3
+
4
+ <div class="inputs">
5
+ <%- attributes.each do |attribute| -%>
6
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7
+ <%- end -%>
8
+ </div>
9
+
10
+ <div class="actions">
11
+ <%%= f.button :submit %>
12
+ </div>
13
+ <%% end %>
@@ -0,0 +1,362 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe SurveyorGui::SurveyformsController do
4
+ include Surveyor::Engine.routes.url_helpers
5
+ include SurveyorGui::Engine.routes.url_helpers
6
+ before do
7
+ self.routes = SurveyorGui::Engine.routes
8
+ end
9
+
10
+ let!(:survey) { FactoryGirl.create(:survey, :title => "Alphabet", :access_code => "alpha", :survey_version => 0)}
11
+ let!(:survey_beta) { FactoryGirl.create(:survey, :title => "Alphabet", :access_code => "alpha", :survey_version => 1)}
12
+ let!(:survey_with_no_responses) {FactoryGirl.create(:survey)}
13
+ let!(:survey_with_responses) {FactoryGirl.create(:survey)}
14
+ let!(:template) {FactoryGirl.create(:template)}
15
+ let!(:surveyform) {FactoryGirl.create(:surveyform)}
16
+ let!(:response_set) { FactoryGirl.create(:survey_sections, :survey => survey_with_responses)}
17
+ let!(:response_set) { FactoryGirl.create(:response_set, :survey => survey_with_responses, :access_code => "pdq")}
18
+
19
+ def survey_with_sections
20
+ {
21
+ :title=>'New Survey',
22
+ :survey_sections_attributes => {
23
+ "0" => {
24
+ :title => 'New Section',
25
+ :display_order => 0
26
+ }
27
+ }
28
+ }
29
+ end
30
+
31
+ context "#index" do
32
+ def do_get(params = {})
33
+ get :index, params
34
+ end
35
+
36
+ context "index parameters specify surveys" do
37
+
38
+ it "set the title to 'manage surveys'" do
39
+ do_get()
40
+ assigns(:title).should eq("Manage Surveys")
41
+ end
42
+
43
+ it "should not populate an array of templates" do
44
+ do_get()
45
+ expect(assigns(:surveyforms)).not_to eq([template])
46
+ end
47
+
48
+ it "should populate an array of surveys" do
49
+ do_get()
50
+ expect(assigns(:surveyforms)).to include(surveyform)
51
+ end
52
+
53
+ it "shows the surveys" do
54
+ do_get()
55
+ expect(response).to render_template('index')
56
+ end
57
+ end
58
+
59
+ context "index parameters specify survey templates" do
60
+
61
+ it "set the title to 'manage templates'" do
62
+ do_get(:template=>"true")
63
+ assigns(:title).should eq("Manage Templates")
64
+ end
65
+
66
+ it "should populate an array of templates" do
67
+ do_get(params={:template=>"true"})
68
+ expect(assigns(:surveyforms)).to eq([template])
69
+ end
70
+
71
+ it "should not populate an array of surveys" do
72
+ do_get(params={:template=>"true"})
73
+ expect(assigns(:surveyforms)).not_to eq([surveyform])
74
+ end
75
+
76
+ it "shows the survey templates" do
77
+ do_get(:template=>"true")
78
+ expect(response).to render_template('index')
79
+ end
80
+ end
81
+ end
82
+
83
+ context "#new" do
84
+ def do_get
85
+ get :new
86
+ end
87
+
88
+ it "renders new" do
89
+ do_get
90
+ expect(response).to be_success
91
+ expect(response).to render_template('new')
92
+ end
93
+
94
+ it "populates an empty survey" do
95
+ do_get
96
+ expect(assigns(:surveyform).id).to eq(nil)
97
+ end
98
+ end
99
+
100
+ context "#create" do
101
+
102
+ def do_post(params = {})
103
+ post :create, :surveyform=>params
104
+ end
105
+
106
+ context "it saves successfully" do
107
+
108
+ it "returns to the edit page" do
109
+ do_post(:title=>'New surv')
110
+ expect(response).to redirect_to(edit_surveyform_path(assigns(:surveyform).id))
111
+ end
112
+
113
+ it "resets question_no to 0" do
114
+ do_post(:title=>'New surv')
115
+ expect(assigns(:question_no)).to eq(0)
116
+ end
117
+
118
+ end
119
+
120
+ context "it fails to save" do
121
+
122
+ it "renders new" do
123
+ do_post()
124
+ expect(response).to render_template('new')
125
+ end
126
+ end
127
+
128
+ context "if it includes survey sections" do
129
+
130
+ before :each do
131
+ @survey_with_sections = survey_with_sections
132
+ end
133
+
134
+ context "when sections are valid" do
135
+ it "redirects to the edit page" do
136
+ do_post @survey_with_sections
137
+ expect(response).to redirect_to(edit_surveyform_path(assigns(:surveyform).id))
138
+ end
139
+ end
140
+
141
+ context "when sections are not valid" do
142
+ before :each do
143
+ @survey_with_sections[:survey_sections_attributes]["0"][:display_order]=nil
144
+ end
145
+ it "renders new" do
146
+ do_post()
147
+ expect(response).to render_template('new')
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ context "#edit" do
154
+
155
+ context "the survey has no responses" do
156
+
157
+ def do_get(params = {})
158
+ get :edit, {:id => survey_with_no_responses.id}.merge(params)
159
+ end
160
+
161
+ it "renders edit" do
162
+ do_get
163
+ expect(response).to be_success
164
+ expect(response).to render_template('edit')
165
+ end
166
+ end
167
+
168
+ context "the survey has responses" do
169
+
170
+ def do_get(params = {})
171
+ get :edit, {:id => survey_with_responses.id}.merge(params)
172
+ end
173
+
174
+ it "still lets you see the edit page" do
175
+ do_get
176
+ expect(response).to be_success
177
+ expect(response).to render_template('edit')
178
+ end
179
+ it "warns that responses have been collected" do
180
+ expect(flash[:error]) =~ /been collected/i
181
+ end
182
+ end
183
+ end
184
+
185
+ context "#update" do
186
+
187
+ context "it saves successfully" do
188
+
189
+ def do_put(params = {})
190
+ put :update, params
191
+ end
192
+
193
+ it "redirects to index" do
194
+ do_put(:id=>survey.id,:surveyform=>{:id=>survey.id})
195
+ expect(response).to redirect_to(surveyforms_path)
196
+ end
197
+
198
+ end
199
+
200
+ context "it fails to save" do
201
+
202
+ def do_put(params = {})
203
+ put :update, params
204
+ end
205
+
206
+ it "renders edit" do
207
+ do_put(:id=>survey.id, :surveyform=>{:id=>survey.id,:title=>''})
208
+ expect(response).to render_template('edit')
209
+ end
210
+
211
+ it "resets question_no to 0" do
212
+ do_put(:id=>survey.id,:surveyform=>{:id=>survey.id,:title=>''})
213
+ expect(assigns(:question_no)).to eq(0)
214
+ end
215
+
216
+ end
217
+
218
+ end
219
+
220
+
221
+ context "#show" do
222
+ def do_get
223
+ get :show, {:id => survey.id}
224
+ end
225
+
226
+ it "shows survey" do
227
+ do_get
228
+ expect(response).to be_success
229
+ expect(response).to render_template('show')
230
+ end
231
+ end
232
+
233
+ context "#destroy" do
234
+
235
+ context "no responses were submitted" do
236
+ def do_delete
237
+ delete :destroy, :id => survey_with_no_responses
238
+ end
239
+
240
+ it "successfully destroys the survey" do
241
+ do_delete
242
+ expect(response).to redirect_to(surveyforms_path)
243
+ expect(Survey.exists?(survey_with_no_responses.id)).to be_false
244
+ end
245
+ end
246
+
247
+ context "responses were submitted" do
248
+ def do_delete
249
+ delete :destroy, :id => survey_with_responses
250
+ end
251
+
252
+ it "fails to delete the survey" do
253
+ do_delete
254
+ expect(response).to redirect_to(surveyforms_path)
255
+ expect(Survey.exists?(survey_with_responses.id)).to be_true
256
+ end
257
+
258
+ it "displays a flash message warning responses were collected" do
259
+ do_delete
260
+ expect(flash[:error]).to have_content /not be deleted/i
261
+ end
262
+ end
263
+ end
264
+
265
+ context "#replace form" do
266
+
267
+ def do_get(params = {})
268
+ FactoryGirl.create(:survey_section, :survey => survey)
269
+ get :replace_form, {:id=>survey.id,:survey_section_id=>survey.sections.first.id}.merge(params)
270
+ end
271
+
272
+ it "resets question_no to 0" do
273
+ do_get
274
+ expect(assigns(:question_no)).to eq(0)
275
+ end
276
+
277
+ it "renders new" do
278
+ do_get
279
+ expect(response).to be_success
280
+ expect(response).to render_template('new')
281
+ end
282
+
283
+ end
284
+
285
+ context "#insert_survey_section" do
286
+ def do_get(params = {})
287
+ survey.sections = [FactoryGirl.create(:survey_section, :survey => survey)]
288
+ get :insert_survey_section,{id: survey.id}.merge(params)
289
+ end
290
+ it "inserts a survey section" do
291
+ do_get
292
+ expect(response).to be_success
293
+ expect(response).to render_template('_survey_section_fields')
294
+ end
295
+ end
296
+
297
+ context "#replace_survey_section" do
298
+
299
+ def do_get(params = {})
300
+ FactoryGirl.create(:survey_section, :survey => survey)
301
+ get :replace_survey_section, {:id=>survey.id,:survey_section_id=>survey.sections.first.id}.merge(params)
302
+ end
303
+
304
+ it "resets question_no to 0" do
305
+ do_get
306
+ expect(assigns(:question_no)).to eq(0)
307
+ end
308
+
309
+ it "renders survey_section partial" do
310
+ do_get
311
+ expect(response).to be_success
312
+ expect(response).to render_template('_survey_section_fields')
313
+ end
314
+
315
+ end
316
+ context "#insert_new_question" do
317
+ def do_get(params = {})
318
+ survey.sections = [FactoryGirl.create(:survey_section, :survey => survey)]
319
+ survey.sections.first.questions = [FactoryGirl.create(:question, :survey_section => survey.sections.first)]
320
+ get :insert_new_question,{:id => survey.id, :question_id => survey.sections.first.questions.first.id}.merge(params)
321
+ end
322
+ it "inserts a question" do
323
+ do_get
324
+ expect(response).to be_success
325
+ expect(response).to render_template('new')
326
+ end
327
+ end
328
+
329
+ context "#cut_question" do
330
+ def do_get(params = {})
331
+ survey.sections = [FactoryGirl.create(:survey_section, :survey => survey)]
332
+ survey.sections.first.questions = [FactoryGirl.create(:question, :survey_section => survey.sections.first)]
333
+ get :cut_question,{:id => survey.id, :question_id => survey.sections.first.questions.first.id}.merge(params)
334
+ end
335
+ it "cuts a question" do
336
+ do_get
337
+ expect(response).to be_success
338
+ end
339
+ end
340
+
341
+ context "#clone_survey" do
342
+ def do_put(params={})
343
+ survey.sections = [FactoryGirl.create(:survey_section, :survey => survey)]
344
+ survey.sections.first.questions = [FactoryGirl.create(:question, :survey_section => survey.sections.first, text: 'my cloned question')]
345
+ put :clone_survey,{id: survey.id}
346
+ end
347
+
348
+ it "creates a new survey" do
349
+ expect{do_put}.to change{Survey.count}.by(1)
350
+ end
351
+
352
+ it "gives a different id to the clone" do
353
+ do_put
354
+ expect(Survey.last.id).not_to eql survey.id
355
+ end
356
+
357
+ it "copies the text of the question" do
358
+ do_put
359
+ expect(Survey.last.survey_sections.first.questions.first.text).to eql 'my cloned question'
360
+ end
361
+ end
362
+ end
@@ -0,0 +1,303 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe SurveyorController do
4
+ include Surveyor::Engine.routes.url_helpers
5
+ before do
6
+ @routes = Surveyor::Engine.routes
7
+ end
8
+
9
+ let!(:survey) { FactoryGirl.create(:survey, :title => "Alphabet", :access_code => "alpha", :survey_version => 0)}
10
+ let!(:survey_beta) { FactoryGirl.create(:survey, :title => "Alphabet", :access_code => "alpha", :survey_version => 1)}
11
+ let!(:response_set) { FactoryGirl.create(:response_set, :survey => survey, :access_code => "pdq")}
12
+
13
+ before { ResponseSet.stub(:create).and_return(response_set) }
14
+
15
+ # match '/', :to => 'surveyor#new', :as => 'available_surveys', :via => :get
16
+ # match '/:survey_code', :to => 'surveyor#create', :as => 'take_survey', :via => :post
17
+ # match '/:survey_code', :to => 'surveyor#export', :as => 'export_survey', :via => :get
18
+ # match '/:survey_code/:response_set_code', :to => 'surveyor#show', :as => 'view_my_survey', :via => :get
19
+ # match '/:survey_code/:response_set_code/take', :to => 'surveyor#edit', :as => 'edit_my_survey', :via => :get
20
+ # match '/:survey_code/:response_set_code', :to => 'surveyor#update', :as => 'update_my_survey', :via => :put
21
+
22
+ context "#new" do
23
+ def do_get
24
+ get :new
25
+ end
26
+ it "renders new" do
27
+ do_get
28
+ response.should be_success
29
+ response.should render_template('new')
30
+ end
31
+ it "assigns surveys_by_access_code" do
32
+ do_get
33
+ assigns(:surveys_by_access_code).should == {"alpha" => [survey_beta,survey]}
34
+ end
35
+ end
36
+
37
+ context "#create" do
38
+ def do_post(params = {})
39
+ post :create, {:survey_code => "alpha"}.merge(params)
40
+ end
41
+ it "finds latest version" do
42
+ do_post
43
+ assigns(:survey).should == survey_beta
44
+ end
45
+ it "finds specified survey_version" do
46
+ do_post :survey_version => 0
47
+ assigns(:survey).should == survey
48
+ end
49
+ it "creates a new response_set" do
50
+ ResponseSet.should_receive(:create)
51
+ do_post
52
+ end
53
+ it "should redirects to the new response_set" do
54
+ do_post
55
+ response.should redirect_to( edit_my_survey_path(:survey_code => "alpha", :response_set_code => "pdq"))
56
+ end
57
+
58
+ context "with failures" do
59
+ it "redirect to #new on failed ResponseSet#create" do
60
+ ResponseSet.should_receive(:create).and_return(false)
61
+ do_post
62
+ response.should redirect_to(available_surveys_path)
63
+ end
64
+ it "redirect to #new on failed Survey#find" do
65
+ do_post :survey_code => "missing"
66
+ response.should redirect_to(available_surveys_path)
67
+ end
68
+ end
69
+
70
+ context "with javascript check, assigned in session" do
71
+ it "enabled" do
72
+ do_post :surveyor_javascript_enabled => "true"
73
+ session[:surveyor_javascript].should_not be_nil
74
+ session[:surveyor_javascript].should == "enabled"
75
+ end
76
+ it "disabled" do
77
+ post :create, :survey_code => "xyz", :surveyor_javascript_enabled => "not_true"
78
+ session[:surveyor_javascript].should_not be_nil
79
+ session[:surveyor_javascript].should == "not_enabled"
80
+ end
81
+ end
82
+ end
83
+
84
+ context "#show" do
85
+ def do_get(params = {})
86
+ get :show, {:survey_code => "alpha", :response_set_code => "pdq"}.merge(params)
87
+ end
88
+ it "renders show" do
89
+ do_get
90
+ response.should be_success
91
+ response.should render_template('show')
92
+ end
93
+ it "redirects for missing response set" do
94
+ do_get :response_set_code => "DIFFERENT"
95
+ response.should redirect_to(available_surveys_path)
96
+ end
97
+ it "assigns earlier survey_version" do
98
+ response_set
99
+ do_get
100
+ assigns[:response_set].should == response_set
101
+ assigns[:survey].should == survey
102
+ end
103
+ it "assigns later survey_version" do
104
+ response_set_beta = FactoryGirl.create(:response_set, :survey => survey_beta, :access_code => "rst")
105
+ do_get :response_set_code => "rst"
106
+ assigns[:response_set].should == response_set_beta
107
+ assigns[:survey].should == survey_beta
108
+ end
109
+ end
110
+
111
+ context "#edit" do
112
+ context "responses have been collected" do
113
+ def do_get(params = {})
114
+ @survey = FactoryGirl.create(:survey, :title => "Alphabet Soup", :access_code => "alphasoup", :survey_version => 0)
115
+ @survey.sections = [FactoryGirl.create(:survey_section, :survey => @survey)]
116
+ @response_set = FactoryGirl.create(:response_set, :survey => @survey, :access_code => "foo")
117
+ get :edit, {:survey_code => "alphasoup", :response_set_code => "foo"}.merge(params)
118
+ end
119
+ it "renders edit" do
120
+ do_get
121
+ response.should be_success
122
+ response.should render_template('edit')
123
+ end
124
+ it "assigns survey and response set" do
125
+ do_get
126
+ assigns[:survey].should == @survey
127
+ assigns[:response_set].should == @response_set
128
+ end
129
+ it "redirects for missing response set" do
130
+ do_get :response_set_code => "DIFFERENT"
131
+ response.should redirect_to(available_surveys_path)
132
+ end
133
+ it "assigns dependents if javascript not enabled" do
134
+ controller.stub(:get_unanswered_dependencies_minus_section_questions).and_return([FactoryGirl.create(:question)])
135
+ session[:surveyor_javascript].should be_nil
136
+ do_get
137
+ assigns[:dependents].should_not be_empty
138
+ end
139
+ it "does not assign dependents if javascript is enabled" do
140
+ controller.stub(:get_unanswered_dependencies_minus_section_questions).and_return([FactoryGirl.create(:question)])
141
+ session[:surveyor_javascript] = "enabled"
142
+ do_get
143
+ assigns[:dependents].should be_empty
144
+ end
145
+ it "assigns earlier survey_version" do
146
+ do_get
147
+ assigns[:response_set].should == @response_set
148
+ assigns[:survey].should == @survey
149
+ end
150
+ it "assigns later survey_version" do
151
+ survey_beta.sections = [FactoryGirl.create(:survey_section, :survey => survey_beta)]
152
+ response_set_beta = FactoryGirl.create(:response_set, :survey => survey_beta, :access_code => "rst")
153
+ do_get :response_set_code => "rst"
154
+ assigns[:survey].should == survey_beta
155
+ assigns[:response_set].should == response_set_beta
156
+ end
157
+ end
158
+ end
159
+
160
+ context "#update" do
161
+ let(:responses_ui_hash) { {} }
162
+ let(:update_params) {
163
+ {
164
+ :survey_code => "alpha",
165
+ :response_set_code => "pdq"
166
+ }
167
+ }
168
+ shared_examples "#update action" do
169
+ before do
170
+ ResponseSet.stub_chain(:includes, :where, :first).and_return(response_set)
171
+ responses_ui_hash['11'] = {'api_id' => 'something', 'answer_id' => '56', 'question_id' => '9'}
172
+ end
173
+ it "saves responses" do
174
+ response_set.should_receive(:update_from_ui_hash).with(responses_ui_hash)
175
+
176
+ do_put(:r => responses_ui_hash)
177
+ end
178
+ it "does not fail when there are no responses" do
179
+ lambda { do_put }.should_not raise_error
180
+ end
181
+ context "with update exceptions" do
182
+ it 'retries the update on a constraint violation' do
183
+ response_set.should_receive(:update_from_ui_hash).ordered.with(responses_ui_hash).and_raise(ActiveRecord::StatementInvalid.new(''))
184
+ response_set.should_receive(:update_from_ui_hash).ordered.with(responses_ui_hash)
185
+
186
+ expect { do_put(:r => responses_ui_hash) }.to_not raise_error
187
+ end
188
+
189
+ it 'only retries three times' do
190
+ response_set.should_receive(:update_from_ui_hash).exactly(3).times.with(responses_ui_hash).and_raise(ActiveRecord::StatementInvalid.new(''))
191
+
192
+ expect { do_put(:r => responses_ui_hash) }.to raise_error(ActiveRecord::StatementInvalid)
193
+ end
194
+
195
+ it 'does not retry for other errors' do
196
+ response_set.should_receive(:update_from_ui_hash).once.with(responses_ui_hash).and_raise('Bad news')
197
+
198
+ expect { do_put(:r => responses_ui_hash) }.to raise_error('Bad news')
199
+ end
200
+ end
201
+ end
202
+
203
+ context "with form submission" do
204
+ def do_put(extra_params = {})
205
+ put :update, update_params.merge(extra_params)
206
+ end
207
+
208
+ it_behaves_like "#update action"
209
+ it "redirects to #edit without params" do
210
+ do_put
211
+ response.should redirect_to(edit_my_survey_path(:survey_code => "alpha", :response_set_code => "pdq"))
212
+ end
213
+ it "completes the found response set on finish" do
214
+ do_put :finish => 'finish'
215
+ response_set.reload.should be_complete
216
+ end
217
+ it 'flashes completion' do
218
+ do_put :finish => 'finish'
219
+ flash[:notice].should == "Completed survey"
220
+ end
221
+ it "redirects for missing response set" do
222
+ do_put :response_set_code => "DIFFERENT"
223
+ response.should redirect_to(available_surveys_path)
224
+ flash[:notice].should == "Unable to find your responses to the survey"
225
+ end
226
+ end
227
+
228
+ context 'with ajax' do
229
+ def do_put(extra_params = {})
230
+ xhr :put, :update, update_params.merge(extra_params)
231
+ end
232
+
233
+ it_behaves_like "#update action"
234
+ it "returns dependencies" do
235
+ ResponseSet.stub_chain(:includes, :where, :first).and_return(response_set)
236
+ response_set.should_receive(:all_dependencies).and_return({"show" => ['q_1'], "hide" => ['q_2']})
237
+
238
+ do_put
239
+ JSON.parse(response.body).should == {"show" => ['q_1'], "hide" => ["q_2"]}
240
+ end
241
+ it "returns 404 for missing response set" do
242
+ do_put :response_set_code => "DIFFERENT"
243
+ response.status.should == 404
244
+ end
245
+ end
246
+ end
247
+
248
+ context "#export" do
249
+ render_views
250
+
251
+ let(:json) {
252
+ get :export, :survey_code => survey.access_code, :format => 'json'
253
+ JSON.parse(response.body)
254
+ }
255
+
256
+ context "question inside and outside a question group" do
257
+ def question_text(refid)
258
+ <<-SURVEY
259
+ q "Where is a foo?", :pick => :one, :help_text => 'Look around.', :reference_identifier => #{refid.inspect},
260
+ :data_export_identifier => 'X.FOO', :common_namespace => 'F', :common_identifier => 'f'
261
+ a_L 'To the left', :data_export_identifier => 'X.L', :common_namespace => 'F', :common_identifier => 'l'
262
+ a_R 'To the right', :data_export_identifier => 'X.R', :common_namespace => 'F', :common_identifier => 'r'
263
+ a_O 'Elsewhere', :string
264
+
265
+ dependency :rule => 'R'
266
+ condition_R :q_bar, "==", :a_1
267
+ SURVEY
268
+ end
269
+ let(:survey_text) {
270
+ <<-SURVEY
271
+ survey 'xyz' do
272
+ section 'Sole' do
273
+ q_bar "Should that other question show up?", :pick => :one
274
+ a_1 'Yes'
275
+ a_2 'No'
276
+
277
+ #{question_text('foo_solo')}
278
+
279
+ group do
280
+ #{question_text('foo_grouped')}
281
+ end
282
+ end
283
+ end
284
+ SURVEY
285
+ }
286
+ let(:survey) { Surveyor::Parser.new.parse(survey_text) }
287
+ let(:solo_question_json) { json['sections'][0]['questions_and_groups'][1] }
288
+ let(:grouped_question_json) { json['sections'][0]['questions_and_groups'][2]['questions'][0] }
289
+
290
+ it "produces identical JSON except for API IDs and question reference identifers" do
291
+ solo_question_json['answers'].to_json.should be_json_eql( grouped_question_json['answers'].to_json).excluding("uuid", "reference_identifier")
292
+ solo_question_json['dependency'].to_json.should be_json_eql( grouped_question_json['dependency'].to_json).excluding("uuid", "reference_identifier")
293
+ solo_question_json.to_json.should be_json_eql( grouped_question_json.to_json).excluding("uuid", "reference_identifier")
294
+ end
295
+ it "produces the expected reference identifier for the solo question" do
296
+ solo_question_json['reference_identifier'].should == 'foo_solo'
297
+ end
298
+ it "produces the expected reference identifer for the question in the group" do
299
+ grouped_question_json['reference_identifier'].should == 'foo_grouped'
300
+ end
301
+ end
302
+ end
303
+ end