mumuki-laboratory 7.6.2 → 7.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +193 -2
  3. data/Rakefile +3 -0
  4. data/app/assets/javascripts/mumuki_laboratory/application.js +0 -1
  5. data/app/assets/javascripts/mumuki_laboratory/application/assets-loader.js +1 -1
  6. data/app/assets/javascripts/mumuki_laboratory/application/bridge.js +36 -10
  7. data/app/assets/javascripts/mumuki_laboratory/application/button.js +90 -1
  8. data/app/assets/javascripts/mumuki_laboratory/application/codemirror.js +1 -0
  9. data/app/assets/javascripts/mumuki_laboratory/application/custom-editor.js +46 -4
  10. data/app/assets/javascripts/mumuki_laboratory/application/discussions.js +14 -13
  11. data/app/assets/javascripts/mumuki_laboratory/application/kids.js +73 -36
  12. data/app/assets/javascripts/mumuki_laboratory/application/progress.js +3 -0
  13. data/app/assets/javascripts/mumuki_laboratory/application/results-renderer.js +51 -0
  14. data/app/assets/javascripts/mumuki_laboratory/application/submission.js +184 -35
  15. data/app/assets/stylesheets/mumuki_laboratory/application/_modules.scss +1 -0
  16. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_discussion.scss +43 -5
  17. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kids.scss +3 -3
  18. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kindergarten.scss +55 -0
  19. data/app/controllers/assets_controller.rb +2 -0
  20. data/app/controllers/concerns/with_authorization.rb +4 -0
  21. data/app/controllers/concerns/with_user_discussion_validation.rb +14 -0
  22. data/app/controllers/discussions_controller.rb +6 -14
  23. data/app/controllers/discussions_messages_controller.rb +10 -1
  24. data/app/controllers/exercise_solutions_controller.rb +4 -2
  25. data/app/helpers/application_helper.rb +9 -5
  26. data/app/helpers/discussions_helper.rb +37 -23
  27. data/app/helpers/exercise_input_helper.rb +1 -1
  28. data/app/helpers/icons_helper.rb +3 -3
  29. data/app/views/book_discussions/index.html.erb +3 -3
  30. data/app/views/discussions/_message.html.erb +20 -8
  31. data/app/views/discussions/index.html.erb +0 -1
  32. data/app/views/discussions/new.html.erb +33 -0
  33. data/app/views/discussions/show.html.erb +18 -46
  34. data/app/views/exercise_solutions/_contextualization_results_container.html.erb +1 -1
  35. data/app/views/exercise_solutions/_results_title.html.erb +2 -2
  36. data/app/views/exercises/_read_only.html.erb +33 -6
  37. data/app/views/layouts/_copyright.html.erb +1 -1
  38. data/app/views/layouts/_discussions.html.erb +21 -3
  39. data/app/views/layouts/_test_results.html.erb +1 -1
  40. data/app/views/layouts/exercise_inputs/editors/_custom.html.erb +1 -1
  41. data/app/views/layouts/exercise_inputs/forms/_kids_form.html.erb +1 -1
  42. data/app/views/layouts/exercise_inputs/forms/_problem_form.html.erb +1 -1
  43. data/app/views/layouts/exercise_inputs/layouts/_input_bottom.html.erb +1 -1
  44. data/app/views/layouts/exercise_inputs/layouts/_input_kindergarten.html.erb +40 -0
  45. data/app/views/layouts/exercise_inputs/layouts/{_input_kids.html.erb → _input_primary.html.erb} +1 -1
  46. data/app/views/layouts/exercise_inputs/layouts/_input_right.html.erb +1 -1
  47. data/app/views/layouts/modals/_kids_context.html.erb +1 -8
  48. data/app/views/user_mailer/1st_reminder.html.erb +1 -1
  49. data/app/views/user_mailer/1st_reminder.text.erb +1 -1
  50. data/app/views/user_mailer/2nd_reminder.html.erb +1 -1
  51. data/app/views/user_mailer/2nd_reminder.text.erb +1 -1
  52. data/app/views/user_mailer/3rd_reminder.html.erb +1 -1
  53. data/app/views/user_mailer/3rd_reminder.text.erb +1 -1
  54. data/app/views/user_mailer/no_submissions_reminder.html.erb +1 -1
  55. data/app/views/user_mailer/no_submissions_reminder.text.erb +1 -1
  56. data/config/routes.rb +2 -1
  57. data/lib/mumuki/laboratory/controllers/results_rendering.rb +1 -2
  58. data/lib/mumuki/laboratory/locales/en.yml +8 -2
  59. data/lib/mumuki/laboratory/locales/es-CL.yml +292 -0
  60. data/lib/mumuki/laboratory/locales/es.yml +7 -1
  61. data/lib/mumuki/laboratory/locales/pt.yml +8 -4
  62. data/lib/mumuki/laboratory/version.rb +1 -1
  63. data/spec/controllers/confirmations_controller_spec.rb +1 -1
  64. data/spec/controllers/discussions_messages_controller_spec.rb +73 -0
  65. data/spec/controllers/exercise_solutions_controller_spec.rb +41 -6
  66. data/spec/dummy/db/schema.rb +12 -1
  67. data/spec/features/discussion_flow_spec.rb +190 -0
  68. data/spec/features/exercise_flow_spec.rb +1 -1
  69. data/spec/features/menu_bar_spec.rb +88 -7
  70. data/spec/helpers/breadcrumbs_helper_spec.rb +1 -1
  71. data/spec/javascripts/bridge-spec.js +5 -0
  72. data/spec/javascripts/csrf-token-spec.js +7 -0
  73. data/spec/javascripts/elipsis-spec.js +25 -0
  74. data/spec/javascripts/results-renderers-spec.js +17 -0
  75. data/spec/javascripts/spec-helper.js +30 -0
  76. data/spec/javascripts/speech-bubble-renderer-spec.js +11 -0
  77. data/spec/javascripts/timeout-spec.js +5 -0
  78. data/spec/javascripts/timer-spec.js +5 -0
  79. data/spec/teaspoon_env.rb +187 -0
  80. metadata +34 -9
  81. data/app/views/layouts/modals/_new_discussion.html.erb +0 -27
  82. data/vendor/assets/javascripts/hotjar.js +0 -8
