helena 0.3.3 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -4
  3. data/Gemfile +1 -2
  4. data/Gemfile.lock +88 -95
  5. data/README.md +10 -25
  6. data/app/controllers/helena/application_controller.rb +0 -10
  7. data/app/controllers/helena/sessions_controller.rb +17 -6
  8. data/app/models/helena/answer.rb +1 -2
  9. data/app/models/helena/concerns/application_model.rb +0 -9
  10. data/app/models/helena/concerns/questions/validates_one_label.rb +1 -1
  11. data/app/models/helena/question.rb +5 -5
  12. data/app/models/helena/question_group.rb +4 -3
  13. data/app/models/helena/session.rb +27 -0
  14. data/app/models/helena/survey.rb +2 -7
  15. data/app/models/helena/version.rb +6 -4
  16. data/app/views/helena/questions/_static_text.html.slim +1 -0
  17. data/app/views/helena/sessions/_progressbar.html.slim +9 -0
  18. data/app/views/helena/sessions/edit.html.slim +18 -0
  19. data/app/views/helena/sessions/{end_message.html.haml → end_message.html.slim} +1 -1
  20. data/config/locales/models/question_group/en.yml +1 -0
  21. data/config/locales/models/session/en.yml +4 -0
  22. data/config/locales/models/survey/en.yml +3 -0
  23. data/config/locales/views/sessions/en.yml +4 -0
  24. data/config/routes.rb +1 -25
  25. data/db/seeds.rb +12 -140
  26. data/db/swls_survey.en.yml +67 -0
  27. data/helena.gemspec +1 -0
  28. data/lib/helena/engine.rb +11 -0
  29. data/lib/helena/survey_importer.rb +52 -0
  30. data/lib/helena/version.rb +1 -1
  31. data/lib/helena/version_publisher.rb +34 -2
  32. data/lib/helena.rb +3 -0
  33. data/spec/controllers/helena/sessions_controller_spec.rb +8 -3
  34. data/spec/dummy/app/controllers/application_controller.rb +0 -4
  35. data/spec/factories/helena/labels.rb +0 -1
  36. data/spec/factories/helena/question_groups.rb +0 -1
  37. data/spec/factories/helena/questions.rb +0 -1
  38. data/spec/factories/helena/sub_questions.rb +0 -1
  39. data/spec/factories/helena/surveys.rb +0 -1
  40. data/spec/features/helena/manage_session_spec.rb +76 -16
  41. data/spec/lib/survey_importer_spec.rb +14 -0
  42. data/spec/lib/version_publisher_spec.rb +5 -4
  43. data/spec/models/helena/answer_spec.rb +0 -1
  44. data/spec/models/helena/question_group_spec.rb +2 -1
  45. data/spec/models/helena/question_spec.rb +12 -4
  46. data/spec/models/helena/questions/checkbox_group_spec.rb +17 -0
  47. data/spec/models/helena/questions/radio_group_spec.rb +6 -0
  48. data/spec/models/helena/questions/radio_matrix_spec.rb +7 -0
  49. data/spec/models/helena/session_spec.rb +50 -0
  50. data/spec/models/helena/survey_spec.rb +12 -1
  51. data/spec/models/helena/version_spec.rb +11 -2
  52. metadata +26 -73
  53. data/app/assets/images/helena/icons/export.svg +0 -29
  54. data/app/assets/stylesheets/helena/admin/labels.css.sass +0 -7
  55. data/app/assets/stylesheets/helena/admin/layout.css.sass +0 -6
  56. data/app/assets/stylesheets/helena/admin/question_groups.css.sass +0 -7
  57. data/app/assets/stylesheets/helena/admin/questions.css.sass +0 -9
  58. data/app/assets/stylesheets/helena/admin/sessions.css.sass +0 -5
  59. data/app/assets/stylesheets/helena/admin/subquestions.css.sass +0 -7
  60. data/app/assets/stylesheets/helena/admin/versions.css.sass +0 -9
  61. data/app/controllers/helena/admin/application_controller.rb +0 -31
  62. data/app/controllers/helena/admin/question_groups_controller.rb +0 -78
  63. data/app/controllers/helena/admin/questions/checkbox_groups_controller.rb +0 -17
  64. data/app/controllers/helena/admin/questions/checkbox_matrix_controller.rb +0 -9
  65. data/app/controllers/helena/admin/questions/long_texts_controller.rb +0 -13
  66. data/app/controllers/helena/admin/questions/radio_groups_controller.rb +0 -17
  67. data/app/controllers/helena/admin/questions/radio_matrix_controller.rb +0 -9
  68. data/app/controllers/helena/admin/questions/short_texts_controller.rb +0 -13
  69. data/app/controllers/helena/admin/questions/static_texts_controller.rb +0 -13
  70. data/app/controllers/helena/admin/questions_controller.rb +0 -105
  71. data/app/controllers/helena/admin/sessions_controller.rb +0 -35
  72. data/app/controllers/helena/admin/surveys_controller.rb +0 -78
  73. data/app/controllers/helena/admin/versions_controller.rb +0 -71
  74. data/app/controllers/helena/surveys_controller.rb +0 -11
  75. data/app/views/helena/admin/question_groups/_form.html.haml +0 -3
  76. data/app/views/helena/admin/question_groups/edit.html.haml +0 -3
  77. data/app/views/helena/admin/question_groups/index.html.haml +0 -41
  78. data/app/views/helena/admin/question_groups/new.html.haml +0 -3
  79. data/app/views/helena/admin/questions/_form.html.haml +0 -15
  80. data/app/views/helena/admin/questions/_labels.html.haml +0 -24
  81. data/app/views/helena/admin/questions/_sub_questions.html.haml +0 -32
  82. data/app/views/helena/admin/questions/edit.html.haml +0 -3
  83. data/app/views/helena/admin/questions/index.html.haml +0 -49
  84. data/app/views/helena/admin/questions/new.html.haml +0 -3
  85. data/app/views/helena/admin/sessions/index.html.haml +0 -46
  86. data/app/views/helena/admin/surveys/_form.html.haml +0 -10
  87. data/app/views/helena/admin/surveys/edit.html.haml +0 -5
  88. data/app/views/helena/admin/surveys/index.html.haml +0 -35
  89. data/app/views/helena/admin/surveys/new.html.haml +0 -3
  90. data/app/views/helena/admin/versions/_form.html.haml +0 -5
  91. data/app/views/helena/admin/versions/default_session_report.html.haml +0 -17
  92. data/app/views/helena/admin/versions/edit.html.haml +0 -3
  93. data/app/views/helena/admin/versions/index.html.haml +0 -35
  94. data/app/views/helena/admin/versions/new.html.haml +0 -3
  95. data/app/views/helena/sessions/edit.html.haml +0 -16
  96. data/app/views/helena/surveys/_survey.html.haml +0 -3
  97. data/app/views/helena/surveys/index.html.haml +0 -2
  98. data/config/locales/views/admin/question_groups/en.yml +0 -12
  99. data/config/locales/views/admin/questions/en.yml +0 -16
  100. data/config/locales/views/admin/sessions/en.yml +0 -11
  101. data/config/locales/views/admin/surveys/en.yml +0 -10
  102. data/config/locales/views/admin/versions/en.yml +0 -8
  103. data/spec/controllers/helena/admin/question_group_controller_spec.rb +0 -59
  104. data/spec/controllers/helena/admin/questions_controller_spec.rb +0 -60
  105. data/spec/controllers/helena/admin/sessions_controller_spec.rb +0 -84
  106. data/spec/controllers/helena/admin/survey_controller_spec.rb +0 -89
  107. data/spec/controllers/helena/admin/versions_controller_spec.rb +0 -19
  108. data/spec/controllers/helena/application_controller_spec.rb +0 -15
  109. data/spec/features/helena/admin/manage_question_group_spec.rb +0 -101
  110. data/spec/features/helena/admin/manage_question_spec.rb +0 -105
  111. data/spec/features/helena/admin/manage_session_spec.rb +0 -40
  112. data/spec/features/helena/admin/manage_survey_spec.rb +0 -141
  113. data/spec/features/helena/admin/manage_version_spec.rb +0 -74
  114. data/spec/features/helena/admin/question_types/manage_checkbox_group_question_spec.rb +0 -55
  115. data/spec/features/helena/admin/question_types/manage_long_text_question_spec.rb +0 -21
  116. data/spec/features/helena/admin/question_types/manage_radio_group_question_spec.rb +0 -59
  117. data/spec/features/helena/admin/question_types/manage_radio_matrix_question_spec.rb +0 -80
  118. data/spec/features/helena/admin/question_types/manage_short_text_question_spec.rb +0 -19
  119. data/spec/features/helena/admin/question_types/manage_static_text_question_spec.rb +0 -17
  120. data/spec/features/helena/manage_survey_spec.rb +0 -24
