affectiva-surveyor 1.5.0.pre.disco.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +198 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.rails_version +27 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +166 -0
  9. data/Rakefile +106 -0
  10. data/app/controllers/surveyor_controller.rb +5 -0
  11. data/app/helpers/results_helper.rb +20 -0
  12. data/app/helpers/survey_form_builder.rb +37 -0
  13. data/app/helpers/surveyor_helper.rb +3 -0
  14. data/app/inputs/quiet_input.rb +5 -0
  15. data/app/inputs/surveyor_check_boxes_input.rb +35 -0
  16. data/app/inputs/surveyor_radio_input.rb +18 -0
  17. data/app/models/answer.rb +3 -0
  18. data/app/models/dependency.rb +3 -0
  19. data/app/models/dependency_condition.rb +3 -0
  20. data/app/models/question.rb +3 -0
  21. data/app/models/question_group.rb +4 -0
  22. data/app/models/response.rb +4 -0
  23. data/app/models/response_set.rb +3 -0
  24. data/app/models/survey.rb +3 -0
  25. data/app/models/survey_section.rb +4 -0
  26. data/app/models/survey_section_sweeper.rb +15 -0
  27. data/app/models/survey_translation.rb +4 -0
  28. data/app/models/validation.rb +3 -0
  29. data/app/models/validation_condition.rb +3 -0
  30. data/app/views/layouts/results.html.erb +13 -0
  31. data/app/views/layouts/surveyor_default.html.erb +12 -0
  32. data/app/views/partials/_answer.html.haml +25 -0
  33. data/app/views/partials/_dependents.html.haml +5 -0
  34. data/app/views/partials/_question.html.haml +28 -0
  35. data/app/views/partials/_question_group.html.haml +44 -0
  36. data/app/views/partials/_section.html.haml +12 -0
  37. data/app/views/partials/_section_menu.html.haml +12 -0
  38. data/app/views/surveyor/edit.html.haml +24 -0
  39. data/app/views/surveyor/export.json.rabl +85 -0
  40. data/app/views/surveyor/new.html.haml +24 -0
  41. data/app/views/surveyor/show.html.haml +74 -0
  42. data/app/views/surveyor/show.json.rabl +15 -0
  43. data/ci-exec.sh +56 -0
  44. data/config/routes.rb +8 -0
  45. data/cucumber.yml +10 -0
  46. data/doc/REPRESENTATIONS.md +34 -0
  47. data/doc/api_id_schema.json +7 -0
  48. data/doc/question types.png +0 -0
  49. data/doc/response_set_schema.json +54 -0
  50. data/doc/surveyor question combinations.png +0 -0
  51. data/doc/surveyor reject or delete decision matrix.png +0 -0
  52. data/doc/surveyor_models.png +0 -0
  53. data/doc/surveyor_models2.png +0 -0
  54. data/doc/surveyor_timestamp_schema.json +9 -0
  55. data/features/ajax_submissions.feature +140 -0
  56. data/features/export_to_json.feature +344 -0
  57. data/features/internationalization.feature +121 -0
  58. data/features/no_duplicates.feature +110 -0
  59. data/features/show_survey.feature +71 -0
  60. data/features/step_definitions/parser_steps.rb +145 -0
  61. data/features/step_definitions/surveyor_steps.rb +325 -0
  62. data/features/step_definitions/ui_steps.rb +25 -0
  63. data/features/step_definitions/web_steps.rb +225 -0
  64. data/features/support/REDCapDemoDatabase_DataDictionary.csv +127 -0
  65. data/features/support/database_cleaner.rb +16 -0
  66. data/features/support/env.rb +56 -0
  67. data/features/support/hooks.rb +4 -0
  68. data/features/support/paths.rb +39 -0
  69. data/features/support/redcap_new_headers.csv +1 -0
  70. data/features/support/redcap_siblings.csv +1 -0
  71. data/features/support/redcap_whitespace.csv +1 -0
  72. data/features/support/selectors.rb +39 -0
  73. data/features/support/simultaneous_ajax.rb +101 -0
  74. data/features/support/single_quit_selenium_driver.rb +23 -0
  75. data/features/support/slow_updates.rb +18 -0
  76. data/features/surveyor.feature +895 -0
  77. data/features/surveyor_dependencies.feature +476 -0
  78. data/features/surveyor_parser.feature +504 -0
  79. data/features/z_redcap_parser.feature +62 -0
  80. data/lib/assets/images/surveyor/next.gif +0 -0
  81. data/lib/assets/images/surveyor/prev.gif +0 -0
  82. data/lib/assets/images/surveyor/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  83. data/lib/assets/images/surveyor/ui-bg_flat_75_ffffff_40x100.png +0 -0
  84. data/lib/assets/images/surveyor/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  85. data/lib/assets/images/surveyor/ui-bg_glass_65_ffffff_1x400.png +0 -0
  86. data/lib/assets/images/surveyor/ui-bg_glass_75_dadada_1x400.png +0 -0
  87. data/lib/assets/images/surveyor/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  88. data/lib/assets/images/surveyor/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  89. data/lib/assets/images/surveyor/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  90. data/lib/assets/images/surveyor/ui-icons_222222_256x240.png +0 -0
  91. data/lib/assets/images/surveyor/ui-icons_2e83ff_256x240.png +0 -0
  92. data/lib/assets/images/surveyor/ui-icons_454545_256x240.png +0 -0
  93. data/lib/assets/images/surveyor/ui-icons_888888_256x240.png +0 -0
  94. data/lib/assets/images/surveyor/ui-icons_cd0a0a_256x240.png +0 -0
  95. data/lib/assets/javascripts/surveyor/jquery-1.9.0.js +9555 -0
  96. data/lib/assets/javascripts/surveyor/jquery-ui-1.10.0.custom.js +14850 -0
  97. data/lib/assets/javascripts/surveyor/jquery-ui-timepicker-addon.js +1919 -0
  98. data/lib/assets/javascripts/surveyor/jquery.maskedinput.js +338 -0
  99. data/lib/assets/javascripts/surveyor/jquery.selectToUISlider.js +240 -0
  100. data/lib/assets/javascripts/surveyor/jquery.surveyor.js +154 -0
  101. data/lib/assets/stylesheets/surveyor.sass +132 -0
  102. data/lib/assets/stylesheets/surveyor/jquery-ui-1.10.0.custom.css +1174 -0
  103. data/lib/assets/stylesheets/surveyor/jquery-ui-timepicker-addon.css +11 -0
  104. data/lib/assets/stylesheets/surveyor/reset.css +48 -0
  105. data/lib/assets/stylesheets/surveyor/results.css +125 -0
  106. data/lib/assets/stylesheets/surveyor/ui.slider.extras.css +110 -0
  107. data/lib/generators/surveyor/custom_generator.rb +18 -0
  108. data/lib/generators/surveyor/install_generator.rb +101 -0
  109. data/lib/generators/surveyor/templates/app/assets/javascripts/surveyor_all.js +6 -0
  110. data/lib/generators/surveyor/templates/app/assets/stylesheets/surveyor_all.css +9 -0
  111. data/lib/generators/surveyor/templates/app/controllers/surveyor_controller.rb +40 -0
  112. data/lib/generators/surveyor/templates/app/views/layouts/surveyor_custom.html.erb +13 -0
  113. data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +19 -0
  114. data/lib/generators/surveyor/templates/config/locales/surveyor_es.yml +19 -0
  115. data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +19 -0
  116. data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +19 -0
  117. data/lib/generators/surveyor/templates/db/migrate/add_api_id_to_question_groups.rb +10 -0
  118. data/lib/generators/surveyor/templates/db/migrate/add_api_ids.rb +14 -0
  119. data/lib/generators/surveyor/templates/db/migrate/add_api_ids_to_response_sets_and_responses.rb +12 -0
  120. data/lib/generators/surveyor/templates/db/migrate/add_correct_answer_id_to_questions.rb +10 -0
  121. data/lib/generators/surveyor/templates/db/migrate/add_default_value_to_answers.rb +10 -0
  122. data/lib/generators/surveyor/templates/db/migrate/add_display_order_to_surveys.rb +10 -0
  123. data/lib/generators/surveyor/templates/db/migrate/add_display_type_to_answers.rb +14 -0
  124. data/lib/generators/surveyor/templates/db/migrate/add_index_to_response_sets.rb +10 -0
  125. data/lib/generators/surveyor/templates/db/migrate/add_index_to_surveys.rb +10 -0
  126. data/lib/generators/surveyor/templates/db/migrate/add_input_mask_attributes_to_answer.rb +12 -0
  127. data/lib/generators/surveyor/templates/db/migrate/add_section_id_to_responses.rb +12 -0
  128. data/lib/generators/surveyor/templates/db/migrate/add_unique_index_on_access_code_and_version_in_surveys.rb +10 -0
  129. data/lib/generators/surveyor/templates/db/migrate/add_unique_indicies.rb +18 -0
  130. data/lib/generators/surveyor/templates/db/migrate/add_version_to_surveys.rb +10 -0
  131. data/lib/generators/surveyor/templates/db/migrate/api_ids_must_be_unique.rb +23 -0
  132. data/lib/generators/surveyor/templates/db/migrate/create_answers.rb +38 -0
  133. data/lib/generators/surveyor/templates/db/migrate/create_dependencies.rb +23 -0
  134. data/lib/generators/surveyor/templates/db/migrate/create_dependency_conditions.rb +30 -0
  135. data/lib/generators/surveyor/templates/db/migrate/create_question_groups.rb +28 -0
  136. data/lib/generators/surveyor/templates/db/migrate/create_questions.rb +37 -0
  137. data/lib/generators/surveyor/templates/db/migrate/create_response_sets.rb +23 -0
  138. data/lib/generators/surveyor/templates/db/migrate/create_responses.rb +34 -0
  139. data/lib/generators/surveyor/templates/db/migrate/create_survey_sections.rb +30 -0
  140. data/lib/generators/surveyor/templates/db/migrate/create_survey_translations.rb +19 -0
  141. data/lib/generators/surveyor/templates/db/migrate/create_surveys.rb +32 -0
  142. data/lib/generators/surveyor/templates/db/migrate/create_validation_conditions.rb +33 -0
  143. data/lib/generators/surveyor/templates/db/migrate/create_validations.rb +21 -0
  144. data/lib/generators/surveyor/templates/db/migrate/drop_unique_index_on_access_code_in_surveys.rb +10 -0
  145. data/lib/generators/surveyor/templates/db/migrate/update_blank_api_ids_on_question_group.rb +22 -0
  146. data/lib/generators/surveyor/templates/db/migrate/update_blank_versions_on_surveys.rb +13 -0
  147. data/lib/generators/surveyor/templates/surveys/EXTENDING_SURVEYOR.md +52 -0
  148. data/lib/generators/surveyor/templates/surveys/MODIFYING_SURVEYOR.md +91 -0
  149. data/lib/generators/surveyor/templates/surveys/date_survey.rb +16 -0
  150. data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +280 -0
  151. data/lib/generators/surveyor/templates/surveys/languages.rb +14 -0
  152. data/lib/generators/surveyor/templates/surveys/quiz.rb +11 -0
  153. data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +18 -0
  154. data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +18 -0
  155. data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +18 -0
  156. data/lib/generators/surveyor/templates/vendor/assets/stylesheets/custom.sass +5 -0
  157. data/lib/surveyor.rb +13 -0
  158. data/lib/surveyor/acts_as_response.rb +17 -0
  159. data/lib/surveyor/common.rb +59 -0
  160. data/lib/surveyor/engine.rb +10 -0
  161. data/lib/surveyor/helpers/asset_pipeline.rb +18 -0
  162. data/lib/surveyor/helpers/formtastic_custom_input.rb +13 -0
  163. data/lib/surveyor/helpers/surveyor_helper_methods.rb +103 -0
  164. data/lib/surveyor/models/answer_methods.rb +83 -0
  165. data/lib/surveyor/models/dependency_condition_methods.rb +69 -0
  166. data/lib/surveyor/models/dependency_methods.rb +57 -0
  167. data/lib/surveyor/models/question_group_methods.rb +58 -0
  168. data/lib/surveyor/models/question_methods.rb +112 -0
  169. data/lib/surveyor/models/response_methods.rb +126 -0
  170. data/lib/surveyor/models/response_set_methods.rb +188 -0
  171. data/lib/surveyor/models/survey_methods.rb +100 -0
  172. data/lib/surveyor/models/survey_section_methods.rb +53 -0
  173. data/lib/surveyor/models/survey_translation_methods.rb +30 -0
  174. data/lib/surveyor/models/validation_condition_methods.rb +54 -0
  175. data/lib/surveyor/models/validation_methods.rb +45 -0
  176. data/lib/surveyor/mustache_context.rb +11 -0
  177. data/lib/surveyor/parser.rb +427 -0
  178. data/lib/surveyor/redcap_parser.rb +288 -0
  179. data/lib/surveyor/surveyor_controller_methods.rb +236 -0
  180. data/lib/surveyor/unparser.rb +147 -0
  181. data/lib/surveyor/version.rb +3 -0
  182. data/lib/tasks/surveyor_tasks.rake +88 -0
  183. data/rails/init.rb +1 -0
  184. data/spec/controllers/surveyor_controller_spec.rb +311 -0
  185. data/spec/factories.rb +166 -0
  186. data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
  187. data/spec/helpers/surveyor_helper_spec.rb +117 -0
  188. data/spec/lib/benchmark_spec.rb +22 -0
  189. data/spec/lib/chinese_survey.rb +14 -0
  190. data/spec/lib/common_spec.rb +34 -0
  191. data/spec/lib/parser_spec.rb +204 -0
  192. data/spec/lib/rake_kitchen_sink.rb +40 -0
  193. data/spec/lib/redcap_parser_spec.rb +75 -0
  194. data/spec/lib/tasks_spec.rake +26 -0
  195. data/spec/lib/unparser_spec.rb +126 -0
  196. data/spec/models/answer_spec.rb +174 -0
  197. data/spec/models/dependency_condition_spec.rb +439 -0
  198. data/spec/models/dependency_spec.rb +101 -0
  199. data/spec/models/question_group_spec.rb +93 -0
  200. data/spec/models/question_spec.rb +206 -0
  201. data/spec/models/response_set_spec.rb +477 -0
  202. data/spec/models/response_spec.rb +218 -0
  203. data/spec/models/survey_section_spec.rb +85 -0
  204. data/spec/models/survey_spec.rb +191 -0
  205. data/spec/models/validation_condition_spec.rb +113 -0
  206. data/spec/models/validation_spec.rb +74 -0
  207. data/spec/rcov.opts +2 -0
  208. data/spec/spec.opts +4 -0
  209. data/spec/spec_helper.rb +56 -0
  210. data/stacktests.sh +65 -0
  211. data/surveyor.gemspec +53 -0
  212. metadata +601 -0
