surveyor_gui 0.0.3

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 (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,268 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe QuestionType do
5
+ let(:grid) { FactoryGirl.create(:question_group, display_type: "grid") }
6
+ let(:inline) { FactoryGirl.create(:question_group, display_type: "inline") }
7
+ let(:repeater){ FactoryGirl.create(:question_group, display_type: "inline") }
8
+
9
+ let(:textbox) { FactoryGirl.create(
10
+ :question,
11
+ pick: "none",
12
+ display_type: "default",
13
+ question_group_id: nil
14
+ )
15
+ }
16
+ let(:textbox_a) { FactoryGirl.create(
17
+ :answer,
18
+ question_id: textbox.id,
19
+ response_class: :text
20
+ )
21
+ }
22
+ let(:text) { FactoryGirl.create(
23
+ :question,
24
+ pick: "none",
25
+ display_type: "default",
26
+ question_group_id: nil
27
+ )
28
+ }
29
+ let(:text_a) { FactoryGirl.create(
30
+ :answer,
31
+ question_id: text.id,
32
+ response_class: :string
33
+ )
34
+ }
35
+ let(:float) { FactoryGirl.create(
36
+ :question,
37
+ pick: "none",
38
+ display_type: "default",
39
+ question_group_id: nil
40
+ )
41
+ }
42
+ let(:float_a) { FactoryGirl.create(
43
+ :answer,
44
+ question_id: float.id,
45
+ response_class: :float
46
+ )
47
+ }
48
+ let(:integer) { FactoryGirl.create(
49
+ :question,
50
+ pick: "none",
51
+ display_type: "default",
52
+ question_group_id: nil
53
+ )
54
+ }
55
+ let(:integer_a) { FactoryGirl.create(
56
+ :answer,
57
+ question_id: integer.id,
58
+ response_class: :integer
59
+ )
60
+ }
61
+ let(:date) { FactoryGirl.create(
62
+ :question,
63
+ pick: "none",
64
+ display_type: "default",
65
+ question_group_id: nil
66
+ )
67
+ }
68
+ let(:date_a) { FactoryGirl.create(
69
+ :answer,
70
+ question_id: date.id,
71
+ response_class: :date
72
+ )
73
+ }
74
+ let(:file) { FactoryGirl.create(
75
+ :question,
76
+ pick: "none",
77
+ display_type: "default",
78
+ question_group_id: nil
79
+ )
80
+ }
81
+ let(:file_a) { FactoryGirl.create(
82
+ :answer,
83
+ question_id: file.id,
84
+ response_class: :blob
85
+ )
86
+ }
87
+ let(:label) { FactoryGirl.create(
88
+ :question,
89
+ pick: "none",
90
+ display_type: "label",
91
+ question_group_id: nil
92
+ )
93
+ }
94
+ let(:pick_one) { FactoryGirl.create(
95
+ :question,
96
+ pick: "one",
97
+ display_type: "default",
98
+ question_group_id: nil
99
+ )
100
+ }
101
+ let(:pick_any) { FactoryGirl.create(
102
+ :question,
103
+ pick: "any",
104
+ display_type: "default",
105
+ question_group_id: nil
106
+ )
107
+ }
108
+ let(:pick_one_inline) { FactoryGirl.create(
109
+ :question,
110
+ pick: "one",
111
+ display_type: "default",
112
+ question_group_id: inline.id
113
+ )
114
+ }
115
+ let(:pick_any_inline) { FactoryGirl.create(
116
+ :question,
117
+ pick: "any",
118
+ display_type: "default",
119
+ question_group_id: inline.id
120
+ )
121
+ }
122
+ let(:dropdown) { FactoryGirl.create(
123
+ :question,
124
+ pick: "one",
125
+ display_type: "dropdown",
126
+ question_group_id: nil
127
+ )
128
+ }
129
+ let(:slider) { FactoryGirl.create(
130
+ :question,
131
+ pick: "one",
132
+ display_type: "slider",
133
+ question_group_id: nil
134
+ )
135
+ }
136
+ let(:stars) { FactoryGirl.create(
137
+ :question,
138
+ pick: "one",
139
+ display_type: "stars",
140
+ question_group_id: nil
141
+ )
142
+ }
143
+ let(:grid_one) { FactoryGirl.create(
144
+ :question,
145
+ pick: "one",
146
+ display_type: "default",
147
+ question_group_id: grid.id
148
+ )
149
+ }
150
+ let(:grid_any) { FactoryGirl.create(
151
+ :question,
152
+ pick: "any",
153
+ display_type: "default",
154
+ question_group_id: grid.id
155
+ )
156
+ }
157
+ let(:grid_dropdown) { FactoryGirl.create(
158
+ :question,
159
+ pick: "one",
160
+ display_type: "dropdown",
161
+ question_group_id: grid.id
162
+ )
163
+ }
164
+ let(:group_inline) { FactoryGirl.create(
165
+ :question,
166
+ pick: "",
167
+ display_type: "",
168
+ question_group_id: inline.id
169
+ )
170
+ }
171
+ let(:repeater) { FactoryGirl.create(
172
+ :question,
173
+ pick: "",
174
+ display_type: "",
175
+ question_group_id: repeater.id
176
+ )
177
+ }
178
+
179
+
180
+ context "when categorizing question" do
181
+ before do
182
+ text.reload
183
+ text_a.reload
184
+ textbox.reload
185
+ textbox_a.reload
186
+ float.reload
187
+ float_a.reload
188
+ integer.reload
189
+ integer_a.reload
190
+ date.reload
191
+ date_a.reload
192
+ file.reload
193
+ file_a.reload
194
+ end
195
+
196
+ it "recognizes a textbox question" do
197
+ textbox.reload
198
+ textbox_a.reload
199
+ expect(textbox.question_type.id).to eql :box
200
+ end
201
+
202
+ it "recognizes a text question" do
203
+ expect(text.question_type.id).to eql :string
204
+ end
205
+
206
+ it "recognizes a float question" do
207
+ expect(float.question_type.id).to eql :number
208
+ end
209
+
210
+ it "recognizes an date question" do
211
+ expect(date.question_type.id).to eql :date
212
+ end
213
+
214
+ it "recognizes a file question" do
215
+ expect(file.question_type.id).to eql :file
216
+ end
217
+
218
+ it "recognizes a label" do
219
+ expect(label.question_type.id).to eql :label
220
+ end
221
+
222
+ it "recognizes a pick one question" do
223
+ expect(pick_one.question_type.id).to eql :pick_one
224
+ end
225
+
226
+ it "recognizes a pick any question" do
227
+ expect(pick_any.question_type.id).to eql :pick_any
228
+ end
229
+
230
+ it "recognizes an inline pick one question" do
231
+ expect(pick_one_inline.question_type.id).to eql :pick_one
232
+ end
233
+
234
+ it "recognizes an inline pick any question" do
235
+ expect(pick_any_inline.question_type.id).to eql :pick_any
236
+ end
237
+
238
+ it "recognizes a dropdown question" do
239
+ expect(dropdown.question_type.id).to eql :dropdown
240
+ end
241
+
242
+ it "recognizes a slider question" do
243
+ expect(slider.question_type.id).to eql :slider
244
+ end
245
+
246
+ it "recognizes a stars question" do
247
+ expect(stars.question_type.id).to eql :stars
248
+ end
249
+
250
+ it "recognizes a grid one question" do
251
+ expect(grid_one.question_type.id).to eql :grid_one
252
+ end
253
+
254
+ it "recognizes a grid any question" do
255
+ expect(grid_any.question_type.id).to eql :grid_any
256
+ end
257
+
258
+ it "recognizes a grid dropdown question" do
259
+ expect(grid_dropdown.question_type.id).to eql :grid_dropdown
260
+ end
261
+
262
+ it "recognizes a group inline question" do
263
+ expect(group_inline.question_type.id).to eql :group_inline
264
+ end
265
+
266
+ end
267
+
268
+ end
@@ -0,0 +1,98 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ValidationCondition do
4
+ before(:each) do
5
+ @validation_condition = FactoryGirl.create(:validation_condition)
6
+ end
7
+
8
+ it "should be valid" do
9
+ @validation_condition.should be_valid
10
+ end
11
+ # this causes issues with building and saving
12
+ # it "should be invalid without a parent validation_id" do
13
+ # @validation_condition.validation_id = nil
14
+ # @validation_condition.should have(1).errors_on(:validation_id)
15
+ # end
16
+
17
+ it "should be invalid without an operator" do
18
+ @validation_condition.operator = nil
19
+ @validation_condition.should have(2).errors_on(:operator)
20
+ end
21
+
22
+ it "should be invalid without a rule_key" do
23
+ @validation_condition.should be_valid
24
+ @validation_condition.rule_key = nil
25
+ @validation_condition.should_not be_valid
26
+ @validation_condition.should have(1).errors_on(:rule_key)
27
+ end
28
+
29
+ it "should have unique rule_key within the context of a validation" do
30
+ @validation_condition.should be_valid
31
+ FactoryGirl.create(:validation_condition, :validation_id => 2, :rule_key => "2")
32
+ @validation_condition.rule_key = "2" #rule key uniquness is scoped by validation_id
33
+ @validation_condition.validation_id = 2
34
+ @validation_condition.should_not be_valid
35
+ @validation_condition.should have(1).errors_on(:rule_key)
36
+ end
37
+
38
+ it "should have an operator in Surveyor::Common::OPERATORS" do
39
+ Surveyor::Common::OPERATORS.each do |o|
40
+ @validation_condition.operator = o
41
+ @validation_condition.should have(0).errors_on(:operator)
42
+ end
43
+ @validation_condition.operator = "#"
44
+ @validation_condition.should have(1).error_on(:operator)
45
+ end
46
+ end
47
+
48
+ describe ValidationCondition, "validating responses" do
49
+ def test_var(vhash, ahash, rhash)
50
+ v = FactoryGirl.create(:validation_condition, vhash)
51
+ a = FactoryGirl.create(:answer, ahash)
52
+ r = FactoryGirl.create(:response, {:answer => a, :question => a.question}.merge(rhash))
53
+ return v.is_valid?(r)
54
+ end
55
+
56
+ it "should validate a response by regexp" do
57
+ test_var({:operator => "=~", :regexp => /^[a-z]{1,6}$/.to_s}, {:response_class => "string"}, {:string_value => "clear"}).should be_true
58
+ test_var({:operator => "=~", :regexp => /^[a-z]{1,6}$/.to_s}, {:response_class => "string"}, {:string_value => "foobarbaz"}).should be_false
59
+ end
60
+ it "should validate a response by integer comparison" do
61
+ test_var({:operator => ">", :integer_value => 3}, {:response_class => "integer"}, {:integer_value => 4}).should be_true
62
+ test_var({:operator => "<=", :integer_value => 256}, {:response_class => "integer"}, {:integer_value => 512}).should be_false
63
+ end
64
+ it "should validate a response by (in)equality" do
65
+ test_var({:operator => "!=", :datetime_value => Date.today + 1}, {:response_class => "date"}, {:datetime_value => Date.today}).should be_true
66
+ test_var({:operator => "==", :string_value => "foo"}, {:response_class => "string"}, {:string_value => "foo"}).should be_true
67
+ end
68
+ it "should represent itself as a hash" do
69
+ @v = FactoryGirl.create(:validation_condition, :rule_key => "A")
70
+ @v.stub(:is_valid?).and_return(true)
71
+ @v.to_hash("foo").should == {:A => true}
72
+ @v.stub(:is_valid?).and_return(false)
73
+ @v.to_hash("foo").should == {:A => false}
74
+ end
75
+ end
76
+
77
+ describe ValidationCondition, "validating responses by other responses" do
78
+ def test_var(v_hash, a_hash, r_hash, ca_hash, cr_hash)
79
+ ca = FactoryGirl.create(:answer, ca_hash)
80
+ cr = FactoryGirl.create(:response, cr_hash.merge(:answer => ca, :question => ca.question))
81
+ v = FactoryGirl.create(:validation_condition, v_hash.merge({:question_id => ca.question.id, :answer_id => ca.id}))
82
+ a = FactoryGirl.create(:answer, a_hash)
83
+ r = FactoryGirl.create(:response, r_hash.merge(:answer => a, :question => a.question))
84
+ return v.is_valid?(r)
85
+ end
86
+ it "should validate a response by integer comparison" do
87
+ test_var({:operator => ">"}, {:response_class => "integer"}, {:integer_value => 4}, {:response_class => "integer"}, {:integer_value => 3}).should be_true
88
+ test_var({:operator => "<="}, {:response_class => "integer"}, {:integer_value => 512}, {:response_class => "integer"}, {:integer_value => 4}).should be_false
89
+ end
90
+ it "should validate a response by (in)equality" do
91
+ test_var({:operator => "!="}, {:response_class => "date"}, {:datetime_value => Date.today}, {:response_class => "date"}, {:datetime_value => Date.today + 1}).should be_true
92
+ test_var({:operator => "=="}, {:response_class => "string"}, {:string_value => "donuts"}, {:response_class => "string"}, {:string_value => "donuts"}).should be_true
93
+ end
94
+ it "should not validate a response by regexp" do
95
+ test_var({:operator => "=~"}, {:response_class => "date"}, {:datetime_value => Date.today}, {:response_class => "date"}, {:datetime_value => Date.today + 1}).should be_false
96
+ test_var({:operator => "=~"}, {:response_class => "string"}, {:string_value => "donuts"}, {:response_class => "string"}, {:string_value => "donuts"}).should be_false
97
+ end
98
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Validation do
4
+ before(:each) do
5
+ @validation = FactoryGirl.create(:validation)
6
+ end
7
+
8
+ it "should be valid" do
9
+ @validation.should be_valid
10
+ end
11
+
12
+ it "should be invalid without a rule" do
13
+ @validation.rule = nil
14
+ @validation.should have(2).errors_on(:rule)
15
+ @validation.rule = " "
16
+ @validation.should have(1).errors_on(:rule)
17
+ end
18
+
19
+ # this causes issues with building and saving
20
+ # it "should be invalid without a answer_id" do
21
+ # @validation.answer_id = nil
22
+ # @validation.should have(1).error_on(:answer_id)
23
+ # end
24
+
25
+ it "should be invalid unless rule composed of only references and operators" do
26
+ @validation.rule = "foo"
27
+ @validation.should have(1).error_on(:rule)
28
+ @validation.rule = "1 to 2"
29
+ @validation.should have(1).error_on(:rule)
30
+ @validation.rule = "a and b"
31
+ @validation.should have(1).error_on(:rule)
32
+ end
33
+ end
34
+ describe Validation, "reporting its status" do
35
+ def test_var(vhash, vchashes, ahash, rhash)
36
+ a = FactoryGirl.create(:answer, ahash)
37
+ v = FactoryGirl.create(:validation, {:answer => a, :rule => "A"}.merge(vhash))
38
+ vchashes.each do |vchash|
39
+ FactoryGirl.create(:validation_condition, {:validation => v, :rule_key => "A"}.merge(vchash))
40
+ end
41
+ rs = FactoryGirl.create(:response_set)
42
+ r = FactoryGirl.create(:response, {:answer => a, :question => a.question}.merge(rhash))
43
+ rs.responses << r
44
+ return v.is_valid?(rs)
45
+ end
46
+
47
+ it "should validate a response by integer comparison" do
48
+ test_var({:rule => "A and B"}, [{:operator => ">=", :integer_value => 0}, {:rule_key => "B", :operator => "<=", :integer_value => 120}], {:response_class => "integer"}, {:integer_value => 48}).should be_true
49
+ end
50
+ it "should validate a response by regexp" do
51
+ test_var({}, [{:operator => "=~", :regexp => '/^[a-z]{1,6}$/'}], {:response_class => "string"}, {:string_value => ""}).should be_false
52
+ end
53
+ end
54
+ describe Validation, "with conditions" do
55
+ it "should destroy conditions when destroyed" do
56
+ @validation = FactoryGirl.create(:validation)
57
+ FactoryGirl.create(:validation_condition, :validation => @validation, :rule_key => "A")
58
+ FactoryGirl.create(:validation_condition, :validation => @validation, :rule_key => "B")
59
+ FactoryGirl.create(:validation_condition, :validation => @validation, :rule_key => "C")
60
+ v_ids = @validation.validation_conditions.map(&:id)
61
+ @validation.destroy
62
+ v_ids.each{|id| DependencyCondition.find_by_id(id).should == nil}
63
+ end
64
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,119 @@
1
+ # This file is customized to run specs withing the testbed environemnt
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ begin
4
+ require File.expand_path("../../testbed/config/environment", __FILE__)
5
+ rescue LoadError => e
6
+ fail "Could not load the testbed app. Have you generated it?\n#{e.class}: #{e}"
7
+ end
8
+
9
+ require 'rspec/rails'
10
+ require 'rspec/autorun'
11
+
12
+ require 'capybara/rails'
13
+ require 'capybara/rspec'
14
+ require 'capybara/poltergeist'
15
+ require 'capybara/webkit'
16
+ require 'factories'
17
+ require 'json_spec'
18
+ require 'database_cleaner'
19
+ require 'rspec/retry'
20
+ require 'rack/utils'
21
+
22
+ # Requires supporting ruby files with custom matchers and macros, etc,
23
+ # in spec/support/ and its subdirectories.
24
+ Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
25
+
26
+ Capybara.app = Rack::ShowExceptions.new(Testbed::Application)
27
+ # Checks for pending migrations before tests are run.
28
+ # If you are not using ActiveRecord, you can remove this line.
29
+ ActiveRecord::Migration.check_pending! if ::Rails.version >= "4.0" && defined?(ActiveRecord::Migration)
30
+
31
+
32
+ Capybara.register_driver :poltergeist do |app|
33
+ Capybara::Poltergeist::Driver.new(app, debug: false)
34
+ end
35
+
36
+ Capybara.server_port = 3001
37
+ Capybara.asset_host = "http://lvh.me:3001"
38
+
39
+ Capybara.javascript_driver = :poltergeist
40
+
41
+ RSpec.configure do |config|
42
+ config.include JsonSpec::Helpers
43
+ config.include SurveyorAPIHelpers
44
+ config.include SurveyorUIHelpers
45
+ config.include WaitForAjax
46
+
47
+ config.treat_symbols_as_metadata_keys_with_true_values = true
48
+
49
+ # == Mock Framework
50
+ #
51
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
52
+ #
53
+ # config.mock_with :mocha
54
+ # config.mock_with :flexmock
55
+ # config.mock_with :rr
56
+ config.mock_with :rspec
57
+
58
+ # config.expect_with :rspec do |c|
59
+ # c.syntax = :expect
60
+ # end
61
+
62
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
63
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
64
+
65
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
66
+ # examples within a transaction, remove the following line or assign false
67
+ # instead of true.
68
+ config.use_transactional_fixtures = false
69
+
70
+ # If true, the base class of anonymous controllers will be inferred
71
+ # automatically. This will be the default behavior in future versions of
72
+ # rspec-rails.
73
+ config.infer_base_class_for_anonymous_controllers = false
74
+
75
+ # Run specs in random order to surface order dependencies. If you find an
76
+ # order dependency and want to debug it, you can fix the order by providing
77
+ # the seed, which is printed after each run.
78
+ # --seed 1234
79
+ config.order = "random"
80
+
81
+ # rspec-retry
82
+ # https://github.com/rspec/rspec-core/issues/456
83
+ config.verbose_retry = true # show retry status in spec process
84
+ retry_count = ENV['RSPEC_RETRY_COUNT']
85
+ config.default_retry_count = retry_count.try(:to_i) || 1
86
+ puts "RSpec retry count is #{config.default_retry_count}"
87
+
88
+ # host
89
+ config.before :each do
90
+ # host = "lvh.me:"+Capybara.current_session.driver.server.port.to_s
91
+ ## puts host
92
+ # Capybara.asset_host = "http://#{host}"
93
+ # Rails.application.routes.default_url_options[:host] = host
94
+ ## #"lvh.me:"+Capybara.current_session.driver.server.port.to_s
95
+ end
96
+
97
+ # Database Cleaner
98
+ config.before :suite do
99
+ DatabaseCleaner.clean_with :truncation
100
+ DatabaseCleaner.strategy = :transaction
101
+ end
102
+
103
+ config.before :each do
104
+ if example.metadata[:clean_with_truncation] || example.metadata[:js]
105
+ DatabaseCleaner.strategy = :truncation
106
+ else
107
+ DatabaseCleaner.strategy = :transaction
108
+ end
109
+ DatabaseCleaner.start
110
+ end
111
+
112
+ config.after :each do
113
+ Capybara.reset_sessions!
114
+ DatabaseCleaner.clean
115
+ end
116
+ end
117
+ JsonSpec.configure do
118
+ exclude_keys "id", "created_at", "updated_at", "uuid", "modified_at", "completed_at"
119
+ end