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
@@ -3,11 +3,10 @@ require 'spec_helper'
3
3
  feature 'Session management' do
4
4
  let(:survey) { create :survey, name: 'dummy' }
5
5
  let(:base_version) { survey.versions.create version: 0 }
6
- let(:first_question_group) { build(:question_group, title: 'Page 1', position: 1) }
6
+ let!(:first_question_group) { base_version.question_groups.create title: 'Question Group 1' }
7
7
 
8
8
  background do
9
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
10
  end
12
11
 
13
12
  scenario 'edits a session' do
@@ -17,8 +16,7 @@ feature 'Session management' do
17
16
  long_text_question = build :long_text_question, code: 'selfdescription', question_text: 'Give a brief description of yourself'
18
17
  first_question_group.questions << long_text_question
19
18
 
20
- second_question_group = build(:question_group, title: 'Page 2', position: 2)
21
- base_version.question_groups << second_question_group
19
+ second_question_group = base_version.question_groups.create title: 'Question Group 2', allow_to_go_back: true
22
20
 
23
21
  all_and_everything = build :radio_group_question, code: :all_and_everything,
24
22
  question_text: 'What is the answer to the Ultimate Question of Life, the Universe, and Everything?',
@@ -41,13 +39,7 @@ feature 'Session management' do
41
39
 
42
40
  second_question_group.questions << food_allergy
43
41
 
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
42
+ third_question_group = base_version.question_groups.create title: 'Question Group 3', allow_to_go_back: true
51
43
 
52
44
  satisfaction_matrix = build :radio_matrix_question, code: :satisfaction,
53
45
  question_text: 'Below are five statements with which you may agree or disagree.',
@@ -73,16 +65,21 @@ feature 'Session management' do
73
65
  position: 5)
74
66
 
75
67
  third_question_group.questions << satisfaction_matrix
76
-
77
68
  version = Helena::VersionPublisher.publish(base_version)
69
+ version.settings = { display_progressbar: true }
78
70
  version.save
79
71
 
80
72
  session = survey.sessions.create version_id: version.id, token: 'abc'
81
73
 
82
74
  visit helena.edit_session_path(session.token)
83
75
 
76
+ within '#survey_progress' do
77
+ expect(page).to have_content 'Page 1 of 3'
78
+ expect(page).to have_content '33%'
79
+ end
80
+
84
81
  expect(page).to have_content 'Dummy Survey'
85
- expect(page).to have_content 'Page 1'
82
+ expect(page).to have_content 'Question Group 1'
86
83
  expect(page).to have_content "What's your name?"
87
84
  expect(page).to have_content 'Give a brief description of yourself'
88
85
 
@@ -92,9 +89,14 @@ feature 'Session management' do
92
89
  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
90
 
94
91
  expect { click_button 'Next' }.to change { session.reload.answers.count }.from(0).to(2)
92
+ expect(session.reload.last_question_group_id).to eq second_question_group.id
95
93
 
96
- expect(page).to have_content 'Page 2'
94
+ within '#survey_progress' do
95
+ expect(page).to have_content 'Page 2 of 3'
96
+ expect(page).to have_content '67%'
97
+ end
97
98
 
99
+ expect(page).to have_content 'Question Group 2'
98
100
  expect(page).to have_content 'What is the answer to the Ultimate Question of Life, the Universe, and Everything?'
99
101
  expect(page).to have_content 'Just Chuck Norris knows it'
100
102
  expect(page).to have_content 'God'
@@ -112,10 +114,16 @@ feature 'Session management' do
112
114
  check('Oats')
113
115
  check('Meat')
114
116
 
115
- expect(page).to have_link 'Back'
117
+ expect(page).to have_link 'Back', href: helena.edit_session_path(session.token, question_group: version.question_groups.find_by(position: 1))
116
118
  expect { click_button 'Next' }.to change { session.reload.answers.count }.from(2).to(6)
119
+ expect(session.reload.last_question_group_id).to eq third_question_group.id
120
+
121
+ within '#survey_progress' do
122
+ expect(page).to have_content 'Page 3 of 3'
123
+ expect(page).to have_content '100%'
124
+ end
117
125
 