@@ -11,6 +11,7 @@ es:
11
11
  and: y
12
12
  appendix: "Apéndice"
13
13
  appendix_teaser: ¿Querés saber más? <a href="%{link}">Consultá el apéndice de este capítulo</a>
14
+ approved_message: Validado por mentor
14
15
  are_you_sure: '¿Estás seguro que querés %{action}?'
15
16
  ask_a_question: ¡Hacé una pregunta!
16
17
  ask_community: Preguntá a la comunidad
@@ -65,6 +66,7 @@ es:
65
66
  details: Detalles
66
67
  disabled_explanation: Estás intentando acceder a un recurso que fue deshabilitado o eliminado de forma permamente
67
68
  disabled_organization_explanation: ¡Este recorrido ha finalizado!
69
+ discussion_description_placeholder: Podés agregar información para detallar más tu consulta
68
70
  discussion_updated: Consulta actualizada
69
71
  discussions: Consultas
70
72
  dont_leave_us: ¡No nos abandones! Aprender a programar es divertido. Sólo tenés que seguir practicando.
@@ -123,6 +125,7 @@ es:
123
125
  language: Lenguaje
124
126
  languages: Lenguajes
125
127
  last_name: Apellido
128
+ last_seen: "Visto por %{name}"
126
129
  last_submission_date: Última solución
127
130
  latest_exercises: Últimos ejercicios
128
131
  learning: Aprendizaje
@@ -144,7 +147,7 @@ es:
144
147
  minute: minuto
145
148
  minutes: minutos
146
149
  more_messages: Ver mensajes anteriores
147
- moderator: Moderador
150
+ moderator: Mentor
148
151
  mumuki_catchphrase: Aprendé a programar
149
152
  mumuki_short_description: Mumuki es la plataforma libre y gratuita para aprender a programar, de la práctica a la teoría y en tu idioma
150
153
  my_doubts: Mis consultas
@@ -202,7 +205,10 @@ es:
202
205
  read: Leido