@@ -1,32 +0,0 @@
1
- %h3= t '.options'
2
- .table-responsive
3
- %table.table.sub_questions
4
- %thead
5
- %tr
6
- %th.position= Helena::SubQuestion.human_attribute_name :position
7
- %th.position= Helena::SubQuestion.human_attribute_name :code
8
- - if @question.is_a?(Helena::Questions::CheckboxGroup)
9
- %th.preselected
10
- %th.text= Helena::SubQuestion.human_attribute_name :text
11
- - if @question.is_a?(Helena::Questions::CheckboxGroup)
12
- %th.value= Helena::SubQuestion.human_attribute_name :value
13
- %th.delete
14
- %tbody
15
- = form.simple_fields_for :sub_questions do |sub_question|
16
- %tr[sub_question.object]
17
- %td.position
18
- = sub_question.input :position, as: :integer, label: false
19
- %td.code
20
- = sub_question.input :code, label: false, hint: t('shared.code_hint')
21
- - if @question.is_a?(Helena::Questions::CheckboxGroup)
22
- %td.preselected
23
- = sub_question.input :preselected, as: :boolean
24
- %td.text
25
- = sub_question.input :text, label: false
26
- - if @question.is_a?(Helena::Questions::CheckboxGroup)
27
- %td.value
28
- = sub_question.input :value, label: false, as: :hidden, value: 1
29
- %td.delete
30
- - unless sub_question.object.new_record?
31
- = sub_question.input :_destroy, as: :boolean,
32
- label: Helena::SubQuestion.human_attribute_name(:_destroy)
@@ -1,3 +0,0 @@
1
- .helena-admin
2
- %h2= t 'shared.edit'
3
- = render 'form'
@@ -1,49 +0,0 @@
1
- .helena-admin
2
- %h2
3
- = Helena::Question.model_name.human(count: 2)
4
- = "(#{@questions.count})"
5
- - if @questions.empty?
6
- .alert.alert-warning
7
- = t '.empty'
8
- - else
9
- .table-responsive
10
- %table.table.questions
11
- %thead
12
- %tr
13
- %th.position= Helena::Question.human_attribute_name(:position)
14
- %th= Helena::Question.human_attribute_name(:code)
15
- %th= Helena::Question.human_attribute_name(:type)
16
- %th= Helena::Question.human_attribute_name(:question_text)
17
- %th
18
- %tbody
19
- - @questions.each_with_index do |question, index|
20
- %tr[question]
21
- %td.position
22
- = question.position
23
- %td.code
24
- = question.code
25
- %td.type
26
- = question.class.model_name.human
27
- - if question.try :required
28
- %span.glyphicon.glyphicon-flag{ title: Helena::Question.human_attribute_name(:require) }
29
- %td.question_text
30
- = question.question_text
31
- %td
32
- .btn-group.btn-group-sm
33
- - unless question.last?
34
- = link_to move_down_admin_survey_question_group_question_path(@survey, @question_group, question), class: 'btn btn-primary',
35
- method: :patch,
36
- title: t('shared.move_down') do
37
- %i.glyphicon.glyphicon-chevron-down
38
- - unless question.first?
39
- = link_to move_up_admin_survey_question_group_question_path(@survey, @question_group, question), class: 'btn btn-primary',
40
- method: :patch,
41
- title: t('shared.move_up') do
42
- %i.glyphicon.glyphicon-chevron-up
43
-
44
- = link_to t('shared.edit'), [:edit, :admin, @survey, @question_group, question], class: 'btn btn-primary'
45
-
46
- = link_to t('shared.delete'), admin_survey_question_group_question_path(@survey, @question_group, question), method: :delete, class: 'btn btn-danger', data: { confirm: t('shared.delete_question') }
47
-
48
- %a.btn.btn-success{ href: new_admin_survey_question_group_question_path(@survey, @question_group) }
49
- = t '.add'
@@ -1,3 +0,0 @@
1
- .helena-admin
2
- %h2= t '.new'
3
- = render 'form'
@@ -1,46 +0,0 @@
1
- .helena-admin
2
- - if @sessions.empty?
3
- .alert.alert-warning
4
- = t '.empty'
5
- - else
6
- .actions
7
- = link_to admin_survey_sessions_path(@survey, format: :csv) do
8
- = image_tag('helena/icons/export.svg', class: :icon)
9
- = t('.export_sessions_csv')
10
- = link_to admin_survey_sessions_path(@survey, format: :json) do
11
- = t('.export_sessions_json')
12
- %h2
13
- = Helena::Session.model_name.human(count: 2)
14
- = "(#{@sessions.count})"
15
- .table-responsive
16
- %table.table.sessions
17
- %thead
18
- %tr
19
- %th.updated_at= Helena::Session.human_attribute_name(:updated_at)
20
- %th.token= Helena::Session.human_attribute_name(:token)
21
- %th.completed= Helena::Session.human_attribute_name(:completed)
22
- %th.version= Helena::Session.human_attribute_name(:version)
23
- %th.answers= Helena::Session.human_attribute_name(:answers)
24
- %th
25
- %tbody
26
- - @sessions.each do |session|
27
- %tr[session]
28
- %td.updated_at
29
- = time_ago_in_words(session.updated_at)
30
- %td.token
31
- = session.token
32
- %td.completed
33
- .label{class: "label-#{session.completed? ? 'success' : 'danger'}"}
34
- = t ".#{session.completed}"
35
- %td.version
36
- = @survey.versions.find(session.version_id).version if session.version_id
37
- %td.answers
38
- = session.answers.count
39
-
40
- %td
41
- .btn-group
42
- - if session.completed?
43
- = link_to t('shared.show'), session_path(session.view_token), class: 'btn btn-primary'
44
- = link_to t('shared.edit'), edit_session_path(session.token), class: 'btn btn-success'
45
- = link_to t('shared.delete'), admin_survey_session_path(@survey, session),
46
- method: :delete, class: 'btn btn-danger', data: { confirm: t('shared.delete_question') }
@@ -1,10 +0,0 @@
1
- = simple_form_for [:admin, @survey] do |f|
2
- = f.input :name
3
- = f.input :tag_list
4
- = f.input :language, collection: I18n.available_locales, include_blank: false
5
- = f.simple_fields_for :versions do |v|
6
- = v.input :version, as: :hidden, value: 0 if @survey.new_record?
7
- = v.simple_fields_for :survey_detail do |detail|
8
- = detail.input :title
9
- = detail.input :description, as: :text, input_html: { cols: 60, rows: 10 }
10
- = f.submit t('shared.save'), class: 'btn btn-success'
@@ -1,5 +0,0 @@
1
- .helena-admin
2
- %h2
3
- Edit
4
- = @survey.name
5
- = render 'form'
@@ -1,35 +0,0 @@
1
- .helena-admin
2
- %h2
3
- = Helena::Survey.model_name.human(count: 2)
4
- = "(#{@surveys.count})"
5
- - if @surveys.empty?
6
- .alert.alert-warning
7
- = t('.empty')
8
- - else
9
- - @surveys.each do |survey|
10
- %div[survey]
11
- %h3= survey.name
12
- - if survey.draft_version.survey_detail.present?
13
- %h4= survey.draft_version.survey_detail.title
14
- %p= survey.draft_version.survey_detail.description
15
- - if survey.tag_list.present?
16
- %p
17
- = "#{Helena::Survey.human_attribute_name :tags}:"
18
- = survey.tag_list
19
- .btn-group
20
- - unless survey.last?
21
- = link_to move_down_admin_survey_path(survey), class: 'btn btn-primary', method: :patch, title: t('shared.move_down') do
22
- %i.glyphicon.glyphicon-chevron-down
23
- - unless survey.first?
24
- = link_to move_up_admin_survey_path(survey), class: 'btn btn-primary', method: :patch, title: t('shared.move_up') do
25
- %i.glyphicon.glyphicon-chevron-up
26
-
27
- = link_to t('shared.edit'), edit_admin_survey_path(survey), class: 'btn btn-primary'
28
- = link_to Helena::QuestionGroup.model_name.human(count: 2), admin_survey_question_groups_path(survey), class: 'btn btn-primary'
29
- = link_to Helena::Session.model_name.human(count: 2), admin_survey_sessions_path(survey), class: 'btn btn-primary'
30
- = link_to Helena::Version.model_name.human(count: 2), admin_survey_versions_path(survey), class: 'btn btn-primary'
31
- = link_to t('shared.delete'), admin_survey_path(survey), method: :delete, class: 'btn btn-danger', data: { confirm: t('shared.delete_question') }
32
-
33
- %br
34
- %a.btn.btn-success{ href: new_admin_survey_path}
35
- = t '.add'
@@ -1,3 +0,0 @@
1
- .helena-admin
2
- %h2= t '.new'
3
- = render 'form'
@@ -1,5 +0,0 @@
1
- = simple_form_for [:admin, @survey, @version] do |f|
2
- = f.input :notes
3
- = f.input :session_report, as: :text, input_html: { cols: 60, rows: 10 }
4
-
5
- = f.submit t('shared.save'), class: 'btn btn-success'
@@ -1,17 +0,0 @@
1
- %h1 {{ survey_title }}
2
- %p {{ survey_description }}
3
- %table
4
- %thead
5
- %tr
6
- %th Code
7
- %th Value
8
- %tbody
9
- {% for answer in survey_answers %}
10
- %tr
11
- %td {{ answer.code }}
12
- %td {{ answer.value }}
13
- {% endfor %}
14
- %tfoot
15
- %tr
16
- %td{ colspan: 2}
17
- {{ survey_answers.size }} answers
@@ -1,3 +0,0 @@
1
- .helena-admin
2
- %h2= t 'shared.edit'
3
- = render 'form'
@@ -1,35 +0,0 @@
1
- .helena-admin
2
- %h2
3
- = Helena::Version.model_name.human(count: 2)
4
- = "(#{@versions.count})"
5
- - if @versions.empty?
6
- .alert.alert-warning
7
- = t('.empty')
8
- - else
9
- .table-responsive
10
- %table.table.versions
11
- %thead
12
- %tr
13
- %th.version= Helena::Version.human_attribute_name(:version)
14
- %th.notes= Helena::Version.human_attribute_name(:notes)
15
- %th.sessions= Helena::Session.model_name.human(count: 2)
16
- %th.created_at= Helena::Version.human_attribute_name(:created_at)
17
- %th
18
- %tbody
19
- - @versions.each do |version|
20
- %tr[version]
21
- %td.version
22
- = version.version
23
- %td.notes
24
- = version.notes
25
- %td.sessions
26
- = Helena::Session.where(version: version).count
27
- %td.created_at
28
- = time_ago_in_words(version.created_at)
29
- %td
30
- .btn-group
31
- = link_to t('shared.edit'), edit_admin_survey_version_path(@survey, version), class: 'btn btn-success'
32
- = link_to t('shared.delete'), admin_survey_version_path(@survey, version), method: :delete, class: 'btn btn-danger', data: { confirm: t('shared.delete_question') }
33
-
34
- %a.btn.btn-success{ href: new_admin_survey_version_path(@survey)}
35
- = t 'shared.add'
@@ -1,3 +0,0 @@
1
- .helena-admin
2
- %h2= t '.new'
3
- = render 'form'
@@ -1,16 +0,0 @@
1
- %h1.survey_title
2
- = @version.survey_detail.title
3
- %fieldset[@question_group]
4
- %legend= @question_group.title
5
- = simple_form_for(@session, url: helena.session_path(@session.token), as: :session) do |f|
6
- - @questions.each do |question|
7
- = render "#{question.class.to_s.underscore}", form: f, question: question, answers: @answers, errors: @errors
8
-
9
- = hidden_field_tag :question_group, @question_group.id
10
-
11
- - if @question_group.previous_items.any?
12
- = link_to t('.back'), edit_session_path(@session.token, question_group: @question_group.previous_item), class: 'btn btn-default'
13
-
14
- = f.submit class: 'btn btn-success pull-right', value: @question_group.last? ? t('.save') : t('.next')
15
-
16
- = t('shared.required')
@@ -1,3 +0,0 @@
1
- %div[survey]
2
- %h2= survey.newest_version.survey_detail.title
3
- %p= survey.newest_version.survey_detail.description
@@ -1,2 +0,0 @@
1
- %h1 Surveys
2
- = render @surveys
@@ -1,12 +0,0 @@
1
- en:
2
- helena:
3
- admin:
4
- question_groups:
5
- index:
6
- empty: There are no question groups in this survey
7
- add: Add a new question group
8
- delete: Delete
9
- edit: Edit
10
- new: &new_question_group
11
- new: New question group
12
- create: *new_question_group
@@ -1,16 +0,0 @@
1
- en:
2
- helena:
3
- admin:
4
- radio_group:
5
- only_one_preselection_allowed: only have one preselection
6
- questions:
7
- index:
8
- empty: There are no questions in this question group
9
- add: Add a new question
10
- new: &new_question
11
- new: New question
12
- create: *new_question
13
- labels:
14
- labels: Labels
15
- sub_questions:
16
- options: Options
@@ -1,11 +0,0 @@
1
- en:
2
- helena:
3
- admin:
4
- sessions:
5
- index:
6
- empty: This survey has no sessions.
7
- 'false': "No"
8
- 'true': "Yes"
9
- edit: Edit
10
- export_sessions_csv: I want to export all session from this survey to my local computer as CSV
11
- export_sessions_json: ... or as JSON
@@ -1,10 +0,0 @@
1
- en:
2
- helena:
3
- admin:
4
- surveys:
5
- index:
6
- add: Add a new survey
7
- empty: There are no surveys available
8
- new: &new_survey
9
- new: New Survey
10
- create: *new_survey
@@ -1,8 +0,0 @@
1
- en:
2
- helena:
3
- admin:
4
- versions:
5
- index:
6
- empty: No versions published at the moment.
7
- new:
8
- new: Publish new version
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Helena::Admin::QuestionGroupsController do
4
- routes { Helena::Engine.routes }
5
-
6
- let!(:survey) { create :survey }
7
- let!(:draft_version) { create :version, version: 0, survey: survey }
8
- let!(:first_question_group) { create :question_group, position: 1, version: draft_version }
9
- let!(:second_question_group) { create :question_group, position: 2, version: draft_version }
10
- let!(:third_question_group) { create :question_group, position: 3, version: draft_version }
11
-
12
- it 'moves a question group down with resort' do
13
- patch :move_down, survey_id: survey, id: first_question_group
14
-
15
- expect(first_question_group.reload.position).to eq 2
16
- expect(second_question_group.reload.position).to eq 1
17
- expect(third_question_group.reload.position).to eq 3
18
- end
19
-
20
- it 'moves a question group up with resort' do
21
- patch :move_up, survey_id: survey, id: third_question_group
22
-
23
- expect(first_question_group.reload.position).to eq 1
24
- expect(second_question_group.reload.position).to eq 3
25
- expect(third_question_group.reload.position).to eq 2
26
- end
27
-
28
- it 'does not moves a question group down when already the first with resort' do
29
- patch :move_down, survey_id: survey, id: third_question_group
30
-
31
- expect(first_question_group.reload.position).to eq 1
32
- expect(second_question_group.reload.position).to eq 2
33
- expect(third_question_group.reload.position).to eq 3
34
- end
35
-
36
- it 'does not moves a question group up when already the first with resort' do
37
- patch :move_up, survey_id: survey, id: first_question_group
38
-
39
- expect(first_question_group.reload.position).to eq 1
40
- expect(second_question_group.reload.position).to eq 2
41
- expect(third_question_group.reload.position).to eq 3
42
- end
43
-
44
- it 'resort after deleting a question group' do
45
- delete :destroy, survey_id: survey, id: first_question_group
46
- # Note: first is destroyed, the others moving along so second_question_group becomes first_question_group and so on.
47
- expect(first_question_group.reload.position).to eq 1
48
- expect(second_question_group.reload.position).to eq 2
49
- end
50
-
51
- it 'counts position up when creating a new survey' do
52
- post :create, survey_id: survey, question_group: { title: 'something' }
53
-
54
- expect(first_question_group.reload.position).to eq 1
55
- expect(second_question_group.reload.position).to eq 2
56
- expect(third_question_group.reload.position).to eq 3
57
- expect(draft_version.reload.question_groups.last.position).to eq 4
58
- end
59
- end
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Helena::Admin::QuestionsController do
4
- routes { Helena::Engine.routes }
5
-
6
- let(:survey) { create :survey }
7
- let(:draft_version) { create :version, survey: survey, version: 0 }
8
- let(:question_group) { create :question_group, version: draft_version }
9
- let!(:first_question) { create :question, position: 1, question_group: question_group }
10
- let!(:second_question) { create :question, position: 2, question_group: question_group }
11
- let!(:third_question) { create :question, position: 3, question_group: question_group }
12
-
13
- it 'moves a question down with resort' do
14
- patch :move_down, survey_id: survey, question_group_id: question_group, id: first_question
15
-
16
- expect(first_question.reload.position).to eq 2
17
- expect(second_question.reload.position).to eq 1
18
- expect(third_question.reload.position).to eq 3
19
- end
20
-
21
- it 'moves a question up with resort' do
22
- patch :move_up, survey_id: survey, question_group_id: question_group, id: third_question
23
-
24
- expect(first_question.reload.position).to eq 1
25
- expect(second_question.reload.position).to eq 3
26
- expect(third_question.reload.position).to eq 2
27
- end
28
-
29
- it 'does not moves a question down when already the first with resort' do
30
- patch :move_down, survey_id: survey, question_group_id: question_group, id: third_question
31
-
32
- expect(first_question.reload.position).to eq 1
33
- expect(second_question.reload.position).to eq 2
34
- expect(third_question.reload.position).to eq 3
35
- end
36
-
37
- it 'does not moves a question up when already the first with resort' do
38
- patch :move_up, survey_id: survey, question_group_id: question_group, id: first_question
39
-
40
- expect(first_question.reload.position).to eq 1
41
- expect(second_question.reload.position).to eq 2
42
- expect(third_question.reload.position).to eq 3
43
- end
44
-
45
- it 'resort after deleting a question' do
46
- delete :destroy, survey_id: survey, question_group_id: question_group, id: first_question
47
- # Note: first is destroyed, the others moving along so second_question_group becomes first_question_group and so on.
48
- expect(first_question.reload.position).to eq 1
49
- expect(second_question.reload.position).to eq 2
50
- end
51
-
52
- it 'counts position up when creating a new survey' do
53
- post :create, survey_id: survey, question_group_id: question_group, question: { question_text: 'something?', code: 'a38' }
54
-
55
- expect(first_question.reload.position).to eq 1
56
- expect(second_question.reload.position).to eq 2
57
- expect(third_question.reload.position).to eq 3
58
- expect(question_group.reload.questions.last.position).to eq 4
59
- end
60
- end
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Helena::Admin::SessionsController do
4
- routes { Helena::Engine.routes }
5
-
6
- let(:survey) { create :survey }
7
-
8
- context 'without authorization' do
9
- before { allow_any_instance_of(ApplicationController).to receive(:can_administer?).and_return false }
10
-
11
- specify 'trying to list surveys throws an error' do
12
- expect { get :index, survey_id: survey }.to raise_error(ActionController::RoutingError, 'Access Denied')
13
- end
14
-
15
- specify 'trying to export surveys as json throws an error' do
16
- expect { get :index, survey_id: survey, format: :json }.to raise_error(ActionController::RoutingError, 'Access Denied')
17
- end
18
-
19
- specify 'trying to export surveys as csv throws an error' do
20
- expect { get :index, survey_id: survey, format: :csv }.to raise_error(ActionController::RoutingError, 'Access Denied')
21
- end
22
- end
23
-
24
- context 'with authorization' do
25
- before do
26
- create :session, survey: survey, answers: [
27
- build(:string_answer, code: 'string_answer_1', value: 'abc'),
28
- build(:integer_answer, code: 'integer_answer_1', value: '123')
29
- ]
30
- create :session, survey: survey, answers: [
31
- build(:string_answer, code: 'string_answer_2', value: 'def, xyz'),
32
- build(:integer_answer, code: 'integer_answer_2', value: '456')
33
- ]
34
- end
35
-
36
- it 'return json result of all sessions' do
37
- get :index, survey_id: survey, format: :json
38
-
39
- first_result = ActiveSupport::JSON.decode(response.body).first
40
-
41
- expect(first_result['answers'].first['code']).to eq 'string_answer_2'
42
- expect(first_result['answers'].first['value']).to eq 'def, xyz'
43
- expect(first_result['answers'].last['code']).to eq 'integer_answer_2'
44
- expect(first_result['answers'].last['value']).to eq 456
45
-
46
- last_result = ActiveSupport::JSON.decode(response.body).last
47
-
48
- expect(last_result['answers'].first['code']).to eq 'string_answer_1'
49
- expect(last_result['answers'].first['value']).to eq 'abc'
50
- expect(last_result['answers'].last['code']).to eq 'integer_answer_1'
51
- expect(last_result['answers'].last['value']).to eq 123
52
- end
53
-
54
- it 'return csv result of all sessions' do
55
- get :index, survey_id: survey, format: :csv
56
-
57
- csv = CSV.parse(response.body)
58
- %w(string_answer_2 integer_answer_2 string_answer_1 integer_answer_1).each do |code|
59
- expect(csv.first).to include code
60
- end
61
-
62
- ['456', 'def, xyz'].each do |value|
63
- expect(csv[1]).to include value
64
- end
65
-
66
- %w(123 abc).each do |value|
67
- expect(csv[2]).to include value
68
- end
69
- end
70
-
71
- specify 'csv header for all sessions does not allow same column names for answers and session fields' do
72
- create :session, survey: survey, answers: [
73
- build(:boolean_answer, code: 'completed', value: true),
74
- build(:string_answer, code: 'token', value: 'abcdefghijklmnopqrstuvwxyz')
75
- ]
76
- get :index, survey_id: survey, format: :csv
77
-
78
- csv = CSV.parse(response.body)
79
- %w(answer_token answer_completed).each do |code|
80
- expect(csv.first).to include code
81
- end
82
- end
83
- end
84
- end
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Helena::Admin::SurveysController do
4
- routes { Helena::Engine.routes }
5
-
6
- context 'without authorization' do
7
- before { allow_any_instance_of(ApplicationController).to receive(:can_administer?).and_return false }
8
-
9
- specify 'trying to list surveys throws an error' do
10
- expect { get :index }.to raise_error(ActionController::RoutingError, 'Access Denied')
11
- end
12
-
13
- specify 'trying to edit a survey throws an error' do
14
- survey = create :survey
15
- expect { get :edit, id: survey }.to raise_error(ActionController::RoutingError, 'Access Denied')
16
- end
17
-
18
- specify 'trying to update a survey throws an error' do
19
- survey = create :survey
20
- expect { patch :update, id: survey }.to raise_error(ActionController::RoutingError, 'Access Denied')
21
- end
22
-
23
- specify 'trying to delete a survey throws an error' do
24
- survey = create :survey
25
- expect { delete :destroy, id: survey }.to raise_error(ActionController::RoutingError, 'Access Denied')
26
- end
27
-
28
- specify 'trying to add a survey throws an error' do
29
- expect { get :new }.to raise_error(ActionController::RoutingError, 'Access Denied')
30
- end
31
-
32
- specify 'trying to create a survey throws an error' do
33
- expect { post :create, some: :data }.to raise_error(ActionController::RoutingError, 'Access Denied')
34
- end
35
- end
36
-
37
- context 'with authorization' do
38
- let!(:first_survey) { create :survey, position: 1, versions: [build(:base_version)] }
39
- let!(:second_survey) { create :survey, position: 2, versions: [build(:base_version)] }
40
- let!(:third_survey) { create :survey, position: 3, versions: [build(:base_version)] }
41
-
42
- it 'moves a question group down with resort' do
43
- patch :move_down, id: first_survey
44
- expect(first_survey.reload.position).to eq 2
45
- expect(second_survey.reload.position).to eq 1
46
- expect(third_survey.reload.position).to eq 3
47
- end
48
-
49
- it 'moves a question group up with resort' do
50
- patch :move_up, id: third_survey
51
-
52
- expect(first_survey.reload.position).to eq 1
53
- expect(second_survey.reload.position).to eq 3
54
- expect(third_survey.reload.position).to eq 2
55
- end
56
-
57
- it 'does not moves a question group down when already the first with resort' do
58
- patch :move_down, id: third_survey
59
-
60
- expect(first_survey.reload.position).to eq 1
61
- expect(second_survey.reload.position).to eq 2
62
- expect(third_survey.reload.position).to eq 3
63
- end
64
-
65
- it 'does not moves a question group up when already the first with resort' do
66
- patch :move_up, id: first_survey
67
-
68
- expect(first_survey.reload.position).to eq 1
69
- expect(second_survey.reload.position).to eq 2
70
- expect(third_survey.reload.position).to eq 3
71
- end
72
-
73
- it 'resorts after deleting a question group' do
74
- delete :destroy, id: first_survey
75
-
76
- expect(second_survey.reload.position).to eq 1
77
- expect(third_survey.reload.position).to eq 2
78
- end
79
-
80
- it 'counts position up when creating a new survey' do
81
- post :create, survey: { name: 'New Survey', language: 'en' }
82
-
83
- expect(first_survey.reload.position).to eq 1
84
- expect(second_survey.reload.position).to eq 2
85
- expect(third_survey.reload.position).to eq 3
86
- expect(Helena::Survey.find_by(name: 'New Survey').position).to eq 4
87
- end
88
- end
89
- end