118
- expect(page).to have_content 'Page 3'
126
+ expect(page).to have_content 'Question Group 3'
119
127
 
120
128
  expect(page).to have_content 'Below are five statements with which you may agree or disagree.'
121
129
 
@@ -139,9 +147,26 @@ feature 'Session management' do
139
147
  choose('session_answers_nothing_to_change_5')
140
148
  choose('session_answers_satisfied_with_life_7')
141
149
 
150
+ expect(page).to have_link 'Back', href: helena.edit_session_path(session.token, question_group: version.question_groups.find_by(position: 2))
142
151
  expect { click_button 'Save' }.to change { session.reload.answers.count }.from(6).to(11)
143
152
  end
144
153
 
154
+ scenario 'a user resumes the questionary and starts with ne first unfinished question group' do
155
+ second_question_group = base_version.question_groups.create title: 'Question Group 2'
156
+
157
+ session = survey.sessions.create version_id: base_version.id, token: 'abcdefg'
158
+
159
+ visit helena.edit_session_path(session.token)
160
+
161
+ expect(page).to have_content 'Question Group 1'
162
+ click_button 'Next'
163
+
164
+ expect(session.reload.last_question_group_id).to eq second_question_group.id
165
+
166
+ visit helena.edit_session_path(session.token)
167
+ expect(page).to have_content 'Question Group 2'
168
+ end
169
+
145
170
  scenario 'does not save an empty short text field when required' do
146
171
  short_text_question = build :short_text_question, code: 'a_name', question_text: "What's your name?", required: true
147
172
  first_question_group.questions << short_text_question
@@ -154,10 +179,23 @@ feature 'Session management' do
154
179
  visit helena.edit_session_path(session.token)
155
180
 
156
181
  expect(page).to have_content "What's your name? *"
182
+ expect(page).to have_content '* indicates required fields'
157
183
  expect { click_button 'Save' }.not_to change { session.reload.answers.count }
158
184
  expect(page).to have_content("can't be blank")
159
185
  end
160
186
 
187
+ scenario 'does not display "* indicates required fields" when no required fields are in question group' do
188
+ short_text_question = build :short_text_question, code: 'a_name', question_text: "What's your name?", required: false
189
+ first_question_group.questions << short_text_question
190
+
191
+ session = survey.sessions.create version_id: base_version.id, token: 'abc'
192
+
193
+ visit helena.edit_session_path(session.token)
194
+
195
+ expect(page).to have_content "What's your name?"
196
+ expect(page).not_to have_content '* indicates required fields'
197
+ end
198
+
161
199
  scenario 'does not save an empty long text field when required' do
162
200
  long_text_question = build :long_text_question, code: 'selfdescription', question_text: 'Give a brief description of yourself', required: true
163
201
  first_question_group.questions << long_text_question
@@ -281,4 +319,26 @@ feature 'Session management' do
281
319
 
282
320
  expect(page).to have_content("can't be blank")
283
321
  end
322
+
323
+ scenario 'Allows to define whether a user an jump back for each question group seperately' do
324
+ second_question_group = base_version.question_groups.create title: 'Question Group 2', allow_to_go_back: true
325
+ base_version.question_groups.create title: 'Question Group 3', allow_to_go_back: false
326
+
327
+ session = survey.sessions.create version_id: base_version.id, token: 'abcdefg'
328
+
329
+ visit helena.edit_session_path(session.token)
330
+
331
+ expect(page).to have_content 'Question Group 1'
332
+ expect(page).not_to have_link 'Back'
333
+
334
+ click_button 'Next'
335
+
336
+ expect(page).to have_link 'Back', href: helena.edit_session_path(session.token, question_group: second_question_group.previous_item)
337
+ expect(page).to have_content 'Question Group 2'
338
+
339
+ click_button 'Next'
340
+
341
+ expect(page).to have_content 'Question Group 3'
342
+ expect(page).not_to have_link 'Back'
343
+ end
284
344
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::SurveyImporter do
4
+ it 'imports a new survey' do
5
+ survey_importer = Helena::SurveyImporter.new File.read(File.dirname(__FILE__) + '/../../db/swls_survey.en.yml')
6
+ survey = survey_importer.survey
7
+
8
+ expect(survey).to have_exactly(1).versions
9
+ expect(survey.versions.first).to have_exactly(1).question_groups
10
+ expect(survey.versions.first.question_groups.first).to have_exactly(1).questions
11
+ expect(survey.versions.first.question_groups.first.questions.first).to have_exactly(7).labels
12
+ expect(survey.versions.first.question_groups.first.questions.first).to have_exactly(5).sub_questions
13
+ end
14
+ end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Helena::VersionPublisher do
4
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 }
5
+ let!(:source_version) { survey.versions.create version: 42, active: true }
6
+ let!(:survey_detail) { source_version.survey_detail = build :survey_detail }
7
+ let!(:question_group) { source_version.question_groups.create }
8
8
  let!(:question) { build(:radio_matrix_question, code: 'abc', question_group: question_group) }
