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,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,312 @@
1
+ module SurveyFormsCreationHelpers
2
+ module CreateSurvey
3
+ def start_a_new_survey
4
+ visit 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
+ expect(page).not_to have_css('div.jquery_add_question_started')
33
+ end
34
+
35
+ def add_section
36
+ fix_node_error do
37
+ all('#add_section').last.click
38
+ expect(page).to have_css('iframe')
39
+ end
40
+ end
41
+
42
+ def fix_node_error(&block)
43
+ # fix Capybara::Poltergeist::ObsoleteNode: - seems like some kind of race problem
44
+ begin
45
+ yield(block)
46
+ rescue
47
+ sleep(1)
48
+ yield(block)
49
+ end
50
+ end
51
+
52
+ def select_question_type(type)
53
+ #within ".question_type" do
54
+ choose(type)
55
+ #end
56
+ end
57
+
58
+ def add_answers
59
+ wait_for_ajax
60
+ page.all("div.answer .question_answers_text input")
61
+ end
62
+ end
63
+
64
+ module BuildASurvey
65
+ def build_a_survey
66
+ #Given I'm on the "Create New Survey" page
67
+ visit new_surveyform_path
68
+
69
+ title_the_survey
70
+ title_the_first_section
71
+ add_a_text_question("Describe your day at Fenway Park.")
72
+ add_a_number_question
73
+ add_a_pick_one_question
74
+ add_a_pick_any_question
75
+ add_a_dropdown_question
76
+ add_a_date_question
77
+ add_a_label
78
+ add_a_slider_question
79
+ add_a_star_question
80
+ add_a_file_upload
81
+
82
+ add_a_new_section("Entertainment")
83
+ question_maker = QuestionsFactory.new
84
+ question_maker.make_question(3){|text| add_a_text_question(text)}
85
+ add_a_text_question("Describe your room.")
86
+
87
+ add_a_new_section("Food")
88
+ question_maker.make_question(3){|text| add_a_text_question(text)}
89
+ end
90
+
91
+ def build_a_three_question_survey
92
+ visit new_surveyform_path
93
+ title_the_survey
94
+ question_maker = QuestionsFactory.new
95
+ question_maker.make_question(3){|text| add_a_text_question(text)}
96
+ end
97
+
98
+ def build_a_three_section_survey
99
+ visit new_surveyform_path
100
+ title_the_survey
101
+ title_the_first_section ("Unique Section 1")
102
+ add_a_new_section("Unique Section 2")
103
+ add_a_new_section("Unique Section 3")
104
+ end
105
+
106
+ def title_the_survey
107
+ #When I fill in a title
108
+ fill_in "Title", with: "How was Boston?"
109
+ #And I save the survey
110
+ click_button "Save Changes"
111
+ end
112
+
113
+ def title_the_first_section(title="Accommodations")
114
+ #And I click "Edit Section Title"
115
+ click_button "Edit Section Title"
116
+ #Then I see a window pop-up
117
+ expect(page).to have_css('iframe')
118
+ within_frame 0 do
119
+ #And I enter a title
120
+ fill_in "Title", with: title
121
+ #And I save the title
122
+ click_button "Save Changes"
123
+ end
124
+ end
125
+
126
+ def add_a_text_question(text="Where did you stay?")
127
+ add_question do
128
+ #And I see a new form for "Add Question"
129
+ find('form')
130
+ expect(find('h1')).to have_content("Add Question")
131
+ #And I frame the question
132
+ fill_in "question_text", with: text
133
+ #And I select the "text" question type
134
+ select_question_type "Text"
135
+ #And I save the question
136
+ click_button "Save Changes"
137
+ #Then the window goes away
138
+ end
139
+ end
140
+
141
+ def add_a_number_question
142
+ add_question do
143
+ #Given I've added a new question
144
+ #Then I select the "number" question type
145
+ select_question_type "Number"
146
+ #And I frame the question
147
+ fill_in "question_text", with: "How many days did you stay?"
148
+ #And I add the suffix, "days"
149
+ fill_in "question_suffix", with: "days"
150
+ #And I sav the question
151
+ click_button "Save Changes"
152
+ #Then the window goes away
153
+ end
154
+ end
155
+
156
+ def add_a_pick_one_question
157
+ add_question do
158
+ #Then I select the "multiple choice" question type
159
+ select_question_type "Multiple Choice (only one answer)"
160
+ #And I frame the question
161
+ fill_in "question_text", with: "What type of room did you get?"
162
+ #And I add some choices"
163
+ fill_in "question_answers_textbox", with: """Deluxe King
164
+ Standard Queen
165
+ Standard Double"""
166
+ #And I save the question
167
+ click_button "Save Changes"
168
+ #Then the window goes away
169
+ end
170
+ end
171
+
172
+ def add_a_pick_any_question
173
+ #Given I've added a new question
174
+ add_question do
175
+ #Then I select the "number" question type
176
+ select_question_type "Multiple Choice (multiple answers)"
177
+ #And I frame the question
178
+ fill_in "question_text", with: "What did you order from the minibar?"
179
+ #And I add some choices"
180
+ fill_in "question_answers_textbox", with: """Bottled Water
181
+ Kit Kats
182
+ Scotch"""
183
+ #And I save the question
184
+ click_button "Save Changes"
185
+ #Then the window goes away
186
+ end
187
+ end
188
+
189
+ def add_a_dropdown_question
190
+ #Given I've added a new question
191
+ add_question do
192
+ #Then I select the "number" question type
193
+ select_question_type "Dropdown List"
194
+ #And I frame the question
195
+ fill_in "question_text", with: "What neighborhood were you in?"
196
+ #And I add some choices"
197
+ fill_in "question_answers_textbox", with: """ Financial District
198
+ Back Bay
199
+ North End"""
200
+ #And I save the question
201
+ click_button "Save Changes"
202
+ #Then the window goes away
203
+ end
204
+ end
205
+
206
+ def add_a_date_question
207
+ #And I can see the question in my survey
208
+ #Given I've added a new question
209
+ add_question do
210
+ #Then I select the "number" question type
211
+ select_question_type "Date"
212
+ #And I frame the question
213
+ fill_in "question_text", with: "When did you checkout?"
214
+ #And I save the question
215
+ click_button "Save Changes"
216
+ #Then the window goes away
217
+ end
218
+ end
219
+
220
+ def add_a_label
221
+ add_question do
222
+ #Then I select the "Label" question type
223
+ select_question_type "Label"
224
+ #And I frame the question
225
+ fill_in "question_text", with: "You don't need to answer the following questions if you are not comfortable."
226
+ #And I save the question
227
+ click_button "Save Changes"
228
+ #Then the window goes away
229
+ end
230
+ end
231
+
232
+ def add_a_text_box_question
233
+ #Given I've added a new question
234
+ add_question do
235
+ #Then I select the "Text Box" question type
236
+ select_question_type "Text Box (for extended text, like notes, etc.)"
237
+ #And I frame the question
238
+ fill_in "question_text", with: "What did you think of the staff?"
239
+ #And I save the question
240
+ click_button "Save Changes"
241
+ #Then the window goes away
242
+ end
243
+ end
244
+
245
+ def add_a_slider_question
246
+ #Given I've added a new question
247
+ add_question do
248
+ #Then I select the "Slider" question type
249
+ select_question_type "Slider"
250
+ #And I frame the question
251
+ fill_in "question_text", with: "What did you think of the food?"
252
+ #And I add some choices"
253
+ fill_in "question_answers_textbox", with: """Sucked!
254
+ Meh
255
+ Good
256
+ Wicked good!"""
257
+ #And I save the question
258
+ click_button "Save Changes"
259
+ #Then the window goes away
260
+ end
261
+ end
262
+
263
+ def add_a_star_question
264
+ #Given I've added a new question
265
+ add_question do
266
+ #Then I select the "Star" question type
267
+ select_question_type "Star"
268
+ #And I frame the question
269
+ fill_in "question_text", with: "How would you rate your stay?"
270
+ #And I save the question
271
+ click_button "Save Changes"
272
+ #Then the window goes away
273
+ end
274
+ end
275
+
276
+ def add_a_file_upload
277
+ #Given I've added a new question
278
+ add_question do
279
+ #Then I select the "Star" question type
280
+ select_question_type "File Upload"
281
+ #And I frame the question
282
+ fill_in "question_text", with: "Please upload a copy of your bill."
283
+ #And I save the question
284
+ click_button "Save Changes"
285
+ #Then the window goes away
286
+ end
287
+ end
288
+
289
+ def add_a_new_section(title)
290
+ #Then I add Section II
291
+ add_section
292
+ within_frame 0 do
293
+ fill_in "Title", with: title
294
+ click_button "Save Changes"
295
+ end
296
+ end
297
+
298
+ class QuestionsFactory
299
+ attr_reader :question_no
300
+ def initialize
301
+ @question_no = 1
302
+ end
303
+
304
+ def make_question(quantity,&block)
305
+ quantity.times do
306
+ block.call("Unique Question "+@question_no.to_s)
307
+ @question_no += 1
308
+ end
309
+ end
310
+ end
311
+ end
312
+ 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