203
206
  read_messages: Ver mensajes
204
207
  refresh_or_wait: Si no se muestra automáticamente en unos segundos, presioná F5
208
+ requires_attention: Requiere atención
205
209
  reset_query: Borrar los filtros de búsqueda actuales
210
+ responses_count_asc: Con menos respuestas validadas
211
+ responses_count_desc: Con más respuestas validadas
206
212
  restart: Reiniciar
207
213
  results_hidden: ¡Tu solución fue enviada con éxito!
208
214
  results: Resultados
@@ -11,6 +11,7 @@ pt:
11
11
  and: e
12
12
  appendix: Apêndice
13
13
  appendix_teaser: Você quer saber mais? <a href="%{link}"> Consulte o apêndice deste capítulo </a>
14
+ approved_message: Validado pelo mentor
14
15
  are_you_sure: 'Tem certeza de que deseja %{action}?'
15
16
  ask_a_question: Faça uma pergunta!
16
17
  ask_community: Pergunte à comunidade
@@ -62,6 +63,7 @@ pt:
62
63
  details: Detalhes
63
64
  disabled_explanation: Você está tentando acessar um recurso que foi desativado ou removido permanentemente
64
65
  disabled_organization_explanation: Este curso terminou!
66
+ discussion_description_placeholder: Você pode adicionar mais informações sobre sua dúvida
65
67
  discussion_updated: Consulta actualizada
66
68
  discussions: Consultas
67
69
  download: Faça o download do que você fez
@@ -119,6 +121,7 @@ pt:
119
121
  language: Linguagem
120
122
  languages: Linguagens
121
123
  last_name: Sobrenome
124
+ last_seen: "Visto por %{name}"
122
125
  last_submission_date: Última solução
123
126
  latest_exercises: Últimos exercícios
124
127
  learning: Aprendendo
@@ -132,15 +135,15 @@ pt:
132
135
  male: Masculino
133
136
  manual_evaluation_pending: Obrigado por enviar sua solução! Seus professores irão corrigi-lo em breve
134
137
  message_count:
135
- one: 1 mensagem
136
- other: '%{count} mensagens'
138
+ one: 1 mensagem
139
+ other: '%{count} mensagens'
137
140
  message: Mensagem
138
141
  messages: Mensagens
139
142
  messages_error: As mensagens acima não estão disponíveis no momento. Eu tentei novamente mais tarde!
140
143
  minute: minuto
141
144
  minutes: minutos
142
145
  more_messages: Ver as mensagens anteriores
143
- moderator: Moderador
146
+ moderator: Mentor
144
147
  mumuki_catchphrase: Aprendi a programar
145
148
  mumuki_short_description: Mumuki é a plataforma gratuita e gratuita para aprender a programar, desde a prática até a teoria e no seu idioma
146
149
  my_doubts: Minhas duvidas
@@ -162,7 +165,7 @@ pt:
162
165
  no_messages: Parece que você ainda não tem uma mensagem!
163
166
  no_questions: Parece que ainda não há dúvida.
164
167
  no_submissions: Parece que você ainda não tentou resolver este exercício!
165
- no_useful_result: Didn't find what you were looking for
168
+ no_useful_result: Não encontrou o que estava buscando?
166
169
  not_found: A página que você pesquisou não existe!
167
170
  not_found_explanation: Olhe se você escreveu o endereço corretamente. Mas...
168
171
  not_in_any_organizations: Parece que você ainda não está em nenhuma organização!
@@ -195,6 +198,7 @@ pt:
195
198
  read: Ler
196
199
  read_messages: Ver mensagens
197
200
  refresh_or_wait: Se não mostrar automaticamente em alguns segundos, pressione F5
201
+ requires_attention: Requer atenção
198
202
  reset_query: Limpar filtros de pesquisa atuais
199
203
  restart: Reiniciar
200
204
  results: Resultados
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Laboratory
3
- VERSION = '7.6.2'
3
+ VERSION = '7.7.4'
4
4
  end
5
5
  end
@@ -15,6 +15,6 @@ describe ExerciseConfirmationsController, organization_workspace: :test do
15
15
  before { post :create, params: { exercise_id: reading.id } }