9
9
  let!(:label) { build(:label, text: 'xyz', value: 'asdf', question: question) }
10
10
  let!(:sub_question) { build(:sub_question, text: 'ymca', code: 'cde', question: question) }
@@ -12,7 +12,7 @@ describe Helena::VersionPublisher do
12
12
  it 'creates a new version' do
13
13
  allow(DateTime).to receive(:now).and_return('Tue, 24 Jun 2014 10:24:08 +0200')
14
14
 
15
- new_version = Helena::VersionPublisher.publish(base_version)
15
+ new_version = Helena::VersionPublisher.publish(source_version)
16
16
 
17
17
  expect(new_version.version).to eq 43
18
18
  expect(new_version.survey_detail).to be_a Helena::SurveyDetail
@@ -22,5 +22,6 @@ describe Helena::VersionPublisher do
22
22
  expect(new_version.question_groups.first.questions.first).to have_exactly(1).sub_questions
23
23
  expect(new_version.created_at).to eq 'Tue, 24 Jun 2014 10:24:08 +0200'
24
24
  expect(new_version.updated_at).to eq 'Tue, 24 Jun 2014 10:24:08 +0200'
25
+ expect(new_version.active).to be false
25
26
  end
26
27
  end
@@ -10,7 +10,6 @@ describe Helena::Answer do
10
10
 
11
11
  it { expect(subject).to validate_presence_of(:code) }
12
12
  it { expect(subject).to validate_uniqueness_of(:code) }
13
- it { expect(subject).to validate_presence_of(:ip_address) }
14
13
 
15
14
  it 'saves the created_at time when create an answer' do
16
15
  expect(build(:answer).created_at).to be_kind_of(DateTime)
@@ -3,7 +3,8 @@ require 'spec_helper'
3
3
  describe Helena::QuestionGroup do
4
4
  let!(:version) { create :version, survey: create(:survey) }
5
5
 
6
- it { expect(subject).to be_embedded_in(:version) }
6
+ it { expect(subject).to have_many(:questions).with_dependent(:destroy) }
7
+ it { expect(subject).to belong_to(:version) }
7
8
 
8
9
  it 'has a valid factory' do
9
10
  expect(build :question_group).to be_valid
@@ -2,20 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  describe Helena::Question do
4
4
  let!(:version) { create :version, survey: create(:survey) }
5
+ let(:question_group) { build :question_group, version: version }
5
6
 
6
- it { expect(subject).to be_embedded_in(:question_group) }
7
+ it { expect(subject).to belong_to(:question_group) }
7
8
 
8
9
  it { expect(subject).to validate_presence_of(:code) }
9
10
 
10
11
  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
+ a_question = build :question, question_group: question_group, code: :preferred_color
12
13
  expect(a_question).to be_valid
13
14
 
14
- another_question = build :question, question_group: build(:question_group, version: version), code: :preferred_color
15
+ another_question = build :question, question_group: question_group, code: :preferred_color
15
16
  expect(another_question).not_to be_valid
16
17
  end
17
18
 
18
19
  it 'has a valid factory' do
19
- expect(build :question, question_group: build(:question_group, version: version)).to be_valid
20
+ expect(build :question, question_group: question_group).to be_valid
21
+ end
22
+
23
+ it 'indicates that it does not include sub_questions or labels' do
24
+ question = build :question, question_group: question_group
25
+
26
+ expect(question.includes_subquestions?).to eq false
27
+ expect(question.includes_labels?).to eq false
20
28
  end