@@ -0,0 +1,325 @@
1
+ When /^I start the "([^"]*)" survey$/ do |name|
2
+ steps %Q{
3
+ When I go to the surveys page
4
+ Then I should see "#{name}\"
5
+ When I press "Take it"
6
+ }
7
+ @survey_code = current_path.split("/")[2] # /surveys/:survey_code/:response_set_code/take
8
+ @response_set_code = current_path.split("/")[3] # /surveys/:survey_code/:response_set_code/take
9
+ end
10
+
11
+ When /^I start the survey$/ do
12
+ steps %Q{
13
+ When I go to the surveys page
14
+ And I press "Take it"
15
+ }
16
+ @survey_code = current_path.split("/")[2] # /surveys/:survey_code/:response_set_code/take
17
+ @response_set_code = current_path.split("/")[3] # /surveys/:survey_code/:response_set_code/take
18
+ end
19
+
20
+ When /^I start the survey in "(.*?)"$/ do |locale|
21
+ step %Q{I go to the surveys page in "#{locale}"}
22
+ # these steps need to be separated so the url param has a chance to set I18n.locale
23
+ step %Q{I press "#{I18n.t 'surveyor.take_it'}"}
24
+ end
25
+
26
+
27
+ # When I fill in the (nth) (string) for "(ref_id)" with "(value to fill)"
28
+ When /^I fill in the (\d+[a-z]{0,2} )?(\w+) for "([^"]+)" with "([^"]+)"$/ do |index, type, answer_reference_id, value|
29
+ answer = Answer.where(:reference_identifier => answer_reference_id).first
30
+ fail "No answer with ref ID #{answer_reference_id.inspect}" unless answer
31
+
32
+ i = index ? index.to_i - 1 : 0
33
+
34
+ answer_input_id = page.all("input[@value='#{answer.id}']").
35
+ select { |x| x['id'] =~ /answer_id/ }[i]['id']
36
+ ordinal = answer_input_id.scan(/r_(\d+)/).first.first
37
+ value_input_id = "r_#{ordinal}_#{type}_value"
38
+ page.fill_in(value_input_id, :with => value)
39
+ end
40
+
41
+ Then /^there should be (\d+) response set with (\d+) responses? with:$/ do |rs_num, r_num, table|
42
+ ResponseSet.count.should == rs_num.to_i
43
+ Response.count.should == r_num.to_i
44
+ table.hashes.each do |hash|
45
+ if hash.keys == ["answer"]
46
+ a = Answer.find_by_text(hash["answer"])
47
+ a.should_not be_nil
48
+ Response.first(:conditions => {:answer_id => a.id}).should_not be_nil
49
+ else
50
+ if !(a = hash.delete("answer")).blank? and !(answer = Answer.find_by_text(a)).blank?
51
+ Response.first(:conditions => hash.merge({:answer_id => answer.id})).should_not be_nil
52
+ elsif
53
+ Response.first(:conditions => hash).should_not be_nil
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ Then /^there should be (\d+) dependenc(?:y|ies)$/ do |x|
60
+ Dependency.count.should == x.to_i
61
+ end
62
+
63
+ Then /^question "([^"]*)" should have a dependency with rule "([^"]*)"$/ do |qr, rule|
64
+ q = Question.find_by_reference_identifier(qr)
65
+ q.should_not be_blank
66
+ q.dependency.should_not be_nil
67
+ q.dependency.rule.should == rule
68
+ end
69
+
70
+ Then /^the element "([^"]*)" should have the class "([^"]*)"$/ do |selector, css_class|
71
+ page.should have_selector(selector, :class => css_class)
72
+ end
73
+
74
+ Then /^the element "([^"]*)" should exist$/ do |selector|
75
+ page.should have_selector(selector)
76
+ end
77
+
78
+ Then /^the survey should be complete$/ do
79
+ ResponseSet.first.should be_complete
80
+ end
81
+
82
+ Then /^a dropdown should exist with the options "([^"]*)"$/ do |options_text|
83
+ page.should have_selector('select')
84
+ options = options_text.split(',').collect(&:strip)
85
+ within "select" do |select|
86
+ options.each do |o|
87
+ select o
88
+ end
89
+ end
90
+ end
91
+
92
+ Then /^there should be (\d+) checkboxes$/ do |count|
93
+ page.should have_selector('input[type=checkbox]', :count => count.to_i)
94
+ end
95
+
96
+ Then /^there should be (\d+) text areas$/ do |count|
97
+ page.should have_selector('textarea', :count => count.to_i)
98
+ end
99
+
100
+ Then /^the question "([^"]*)" should be triggered$/ do |text|
101
+ q = Question.find_by_text(text)
102
+ page.should_not have_css %(fieldset#q_#{q.id}.q_hidden)
103
+ end
104
+
105
+ Then /^the question "(.*?)" should be hidden$/ do |text|
106
+ q = Question.find_by_text(text)
107
+ page.should have_css %(fieldset#q_#{q.id}.q_hidden)
108
+ end
109
+
110
+ Then /^there should be (\d+) response with answer "([^"]*)"$/ do |count, answer_text|
111
+ Response.count.should == count.to_i
112
+ Response.find_by_answer_id(Answer.find_by_text(answer_text)).should_not be_blank
113
+ end
114
+
115
+ When /^I choose row (\d+), column (\d+) of the grid$/ do |row, col|
116
+ find(".g_grid").find("tr:nth-child(#{row.to_i + 1})").find("td:nth-child(#{col.to_i + 1})").find("input").set(true)
117
+ end
118
+
119
+ Then /^there should (not )?be a (\w+ )?response(?: for answer "([^"]+)")?(?: with value "([^"]+)")?(?: on question "([^"]+)")?$/ do |neg, type, answer_reference_id, value, question_reference_id|
120
+ conditions = []
121
+ values = []
122
+ where = {}
123
+ expected_count = neg.blank? ? 1 : 0
124
+ if type
125
+ attribute = case type.strip
126
+ when 'date'
127
+ 'datetime_value'
128
+ when 'time'
129
+ 'datetime_value'
130
+ else
131
+ "#{type.strip}_value"
132
+ end
133
+ if value
134
+ case type.strip
135
+ when 'date' || 'datetime' || 'time'
136
+ where[:datetime_value] = Time.zone.parse(value).utc
137
+ else
138
+ conditions << "#{attribute} = ?"
139
+ values << value
140
+ end
141
+ else
142
+ conditions << "#{attribute} IS NOT NULL"
143
+ end
144
+ end
145
+
146
+ if question_reference_id
147
+ question = Question.where(:reference_identifier => question_reference_id).first
148
+ fail "No question with ref ID #{question_reference_id}" unless question
149
+ conditions << 'question_id = ?'
150
+ values << question
151
+ end
152
+
153
+ if answer_reference_id
154
+ a_conds = { :reference_identifier => answer_reference_id }
155
+ if question
156
+ a_conds[:question_id] = question
157
+ end
158
+ answer = Answer.where(a_conds).first
159
+ fail "No answer with ref ID #{answer_reference_id}" unless answer
160
+ conditions << 'answer_id = ?'
161
+ values << answer
162
+ end
163
+
164
+ Response.where(conditions.join(' AND '), *values).where(where).count.should == expected_count
165
+ end
166
+
167
+ Then /^I should see the image "([^"]*)"$/ do |src|
168
+ page.should have_selector %(img[src^="#{src}"])
169
+ end
170
+
171
+ Then /^I click elsewhere$/ do
172
+ page.find('.survey_title').click
173
+ end
174
+
175
+ Then /^(\d+) responses should exist$/ do |response_count|
176
+ Response.count.should == response_count.to_i
177
+ end
178
+
179
+ ## JSON
180
+
181
+ def last_json
182
+ page.find('body').text
183
+ end
184
+
185
+ When /^I visit "(.*?)"$/ do |path|
186
+ visit path
187
+ end
188
+
189
+ Then /^I export the response set$/ do
190
+ visit "/surveys/#{@survey_code}/#{@response_set_code}.json"
191
+ end
192
+
193
+ Then /^the JSON response at "(.*?)" should correspond to an answer with text "(.*?)"$/ do |path, text|
194
+ last_json.should be_json_eql(JsonSpec.remember("\"#{Answer.find_by_text(text).api_id}\"")).at_path(path)
195
+ end
196
+
197
+ Then /^the JSON representation for "(.*?)" should be:$/ do |title, string|
198
+ Survey.find_by_title(title).as_json.to_json.should be_json_eql(string)
199
+ end
200
+
201
+ Given /^I prefix the titles of exported surveys with "(.*?)"$/ do |prefix|
202
+ PREFIX = prefix
203
+ class Survey < ActiveRecord::Base
204
+ include Surveyor::Models::SurveyMethods
205
+ def filtered_for_json
206
+ dolly = self.clone
207
+ dolly.sections = self.sections
208
+ dolly.title = "#{PREFIX}#{dolly.title}"
209
+ dolly
210
+ end
211
+ end
212
+ end
213
+
214
+ ## Hidden and shown elements
215
+
216
+ Then /the element "([^\"]*)" should be hidden$/ do |selector|
217
+ wait_until do
218
+ its_hidden = page.evaluate_script("$('#{selector}').is(':hidden');")
219
+ its_not_in_dom = page.evaluate_script("$('#{selector}').length == 0;")
220
+ (its_hidden || its_not_in_dom).should be_true
221
+ end
222
+ end
223
+
224
+ Then /the element "([^\"]*)" should not be hidden$/ do |selector|
225
+ wait_until do
226
+ its_not_hidden = page.evaluate_script("$('#{selector}').is(':not(:hidden)');")
227
+ its_in_dom = page.evaluate_script("$('#{selector}').length > 0;")
228
+ (its_not_hidden && its_in_dom).should be_true
229
+ end
230
+ end
231
+
232
+ ## Context and substitution with mustache
233
+
234
+ Given /^I have survey context of "(.*)"$/ do |context|
235
+ class SurveyorController < ApplicationController
236
+ require 'mustache'
237
+ class FakeMustacheContext < ::Mustache
238
+ def name
239
+ "Santa Claus"
240
+ end
241
+ def site
242
+ "Northwestern"
243
+ end
244
+ end
245
+ def render_context
246
+ FakeMustacheContext
247
+ end
248
+ end
249
+ end
250
+
251
+ Given /^I have a simple hash context$/ do
252
+ class SurveyorController < ApplicationController
253
+ def render_context
254
+ {:name => "Moses", :site => "Northwestern"}
255
+ end
256
+ end
257
+ end
258
+
259
+ Given /^I replace question numbers with letters$/ do
260
+ module SurveyorHelper
261
+ include Surveyor::Helpers::SurveyorHelperMethods
262
+ def next_question_number(question)
263
+ @letters ||= ("A".."Z").to_a
264
+ @n ||= 25
265
+ "<span class='qnum'>#{@letters[(@n += 1)%26]}. </span>"
266
+ end
267
+ end
268
+ end
269
+
270
+ ## Various input elements
271
+
272
+ Then /^I should see (\d+) textarea(?:s?) on the page$/ do |i|
273
+ page.has_css?('textarea', :count => i).should == true
274
+ end
275
+
276
+ Then /^I should see (\d+) text input(?:s?) on the page$/ do |i|
277
+ page.has_css?('input[type="text"]', :count => i).should == true
278
+ end
279
+
280
+ Then /^I should see no text input(?:s?) on the page$/ do
281
+ page.has_css?('input[type="text"]').should == false
282
+ end
283
+
284
+ Then /^I should see (\d+) "(.*?)" input(?:s?) on the page$/ do |i, css_class|
285
+ page.has_css?("input.#{css_class}", :count => i).should == true
286
+ end
287
+
288
+ Then /^I should see (\d+) select on the page$/ do |i|
289
+ page.has_css?("select", :count => i)
290
+ end
291
+
292
+ Then /^the checkbox for "(.*?)" should be (dis|en)abled$/ do |text, dis_or_en|
293
+ a = Answer.find_by_text(text)
294
+ a.should_not be_nil
295
+ element = find("input[value='#{a.id}']")
296
+ if dis_or_en == 'dis'
297
+ element['disabled'].should == 'true'
298
+ else
299
+ [nil, 'false'].should include(element['disabled'])
300
+ end
301
+ end
302
+
303
+ # see support/simultaneous_ajax.rb
304
+ Then /^I wait for things to settle out( longer)?$/ do |longer|
305
+ if @simultaneous_ajax
306
+ Capybara.timeout(longer ? 120 : 10, page.driver, "waiting for all AJAX requests timed out") do
307
+ page.evaluate_script("window.surveyorIntegratedTestsRequestsOutstanding <= 0")
308
+ end
309
+ end
310
+ end
311
+
312
+ ## quizzes
313
+
314
+ Then /^the question "(.*?)" should have correct answer "(.*?)"$/ do |q, a|
315
+ Question.find_by_reference_identifier(q).correct_answer.reference_identifier.should == a
316
+ end
317
+
318
+ ## for Rails 3.0
319
+ Then /^I set the asset directory$/ do
320
+ ActionController::Base.helpers.config.assets_dir = "public" unless asset_pipeline_enabled?
321
+ end
322
+
323
+ When(/^I change the locale to "(.*?)"$/) do |locale|
324
+ steps %Q{When I select "#{locale}" from "new_locale"}
325
+ end
@@ -0,0 +1,25 @@
1
+ When /^I select "([^"]+)" as the datepicker's (\w+)$/ do |selection, type|
2
+ page.find(".ui-datepicker-#{type}").select(selection)
3
+ end
4
+
5
+ When /^I click the first date field$/ do
6
+ first(:css, "input.date[type='text']").click
7
+ end
8
+
9
+ Then /^the first date field should contain "(.*?)"$/ do |value|
10
+ field_value = first(:css, "input.date[type='text']").value
11
+ if field_value.respond_to? :should
12
+ field_value.should =~ /#{value}/
13
+ else
14
+ assert_match(/#{value}/, field_value)
15
+ end
16
+ end
17
+
18
+ Then /^the first date field should not contain "(.*?)"$/ do |value|
19
+ field_value = first(:css, "input.date[type='text']").value
20
+ if field_value.respond_to? :should_not
21
+ field_value.should_not =~ /#{value}/
22
+ else
23
+ assert_no_match(/#{value}/, field_value)
24
+ end
25
+ end
@@ -0,0 +1,225 @@
1
+ # TL;DR: YOU SHOULD DELETE THIS FILE
2
+ #
3
+ # This file was generated by Cucumber-Rails and is only here to get you a head start
4
+ # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5
+ # visit pages, interact with widgets and make assertions about page content.
6
+ #
7
+ # If you use these step definitions as basis for your features you will quickly end up
8
+ # with features that are:
9
+ #
10
+ # * Hard to maintain
11
+ # * Verbose to read
12
+ #
13
+ # A much better approach is to write your own higher level step definitions, following
14
+ # the advice in the following blog posts:
15
+ #
16
+ # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17
+ # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18
+ # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19
+ #
20
+
21
+
22
+ require 'uri'
23
+ require 'cgi'
24
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
26
+
27
+ module WithinHelpers
28
+ def with_scope(locator)
29
+ locator ? within(*selector_for(locator)) { yield } : yield
30
+ end
31
+ end
32
+ World(WithinHelpers)
33
+
34
+ # Single-line step scoper
35
+ When /^(.*) within (.*[^:])$/ do |step, parent|
36
+ with_scope(parent) { When step }
37
+ end
38
+
39
+ # Multi-line step scoper
40
+ When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
41
+ with_scope(parent) { When "#{step}:", table_or_string }
42
+ end
43
+
44
+ Given /^(?:|I )am on (.+)$/ do |page_name|
45
+ visit path_to(page_name)
46
+ end
47
+
48
+ When /^(?:|I )go to (.+)$/ do |page_name|
49
+ visit path_to(page_name)
50
+ end
51
+
52
+ When /^(?:|I )press "([^"]*)"$/ do |button|
53
+ click_button(button)
54
+ end
55
+
56
+ When /^(?:|I )follow "([^"]*)"$/ do |link|
57
+ click_link(link)
58
+ end
59
+
60
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
61
+ fill_in(field, :with => value)
62
+ end
63
+
64
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
65
+ fill_in(field, :with => value)
66
+ end
67
+
68
+ # Use this to fill in an entire form with data from a table. Example:
69
+ #
70
+ # When I fill in the following:
71
+ # | Account Number | 5002 |
72
+ # | Expiry date | 2009-11-01 |
73
+ # | Note | Nice guy |
74
+ # | Wants Email? | |
75
+ #
76
+ # TODO: Add support for checkbox, select og option
77
+ # based on naming conventions.
78
+ #
79
+ When /^(?:|I )fill in the following:$/ do |fields|
80
+ fields.rows_hash.each do |name, value|
81
+ When %{I fill in "#{name}" with "#{value}"}
82
+ end
83
+ end
84
+
85
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
86
+ select(value, :from => field)
87
+ end
88
+
89
+ When /^(?:|I )check "([^"]*)"$/ do |field|
90
+ check(field)
91
+ end
92
+
93
+ When /^(?:|I )uncheck "([^"]*)"$/ do |field|
94
+ uncheck(field)
95
+ end
96
+
97
+ When /^(?:|I )choose "([^"]*)"$/ do |field|
98
+ choose(field)
99
+ end
100
+
101
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
102
+ attach_file(field, File.expand_path(path))
103
+ end
104
+
105
+ When /^(?:|I )click "([^"]*)"$/ do |field|
106
+ find_field(field).click
107
+ end
108
+
109
+ When /^(?:|I )change "([^"]*)" to "([^"]*)"$/ do |field, value|
110
+ fill_in(field, :with => value)
111
+ id = "#" + find_field(field)[:id]
112
+ page.execute_script("$('#{id}').trigger('change');")
113
+ end
114
+
115
+ Then /^(?:|I )should see "([^"]*)"$/ do |text|
116
+ if page.respond_to? :should
117
+ page.should have_content(text)
118
+ else
119
+ assert page.has_content?(text)
120
+ end
121
+ end
122
+
123
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
124
+ regexp = Regexp.new(regexp)
125
+
126
+ if page.respond_to? :should
127
+ page.should have_xpath('//*', :text => regexp)
128
+ else
129
+ assert page.has_xpath?('//*', :text => regexp)
130
+ end
131
+ end
132
+
133
+ Then /^(?:|I )should not see "([^"]*)"$/ do |text|
134
+ if page.respond_to? :should
135
+ page.should have_no_content(text)
136
+ else
137
+ assert page.has_no_content?(text)
138
+ end
139
+ end
140
+
141
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
142
+ regexp = Regexp.new(regexp)
143
+
144
+ if page.respond_to? :should
145
+ page.should have_no_xpath('//*', :text => regexp)
146
+ else
147
+ assert page.has_no_xpath?('//*', :text => regexp)
148
+ end
149
+ end
150
+
151
+ Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
152
+ with_scope(parent) do
153
+ field = find_field(field)
154
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
155
+ if field_value.respond_to? :should
156
+ field_value.should =~ /#{value}/
157
+ else
158
+ assert_match(/#{value}/, field_value)
159
+ end
160
+ end
161
+ end
162
+
163
+ Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
164
+ with_scope(parent) do
165
+ field = find_field(field)
166
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
167
+ if field_value.respond_to? :should_not
168
+ field_value.should_not =~ /#{value}/
169
+ else
170
+ assert_no_match(/#{value}/, field_value)
171
+ end
172
+ end
173
+ end
174
+
175
+ Then /^the "([^"]*)" (checkbox|radiobutton)(?: within (.*))? should be checked$/ do |label, _, parent|
176
+ with_scope(parent) do
177
+ field_checked = find_field(label)['checked']
178
+ if field_checked.respond_to? :should
179
+ field_checked.should be_true
180
+ else
181
+ assert field_checked
182
+ end
183
+ end
184
+ end
185
+
186
+ Then /^the "([^"]*)" (checkbox|radiobutton)(?: within (.*))? should not be checked$/ do |label, _, parent|
187
+ with_scope(parent) do
188
+ field_checked = find_field(label)['checked']
189
+ if field_checked.respond_to? :should
190
+ field_checked.should be_false
191
+ else
192
+ assert !field_checked
193
+ end
194
+ end
195
+ end
196
+
197
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
198
+ current_path = URI.parse(current_url).path
199
+ if current_path.respond_to? :should
200
+ current_path.should == path_to(page_name)
201
+ else
202
+ assert_equal path_to(page_name), current_path
203
+ end
204
+ end
205
+
206
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
207
+ query = URI.parse(current_url).query
208
+ actual_params = query ? CGI.parse(query) : {}
209
+ expected_params = {}
210
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
211
+
212
+ if actual_params.respond_to? :should
213
+ actual_params.should == expected_params
214
+ else
215
+ assert_equal expected_params, actual_params
216
+ end
217
+ end
218
+
219
+ Then /^show me the page$/ do
220
+ save_and_open_page
221
+ end
222
+
223
+ Then /^I should get a "(\d+)" response$/ do |http_status|
224
+ page.status_code.should == http_status.to_i
225
+ end