upgrade_surveyor_gui 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
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,39 @@
1
+ require 'stringio'
2
+ require 'ostruct'
3
+
4
+ class ScenarioOutline
5
+ attr_reader :examples
6
+
7
+ def initialize(example_string)
8
+ @example_string = example_string.gsub(/(^\n*)|(\s*\n*$)/,'')
9
+ @examples = parse_example_string
10
+ end
11
+
12
+ private
13
+ def parse_example_string
14
+ example_string = StringIO.new(@example_string)
15
+ header = parse_line(example_string.readline)
16
+ example_lines = example_string.readlines
17
+ parse_example_lines(header, example_lines)
18
+ end
19
+
20
+ def parse_line(line)
21
+ line.lstrip.slice(1..line.length).chomp.split('|')
22
+ end
23
+
24
+ def parse_example_lines (header, example_lines)
25
+ examples=[]
26
+ example_lines.each do |example_line|
27
+ examples << make_an_example(header, example_line)
28
+ end
29
+ examples
30
+ end
31
+
32
+ def make_an_example(header, example_line)
33
+ newstruct = "{"
34
+ parse_line(example_line).each_with_index do |example, index|
35
+ newstruct += ":#{header[index].strip} => '#{example.strip}',"
36
+ end
37
+ OpenStruct.new(eval(newstruct.chop+"}"))
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ %w(favorites feelings lifestyle numbers favorites-ish everything).each do |name|
2
+ shared_context name do
3
+ before { Surveyor::Parser.parse_file( File.join(Rails.root, '..', 'spec', 'fixtures', "#{name}.rb"), trace: false) }
4
+ end
5
+ end
6
+
7
+ def gem_path(gem_name)
8
+ spec = Gem::Specification.find_by_name(gem_name)
9
+ spec.gem_dir
10
+ end
@@ -0,0 +1,313 @@
1
+ module SurveyFormsCreationHelpers
2
+ module CreateSurvey
3
+ def start_a_new_survey
4
+ visit surveyor_gui.new_surveyform_path
5
+ fill_in "Title", with: "How was Boston?"
6
+ click_button "Save Changes"
7
+ end
8
+
9
+ def first_section_title
10
+ find('.survey_section h2')
11
+ end
12
+
13
+ def first_question
14
+ find('.question span.questions')
15
+ end
16
+
17
+ def add_question(&block)
18
+ #make sure prior jquery was completed
19
+ expect(page).not_to have_css('div.jquery_add_question_started, div.jquery_add_section_started')
20
+ fix_node_error do
21
+ all('#add_question').last.click
22
+ expect(page).to have_css('iframe')
23
+ end
24
+ within_frame 0 do
25
+ #then wait for window to pop up
26
+ find('form')
27
+ expect(find('h1')).to have_content("Add Question")
28
+ #then enter the question details
29
+ block.call
30
+ #then the window closes
31
+ end
32
+ wait_for_ajax
33
+ expect(page).not_to have_css('div.jquery_add_question_started')
34
+ end
35
+
36
+ def add_section
37
+ fix_node_error do
38
+ all('#add_section').last.click
39
+ expect(page).to have_css('iframe')
40
+ end
41
+ end
42
+
43
+ def fix_node_error(&block)
44
+ # fix Capybara::Poltergeist::ObsoleteNode: - seems like some kind of race problem
45
+ begin
46
+ yield(block)
47
+ rescue
48
+ sleep(1)
49
+ yield(block)
50
+ end
51
+ end
52
+
53
+ def select_question_type(type)
54
+ #within ".question_type" do
55
+ choose(type)
56
+ #end
57
+ end
58
+
59
+ def add_answers
60
+ wait_for_ajax
61
+ page.all("div.answer .question_answers_text input")
62
+ end
63
+ end
64
+
65
+ module BuildASurvey
66
+ def build_a_survey
67
+ #Given I'm on the "Create New Survey" page
68
+ visit surveyor_gui.new_surveyform_path
69
+
70
+ title_the_survey
71
+ title_the_first_section
72
+ add_a_text_question("Describe your day at Fenway Park.")
73
+ add_a_number_question
74
+ add_a_pick_one_question
75
+ add_a_pick_any_question
76
+ add_a_dropdown_question
77
+ add_a_date_question
78
+ add_a_label
79
+ add_a_slider_question
80
+ add_a_star_question
81
+ add_a_file_upload
82
+
83
+ add_a_new_section("Entertainment")
84
+ question_maker = QuestionsFactory.new
85
+ question_maker.make_question(3){|text| add_a_text_question(text)}
86
+ add_a_text_question("Describe your room.")
87
+
88
+ add_a_new_section("Food")
89
+ question_maker.make_question(3){|text| add_a_text_question(text)}
90
+ end
91
+
92
+ def build_a_three_question_survey
93
+ visit surveyor_gui.new_surveyform_path
94
+ title_the_survey
95
+ question_maker = QuestionsFactory.new
96
+ question_maker.make_question(3){|text| add_a_text_question(text)}
97
+ end
98
+
99
+ def build_a_three_section_survey
100
+ visit surveyor_gui.new_surveyform_path
101
+ title_the_survey
102
+ title_the_first_section ("Unique Section 1")
103
+ add_a_new_section("Unique Section 2")
104
+ add_a_new_section("Unique Section 3")
105
+ end
106
+
107
+ def title_the_survey
108
+ #When I fill in a title
109
+ fill_in "Title", with: "How was Boston?"
110
+ #And I save the survey
111
+ click_button "Save Changes"
112
+ end
113
+
114
+ def title_the_first_section(title="Accommodations")
115
+ #And I click "Edit Section Title"
116
+ click_button "Edit Section Title"
117
+ #Then I see a window pop-up
118
+ expect(page).to have_css('iframe')
119
+ within_frame 0 do
120
+ #And I enter a title
121
+ fill_in "Title", with: title
122
+ #And I save the title
123
+ click_button "Save Changes"
124
+ end
125
+ end
126
+
127
+ def add_a_text_question(text="Where did you stay?")
128
+ add_question do
129
+ #And I see a new form for "Add Question"
130
+ find('form')
131
+ expect(find('h1')).to have_content("Add Question")
132
+ #And I frame the question
133
+ fill_in "question_text", with: text
134
+ #And I select the "text" question type
135
+ select_question_type "Text"
136
+ #And I save the question
137
+ click_button "Save Changes"
138
+ #Then the window goes away
139
+ end
140
+ end
141
+
142
+ def add_a_number_question
143
+ add_question do
144
+ #Given I've added a new question
145
+ #Then I select the "number" question type
146
+ select_question_type "Number"
147
+ #And I frame the question
148
+ fill_in "question_text", with: "How many days did you stay?"
149
+ #And I add the suffix, "days"
150
+ fill_in "question_suffix", with: "days"
151
+ #And I sav the question
152
+ click_button "Save Changes"
153
+ #Then the window goes away
154
+ end
155
+ end
156
+
157
+ def add_a_pick_one_question
158
+ add_question do
159
+ #Then I select the "multiple choice" question type
160
+ select_question_type "Multiple Choice (only one answer)"
161
+ #And I frame the question
162
+ fill_in "question_text", with: "What type of room did you get?"
163
+ #And I add some choices"
164
+ fill_in "question_answers_textbox", with: """Deluxe King
165
+ Standard Queen
166
+ Standard Double"""
167
+ #And I save the question
168
+ click_button "Save Changes"
169
+ #Then the window goes away
170
+ end
171
+ end
172
+
173
+ def add_a_pick_any_question
174
+ #Given I've added a new question
175
+ add_question do
176
+ #Then I select the "number" question type
177
+ select_question_type "Multiple Choice (multiple answers)"
178
+ #And I frame the question
179
+ fill_in "question_text", with: "What did you order from the minibar?"
180
+ #And I add some choices"
181
+ fill_in "question_answers_textbox", with: """Bottled Water
182
+ Kit Kats
183
+ Scotch"""
184
+ #And I save the question
185
+ click_button "Save Changes"
186
+ #Then the window goes away
187
+ end
188
+ end
189
+
190
+ def add_a_dropdown_question
191
+ #Given I've added a new question
192
+ add_question do
193
+ #Then I select the "number" question type
194
+ select_question_type "Dropdown List"
195
+ #And I frame the question
196
+ fill_in "question_text", with: "What neighborhood were you in?"
197
+ #And I add some choices"
198
+ fill_in "question_answers_textbox", with: """ Financial District
199
+ Back Bay
200
+ North End"""
201
+ #And I save the question
202
+ click_button "Save Changes"
203
+ #Then the window goes away
204
+ end
205
+ end
206
+
207
+ def add_a_date_question
208
+ #And I can see the question in my survey
209
+ #Given I've added a new question
210
+ add_question do
211
+ #Then I select the "number" question type
212
+ select_question_type "Date"
213
+ #And I frame the question
214
+ fill_in "question_text", with: "When did you checkout?"
215
+ #And I save the question
216
+ click_button "Save Changes"
217
+ #Then the window goes away
218
+ end
219
+ end
220
+
221
+ def add_a_label
222
+ add_question do
223
+ #Then I select the "Label" question type
224
+ select_question_type "Label"
225
+ #And I frame the question
226
+ fill_in "question_text", with: "You don't need to answer the following questions if you are not comfortable."
227
+ #And I save the question
228
+ click_button "Save Changes"
229
+ #Then the window goes away
230
+ end
231
+ end
232
+
233
+ def add_a_text_box_question
234
+ #Given I've added a new question
235
+ add_question do
236
+ #Then I select the "Text Box" question type
237
+ select_question_type "Text Box (for extended text, like notes, etc.)"
238
+ #And I frame the question
239
+ fill_in "question_text", with: "What did you think of the staff?"
240
+ #And I save the question
241
+ click_button "Save Changes"
242
+ #Then the window goes away
243
+ end
244
+ end
245
+
246
+ def add_a_slider_question
247
+ #Given I've added a new question
248
+ add_question do
249
+ #Then I select the "Slider" question type
250
+ select_question_type "Slider"
251
+ #And I frame the question
252
+ fill_in "question_text", with: "What did you think of the food?"
253
+ #And I add some choices"
254
+ fill_in "question_answers_textbox", with: """Sucked!
255
+ Meh
256
+ Good
257
+ Wicked good!"""
258
+ #And I save the question
259
+ click_button "Save Changes"
260
+ #Then the window goes away
261
+ end
262
+ end
263
+
264
+ def add_a_star_question
265
+ #Given I've added a new question
266
+ add_question do
267
+ #Then I select the "Star" question type
268
+ select_question_type "Star"
269
+ #And I frame the question
270
+ fill_in "question_text", with: "How would you rate your stay?"
271
+ #And I save the question
272
+ click_button "Save Changes"
273
+ #Then the window goes away
274
+ end
275
+ end
276
+
277
+ def add_a_file_upload
278
+ #Given I've added a new question
279
+ add_question do
280
+ #Then I select the "Star" question type
281
+ select_question_type "File Upload"
282
+ #And I frame the question
283
+ fill_in "question_text", with: "Please upload a copy of your bill."
284
+ #And I save the question
285
+ click_button "Save Changes"
286
+ #Then the window goes away
287
+ end
288
+ end
289
+
290
+ def add_a_new_section(title)
291
+ #Then I add Section II
292
+ add_section
293
+ within_frame 0 do
294
+ fill_in "Title", with: title
295
+ click_button "Save Changes"
296
+ end
297
+ end
298
+
299
+ class QuestionsFactory
300
+ attr_reader :question_no
301
+ def initialize
302
+ @question_no = 1
303
+ end
304
+
305
+ def make_question(quantity,&block)
306
+ quantity.times do
307
+ block.call("Unique Question "+@question_no.to_s)
308
+ @question_no += 1
309
+ end
310
+ end
311
+ end
312
+ end
313
+ end
@@ -0,0 +1,170 @@
1
+ module CutAndPaste
2
+ def construct_scenario
3
+ examples = """
4
+ |from_item | over_under | to_item | order|
5
+ |2 | over | 1 | 213 |
6
+ |2 | over | 3 | 123 |
7
+ |2 | under | 1 | 123 |
8
+ |2 | under | 3 | 132 |
9
+ |1 | over | 2 | 312 |
10
+ |1 | over | 3 | 132 |
11
+ |1 | under | 2 | 321 |
12
+ |1 | under | 3 | 312 |
13
+ |3 | over | 1 | 312 |
14
+ |3 | over | 2 | 132 |
15
+ |3 | under | 1 | 132 |
16
+ |3 | under | 2 | 123 |
17
+ """
18
+ #ScenarioOutline class found in spec/support/scenario_outline_helpers.rb
19
+ #use to simulate Cucumber type Scenario Outline
20
+ ScenarioOutline.new(examples)
21
+ end
22
+
23
+ def run_scenario
24
+ @scenario.examples.each do |example|
25
+ #e.g. puts "cut Unique Question 1 and paste it under Unique Question 2 resulting in 213"
26
+ puts "\tcut #{example.from_item} \
27
+ and paste it #{example.over_under} #{example.to_item}\
28
+ resulting in #{example.order}"
29
+ cut_and_paste_one_item(example)
30
+ end
31
+ end
32
+
33
+ def cut_and_paste_one_item(example)
34
+ _cut_item("Unique #{@item_name} "+example.from_item)
35
+ _paste_item(example.over_under, "Unique #{@item_name} "+example.to_item)
36
+ _check_order(example.order)
37
+ end
38
+
39
+ def cut_question(question)
40
+ cut_button = "$('fieldset.questions:contains(\"#{question}\") button:contains(\"Cut Question\")')[0].click();"
41
+ #When I cut <from_item>
42
+ page.execute_script(cut_button)
43
+ expect(page).not_to have_css('div.jquery_cut_question_started')
44
+ #Then I see paste buttons appear
45
+ expect(page).to have_content('Paste Question')
46
+ end
47
+
48
+ def cut_section(section)
49
+ cut_button = "$('div.survey_section:contains(\"#{section}\") button:contains(\"Cut Section\")')[0].click();"
50
+ #When I cut <from_item>
51
+ page.execute_script(cut_button)
52
+ expect(page).not_to have_css('div.jquery_cut_section_started')
53
+ #Then I see paste buttons appear
54
+ expect(page).to have_content('Paste Section')
55
+ end
56
+
57
+ def paste_section(position, section)
58
+ #And paste it <over_under> <to_item>
59
+ @_click_prev_paste_button_js = method(:_click_prev_paste_section_button_js)
60
+ @_click_next_paste_button_js = method(:_click_next_paste_section_button_js)
61
+ page.execute_script(_click_paste_button_js(position, section))
62
+ expect(page).not_to have_css('div.jquery_paste_section_started')
63
+ #Then I see cut buttons return
64
+ sleep 1
65
+ expect(page).to have_content('Cut Section')
66
+ end
67
+
68
+ def paste_question(position, question)
69
+ #And paste it <over_under> <to_item>
70
+ @_click_prev_paste_button_js = method(:_click_prev_paste_question_button_js)
71
+ @_click_next_paste_button_js = method(:_click_next_paste_question_button_js)
72
+ page.execute_script(_click_paste_button_js(position, question))
73
+ expect(page).not_to have_css('div.jquery_paste_question_started')
74
+ #Then I see cut buttons return
75
+ expect(page).to have_content('Cut Question')
76
+ end
77
+
78
+ def _click_paste_button_js(position, item)
79
+ if position == "over"
80
+ @_click_prev_paste_button_js.call(item)
81
+ else
82
+ @_click_next_paste_button_js.call(item)
83
+ end
84
+ end
85
+
86
+
87
+ def _click_prev_paste_question_button_js(question)
88
+ #If the target question is the first in the section, the previous button will
89
+ #be found in the button bar div. This div is one level up and one position back in the DOM.
90
+ #Otherwise, it will be found at the bottom of the previous question (div.question).
91
+ """
92
+ var to_item = $('fieldset.questions:contains(\"#{question}\")').closest('div.question');
93
+ var prev_question_in_section = to_item.prev('div.question');
94
+ if (prev_question_in_section.length < 1) {
95
+ prev_button_bar = to_item.closest('div.sortable_questions').prev('div.question_buttons_top');
96
+ prev_button = prev_button_bar.find('button:contains(\"Paste Question\")')[0];
97
+ } else {
98
+ prev_button = prev_question_in_section.find('button:contains(\"Paste Question\")')[0];
99
+ }
100
+ prev_button.click();
101
+
102
+ """
103
+ end
104
+
105
+ def _click_next_paste_question_button_js(question)
106
+ """
107
+ $('fieldset.questions:contains(\"#{question}\")').closest('div.question')
108
+ .find('button:contains(\"Paste Question\")')[0].click();
109
+ """
110
+ end
111
+
112
+ def _click_prev_paste_section_button_js(section)
113
+ """
114
+ $('div.survey_section:contains(\"#{section}\") div.section_top_button_bar button:contains(\"Paste Section\")')[0].click();
115
+ """
116
+ end
117
+
118
+ def _click_next_paste_section_button_js(section)
119
+ """
120
+ $('div.survey_section:contains(\"#{section}\") div.section_button_bar_bottom_inner button:contains(\"Paste Section\")')[0].click();
121
+ """
122
+ end
123
+
124
+ def _check_order(order)
125
+ exp = ".*"
126
+ order.split("").each do |question|
127
+ exp += "Unique #{@item_name} #{question}.*"
128
+ end
129
+ regexp = Regexp.new exp
130
+ #Then I see the questions in the correct order
131
+ expect(page).to have_content(regexp)
132
+ end
133
+ end
134
+
135
+ shared_context "question_cut_and_paste" do
136
+ include CutAndPaste
137
+ def initialize
138
+ @scenario = construct_scenario
139
+ @item_name = "Question"
140
+ end
141
+
142
+ def _cut_item(question)
143
+ cut_question(question)
144
+ end
145
+
146
+ def _paste_item(position, question)
147
+ paste_question(position, question)
148
+ end
149
+ end
150
+
151
+
152
+ shared_context "section_cut_and_paste" do
153
+ include CutAndPaste
154
+ def initialize
155
+ @item_name = "Section"
156
+ @scenario = construct_scenario
157
+ end
158
+
159
+ def _cut_item(section)
160
+ cut_section(section)
161
+ end
162
+
163
+ def _paste_item(position, section)
164
+ paste_section(position, section)
165
+ end
166
+ end
167
+
168
+ shared_context "question_and_section_cut_and_paste" do
169
+ include CutAndPaste
170
+ end