21
29
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helena::Questions::CheckboxGroup 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 :checkbox_group_question, question_group: question_group).to be_valid
10
+ end
11
+
12
+ it 'indicates that it includes sub_questions' do
13
+ question = build :checkbox_group_question, question_group: question_group
14
+
15
+ expect(question.includes_subquestions?).to eq true
16
+ end
17
+ end
@@ -29,4 +29,10 @@ describe Helena::Questions::RadioGroup do
29
29
  question.labels << build(:label, preselected: false)
30
30
  expect(question).to be_valid
31
31
  end
32
+
33
+ it 'indicates that it includes labels' do
34
+ question = build :radio_group_question, question_group: question_group
35
+
36
+ expect(question.includes_labels?).to eq true
37
+ end
32
38
  end
@@ -29,4 +29,11 @@ describe Helena::Questions::RadioMatrix do
29
29
  question.labels << build(:label, preselected: false)
30
30
  expect(question).to be_valid
31
31
  end
32
+
33
+ it 'indicates that it includes sub_questions and labels' do
34
+ question = build :radio_matrix_question, question_group: question_group
35
+
36
+ expect(question.includes_subquestions?).to eq true
37
+ expect(question.includes_labels?).to eq true
38
+ end
32
39
  end
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Helena::Session do
4
+ let(:survey) { create :survey }
5
+ let(:version) { survey.versions.create }
6
+ let(:session) { survey.sessions.create version: version }
7
+
4
8
  it { expect(subject).to belong_to(:survey) }
5
9
  it { expect(subject).to belong_to(:version) }
6
10
 
@@ -17,4 +21,50 @@ describe Helena::Session do
17
21
  expect_any_instance_of(Helena::Session).to receive(:generate_token).exactly(2).times.and_return('a493oP')
18
22
  expect(create(:session_without_token).token).to eq 'a493oP'
19
23
  end
24
+
25
+ it 'exports as CSV with answers' do
26
+ session.answers << Helena::Answer.build_generic('a', 42, '192.168.0.1')
27
+ session.answers << Helena::Answer.build_generic('b', true, '192.235.0.1')
28
+ session.answers << Helena::Answer.build_generic('c', 'Barbra Streisand!!', '192.999.0.1')
29
+
30
+ csv = Helena::Session.to_csv
31
+
32
+ expect(csv).to include 'a,b,c'
33
+ expect(csv).to include '42,true,Barbra Streisand!!'
34
+ end
35
+
36
+ describe '#answers_as_yaml and #answer_as_yaml=' do
37
+ before do
38
+ session.answers << Helena::Answer.build_generic('c', 'Barbra Streisand!!', '192.999.0.1')
39
+ session.answers << Helena::Answer.build_generic('a', 42, '192.168.0.1')
40
+ session.answers << Helena::Answer.build_generic('b', true, '192.235.0.1')
41
+ end
42
+
43
+ it 'prints answers as yaml' do
44
+ expect(session.answers_as_yaml).to eq "---\na: 42\nb: 'true'\nc: Barbra Streisand!!\n"
45
+ end
46
+
47
+ it 'updates a value by a given yaml' do
48
+ expect do
49
+ session.answers_as_yaml = 'a: 666'
50
+ session.save
51
+ end.to change { session.answers.find_by(code: 'a').value }.from(42).to(666)
52
+ end
53
+
54
+ it 'does not affect the answer when the value is the same' do
55
+ expect do
56
+ session.answers_as_yaml = 'a: 42'
57
+ session.save
58
+ end.not_to change { session.answers.find_by code: 'a' }
59
+ end
60
+
61
+ it 'removes existings answers that is not in the yaml' do
62
+ expect do
63
+ session.answers_as_yaml = 'x: "test"'
64
+ session.save
65
+ end.to change { session.reload.answers.size }.by(-2)
66
+
67
+ expect(session.answers.in(code: %w(a b c)).size).to eq 0
68
+ end
69
+ end
20
70
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Helena::Survey do
4
- it { expect(subject).to embed_many(:versions) }
4
+ it { expect(subject).to have_many(:versions).with_dependent(:destroy) }
5
5
  it { expect(subject).to have_many(:sessions).with_dependent(:destroy) }