16
16
 
17
17
  it { expect(response.status).to eq 200 }
18
- it { expect(response.body).to json_like(guide_finished_by_solution: true, class_for_progress_list_item: 'progress-list-item text-center success active') }
18
+ it { expect(response.body).to json_like(guide_finished_by_solution: true) }
19
19
  end
20
20
  end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe DiscussionsMessagesController, organization_workspace: :test do
4
+ let(:student) { create(:user, permissions: {student: 'test/*'}) }
5
+ let(:moderator) { create(:user, permissions: {moderator: 'test/*', student: 'test/*'}) }
6
+
7
+ let(:exercise) { create(:exercise) }
8
+ let(:discussion) { create(:discussion, item: exercise, organization: Organization.current) }
9
+
10
+ before { Organization.current.update! forum_enabled: true }
11
+
12
+ describe 'post' do
13
+ describe 'for student' do
14
+ before { set_current_user! student }
15
+ before { allow_any_instance_of(DiscussionsMessagesController).to receive(:message_params).and_return content: 'Need help' }
16
+ before { post :create, params: {discussion_id: discussion.id} }
17
+
18
+ it { expect(response.status).to eq 302 }
19
+ it { expect(discussion.messages.size).to eq 1 }
20
+ it { expect(discussion.messages.last.content).to eq 'Need help' }
21
+ end
22
+
23
+ describe 'for moderator' do
24
+ before { set_current_user! moderator }
25
+ before { allow_any_instance_of(DiscussionsMessagesController).to receive(:message_params).and_return content: 'Do this!' }
26
+ before { post :create, params: {discussion_id: discussion.id} }
27
+
28
+ it { expect(response.status).to eq 302 }
29
+ it { expect(discussion.messages.size).to eq 1 }
30
+ it { expect(discussion.messages.last.content).to eq 'Do this!' }
31
+ end
32
+ end
33
+
34
+ describe 'approve' do
35
+ let(:message) { create(:message, discussion: discussion, sender: student.uid) }
36
+
37
+ describe 'for student' do
38
+ before { set_current_user! student }
39
+ before { post :approve, params: {id: message.id, discussion_id: discussion.id} }
40
+
41
+ it { expect(response.status).to eq 403 }
42
+ it { expect(message.reload.approved).to be false }
43
+ end
44
+
45
+ describe 'for student' do
46
+ before { set_current_user! moderator }
47
+ before { post :approve, params: {id: message.id, discussion_id: discussion.id} }
48
+
49
+ it { expect(response.status).to eq 200 }
50
+ it { expect(message.reload.approved).to be true }
51
+ end
52
+ end
53
+
54
+ describe 'question' do
55
+ let(:message) { create(:message, discussion: discussion, sender: student.uid) }
56
+
57
+ describe 'for student' do
58
+ before { set_current_user! student }
59
+ before { post :question, params: {id: message.id, discussion_id: discussion.id} }
60
+
61
+ it { expect(response.status).to eq 403 }
62
+ it { expect(message.reload.not_actually_a_question).to be false }
63
+ end
64
+
65
+ describe 'for student' do
66
+ before { set_current_user! moderator }
67
+ before { post :question, params: {id: message.id, discussion_id: discussion.id} }
68
+
69
+ it { expect(response.status).to eq 200 }
70
+ it { expect(message.reload.not_actually_a_question).to be true }
71
+ end
72
+ end
73
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe ExerciseSolutionsController, organization_workspace: :test do
4
4
  let(:user) { create(:user) }
5
5
  let(:problem) { create(:problem) }
