helena 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +15 -0
  4. data/.rubocop.yml +16 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +31 -0
  7. data/Gemfile.lock +290 -0
  8. data/LICENSE +16 -0
  9. data/README.md +90 -0
  10. data/Rakefile +29 -0
  11. data/app/assets/images/helena/.keep +0 -0
  12. data/app/assets/images/helena/helena_mobile_view.jpg +0 -0
  13. data/app/assets/images/helena/icons/export.svg +29 -0
  14. data/app/assets/images/helena/swissmadesoftware.png +0 -0
  15. data/app/assets/javascripts/helena/application.js +4 -0
  16. data/app/assets/javascripts/helena/survey.js +2 -0
  17. data/app/assets/stylesheets/helena/admin/labels.css.sass +7 -0
  18. data/app/assets/stylesheets/helena/admin/layout.css.sass +6 -0
  19. data/app/assets/stylesheets/helena/admin/question_groups.css.sass +7 -0
  20. data/app/assets/stylesheets/helena/admin/questions.css.sass +9 -0
  21. data/app/assets/stylesheets/helena/admin/sessions.css.sass +5 -0
  22. data/app/assets/stylesheets/helena/admin/subquestions.css.sass +7 -0
  23. data/app/assets/stylesheets/helena/admin/versions.css.sass +9 -0
  24. data/app/assets/stylesheets/helena/application.css.sass +21 -0
  25. data/app/assets/stylesheets/helena/forms.css.sass +13 -0
  26. data/app/assets/stylesheets/helena/layout.css.sass +3 -0
  27. data/app/assets/stylesheets/helena/question_groups.css.sass +4 -0
  28. data/app/controllers/helena/admin/application_controller.rb +31 -0
  29. data/app/controllers/helena/admin/question_groups_controller.rb +78 -0
  30. data/app/controllers/helena/admin/questions/checkbox_groups_controller.rb +17 -0
  31. data/app/controllers/helena/admin/questions/checkbox_matrix_controller.rb +9 -0
  32. data/app/controllers/helena/admin/questions/long_texts_controller.rb +13 -0
  33. data/app/controllers/helena/admin/questions/radio_groups_controller.rb +17 -0
  34. data/app/controllers/helena/admin/questions/radio_matrix_controller.rb +9 -0
  35. data/app/controllers/helena/admin/questions/short_texts_controller.rb +13 -0
  36. data/app/controllers/helena/admin/questions/static_texts_controller.rb +13 -0
  37. data/app/controllers/helena/admin/questions_controller.rb +105 -0
  38. data/app/controllers/helena/admin/sessions_controller.rb +35 -0
  39. data/app/controllers/helena/admin/surveys_controller.rb +78 -0
  40. data/app/controllers/helena/admin/versions_controller.rb +71 -0
  41. data/app/controllers/helena/application_controller.rb +15 -0
  42. data/app/controllers/helena/concerns/questions/matrix_questions.rb +24 -0
  43. data/app/controllers/helena/sessions_controller.rb +93 -0
  44. data/app/controllers/helena/surveys_controller.rb +11 -0
  45. data/app/helpers/helena/application_helper.rb +4 -0
  46. data/app/models/helena/answer.rb +48 -0
  47. data/app/models/helena/boolean_answer.rb +5 -0
  48. data/app/models/helena/concerns/application_model.rb +19 -0
  49. data/app/models/helena/concerns/questions/requirable.rb +19 -0
  50. data/app/models/helena/concerns/questions/validates_one_label.rb +22 -0
  51. data/app/models/helena/integer_answer.rb +5 -0
  52. data/app/models/helena/label.rb +18 -0
  53. data/app/models/helena/question.rb +63 -0
  54. data/app/models/helena/question_group.rb +18 -0
  55. data/app/models/helena/questions/checkbox_group.rb +17 -0
  56. data/app/models/helena/questions/long_text.rb +9 -0
  57. data/app/models/helena/questions/radio_group.rb +12 -0
  58. data/app/models/helena/questions/radio_matrix.rb +24 -0
  59. data/app/models/helena/questions/short_text.rb +9 -0
  60. data/app/models/helena/questions/static_text.rb +7 -0
  61. data/app/models/helena/session.rb +76 -0
  62. data/app/models/helena/string_answer.rb +5 -0
  63. data/app/models/helena/sub_question.rb +27 -0
  64. data/app/models/helena/survey.rb +29 -0
  65. data/app/models/helena/survey_detail.rb +10 -0
  66. data/app/models/helena/version.rb +33 -0
  67. data/app/views/helena/admin/question_groups/_form.html.haml +3 -0
  68. data/app/views/helena/admin/question_groups/edit.html.haml +3 -0
  69. data/app/views/helena/admin/question_groups/index.html.haml +41 -0
  70. data/app/views/helena/admin/question_groups/new.html.haml +3 -0
  71. data/app/views/helena/admin/questions/_form.html.haml +15 -0
  72. data/app/views/helena/admin/questions/_labels.html.haml +24 -0
  73. data/app/views/helena/admin/questions/_sub_questions.html.haml +32 -0
  74. data/app/views/helena/admin/questions/edit.html.haml +3 -0
  75. data/app/views/helena/admin/questions/index.html.haml +49 -0
  76. data/app/views/helena/admin/questions/new.html.haml +3 -0
  77. data/app/views/helena/admin/sessions/index.html.haml +46 -0
  78. data/app/views/helena/admin/surveys/_form.html.haml +10 -0
  79. data/app/views/helena/admin/surveys/edit.html.haml +5 -0
  80. data/app/views/helena/admin/surveys/index.html.haml +35 -0
  81. data/app/views/helena/admin/surveys/new.html.haml +3 -0
  82. data/app/views/helena/admin/versions/_form.html.haml +5 -0
  83. data/app/views/helena/admin/versions/default_session_report.html.haml +17 -0
  84. data/app/views/helena/admin/versions/edit.html.haml +3 -0
  85. data/app/views/helena/admin/versions/index.html.haml +35 -0
  86. data/app/views/helena/admin/versions/new.html.haml +3 -0
  87. data/app/views/helena/questions/_checkbox_group.html.haml +17 -0
  88. data/app/views/helena/questions/_long_text.html.haml +8 -0
  89. data/app/views/helena/questions/_radio_group.html.haml +13 -0
  90. data/app/views/helena/questions/_radio_matrix.html.haml +27 -0
  91. data/app/views/helena/questions/_short_text.html.haml +8 -0
  92. data/app/views/helena/sessions/edit.html.haml +16 -0
  93. data/app/views/helena/sessions/end_message.html.haml +5 -0
  94. data/app/views/helena/surveys/_survey.html.haml +3 -0
  95. data/app/views/helena/surveys/index.html.haml +2 -0
  96. data/bin/rails +8 -0
  97. data/config/i18n-tasks.yml +3 -0
  98. data/config/initializers/simple_form.rb +162 -0
  99. data/config/initializers/simple_form_bootstrap.rb +132 -0
  100. data/config/locales/en.yml +20 -0
  101. data/config/locales/models/label/en.yml +14 -0
  102. data/config/locales/models/question/en.yml +47 -0
  103. data/config/locales/models/question_group/en.yml +11 -0
  104. data/config/locales/models/session/en.yml +10 -0
  105. data/config/locales/models/sub_question/en.yml +14 -0
  106. data/config/locales/models/survey/en.yml +6 -0
  107. data/config/locales/models/version/en.yml +12 -0
  108. data/config/locales/simple_form.en.yml +26 -0
  109. data/config/locales/views/admin/question_groups/en.yml +12 -0
  110. data/config/locales/views/admin/questions/en.yml +16 -0
  111. data/config/locales/views/admin/sessions/en.yml +11 -0
  112. data/config/locales/views/admin/surveys/en.yml +10 -0
  113. data/config/locales/views/admin/versions/en.yml +8 -0
  114. data/config/locales/views/sessions/en.yml +9 -0
  115. data/config/routes.rb +28 -0
  116. data/db/seeds.rb +182 -0
  117. data/gpl-3.0.txt +674 -0
  118. data/helena.gemspec +40 -0
  119. data/lib/helena/engine.rb +6 -0
  120. data/lib/helena/version.rb +3 -0
  121. data/lib/helena/version_publisher.rb +16 -0
  122. data/lib/helena.rb +10 -0
  123. data/lib/tasks/helena_tasks.rake +4 -0
  124. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  125. data/spec/controllers/helena/admin/question_group_controller_spec.rb +59 -0
  126. data/spec/controllers/helena/admin/questions_controller_spec.rb +60 -0
  127. data/spec/controllers/helena/admin/sessions_controller_spec.rb +84 -0
  128. data/spec/controllers/helena/admin/survey_controller_spec.rb +89 -0
  129. data/spec/controllers/helena/admin/versions_controller_spec.rb +19 -0
  130. data/spec/controllers/helena/application_controller_spec.rb +15 -0
  131. data/spec/controllers/helena/sessions_controller_spec.rb +24 -0
  132. data/spec/dummy/README.rdoc +28 -0
  133. data/spec/dummy/Rakefile +6 -0
  134. data/spec/dummy/app/assets/images/.keep +0 -0
  135. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  136. data/spec/dummy/app/controllers/application_controller.rb +9 -0
  137. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  138. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  139. data/spec/dummy/app/mailers/.keep +0 -0
  140. data/spec/dummy/app/models/.keep +0 -0
  141. data/spec/dummy/app/models/concerns/.keep +0 -0
  142. data/spec/dummy/app/views/layouts/application.html.haml +24 -0
  143. data/spec/dummy/bin/bundle +3 -0
  144. data/spec/dummy/bin/rails +4 -0
  145. data/spec/dummy/bin/rake +4 -0
  146. data/spec/dummy/config/application.rb +27 -0
  147. data/spec/dummy/config/boot.rb +5 -0
  148. data/spec/dummy/config/environment.rb +5 -0
  149. data/spec/dummy/config/environments/development.rb +29 -0
  150. data/spec/dummy/config/environments/production.rb +80 -0
  151. data/spec/dummy/config/environments/test.rb +36 -0
  152. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  153. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  154. data/spec/dummy/config/initializers/session_store.rb +3 -0
  155. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  156. data/spec/dummy/config/locales/en.yml +23 -0
  157. data/spec/dummy/config/mongoid.yml +14 -0
  158. data/spec/dummy/config/routes.rb +4 -0
  159. data/spec/dummy/config.ru +4 -0
  160. data/spec/dummy/db/seeds.rb +1 -0
  161. data/spec/dummy/lib/assets/.keep +0 -0
  162. data/spec/dummy/log/.keep +0 -0
  163. data/spec/dummy/public/404.html +58 -0
  164. data/spec/dummy/public/422.html +58 -0
  165. data/spec/dummy/public/500.html +57 -0
  166. data/spec/dummy/public/favicon.ico +0 -0
  167. data/spec/factories/helena/answers.rb +24 -0
  168. data/spec/factories/helena/labels.rb +7 -0
  169. data/spec/factories/helena/question_groups.rb +6 -0
  170. data/spec/factories/helena/questions.rb +14 -0
  171. data/spec/factories/helena/sessions.rb +9 -0
  172. data/spec/factories/helena/sub_questions.rb +7 -0
  173. data/spec/factories/helena/survey_details.rb +6 -0
  174. data/spec/factories/helena/surveys.rb +7 -0
  175. data/spec/factories/helena/versions.rb +11 -0
  176. data/spec/features/helena/admin/manage_question_group_spec.rb +101 -0
  177. data/spec/features/helena/admin/manage_question_spec.rb +105 -0
  178. data/spec/features/helena/admin/manage_session_spec.rb +40 -0
  179. data/spec/features/helena/admin/manage_survey_spec.rb +141 -0
  180. data/spec/features/helena/admin/manage_version_spec.rb +74 -0
  181. data/spec/features/helena/admin/question_types/manage_checkbox_group_question_spec.rb +55 -0
  182. data/spec/features/helena/admin/question_types/manage_long_text_question_spec.rb +21 -0
  183. data/spec/features/helena/admin/question_types/manage_radio_group_question_spec.rb +59 -0
  184. data/spec/features/helena/admin/question_types/manage_radio_matrix_question_spec.rb +80 -0
  185. data/spec/features/helena/admin/question_types/manage_short_text_question_spec.rb +19 -0
  186. data/spec/features/helena/admin/question_types/manage_static_text_question_spec.rb +17 -0
  187. data/spec/features/helena/manage_session_spec.rb +284 -0
  188. data/spec/features/helena/manage_survey_spec.rb +24 -0
  189. data/spec/lib/version_publisher_spec.rb +26 -0
  190. data/spec/models/helena/answer_spec.rb +53 -0
  191. data/spec/models/helena/label_spec.rb +13 -0
  192. data/spec/models/helena/question_group_spec.rb +11 -0
  193. data/spec/models/helena/question_spec.rb +21 -0
  194. data/spec/models/helena/questions/radio_group_spec.rb +32 -0
  195. data/spec/models/helena/questions/radio_matrix_spec.rb +32 -0
  196. data/spec/models/helena/questions/short_text_spec.rb +10 -0
  197. data/spec/models/helena/session_spec.rb +20 -0
  198. data/spec/models/helena/sub_question_spec.rb +28 -0
  199. data/spec/models/helena/survey_spec.rb +14 -0
  200. data/spec/models/helena/version_spec.rb +15 -0
  201. data/spec/spec_helper.rb +43 -0
  202. metadata +485 -0