6
6
 
7
7
  it { expect(subject).to validate_presence_of(:name) }
@@ -11,4 +11,15 @@ describe Helena::Survey do
11
11
  it 'has a valid factory' do
12
12
  expect(build :survey).to be_valid
13
13
  end
14
+
15
+ it 'returns the newest version if there are any' do
16
+ survey = create :survey
17
+
18
+ expect(survey.newest_version).to be_nil
19
+
20
+ survey.versions.create version: 99
21
+ survey.versions.create version: 0
22
+
23
+ expect(survey.reload.newest_version.version).to be 99
24
+ end
14
25
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Helena::Version do
4
- it { expect(subject).to be_embedded_in(:survey) }
4
+ it { expect(subject).to belong_to(:survey) }
5
5
 
6
- it { expect(subject).to embed_many(:question_groups) }
6
+ it { expect(subject).to have_many(:question_groups).with_dependent(:destroy) }
7
7
  it { expect(subject).to embed_one(:survey_detail) }
8
8
 
9
9
  it { expect(subject).to validate_presence_of(:version) }
@@ -12,4 +12,13 @@ describe Helena::Version do
12
12
  it 'has a valid factory' do
13
13
  expect(build :version, survey: create(:survey)).to be_valid
14
14
  end
15
+
16
+ it 'scopes active versions' do
17
+ survey = create :survey
18
+ survey.versions.create version: 0
19
+ survey.versions.create active: true, version: 1
20
+
21
+ expect(survey.reload.versions.size).to eq 2
22
+ expect(survey.reload.versions.active.size).to eq 1
23
+ end
15
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helena
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Graf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-02 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: slim
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.1.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: jquery-rails
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -268,38 +282,16 @@ files:
268
282
  - Rakefile
269
283
  - app/assets/images/helena/.keep
270
284
  - app/assets/images/helena/helena_mobile_view.jpg
271
- - app/assets/images/helena/icons/export.svg
272
285
  - app/assets/images/helena/swissmadesoftware.png
273
286
  - app/assets/javascripts/helena/application.js
274
287
  - app/assets/javascripts/helena/survey.js
275
- - app/assets/stylesheets/helena/admin/labels.css.sass
276
- - app/assets/stylesheets/helena/admin/layout.css.sass
277
- - app/assets/stylesheets/helena/admin/question_groups.css.sass
278
- - app/assets/stylesheets/helena/admin/questions.css.sass
279
- - app/assets/stylesheets/helena/admin/sessions.css.sass
280
- - app/assets/stylesheets/helena/admin/subquestions.css.sass
281
- - app/assets/stylesheets/helena/admin/versions.css.sass
282
288
  - app/assets/stylesheets/helena/application.css.sass
283
289
  - app/assets/stylesheets/helena/forms.css.sass
284
290
  - app/assets/stylesheets/helena/layout.css.sass
285
291
  - app/assets/stylesheets/helena/question_groups.css.sass
286
- - app/controllers/helena/admin/application_controller.rb
287
- - app/controllers/helena/admin/question_groups_controller.rb
288
- - app/controllers/helena/admin/questions/checkbox_groups_controller.rb
289
- - app/controllers/helena/admin/questions/checkbox_matrix_controller.rb
290
- - app/controllers/helena/admin/questions/long_texts_controller.rb
291
- - app/controllers/helena/admin/questions/radio_groups_controller.rb
292
- - app/controllers/helena/admin/questions/radio_matrix_controller.rb
293
- - app/controllers/helena/admin/questions/short_texts_controller.rb
294
- - app/controllers/helena/admin/questions/static_texts_controller.rb
295
- - app/controllers/helena/admin/questions_controller.rb
296
- - app/controllers/helena/admin/sessions_controller.rb
297
- - app/controllers/helena/admin/surveys_controller.rb
298
- - app/controllers/helena/admin/versions_controller.rb
299
292
  - app/controllers/helena/application_controller.rb
300
293
  - app/controllers/helena/concerns/questions/matrix_questions.rb
301
294
  - app/controllers/helena/sessions_controller.rb
302
- - app/controllers/helena/surveys_controller.rb
303
295
  - app/helpers/helena/application_helper.rb