6
- let(:kids_problem) { create(:problem, layout: :input_kids) }
6
+ let(:kids_problem) { create(:problem, layout: :input_primary) }
7
7
  let!(:chapter) {
8
8
  create(:chapter, name: 'Functional Programming', lessons: [
9
9
  create(:lesson, exercises: [problem, kids_problem])
@@ -13,21 +13,56 @@ describe ExerciseSolutionsController, organization_workspace: :test do
13
13
  before { set_current_user! user }
14
14
 
15
15
  def post_problem(problem)
16
- post :create, params: { exercise_id: problem.id, solution: { content: 'asd' } }
16
+ post :create, params: { exercise_id: problem.id, solution: { content: 'the content' } }
17
17
  end
18
18
 
19
19
 
20
- describe 'when simple content is sent' do
20
+ context 'when submission contains client_result' do
21
+ let(:problem) { create(:problem) }
22
+ let(:assignment) { Assignment.last }
23
+
24
+ before { expect_any_instance_of(Language).to receive(:run_tests!).with(bridge_request) }
25
+ before do
26
+ post :create, params: {
27
+ exercise_id: problem.id,
28
+ solution: { content: 'the content' },
29
+ client_result: {
30
+ status: :passed_with_warnings,
31
+ test_results: [{title: 'everything works', status: 'passed'}]
32
+ }
33
+ }
34
+ end
35
+
36
+ let(:bridge_request) do
37
+ {
38
+ content: 'the content',
39
+ custom_expectations: "\n",
40
+ expectations: [],
41
+ extra: "",
42
+ locale: "en",
43
+ settings: {},
44
+ test: "dont care",
45
+ client_result: {
46
+ status: 'passed_with_warnings',
47
+ test_results: [{title: 'everything works', status: 'passed'}]
48
+ }
49
+ }
50
+ end
51
+
52
+ it { expect(assignment.solution).to eq 'the content' }
53
+ end
54
+
55
+ context 'when simple content is sent' do
21
56
  context 'for a non-kids exercise' do
22
57
  before { post_problem(problem) }
23
58
  let(:assignment) { Assignment.last }
24
59
 
25
60
  context 'without client-side interpolations' do
26
61
  it { expect(response.status).to eq 200 }
27
- it { expect(assignment.solution).to eq('asd')}
62
+ it { expect(assignment.solution).to eq('the content')}
28
63
 
29
64
  it { expect(response.body).to json_eq({ status: :failed, guide_finished_by_solution: false },
30
- except: [:class_for_progress_list_item, :html, :remaining_attempts_html]) }
65
+ except: [:html, :remaining_attempts_html]) }
31
66
 
32
67
 
33
68
  it 'does not include kids specific renders' do
@@ -54,7 +89,7 @@ describe ExerciseSolutionsController, organization_workspace: :test do
54
89
  before { post_problem(kids_problem) }
55
90
 
56
91
  it { expect(response.body).to json_eq({ status: :failed, guide_finished_by_solution: false },
57
- except: [:class_for_progress_list_item, :html, :remaining_attempts_html,
92
+ except: [:html, :remaining_attempts_html,
58
93
  :title_html, :button_html, :expectations, :test_results, :tips]) }
59
94
 
60
95
  it 'includes kids specific renders' do
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 20200608132959) do
13
+ ActiveRecord::Schema.define(version: 20200731081757) do
14
14
 
15
15
  # These are extensions that must be enabled in order to support this database
16
16
  enable_extension "plpgsql"
@@ -117,6 +117,11 @@ ActiveRecord::Schema.define(version: 20200608132959) do
117
117
  t.text "manual_evaluation_comment"
118
118
  t.integer "upvotes_count", default: 0
119
119
  t.bigint "organization_id"
120
+ t.integer "messages_count", default: 0
121
+ t.integer "validated_messages_count", default: 0
122
+ t.boolean "requires_moderator_response", default: true
123
+ t.string "last_moderator_access_by_id"
124
+ t.datetime "last_moderator_access_at"
120
125
  t.index ["initiator_id"], name: "index_discussions_on_initiator_id"
121
126
  t.index ["item_type", "item_id"], name: "index_discussions_on_item_type_and_item_id"
122
127
  t.index ["organization_id"], name: "index_discussions_on_organization_id"
@@ -143,7 +148,11 @@ ActiveRecord::Schema.define(version: 20200608132959) do
143
148
  t.integer "max_problem_submissions"
144
149
  t.integer "max_choice_submissions"
145
150
  t.boolean "results_hidden_for_choices", default: false
151
+ t.bigint "course_id"
152
+ t.integer "passing_criterion_type", default: 0
153
+ t.integer "passing_criterion_value"
146
154
  t.index ["classroom_id"], name: "index_exams_on_classroom_id", unique: true
155
+ t.index ["course_id"], name: "index_exams_on_course_id"
147
156
  t.index ["guide_id"], name: "index_exams_on_guide_id"
148
157
  t.index ["organization_id"], name: "index_exams_on_organization_id"
149
158
  end
@@ -288,6 +297,7 @@ ActiveRecord::Schema.define(version: 20200608132959) do
288
297
  t.boolean "read", default: false
289
298
  t.integer "discussion_id"
290
299
  t.boolean "approved", default: false
300
+ t.boolean "not_actually_a_question", default: false
291
301
  end
292
302
 
293
303
  create_table "organizations", id: :serial, force: :cascade do |t|
@@ -375,6 +385,7 @@ ActiveRecord::Schema.define(version: 20200608132959) do
375
385
  t.string "verified_last_name"
376
386
  t.bigint "avatar_id"
377
387
  t.datetime "disabled_at"
388
+ t.boolean "trusted_for_forum"
378
389
  t.index ["disabled_at"], name: "index_users_on_disabled_at"
379
390
  t.index ["last_organization_id"], name: "index_users_on_last_organization_id"
380
391
  t.index ["uid"], name: "index_users_on_uid", unique: true
@@ -0,0 +1,190 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Discussion Flow', organization_workspace: :test do
4
+
5
+ ## =============
6
+ ## Users
7
+ ## =============
8
+
9
+ let(:student) { create(:user, permissions: {student: 'test/*:other/*:empty/*'}) }
10
+ let(:another_student) { create(:user, permissions: {student: 'test/*:other/*:empty/*'}) }
11
+ let(:moderator) { create(:user, permissions: {moderator: 'test/*:other/*:empty/*', student: 'test/*:other/*:empty/*'}) }
12
+
13
+ ## =================
14
+ ## Organizations
15
+ ## =================
16
+
17
+ let(:test_organization) { Organization.locate! 'test' }
18
+ let(:other_organization) { create(:organization, name: 'other') }
19
+ let!(:empty_organization) { create(:organization, name: 'empty') }
20
+
21
+ ## ================================
22
+ ## Content for test_organization
23
+ ## ================================
24
+
25
+ let(:problem_1) { create(:problem) }
26
+ let(:problem_2) { create(:problem) }
27
+ let(:problem_3) { create(:problem) }
28
+
29
+ let!(:chapter) {
30
+ create(:chapter, lessons: [create(:lesson, exercises: [ problem_1, problem_2, problem_3])])
31
+ }
32
+
33
+ ## =====================================
34
+ ## Discussions for test_organization
35
+ ## =====================================
36
+
37
+ let(:problem_2_discussions) { create_list(:discussion, 5, initiator: another_student, item: problem_2, organization: test_organization) }
38
+ let(:problem_3_discussions) { create_list(:discussion, 5, initiator: student, item: problem_2, organization: test_organization) }
39
+ let!(:test_organization_discussions) { problem_2_discussions + problem_3_discussions }
40
+
41
+ ## ===================================
42
+ ## Content for other_organization
43
+ ## ===================================
44
+
45
+ let(:other_problem) { create(:problem) }
46
+ let!(:other_chapter) {
47
+ create(:chapter, book: other_organization.book, lessons: [create(:lesson, exercises: [other_problem])])
48
+ }
49
+
50
+ ## =====================================
51
+ ## Discussions for other_organization
52
+ ## =====================================
53
+
54
+ let(:other_problem_discussions) { create_list(:discussion, 5, initiator: student, item: problem_2, organization: other_organization) }
55
+ let!(:other_organization_discussions) { other_problem_discussions }
56
+
57
+ before { reindex_current_organization! }
58
+ before { reindex_organization! other_organization }
59
+ before { reindex_organization! empty_organization }
60
+
61
+ shared_examples 'no forum access' do
62
+ scenario 'has no forum access' do
63
+ visit current_path
64
+ expect(page).to have_text('You may have mistyped the address or the page may have moved')
65
+ end
66
+ end
67
+
68
+ context 'exercise discussions' do
69
+ let(:current_path) { "/exercises/#{problem_1.id}/discussions" }
70
+
71
+ context 'with no current user' do
72
+ it_behaves_like 'no forum access'
73
+ end
74
+
75
+ context 'with logged user' do
76
+ before { set_current_user! student }
77
+
78
+ context 'but no forum enabled' do
79
+ it_behaves_like 'no forum access'
80
+ end
81
+
82
+ context 'and forum enabled' do
83
+ before { Organization.current.update! forum_enabled: true }
84
+
85
+ scenario 'empty discussion list for problem 1' do
86
+ visit "/exercises/#{problem_1.id}/discussions"
87
+ expect(page).to have_text(problem_1.name)
88
+ expect(page).to have_text('It seems there isn\'t any question yet.')
89
+ end
90
+
91
+ scenario 'discussion list for problem 2' do
92
+ visit "/exercises/#{problem_2.id}/discussions"
93
+ expect(page).to have_text(problem_2.name)
94
+ problem_2_discussions.each do |discussion|
95
+ expect(page).to have_text(discussion.description)
96
+ end
97
+ expect(page).to have_text('Didn\'t find what you were looking for?')
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ context 'book discussions' do
104
+ let(:current_path) { '/discussions' }
105
+
106
+ context 'with no current user' do
107
+ it_behaves_like 'no forum access'
108
+ end
109
+
110
+ context 'with logged user' do
111
+ before { set_current_user! student }
112
+
113
+ context 'but no forum enabled' do
114
+ it_behaves_like 'no forum access'
115
+ end
116
+
117
+ context 'and forum enabled' do
118
+ before { Organization.current.update! forum_enabled: true }
119
+
120
+ context 'in empty organization' do
121
+ before { empty_organization.update! forum_enabled: true }
122
+ before { set_subdomain_host! 'empty' }
123
+ after { set_subdomain_host! 'test' }
124
+
125
+ scenario 'empty discussion list for book without discussions' do
126
+ visit current_path
127
+ expect(page).to have_text(empty_organization.book.name)
128
+ expect(page).to have_text('It seems there isn\'t any question yet.')
129
+ end
130
+
131
+ end
132
+
133
+ scenario 'discussion list for book with discussions' do
134
+ visit current_path
135
+ expect(page).to have_text(test_organization.book.name)
136
+ test_organization_discussions.each do |discussion|
137
+ expect(page).to have_text(discussion.description)
138
+ end
139
+ other_organization_discussions.each do |discussion|
140
+ expect(page).not_to have_text(discussion.description)
141
+ end
142
+ expect(page).not_to have_text('Didn\'t find what you were looking for?')
143
+ expect(page).not_to have_text('It seems there isn\'t any question yet.')
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ context 'exercise discussion' do
150
+ let(:current_path) { "/exercises/#{problem_2.id}/discussions/#{problem_2_discussions.first.id}" }
151
+ before { test_organization.switch! }
152
+
153
+ context 'with no current user' do
154
+ it_behaves_like 'no forum access'
155
+ end
156
+
157
+ context 'with logged student' do
158
+ before { set_current_user! student }
159
+
160
+ context 'but no forum enabled' do
161
+ it_behaves_like 'no forum access'
162
+ end
163
+
164
+ context 'and forum enabled' do
165
+ before { Organization.current.update! forum_enabled: true }
166
+
167
+ scenario 'newly created discussion' do
168
+ visit current_path
169
+ expect(page).to have_text(problem_2.name)
170
+ expect(page).to have_text('Open')
171
+ expect(page).to have_text('Messages')
172
+ expect(page).not_to have_xpath("//div[@class='discussion-actions']")
173
+ end
174
+
175
+ context 'for moderator' do
176
+ before { set_current_user! moderator }
177
+
178
+ scenario 'newly created discussion' do
179
+ visit current_path
180
+ expect(page).to have_text(problem_2.name)
181
+ expect(page).to have_text('Open')
182
+ expect(page).to have_text('Messages')
183
+ expect(page).to have_xpath("//div[@class='discussion-actions']")
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ end