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,15 @@
1
+ module SurveyorAPIHelpers
2
+ def json_response
3
+ page.source
4
+ end
5
+ def title_modification_module(modifier)
6
+ mod = Module.new
7
+ mod.send(:define_method, :filtered_for_json) do
8
+ dolly = self.clone
9
+ dolly.sections = self.sections
10
+ dolly.title = "#{modifier} #{dolly.title}"
11
+ dolly
12
+ end
13
+ return mod
14
+ end
15
+ end
@@ -0,0 +1,108 @@
1
+ # http://www.elabs.se/blog/51-simple-tricks-to-clean-up-your-capybara-tests
2
+ require 'mustache'
3
+ module SurveyorUIHelpers
4
+ def have_disabled_selected_radio(text)
5
+ within("label", :text => text) do
6
+ have_selector('input[type=radio][disabled=disabled]')
7
+ end
8
+ end
9
+ def have_disabled_selected_checkbox(text)
10
+ within("label", :text => text) do
11
+ have_selector('input[type=checkbox][disabled=disabled]')
12
+ end
13
+ end
14
+ def grid_row(text)
15
+ find("fieldset.g_grid tr#q_#{Question.where(text: text).first.id}")
16
+ end
17
+ def question(reference_identifier, entry = nil)
18
+ if entry
19
+ find("fieldset#q_#{Question.where(reference_identifier: reference_identifier).first.id}_#{entry}")
20
+ else
21
+ find("fieldset#q_#{Question.where(reference_identifier: reference_identifier).first.id}")
22
+ end
23
+ end
24
+ def have_hidden_question(reference_identifier, entry=nil)
25
+ if entry
26
+ have_css("fieldset#q_#{Question.where(reference_identifier: reference_identifier).first.id}_#{entry}.q_hidden")
27
+ else
28
+ have_css("fieldset#q_#{Question.where(reference_identifier: reference_identifier).first.id}.q_hidden")
29
+ end
30
+
31
+ end
32
+ def have_hidden_group(reference_identifier, entry = nil)
33
+ if entry
34
+ have_css("fieldset#g_#{QuestionGroup.where(reference_identifier: reference_identifier).first.id}_#{entry}.g_hidden")
35
+ else
36
+ have_css("fieldset#g_#{QuestionGroup.where(reference_identifier: reference_identifier).first.id}.g_hidden")
37
+ end
38
+ end
39
+ def group(reference_identifier)
40
+ find("fieldset#g_#{QuestionGroup.where(reference_identifier: reference_identifier).first.id}")
41
+ end
42
+ def checkbox(q_ref_id, a_ref_id)
43
+ find("input[value='#{Question.where(reference_identifier: q_ref_id).first.answers.where(reference_identifier: a_ref_id).first.id}']")
44
+ end
45
+ def start_survey(name, opts = {})
46
+ visit(opts[:locale] ? "/surveys?locale=#{opts[:locale]}" : '/surveys')
47
+ within "form", text: name do
48
+ select(opts[:version], from: "version") if opts[:version]
49
+ click_button I18n.t('surveyor.take_it')
50
+ end
51
+ return ResponseSet.where(access_code: current_path.split('/')[3]).first.extend ResponseSetTestingMethods
52
+ end
53
+ def the_15th
54
+ Date.current.beginning_of_month + 14
55
+ end
56
+
57
+ def hash_context_module(hash)
58
+ mod = Module.new
59
+ mod.send(:define_method, :render_context) do
60
+ return hash
61
+ end
62
+ return mod
63
+ end
64
+ def mustache_context_module(hash)
65
+ context = Class.new(::Mustache)
66
+ hash.each do |k,v|
67
+ context.send(:define_method, k.to_sym) do
68
+ v
69
+ end
70
+ end
71
+ mod = Module.new
72
+ mod.send(:define_method, :render_context) do
73
+ context
74
+ end
75
+ return mod
76
+ end
77
+ def override_surveyor_helper_numbering
78
+ SurveyorHelper.module_eval do
79
+ def next_question_number(question)
80
+ @letters ||= ("A".."Z").to_a
81
+ @n ||= 25
82
+ "<span class='qnum'>#{@letters[(@n += 1)%26]}. </span>"
83
+ end
84
+ end
85
+ end
86
+ def restore_surveyor_helper_numbering
87
+ SurveyorHelper.module_eval do
88
+ def next_question_number(question)
89
+ @n ||= 0
90
+ "<span class='qnum'>#{@n += 1}) </span>"
91
+ end
92
+ end
93
+ end
94
+ end
95
+ module ResponseSetTestingMethods
96
+ def for(q_ref_id, a_ref_id = nil)
97
+ q = Question.where(reference_identifier: q_ref_id).first
98
+ if a_ref_id
99
+ a = Answer.where(reference_identifier: a_ref_id, question_id: q.id).first
100
+ responses.where(question_id: q.id, answer_id: a.id)
101
+ else
102
+ responses.where(question_id: q.id)
103
+ end
104
+ end
105
+ def count
106
+ responses.count
107
+ end
108
+ end
@@ -0,0 +1,11 @@
1
+ module WaitForAjax
2
+ def wait_for_ajax(wait_time = 1)
3
+ Timeout.timeout(wait_time) do
4
+ loop until finished_all_ajax_requests?
5
+ end
6
+ end
7
+
8
+ def finished_all_ajax_requests?
9
+ page.evaluate_script('jQuery.active').zero?
10
+ end
11
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ module CapybaraHelper
4
+ Capybara::Session::DSL_METHODS.each do |method|
5
+ define_method method do |*args, &block|
6
+ Capybara.string(response).send method, *args, &block
7
+ end
8
+ end
9
+ end
10
+
11
+ describe "questions/edit.html.erb" do
12
+ include CapybaraHelper
13
+
14
+ let(:question){ FactoryGirl.create(:question) }
15
+ let(:question2){ FactoryGirl.create(:question, :question_type_id => "pick_one") }
16
+ let(:form){find('form')}
17
+
18
+ before do
19
+ assign(:question, question)
20
+ end
21
+
22
+ it "renders a form" do
23
+ render
24
+ expect(response).to have_selector("form")
25
+ end
26
+
27
+ it "will post a new question on submit" do
28
+ render
29
+ expect(form[:action]).to eql(question_path question)
30
+ expect(form[:method]).to eql('post')
31
+ end
32
+
33
+ it "has a save button" do
34
+ render
35
+ expect(form).to have_selector("input[type=submit]")
36
+ end
37
+
38
+ context "It has a multiple choice field" do
39
+ let (:form) {find('form')}
40
+ let(:answer_1){ FactoryGirl.create(:answer, :question => question2, :display_order => 3, :text => "blue")}
41
+ let(:answer_2){ FactoryGirl.create(:answer, :question => question2, :display_order => 1, :text => "red")}
42
+ let(:answer_3){ FactoryGirl.create(:answer, :question => question2, :display_order => 2, :text => "green")}
43
+
44
+ before do
45
+ [answer_1, answer_2, answer_3].each{|a| question2.answers << a }
46
+ assign(:question, question2)
47
+ end
48
+
49
+ #won't work for now because of js
50
+ #it "renders an answer_collection for the answers" do
51
+ # render
52
+ # puts rendered
53
+ # expect(rendered).to have_field(
54
+ # 'question[answers_textbox]',
55
+ # :type => 'textarea',
56
+ # :with => "red\ngreen\nblue")
57
+ #end
58
+ end
59
+
60
+
61
+ # it "renders a text field for the message title" do
62
+ # render
63
+ # expect(form).to have_field(
64
+ # "message[title]",
65
+ # :type => 'text',
66
+ # :with => 'the title')
67
+ # end
68
+ # it "renders a text area for the message text" do
69
+ # render
70
+
71
+ # end
72
+ # end
73
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ module CapybaraHelper
4
+ Capybara::Session::DSL_METHODS.each do |method|
5
+ define_method method do |*args, &block|
6
+ Capybara.string(response).send method, *args, &block
7
+ end
8
+ end
9
+ end
10
+ RSpec.configure do |config|
11
+ config.order = :default
12
+ end
13
+ describe "surveyforms/edit.html.erb" do
14
+ include CapybaraHelper
15
+ let(:surveyform){ FactoryGirl.create(:surveyform) }
16
+ let(:ss){ FactoryGirl.create(:survey_section, :surveyform => surveyform, :title => "Rooms", :display_order => 0)}
17
+ let(:question){ FactoryGirl.create(:question, :survey_section => ss, display_order: 0 )}
18
+ let(:answer){ FactoryGirl.create(:answer, :question => question)}
19
+ let(:question1){ FactoryGirl.create(
20
+ :question,
21
+ survey_section: ss,
22
+ text: 'What rooms do you prefer?',
23
+ question_type_id: "pick_one",
24
+ answers_textbox: "Standard\nDouble\nDeluxe",
25
+ display_order: 1
26
+ ) }
27
+
28
+ let(:qg) {FactoryGirl.create(:question_group, display_type: 'grid', text: 'Rate the meals.') }
29
+ let(:qg2){FactoryGirl.create(:question_group, display_type: 'grid', text: 'Pick your favorite sport') }
30
+ let(:c1) {FactoryGirl.create(:column, question_group_id: qg2.id, text: "Spring", answers_textbox: "Football\nBaseball\nHockey\nSoccer\nBasketball" )}
31
+ let(:c2) {FactoryGirl.create(:column, question_group_id: qg2.id, text: "Summer", answers_textbox: "Football\nBaseball\nHockey\nSoccer\nBasketball" )}
32
+ let(:c3) {FactoryGirl.create(:column, question_group_id: qg2.id, text: "Fall", answers_textbox: "Football\nBaseball\nHockey\nSoccer\nBasketball")}
33
+ let(:c4) {FactoryGirl.create(:column, question_group_id: qg2.id, text: "Winter", answers_textbox: "Football\nBaseball\nHockey\nSoccer\nBasketball")}
34
+ let(:question2){ FactoryGirl.create(
35
+ :question,
36
+ text: 'Rate the meals.',
37
+ survey_section: ss,
38
+ question_group: nil,
39
+ question_type_id: "grid_one",
40
+ grid_columns_textbox: "Good\nBad\nUgly",
41
+ grid_rows_textbox: "Breakfast\nLunch\nDinner",
42
+ display_order: 4
43
+ ) }
44
+
45
+ let(:question5){ FactoryGirl.create(:question, :survey_section => ss, text: "What brand of ketchup do they use?", display_order: 7 )}
46
+ let(:answer1){FactoryGirl.create(:answer, :question => question5)}
47
+ let(:question6) { FactoryGirl.create(
48
+ :question,
49
+ survey_section: ss,
50
+ question_group: qg2,
51
+ question_type_id: "grid_dropdown",
52
+ grid_rows_textbox: "TV\nArena",
53
+ text: "Pick your favorite sport:",
54
+ display_order: 8
55
+ ) }
56
+ let(:number_question) {FactoryGirl.create(
57
+ :question,
58
+ survey_section: ss,
59
+ text: "How much do you spend on Cheese Doodles?",
60
+ question_type_id: "number",
61
+ suffix: "$",
62
+ prefix: "USD",
63
+ display_order: 10
64
+ ) }
65
+
66
+ before do
67
+ surveyform.save
68
+ surveyform.reload
69
+ ss.reload
70
+ qg.reload
71
+ qg2.reload
72
+ answer.reload
73
+ question.reload
74
+ question1.reload
75
+ question2.reload
76
+ question5.reload
77
+ answer1.reload
78
+ c1.reload
79
+ c2.reload
80
+ c3.reload
81
+ c4.reload
82
+ question6.reload
83
+ number_question.reload
84
+ assign(:surveyform, surveyform)
85
+ assign(:question_no, 0)
86
+ end
87
+
88
+ it "renders a form" do
89
+ render
90
+ expect(response).to have_selector("form")
91
+ end
92
+
93
+ it "shows text questions" do
94
+ render
95
+ expect(response).to match(/1\) What is your favorite color?/)
96
+ end
97
+
98
+ it "shows multiple choice questions" do
99
+ render
100
+ expect(response).to have_selector("input[type='radio'][value='Standard']")
101
+ expect(response).to have_selector("input[type='radio'][value='Double']")
102
+ expect(response).to have_selector("input[type='radio'][value='Deluxe']")
103
+ end
104
+
105
+ it "shows grid questions" do
106
+ render
107
+ expect(response).to match (/Rate the meals/)
108
+ expect(response).to match(/3\) Rate the meals\..*Good.*Bad.*Ugly.*(?<!\d\)\s)Breakfast.*(?<!\d\)\s)Lunch.*(?<!\d\)\s)Dinner.*/m)
109
+ end
110
+
111
+ it "shows grid dropdowns" do
112
+ render
113
+ expect(response).to match(/5\) Pick your favorite sport.*Spring.*Summer.*Fall.*Winter.*(?<!\d\)\s)TV.*(?<!\d\)\s)Arena/m)
114
+ end
115
+
116
+ it "maintains correct question numbering after grid questions" do
117
+ render
118
+ expect(response).to match(/4\) What brand of ketchup do they use?/)
119
+ end
120
+
121
+ it "shows a prefix and suffix for number questions" do
122
+ render
123
+ expect(response).to match(/How much do you spend on Cheese Doodles?/)
124
+ end
125
+
126
+ end
@@ -0,0 +1,52 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "surveyor_gui/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "surveyor_gui"
9
+ s.version = SurveyorGui::VERSION
10
+ s.authors = ["Kevin Jay"]
11
+ s.email = ["kjayma@gmail.com"]
12
+ s.homepage = %q{http://github.com/kjayma/surveyor_gui}
13
+ s.post_install_message = %q{Thanks for installing surveyor_gui! The time has come to run the surveyor_gui generator and migrate your database, even if you are upgrading.}
14
+ s.summary = "A Rails gem to supply a front-end and reporting capability to the Surveyor gem."
15
+
16
+ #s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
17
+
18
+ s.files = `git ls-files`.split("\n") - ['irb']
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency 'rails', '> 4.0.0'
24
+ s.add_dependency 'dynamic_form', '~> 1.1.4'
25
+ #s.add_dependency 'jquery-ui-rails'
26
+ s.add_dependency 'jquery-ui-sass-rails'
27
+
28
+ s.add_development_dependency "sqlite3"
29
+
30
+ s.add_development_dependency 'sass-rails','~> 4.0.2'
31
+ s.add_development_dependency 'coffee-rails'
32
+ s.add_development_dependency 'uglifier', '>= 1.0.3'
33
+ s.add_development_dependency('rspec-rails', '~> 2.14.2')
34
+ s.add_development_dependency('capybara', '~> 2.2.1')
35
+ s.add_development_dependency('launchy', '~> 2.4.2')
36
+ s.add_development_dependency('poltergeist', '~>1.5.0')
37
+ s.add_development_dependency('capybara-webkit')
38
+ s.add_development_dependency('json_spec', '~> 1.1.1')
39
+ s.add_development_dependency('factory_girl', '~> 4.4.0')
40
+ s.add_development_dependency('database_cleaner', '~> 1.2.0')
41
+ s.add_development_dependency('rspec-retry')
42
+
43
+ s.add_dependency 'surveyor', '~> 1.4.1.pre'
44
+ s.add_dependency 'will_paginate', '~> 3.0.5'
45
+
46
+ s.add_dependency 'simple_form', '~> 3.0.2'
47
+ s.add_dependency 'carrierwave'
48
+ s.add_dependency 'colorbox-rails', '~> 0.1.1'
49
+ s.add_dependency 'jquery-form-rails', '~> 1.0.1'
50
+ s.add_dependency 'deep_cloneable', '~> 2.0.0'
51
+ s.add_dependency 'lazy_high_charts'
52
+ end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | | |-- images
161
+ | | |-- javascripts
162
+ | | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | |-- assets
177
+ | `-- tasks
178
+ |-- log
179
+ |-- public
180
+ |-- script
181
+ |-- test
182
+ | |-- fixtures
183
+ | |-- functional
184
+ | |-- integration
185
+ | |-- performance
186
+ | `-- unit
187
+ |-- tmp
188
+ | `-- cache
189
+ | `-- assets
190
+ `-- vendor
191
+ |-- assets
192
+ | |-- javascripts
193
+ | `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.