304
296
  - app/models/helena/answer.rb
305
297
  - app/models/helena/boolean_answer.rb
@@ -322,35 +314,15 @@ files:
322
314
  - app/models/helena/survey.rb
323
315
  - app/models/helena/survey_detail.rb
324
316
  - app/models/helena/version.rb
325
- - app/views/helena/admin/question_groups/_form.html.haml
326
- - app/views/helena/admin/question_groups/edit.html.haml
327
- - app/views/helena/admin/question_groups/index.html.haml
328
- - app/views/helena/admin/question_groups/new.html.haml
329
- - app/views/helena/admin/questions/_form.html.haml
330
- - app/views/helena/admin/questions/_labels.html.haml
331
- - app/views/helena/admin/questions/_sub_questions.html.haml
332
- - app/views/helena/admin/questions/edit.html.haml
333
- - app/views/helena/admin/questions/index.html.haml
334
- - app/views/helena/admin/questions/new.html.haml
335
- - app/views/helena/admin/sessions/index.html.haml
336
- - app/views/helena/admin/surveys/_form.html.haml
337
- - app/views/helena/admin/surveys/edit.html.haml
338
- - app/views/helena/admin/surveys/index.html.haml
339
- - app/views/helena/admin/surveys/new.html.haml
340
- - app/views/helena/admin/versions/_form.html.haml
341
- - app/views/helena/admin/versions/default_session_report.html.haml
342
- - app/views/helena/admin/versions/edit.html.haml
343
- - app/views/helena/admin/versions/index.html.haml
344
- - app/views/helena/admin/versions/new.html.haml
345
317
  - app/views/helena/questions/_checkbox_group.html.haml
346
318
  - app/views/helena/questions/_long_text.html.haml
347
319
  - app/views/helena/questions/_radio_group.html.haml
348
320
  - app/views/helena/questions/_radio_matrix.html.haml
349
321
  - app/views/helena/questions/_short_text.html.haml
350
- - app/views/helena/sessions/edit.html.haml
351
- - app/views/helena/sessions/end_message.html.haml
352
- - app/views/helena/surveys/_survey.html.haml
353
- - app/views/helena/surveys/index.html.haml
322
+ - app/views/helena/questions/_static_text.html.slim
323
+ - app/views/helena/sessions/_progressbar.html.slim
324
+ - app/views/helena/sessions/edit.html.slim
325
+ - app/views/helena/sessions/end_message.html.slim
354
326
  - bin/rails
355
327
  - config/i18n-tasks.yml
356
328
  - config/initializers/simple_form.rb
@@ -364,28 +336,19 @@ files:
364
336
  - config/locales/models/survey/en.yml
365
337
  - config/locales/models/version/en.yml
366
338
  - config/locales/simple_form.en.yml
367
- - config/locales/views/admin/question_groups/en.yml
368
- - config/locales/views/admin/questions/en.yml
369
- - config/locales/views/admin/sessions/en.yml
370
- - config/locales/views/admin/surveys/en.yml
371
- - config/locales/views/admin/versions/en.yml
372
339
  - config/locales/views/sessions/en.yml
373
340
  - config/routes.rb
374
341
  - db/seeds.rb
342
+ - db/swls_survey.en.yml
375
343
  - gpl-3.0.txt
376
344
  - helena.gemspec
377
345
  - lib/helena.rb
378
346
  - lib/helena/engine.rb
347
+ - lib/helena/survey_importer.rb
379
348
  - lib/helena/version.rb
380
349
  - lib/helena/version_publisher.rb
381
350
  - lib/tasks/helena_tasks.rake
382
351
  - lib/templates/erb/scaffold/_form.html.erb
383
- - spec/controllers/helena/admin/question_group_controller_spec.rb
384
- - spec/controllers/helena/admin/questions_controller_spec.rb
385
- - spec/controllers/helena/admin/sessions_controller_spec.rb
386
- - spec/controllers/helena/admin/survey_controller_spec.rb
387
- - spec/controllers/helena/admin/versions_controller_spec.rb
388
- - spec/controllers/helena/application_controller_spec.rb
389
352
  - spec/controllers/helena/sessions_controller_spec.rb
390
353
  - spec/dummy/README.rdoc