@@ -0,0 +1,284 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Session management' do
4
+ let(:survey) { create :survey, name: 'dummy' }
5
+ let(:base_version) { survey.versions.create version: 0 }
6
+ let(:first_question_group) { build(:question_group, title: 'Page 1', position: 1) }
7
+
8
+ background do
9
+ base_version.survey_detail = build :survey_detail, title: 'Dummy Survey', description: 'Leucadendron is a plants in the family Proteaceae.'
10
+ base_version.question_groups << first_question_group
11
+ end
12
+
13
+ scenario 'edits a session' do
14
+ short_text_question = build :short_text_question, code: 'a_name', question_text: "What's your name?"
15
+ first_question_group.questions << short_text_question
16
+
17
+ long_text_question = build :long_text_question, code: 'selfdescription', question_text: 'Give a brief description of yourself'
18
+ first_question_group.questions << long_text_question
19
+
20
+ second_question_group = build(:question_group, title: 'Page 2', position: 2)
21
+ base_version.question_groups << second_question_group
22
+
23
+ all_and_everything = build :radio_group_question, code: :all_and_everything,
24
+ question_text: 'What is the answer to the Ultimate Question of Life, the Universe, and Everything?',
25
+ position: 1
26
+
27
+ all_and_everything.labels << build(:label, position: 1, text: 'Just Chuck Norris knows it', value: 'norris')
28
+ all_and_everything.labels << build(:label, position: 2, text: 'God', value: 'god')
29
+ all_and_everything.labels << build(:label, position: 3, text: '42', value: 42)
30
+ all_and_everything.labels << build(:label, position: 4, text: 'Your mom', value: 'mom', preselected: :true)
31
+
32
+ second_question_group.questions << all_and_everything
33
+
34
+ food_allergy = build :checkbox_group_question, code: :food_allergy,
35
+ question_text: 'What kind of food allergy do you have?',
36
+ position: 2
37
+
38
+ food_allergy.sub_questions << build(:sub_question, text: 'Garlic', code: 'garlic', position: 1, preselected: true)
39
+ food_allergy.sub_questions << build(:sub_question, text: 'Oats', code: 'oat', position: 2)
40
+ food_allergy.sub_questions << build(:sub_question, text: 'Meat', code: 'meat', position: 3)
41
+
42
+ second_question_group.questions << food_allergy
43
+
44
+ third_question_group = build(:question_group, title: 'Page 3', position: 3)
45
+
46
+ build :radio_group_question, code: :all_and_everything,
47
+ question_text: 'What is the answer to the Ultimate Question of Life, the Universe, and Everything?',
48
+ position: 1
49
+
50
+ base_version.question_groups << third_question_group
51
+
52
+ satisfaction_matrix = build :radio_matrix_question, code: :satisfaction,
53
+ question_text: 'Below are five statements with which you may agree or disagree.',
54
+ required: true,
55
+ position: 1
56
+
57
+ satisfaction_matrix.labels << build(:label, position: 1, text: 'Strongly Disagree', value: 1)
58
+ satisfaction_matrix.labels << build(:label, position: 2, text: 'Disagree', value: 2)
59
+ satisfaction_matrix.labels << build(:label, position: 3, text: 'Slightly Disagree', value: 3)
60
+ satisfaction_matrix.labels << build(:label, position: 4, text: 'Neither Agree or Disagree', value: 4)
61
+ satisfaction_matrix.labels << build(:label, position: 5, text: 'Slightly Agree', value: 5)
62
+ satisfaction_matrix.labels << build(:label, position: 6, text: 'Agree', value: 6)
63
+ satisfaction_matrix.labels << build(:label, position: 7, text: 'Strongly Agree', value: 7)
64
+
65
+ satisfaction_matrix.sub_questions << build(:sub_question, text: 'In most ways my life is close to my ideal.', code: 'life_is_ideal', position: 1)
66
+ satisfaction_matrix.sub_questions << build(:sub_question, text: 'The conditions of my life are excellent.', code: 'condition', position: 2)
67
+ satisfaction_matrix.sub_questions << build(:sub_question, text: 'I am satisfied with life.', code: 'satisfied_with_life', position: 3)
68
+ satisfaction_matrix.sub_questions << build(:sub_question, text: 'So far I have gotten the important things I want in life.',
69
+ code: 'important_things',
70
+ position: 4)
71
+ satisfaction_matrix.sub_questions << build(:sub_question, text: 'If I could live my life over, I would change almost nothing.',
72
+ code: 'nothing_to_change',
73
+ position: 5)
74
+
75
+ third_question_group.questions << satisfaction_matrix
76
+
77
+ version = Helena::VersionPublisher.publish(base_version)
78
+ version.save
79
+
80
+ session = survey.sessions.create version_id: version.id, token: 'abc'
81
+
82
+ visit helena.edit_session_path(session.token)
83
+
84
+ expect(page).to have_content 'Dummy Survey'
85
+ expect(page).to have_content 'Page 1'
86
+ expect(page).to have_content "What's your name?"
87
+ expect(page).to have_content 'Give a brief description of yourself'
88
+
89
+ expect(page).not_to have_link 'Back'
90
+
91
+ fill_in 'session_answers_a_name', with: 'Hans'
92
+ fill_in 'session_answers_selfdescription', with: 'I am a proud man living in middle earth. Everybody is laughing at me because I do not have hairy feets.'
93
+
94
+ expect { click_button 'Next' }.to change { session.reload.answers.count }.from(0).to(2)
95
+
96
+ expect(page).to have_content 'Page 2'
97
+
98
+ expect(page).to have_content 'What is the answer to the Ultimate Question of Life, the Universe, and Everything?'
99
+ expect(page).to have_content 'Just Chuck Norris knows it'
100
+ expect(page).to have_content 'God'
101
+ expect(page).to have_content '42'
102
+ expect(page).to have_content 'Your mom'
103
+
104
+ choose('42')
105
+
106
+ expect(page).to have_content 'What kind of food allergy do you have?'
107
+ expect(page).to have_content 'Garlic'
108
+ expect(page).to have_content 'Oats'
109
+ expect(page).to have_content 'Meat'
110
+
111
+ uncheck('Garlic')
112
+ check('Oats')
113
+ check('Meat')
114
+
115
+ expect(page).to have_link 'Back'
116
+ expect { click_button 'Next' }.to change { session.reload.answers.count }.from(2).to(6)
117
+
118
+ expect(page).to have_content 'Page 3'
119
+
120
+ expect(page).to have_content 'Below are five statements with which you may agree or disagree.'
121
+
122
+ expect(page).to have_content 'Strongly Disagree'
123
+ expect(page).to have_content 'Disagree'
124
+ expect(page).to have_content 'Slightly Disagree'
125
+ expect(page).to have_content 'Neither Agree or Disagree'
126
+ expect(page).to have_content 'Slightly Agree'
127
+ expect(page).to have_content 'Agree'
128
+ expect(page).to have_content 'Strongly Agree'
129
+
130
+ expect(page).to have_content 'In most ways my life is close to my ideal.'
131
+ expect(page).to have_content 'The conditions of my life are excellent.'
132
+ expect(page).to have_content 'I am satisfied with life.'
133
+ expect(page).to have_content 'So far I have gotten the important things I want in life.'
134
+ expect(page).to have_content 'If I could live my life over, I would change almost nothing.'
135
+
136
+ choose('session_answers_life_is_ideal_1')
137
+ choose('session_answers_important_things_2')
138
+ choose('session_answers_condition_4')
139
+ choose('session_answers_nothing_to_change_5')
140
+ choose('session_answers_satisfied_with_life_7')
141
+
142
+ expect { click_button 'Save' }.to change { session.reload.answers.count }.from(6).to(11)
143
+ end
144
+
145
+ scenario 'does not save an empty short text field when required' do
146
+ short_text_question = build :short_text_question, code: 'a_name', question_text: "What's your name?", required: true
147
+ first_question_group.questions << short_text_question
148
+
149
+ version = Helena::VersionPublisher.publish(base_version)
150
+ version.save
151
+
152
+ session = survey.sessions.create version_id: version.id, token: 'abc'
153
+
154
+ visit helena.edit_session_path(session.token)
155
+
156
+ expect(page).to have_content "What's your name? *"
157
+ expect { click_button 'Save' }.not_to change { session.reload.answers.count }
158
+ expect(page).to have_content("can't be blank")
159
+ end
160
+
161
+ scenario 'does not save an empty long text field when required' do
162
+ long_text_question = build :long_text_question, code: 'selfdescription', question_text: 'Give a brief description of yourself', required: true
163
+ first_question_group.questions << long_text_question
164
+
165
+ version = Helena::VersionPublisher.publish(base_version)
166
+ version.save
167
+
168
+ session = survey.sessions.create version_id: version.id, token: 'abc'
169
+
170
+ visit helena.edit_session_path(session.token)
171
+
172
+ expect(page).to have_content 'Give a brief description of yourself *'
173
+ expect { click_button 'Save' }.not_to change { session.reload.answers.count }
174
+ expect(page).to have_content("can't be blank")
175
+ end
176
+
177
+ scenario 'does not save a non selected radio group when required' do
178
+ all_and_everything = build :radio_group_question, code: :all_and_everything,
179
+ question_text: 'What is the answer to the Ultimate Question of Life, the Universe, and Everything?',
180
+ required: true
181
+
182
+ all_and_everything.labels << build(:label, value: 'norris')
183
+ all_and_everything.labels << build(:label, value: 'god')
184
+ all_and_everything.labels << build(:label, value: 42)
185
+ all_and_everything.labels << build(:label, value: 'mom')
186
+
187
+ first_question_group.questions << all_and_everything
188
+
189
+ version = Helena::VersionPublisher.publish(base_version)
190
+ version.save
191
+
192
+ session = survey.sessions.create version_id: version.id, token: 'abc'
193
+
194
+ visit helena.edit_session_path(session.token)
195
+
196
+ expect(page).to have_content 'What is the answer to the Ultimate Question of Life, the Universe, and Everything? *'
197
+ expect { click_button 'Save' }.not_to change { session.reload.answers.count }
198
+ expect(page).to have_content("can't be blank")
199
+ end
200
+
201
+ scenario 'does not save when no subquestion of a checkbox group is selected if required' do
202
+ food_allergy = build :checkbox_group_question, code: :food_allergy,
203
+ question_text: 'What kind of food allergy do you have?',
204
+ required: true
205
+
206
+ food_allergy.sub_questions << build(:sub_question, text: 'Garlic', code: 'garlic')
207
+ food_allergy.sub_questions << build(:sub_question, text: 'Oats', code: 'oat')
208
+ food_allergy.sub_questions << build(:sub_question, text: 'Meat', code: 'meat')
209
+
210
+ first_question_group.questions << food_allergy
211
+
212
+ version = Helena::VersionPublisher.publish(base_version)
213
+ version.save
214
+
215
+ session = survey.sessions.create version_id: version.id, token: 'abc'
216
+
217
+ visit helena.edit_session_path(session.token)
218
+
219
+ expect(page).to have_content 'What kind of food allergy do you have? *'
220
+ expect { click_button 'Save' }.to change { session.reload.answers.map(&:value) }.from([]).to([0, 0, 0])
221
+ expect(page).to have_content("can't be blank")
222
+ end
223
+
224
+ scenario 'saves when subquestion of a checkbox group is selected if required' do
225
+ food_allergy = build :checkbox_group_question, code: :food_allergy,
226
+ question_text: 'What kind of food allergy do you have?',
227
+ required: true
228
+
229
+ food_allergy.sub_questions << build(:sub_question, text: 'Garlic', code: 'garlic')
230
+ food_allergy.sub_questions << build(:sub_question, text: 'Oats', code: 'oat')
231
+ food_allergy.sub_questions << build(:sub_question, text: 'Meat', code: 'meat')
232
+
233
+ first_question_group.questions << food_allergy
234
+
235
+ version = Helena::VersionPublisher.publish(base_version)
236
+ version.save
237
+
238
+ session = survey.sessions.create version_id: version.id, token: 'abc'
239
+
240
+ visit helena.edit_session_path(session.token)
241
+
242
+ expect(page).to have_content 'What kind of food allergy do you have? *'
243
+ check('Oats')
244
+ expect { click_button 'Save' }.to change { session.reload.answers.count }.from(0).to(3)
245
+ expect(page).not_to have_content("can't be blank")
246
+ end
247
+
248
+ scenario 'does not save when radio matrix is filled out completely if required' do
249
+ satisfaction_matrix = build :radio_matrix_question, code: :satisfaction,
250
+ question_text: 'Below are five statements with which you may agree or disagree.',
251
+ required: true
252
+
253
+ satisfaction_matrix.labels << build(:label, value: 1)
254
+ satisfaction_matrix.labels << build(:label, value: 2)
255
+ satisfaction_matrix.labels << build(:label, value: 3)
256
+ satisfaction_matrix.labels << build(:label, value: 4)
257
+ satisfaction_matrix.labels << build(:label, value: 5)
258
+ satisfaction_matrix.labels << build(:label, value: 6)
259
+ satisfaction_matrix.labels << build(:label, value: 7)
260
+
261
+ satisfaction_matrix.sub_questions << build(:sub_question, code: 'life_is_ideal')
262
+ satisfaction_matrix.sub_questions << build(:sub_question, code: 'condition')
263
+ satisfaction_matrix.sub_questions << build(:sub_question, code: 'satisfied_with_life')
264
+ satisfaction_matrix.sub_questions << build(:sub_question, code: 'important_things')
265
+ satisfaction_matrix.sub_questions << build(:sub_question, code: 'nothing_to_change')
266
+
267
+ first_question_group.questions << satisfaction_matrix
268
+
269
+ version = Helena::VersionPublisher.publish(base_version)
270
+ version.save
271
+
272
+ session = survey.sessions.create version_id: version.id, token: 'abc'
273
+
274
+ visit helena.edit_session_path(session.token)
275
+
276
+ expect(page).to have_content 'Below are five statements with which you may agree or disagree. *'
277
+
278
+ choose('session_answers_satisfied_with_life_3')
279
+
280
+ expect { click_button 'Save' }.to change { session.reload.answers.count }.from(0).to(1)
281
+
282
+ expect(page).to have_content("can't be blank")
283
+ end
284
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Survey management' do
4
+ scenario 'lists all surveys' do
5
+ first_survey = create :survey, name: 'first'
6
+ first_survey.versions.create version: 0
7
+ first_survey.versions.first.survey_detail = Helena::SurveyDetail.new(title: 'My first survey', description: 'I am very proud of it')
8
+ second_survey = create :survey, name: 'second'
9
+ second_survey.versions.create version: 0
10
+ second_survey.versions.first.survey_detail = Helena::SurveyDetail.new(title: 'Another cool survey', description: 'Everybody likes it')
11
+
12
+ visit helena.surveys_path
13
+
14
+ within "#helena_#{dom_id first_survey}" do
15
+ expect(page).to have_text 'My first survey'
16
+ expect(page).to have_text 'I am very proud of it'
17
+ end
18
+
19
+ within "#helena_#{dom_id second_survey}" do
20
+ expect(page).to have_text 'Another cool survey'
21
+ expect(page).to have_text 'Everybody likes it'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::VersionPublisher do
4
+ let!(:survey) { create :survey }
5
+ let!(:base_version) { survey.versions.create version: 42 }
6
+ let!(:survey_detail) { base_version.survey_detail = build :survey_detail }
7
+ let!(:question_group) { base_version.question_groups.create }
8
+ let!(:question) { build(:radio_matrix_question, code: 'abc', question_group: question_group) }
9
+ let!(:label) { build(:label, text: 'xyz', value: 'asdf', question: question) }
10
+ let!(:sub_question) { build(:sub_question, text: 'ymca', code: 'cde', question: question) }
11
+
12
+ it 'creates a new version' do
13
+ allow(DateTime).to receive(:now).and_return('Tue, 24 Jun 2014 10:24:08 +0200')
14
+
15
+ new_version = Helena::VersionPublisher.publish(base_version)
16
+
17
+ expect(new_version.version).to eq 43
18
+ expect(new_version.survey_detail).to be_a Helena::SurveyDetail
19
+ expect(new_version).to have(1).question_groups
20
+ expect(new_version.question_groups.first).to have_exactly(1).questions
21
+ expect(new_version.question_groups.first.questions.first).to have_exactly(1).labels
22
+ expect(new_version.question_groups.first.questions.first).to have_exactly(1).sub_questions
23
+ expect(new_version.created_at).to eq 'Tue, 24 Jun 2014 10:24:08 +0200'
24
+ expect(new_version.updated_at).to eq 'Tue, 24 Jun 2014 10:24:08 +0200'
25
+ end
26
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Answer do
4
+
5
+ let(:survey) { create :survey }
6
+ let(:version) { build :version, survey: survey }
7
+ let(:session) { create :session, survey: survey, version: version }
8
+
9
+ it { expect(subject).to be_embedded_in(:session) }
10
+
11
+ it { expect(subject).to validate_presence_of(:code) }
12
+ it { expect(subject).to validate_uniqueness_of(:code) }
13
+ it { expect(subject).to validate_presence_of(:ip_address) }
14
+
15
+ it 'saves the created_at time when create an answer' do
16
+ expect(build(:answer).created_at).to be_kind_of(DateTime)
17
+ end
18
+
19
+ it 'has a valid factory' do
20
+ expect(build :answer).to be_valid
21
+ end
22
+
23
+ describe '.build_generic' do
24
+ it 'builds an integer answer' do
25
+ expect(Helena::Answer.build_generic('bla', 42, '192.168.0.1')).to be_kind_of(Helena::IntegerAnswer)
26
+ end
27
+
28
+ it 'builds an integer answer from a string integer' do
29
+ expect(Helena::Answer.build_generic('bla', '42', '192.168.0.1')).to be_kind_of(Helena::IntegerAnswer)
30
+ end
31
+
32
+ it 'builds a string answer' do
33
+ expect(Helena::Answer.build_generic('bla', 'look at my horse, my horse is a amazing', '192.168.0.1')).to be_kind_of(Helena::StringAnswer)
34
+ end
35
+
36
+ it 'builds a boolean answer for string "true"' do
37
+ expect(Helena::Answer.build_generic('bla', 'true', '192.168.0.1')).to be_kind_of(Helena::BooleanAnswer)
38
+ end
39
+
40
+ it 'builds a boolean answer for string "false"' do
41
+ expect(Helena::Answer.build_generic('bla', 'false', '192.168.0.1')).to be_kind_of(Helena::BooleanAnswer)
42
+ end
43
+
44
+ it 'builds a boolean answer for true' do
45
+ expect(Helena::Answer.build_generic('bla', 'true', '192.168.0.1')).to be_kind_of(Helena::BooleanAnswer)
46
+ end
47
+
48
+ it 'builds a boolean answer for false' do
49
+ expect(Helena::Answer.build_generic('bla', 'false', '192.168.0.1')).to be_kind_of(Helena::BooleanAnswer)
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Label do
4
+
5
+ it { expect(subject).to be_embedded_in(:question) }
6
+ it { expect(subject).to validate_presence_of(:text) }
7
+ it { expect(subject).to validate_presence_of(:value) }
8
+ it { expect(subject).to validate_uniqueness_of(:value) }
9
+
10
+ it 'has a valid factory' do
11
+ expect(build :label).to be_valid
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::QuestionGroup do
4
+ let!(:version) { create :version, survey: create(:survey) }
5
+
6
+ it { expect(subject).to be_embedded_in(:version) }
7
+
8
+ it 'has a valid factory' do
9
+ expect(build :question_group).to be_valid
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Question do
4
+ let!(:version) { create :version, survey: create(:survey) }
5
+
6
+ it { expect(subject).to be_embedded_in(:question_group) }
7
+
8
+ it { expect(subject).to validate_presence_of(:code) }
9
+
10
+ it 'validates uniqness of code across different question_groups' do
11
+ a_question = build :question, question_group: build(:question_group, version: version), code: :preferred_color
12
+ expect(a_question).to be_valid
13
+
14
+ another_question = build :question, question_group: build(:question_group, version: version), code: :preferred_color
15
+ expect(another_question).not_to be_valid
16
+ end
17
+
18
+ it 'has a valid factory' do
19
+ expect(build :question, question_group: build(:question_group, version: version)).to be_valid
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Questions::RadioGroup do
4
+ let!(:version) { build :version, survey: build(:survey) }
5
+
6
+ let(:question_group) { build :question_group, version: version }
7
+
8
+ it 'has a valid factory' do
9
+ expect(build :radio_group_question, question_group: question_group).to be_valid
10
+ end
11
+
12
+ it 'validates uniquness of label preselection' do
13
+ question = create :radio_group_question, question_group: question_group
14
+ question.labels << build(:label, preselected: true)
15
+ question.labels << build(:label, preselected: true)
16
+ expect(question).not_to be_valid
17
+ end
18
+
19
+ it 'does not validates uniquness of label preselection for no preselection' do
20
+ question = create :radio_group_question, question_group: question_group
21
+ question.labels << build(:label, preselected: false)
22
+ question.labels << build(:label, preselected: false)
23
+ expect(question).to be_valid
24
+ end
25
+
26
+ it 'does not validates uniquness of label preselection for one preselection' do
27
+ question = create :radio_group_question, question_group: question_group
28
+ question.labels << build(:label, preselected: false)
29
+ question.labels << build(:label, preselected: false)
30
+ expect(question).to be_valid
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Questions::RadioMatrix do
4
+ let!(:version) { create :version, survey: create(:survey) }
5
+
6
+ let(:question_group) { build :question_group, version: version }
7
+
8
+ it 'has a valid factory' do
9
+ expect(build :radio_matrix_question, question_group: question_group).to be_valid
10
+ end
11
+
12
+ it 'validates uniquness of label preselection' do
13
+ question = create :radio_matrix_question, question_group: question_group
14
+ question.labels << build(:label, preselected: true)
15
+ question.labels << build(:label, preselected: true)
16
+ expect(question).not_to be_valid
17
+ end
18
+
19
+ it 'does not validates uniquness of label preselection for no preselection' do
20
+ question = create :radio_matrix_question, question_group: question_group
21
+ question.labels << build(:label, preselected: false)
22
+ question.labels << build(:label, preselected: false)
23
+ expect(question).to be_valid
24
+ end
25
+
26
+ it 'does not validates uniquness of label preselection for one preselection' do
27
+ question = create :radio_matrix_question, question_group: question_group
28
+ question.labels << build(:label, preselected: false)
29
+ question.labels << build(:label, preselected: false)
30
+ expect(question).to be_valid
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Questions::ShortText do
4
+ let(:version) { build :version, version: 0 }
5
+ let(:question_group) { build(:question_group, version: version) }
6
+
7
+ it 'has a valid factory' do
8
+ expect(build :short_text_question, question_group: question_group).to be_valid
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Session do
4
+ it { expect(subject).to belong_to(:survey) }
5
+ it { expect(subject).to belong_to(:version) }
6
+
7
+ it { expect(subject).to embed_many(:answers) }
8
+
9
+ it { expect(subject).to validate_uniqueness_of(:token) }
10
+ it { expect(subject).to validate_uniqueness_of(:view_token) }
11
+
12
+ it 'has a valid factory' do
13
+ expect(build :session).to be_valid
14
+ end
15
+
16
+ it 'assigns a token after when creating a session' do
17
+ expect_any_instance_of(Helena::Session).to receive(:generate_token).exactly(2).times.and_return('a493oP')
18
+ expect(create(:session_without_token).token).to eq 'a493oP'
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::SubQuestion do
4
+ let(:version) { create :version, survey: create(:survey) }
5
+ let(:question_group) { build :question_group, version: version }
6
+ let(:question) { build :radio_matrix_question, question_group: question_group }
7
+
8
+ it { expect(subject).to be_embedded_in(:question) }
9
+ it { expect(subject).to validate_uniqueness_of(:text) }
10
+ it { expect(subject).to validate_presence_of(:text) }
11
+
12
+ it 'validates uniqness of code across different question_groups with subquestions' do
13
+ a_question = build :question, question_group: build(:question_group, version: version), code: :preferred_color
14
+ expect(a_question).to be_valid
15
+
16
+ another_question = build :question, question_group: build(:question_group, version: version), code: :colors
17
+
18
+ sub_question = build :sub_question, question: another_question, code: :some_code
19
+ expect(sub_question).to be_valid
20
+
21
+ another_sub_question = build :sub_question, question: another_question, code: :preferred_color
22
+ expect(another_sub_question).not_to be_valid
23
+ end
24
+
25
+ it 'has a valid factory' do
26
+ expect(build :sub_question, question: question).to be_valid
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Survey do
4
+ it { expect(subject).to embed_many(:versions) }
5
+ it { expect(subject).to have_many(:sessions).with_dependent(:destroy) }
6
+
7
+ it { expect(subject).to validate_presence_of(:name) }
8
+ it { expect(subject).to validate_presence_of(:language) }
9
+ it { expect(subject).to validate_uniqueness_of(:name) }
10
+
11
+ it 'has a valid factory' do
12
+ expect(build :survey).to be_valid
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Version do
4
+ it { expect(subject).to be_embedded_in(:survey) }
5
+
6
+ it { expect(subject).to embed_many(:question_groups) }
7
+ it { expect(subject).to embed_one(:survey_detail) }
8
+
9
+ it { expect(subject).to validate_presence_of(:version) }
10
+ it { expect(subject).to validate_uniqueness_of(:version) }
11
+
12
+ it 'has a valid factory' do
13
+ expect(build :version, survey: create(:survey)).to be_valid
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ require 'ffaker'
2
+ require 'coveralls'
3
+
4
+ Coveralls.wear!
5
+
6
+ # Configure Rails Envinronment
7
+ ENV['RAILS_ENV'] = 'test'
8
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
9
+
10
+ require 'rspec/rails'
11
+ require 'factory_girl_rails'
12
+ require 'database_cleaner'
13
+ require 'mongoid-rspec'
14
+ require 'capybara/rspec'
15
+ require 'rspec/collection_matchers'
16
+
17
+ ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
18
+
19
+ # Requires supporting ruby files with custom matchers and macros, etc,
20
+ # in spec/support/ and its subdirectories.
21
+ Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].each { |f| require f }
22
+
23
+ RSpec.configure do |config|
24
+ config.order = :random
25
+ config.include ActionView::RecordIdentifier, type: :feature
26
+
27
+ config.include Mongoid::Matchers, type: :model
28
+
29
+ # We don't want write FactoryGirl all the time
30
+ config.include FactoryGirl::Syntax::Methods
31
+
32
+ config.infer_spec_type_from_file_location!
33
+
34
+ DatabaseCleaner.strategy = :truncation
35
+
36
+ config.before(:each) do
37
+ DatabaseCleaner.start
38
+ end
39
+
40
+ config.after(:each) do
41
+ DatabaseCleaner.clean
42
+ end
43
+ end