391
354
  - spec/dummy/Rakefile
@@ -431,24 +394,14 @@ files:
431
394
  - spec/factories/helena/survey_details.rb
432
395
  - spec/factories/helena/surveys.rb
433
396
  - spec/factories/helena/versions.rb
434
- - spec/features/helena/admin/manage_question_group_spec.rb
435
- - spec/features/helena/admin/manage_question_spec.rb
436
- - spec/features/helena/admin/manage_session_spec.rb
437
- - spec/features/helena/admin/manage_survey_spec.rb
438
- - spec/features/helena/admin/manage_version_spec.rb
439
- - spec/features/helena/admin/question_types/manage_checkbox_group_question_spec.rb
440
- - spec/features/helena/admin/question_types/manage_long_text_question_spec.rb
441
- - spec/features/helena/admin/question_types/manage_radio_group_question_spec.rb
442
- - spec/features/helena/admin/question_types/manage_radio_matrix_question_spec.rb
443
- - spec/features/helena/admin/question_types/manage_short_text_question_spec.rb
444
- - spec/features/helena/admin/question_types/manage_static_text_question_spec.rb
445
397
  - spec/features/helena/manage_session_spec.rb
446
- - spec/features/helena/manage_survey_spec.rb
398
+ - spec/lib/survey_importer_spec.rb
447
399
  - spec/lib/version_publisher_spec.rb
448
400
  - spec/models/helena/answer_spec.rb
449
401
  - spec/models/helena/label_spec.rb
450
402
  - spec/models/helena/question_group_spec.rb
451
403
  - spec/models/helena/question_spec.rb
404
+ - spec/models/helena/questions/checkbox_group_spec.rb
452
405
  - spec/models/helena/questions/radio_group_spec.rb
453
406
  - spec/models/helena/questions/radio_matrix_spec.rb
454
407
  - spec/models/helena/questions/short_text_spec.rb
@@ -472,9 +425,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
472
425
  version: '0'
473
426
  required_rubygems_version: !ruby/object:Gem::Requirement
474
427
  requirements:
475
- - - ">="
428
+ - - ">"
476
429
  - !ruby/object:Gem::Version
477
- version: '0'
430
+ version: 1.3.1
478
431
  requirements: []
479
432
  rubyforge_project:
480
433
  rubygems_version: 2.2.2
@@ -1,29 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
-
3
-
4
- <!-- The icon can be used freely in both personal and commercial projects with no attribution required, but always appreciated.
5
- You may NOT sub-license, resell, rent, redistribute or otherwise transfer the icon without express written permission from iconmonstr.com -->
6
-
7
-
8
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
9
-
10
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
11
-
12
- width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
13
-
14
- <path id="download-11-icon" d="M461.4,244.318c0,50.852-41.371,92.221-92.221,92.221h-36.847v-40h36.847
15
-
16
- c28.795,0,52.221-23.426,52.221-52.221c0-35.412-23.816-53.746-49.18-53.844c-1.303-58.902-40.637-84.982-78.664-84.982
17
-
18
- c-50.308,0-70.974,38.08-76.131,52.662c-20.51-29.582-76.177-7.248-64.641,32.348C118.25,184.24,90.6,210.24,90.6,244.318
19
-
20
- c0,28.795,23.427,52.221,53.222,52.221h50.512v40h-50.512c-51.852,0-93.222-41.369-93.222-92.221
21
-
22
- c0-41.408,27.561-77.127,66.153-88.463c10.854-36.998,49.784-58.686,86.933-48.779c22.24-26.299,54.773-41.584,89.871-41.584
23
-
24
- c57.115,0,105.365,40.816,115.781,95.777C440.941,176.473,461.4,208.404,461.4,244.318z M336.918,372.8h-33.84v-76.261h-79.486
25
-
26
- V372.8h-33.84l73.582,73.708L336.918,372.8z"/>
27
-
28
- </svg>
29
-
@@ -1,7 +0,0 @@
1
- .helena-admin
2
- table.labels
3
-
4
- td.position
5
- input
6
- max-width: 80px
7
-
@@ -1,6 +0,0 @@
1
- .helena-admin
2
- .actions
3
- font-size: 18pt
4
-
5
- .icon
6
- width: 70px