mumuki-laboratory 5.8.3 → 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/application/submission.js +25 -4
  3. data/app/controllers/application_controller.rb +4 -1
  4. data/app/controllers/concerns/organizations_controller_template.rb +3 -2
  5. data/app/controllers/exercise_solutions_controller.rb +1 -1
  6. data/app/controllers/exercises_controller.rb +3 -7
  7. data/app/controllers/login_controller.rb +6 -0
  8. data/app/helpers/contextualization_result_helper.rb +1 -1
  9. data/app/helpers/exercise_input_helper.rb +20 -5
  10. data/app/helpers/messages_helper.rb +4 -4
  11. data/app/helpers/organization_list_helper.rb +4 -0
  12. data/app/models/assignment.rb +50 -7
  13. data/app/models/concerns/contextualization.rb +3 -3
  14. data/app/models/concerns/guide_container.rb +15 -0
  15. data/app/models/concerns/submittable/submittable.rb +1 -1
  16. data/app/models/concerns/with_assignments.rb +10 -41
  17. data/app/models/concerns/with_discussions.rb +1 -1
  18. data/app/models/discussion.rb +7 -1
  19. data/app/models/exam.rb +14 -0
  20. data/app/models/exercise.rb +17 -1
  21. data/app/models/exercise/challenge.rb +1 -5
  22. data/app/models/guide.rb +1 -1
  23. data/app/models/language.rb +25 -8
  24. data/app/models/submission/submission.rb +1 -1
  25. data/app/views/discussions/_message.html.erb +1 -1
  26. data/app/views/exercise_solutions/_out_of_attempts.html.erb +6 -0
  27. data/app/views/exercise_solutions/_results.html.erb +3 -3
  28. data/app/views/exercises/_read_only.html.erb +1 -1
  29. data/app/views/layouts/_kids.html.erb +1 -1
  30. data/app/views/layouts/_organizations_listing.html.erb +1 -1
  31. data/app/views/layouts/exercise_inputs/forms/_interactive_form.html.erb +6 -6
  32. data/app/views/layouts/exercise_inputs/forms/_kids_form.html.erb +1 -1
  33. data/app/views/layouts/exercise_inputs/forms/_playground_form.html.erb +1 -1
  34. data/app/views/layouts/exercise_inputs/forms/_problem_form.html.erb +5 -5
  35. data/app/views/layouts/exercise_inputs/read_only_editors/_text.erb +3 -0
  36. data/app/views/layouts/modals/_kids_results.html.erb +1 -1
  37. data/db/migrate/20180725145801_add_submissions_caps_to_exams.rb +6 -0
  38. data/lib/mumuki/laboratory/controllers/results_rendering.rb +7 -5
  39. data/lib/mumuki/laboratory/locales/en.yml +4 -0
  40. data/lib/mumuki/laboratory/locales/es.yml +5 -0
  41. data/lib/mumuki/laboratory/locales/pt.yml +4 -0
  42. data/lib/mumuki/laboratory/mumukit/directives.rb +1 -0
  43. data/lib/mumuki/laboratory/status.rb +4 -0
  44. data/lib/mumuki/laboratory/status/discussion/discussion.rb +2 -14
  45. data/lib/mumuki/laboratory/status/submission/aborted.rb +4 -4
  46. data/lib/mumuki/laboratory/status/submission/errored.rb +4 -0
  47. data/lib/mumuki/laboratory/status/submission/failed.rb +4 -0
  48. data/lib/mumuki/laboratory/status/submission/manual_evaluation_pending.rb +1 -1
  49. data/lib/mumuki/laboratory/status/submission/passed.rb +0 -4
  50. data/lib/mumuki/laboratory/status/submission/passed_with_warnings.rb +5 -1
  51. data/lib/mumuki/laboratory/status/submission/pending.rb +4 -0
  52. data/lib/mumuki/laboratory/status/submission/running.rb +4 -0
  53. data/lib/mumuki/laboratory/status/submission/submission.rb +7 -17
  54. data/lib/mumuki/laboratory/version.rb +1 -1
  55. data/spec/controllers/discussions_controller_spec.rb +7 -0
  56. data/spec/controllers/exercise_solutions_controller_spec.rb +6 -1
  57. data/spec/controllers/messages_controller_spec.rb +7 -0
  58. data/spec/dummy/db/schema.rb +2 -0
  59. data/spec/factories/exam_factory.rb +1 -2
  60. data/spec/features/progressive_tips_spec.rb +4 -4
  61. data/spec/helpers/organization_list_helper_spec.rb +20 -0
  62. data/spec/models/assignment_spec.rb +2 -0
  63. data/spec/models/event_generation_spec.rb +6 -6
  64. data/spec/models/exercise_spec.rb +39 -32
  65. data/spec/models/guide_spec.rb +2 -2
  66. data/spec/models/interactive_spec.rb +1 -1
  67. data/spec/models/query_spec.rb +1 -2
  68. data/spec/models/question_spec.rb +1 -3
  69. data/spec/models/solution_spec.rb +33 -2
  70. data/spec/spec_helper.rb +1 -0
  71. data/vendor/assets/javascripts/codemirror-modes/php.js +236 -0
  72. metadata +14 -8
@@ -38,6 +38,10 @@ module Mumuki::Laboratory::Status
38
38
  end
39
39
  end
40
40
 
41
+ def test_selectors
42
+ self::STATUSES.map { |it| "#{it}?".to_sym }
43
+ end
44
+
41
45
  def to_mumuki_status(status)
42
46
  status.send(to_status_method)
43
47
  end
@@ -10,20 +10,8 @@ require_relative './pending_review'
10
10
  module Mumuki::Laboratory::Status::Discussion
11
11
  STATUSES = [Opened, Closed, Solved, PendingReview]
12
12
 
13
- def closed?
14
- false
15
- end
16
-
17
- def opened?
18
- false
19
- end
20
-
21
- def solved?
22
- false
23
- end
24
-
25
- def pending_review?
26
- false
13
+ test_selectors.each do |selector|
14
+ define_method(selector) { false }
27
15
  end
28
16
 
29
17
  def allowed_for?(*)
@@ -1,11 +1,11 @@
1
1
  module Mumuki::Laboratory::Status::Submission::Aborted
2
2
  extend Mumuki::Laboratory::Status::Submission
3
3
 
4
- def self.group
5
- Mumuki::Laboratory::Status::Submission::Failed
4
+ def self.aborted?
5
+ true
6
6
  end
7
7
 
8
- def aborted?
9
- true
8
+ def self.group
9
+ Mumuki::Laboratory::Status::Submission::Failed
10
10
  end
11
11
  end
@@ -5,6 +5,10 @@ module Mumuki::Laboratory::Status::Submission::Errored
5
5
  true
6
6
  end
7
7
 
8
+ def self.should_retry?
9
+ true
10
+ end
11
+
8
12
  def self.group
9
13
  Mumuki::Laboratory::Status::Submission::Failed
10
14
  end
@@ -5,6 +5,10 @@ module Mumuki::Laboratory::Status::Submission::Failed
5
5
  true
6
6
  end
7
7
 
8
+ def self.should_retry?
9
+ true
10
+ end
11
+
8
12
  def self.iconize
9
13
  {class: :danger, type: 'times-circle'}
10
14
  end
@@ -1,7 +1,7 @@
1
1
  module Mumuki::Laboratory::Status::Submission::ManualEvaluationPending
2
2
  extend Mumuki::Laboratory::Status::Submission
3
3
 
4
- def self.passed?
4
+ def self.manual_evaluation_pending?
5
5
  true
6
6
  end
7
7
 
@@ -5,10 +5,6 @@ module Mumuki::Laboratory::Status::Submission::Passed
5
5
  true
6
6
  end
7
7
 
8
- def self.should_retry?
9
- false
10
- end
11
-
12
8
  def self.iconize
13
9
  {class: :success, type: 'check-circle'}
14
10
  end
@@ -1,7 +1,11 @@
1
1
  module Mumuki::Laboratory::Status::Submission::PassedWithWarnings
2
2
  extend Mumuki::Laboratory::Status::Submission
3
3
 
4
- def self.passed?
4
+ def self.passed_with_warnings?
5
+ true
6
+ end
7
+
8
+ def self.should_retry?
5
9
  true
6
10
  end
7
11
 
@@ -1,6 +1,10 @@
1
1
  module Mumuki::Laboratory::Status::Submission::Pending
2
2
  extend Mumuki::Laboratory::Status::Submission
3
3
 
4
+ def self.pending?
5
+ true
6
+ end
7
+
4
8
  def self.iconize
5
9
  {class: :muted, type: :circle}
6
10
  end
@@ -1,6 +1,10 @@
1
1
  module Mumuki::Laboratory::Status::Submission::Running
2
2
  extend Mumuki::Laboratory::Status::Submission
3
3
 
4
+ def self.running?
5
+ true
6
+ end
7
+
4
8
  def self.group
5
9
  Mumuki::Laboratory::Status::Submission::Pending
6
10
  end
@@ -14,28 +14,18 @@ require_relative './manual_evaluation_pending'
14
14
  module Mumuki::Laboratory::Status::Submission
15
15
  STATUSES = [Pending, Running, Passed, Failed, Errored, Aborted, PassedWithWarnings, ManualEvaluationPending]
16
16
 
17
- def group
18
- self
19
- end
20
-
21
- def passed?
22
- false
23
- end
24
-
25
- def failed?
26
- false
17
+ test_selectors.each do |selector|
18
+ define_method(selector) { false }
27
19
  end
28
20
 
29
- def errored?
30
- false
31
- end
32
-
33
- def aborted?
34
- false
21
+ def group
22
+ self
35
23
  end
36
24
 
25
+ # Tells if a new, different submission should be tried.
26
+ # True for `failed`, `errored` and `passed_with_warnings`
37
27
  def should_retry?
38
- true
28
+ false
39
29
  end
40
30
 
41
31
  def iconize
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Laboratory
3
- VERSION = '5.8.3'
3
+ VERSION = '5.9.0'
4
4
  end
5
5
  end
@@ -16,5 +16,12 @@ describe DiscussionsController, organization_workspace: :test do
16
16
  it { expect(exercise.discussions.size).to eq 1 }
17
17
  it { expect(user.discussions.size).to eq 1 }
18
18
  it { expect(user.watched_discussions.size).to eq 1 }
19
+
20
+ describe 'deleting exercises does delete all discussions' do
21
+ before { @discussion_id = exercise.discussions.first.id }
22
+ before { exercise.destroy }
23
+
24
+ it { expect { Discussion.find(@discussion_id) }.to raise_exception(ActiveRecord::RecordNotFound) }
25
+ end
19
26
  end
20
27
  end
@@ -16,6 +16,11 @@ describe ExerciseSolutionsController, organization_workspace: :test do
16
16
  before { post :create, params: { exercise_id: problem.id, solution: { content: 'asd' } } }
17
17
 
18
18
  it { expect(response.status).to eq 200 }
19
+ it { expect(response.body).to json_eq(
20
+ {status: :failed, guide_finished_by_solution: false},
21
+ except: [:class_for_progress_list_item,
22
+ :html, :title_html, :button_html,
23
+ :expectations_html, :remaining_attempts_html]) }
19
24
  it { expect(Assignment.last.solution).to eq('asd')}
20
25
  end
21
26
 
@@ -25,7 +30,7 @@ describe ExerciseSolutionsController, organization_workspace: :test do
25
30
  'a_file.css' => 'a css content',
26
31
  'a_file.js' => 'a js content'
27
32
  } } } }
28
- let(:files) { problem.files_for(user) }
33
+ let(:files) { problem.assignment_for(user).files }
29
34
 
30
35
  it { expect(response.status).to eq 200 }
31
36
  it { expect(Assignment.last.solution).to eq("/*<a_file.css#*/a css content/*#a_file.css>*/\n/*<a_file.js#*/a js content/*#a_file.js>*/") }
@@ -12,6 +12,13 @@ describe MessagesController, organization_workspace: :test do
12
12
  it { expect(response.status).to eq 302 }
13
13
  it { expect(user.assignments.size).to eq 1 }
14
14
  it { expect(user.messages.size).to eq 1 }
15
+
16
+ describe 'deleting exercises does delete all messages' do
17
+ before { @message_id = user.messages.first.id }
18
+ before { exercise.destroy }
19
+
20
+ it { expect { Message.find(@message_id) }.to raise_exception(ActiveRecord::RecordNotFound) }
21
+ end
15
22
  end
16
23
 
17
24
  describe 'post when previous assignment' do
@@ -128,6 +128,8 @@ ActiveRecord::Schema.define(version: 20180802190437) do
128
128
  t.datetime "end_time", null: false
129
129
  t.string "classroom_id"
130
130
  t.integer "duration"
131
+ t.integer "max_problem_submissions"
132
+ t.integer "max_choice_submissions"
131
133
  t.index ["classroom_id"], name: "index_exams_on_classroom_id", unique: true
132
134
  t.index ["guide_id"], name: "index_exams_on_guide_id"
133
135
  t.index ["organization_id"], name: "index_exams_on_organization_id"
@@ -1,7 +1,6 @@
1
1
  FactoryBot.define do
2
2
 
3
- factory :exam do
4
- guide
3
+ factory :exam, traits: [:guide_container] do
5
4
  duration { Faker::Number.between(10, 60).minutes }
6
5
  organization { Organization.current }
7
6
  start_time { 5.minutes.ago }
@@ -8,7 +8,7 @@ feature 'Progressive Tips', organization_workspace: :test do
8
8
  let!(:problem) { build(:problem,
9
9
  name: 'Succ1', description: 'Description of Succ1',
10
10
  layout: :input_right, assistance_rules: [{when: :submission_failed, then: ['try this', 'try that']}] ) }
11
- let(:assignment) { problem.find_or_init_assignment_for(user) }
11
+ let(:assignment) { problem.assignment_for(user) }
12
12
 
13
13
  let!(:chapter) {
14
14
  create(:chapter, name: 'Functional Programming', lessons: [
@@ -22,7 +22,7 @@ feature 'Progressive Tips', organization_workspace: :test do
22
22
  before { assignment.update! status: :failed }
23
23
 
24
24
  scenario '2 failed submissions' do
25
- assignment.update! attemps_count: 2
25
+ assignment.update! attempts_count: 2
26
26
  visit "/exercises/#{problem.slug}"
27
27
 
28
28
  expect(page).to have_text('Try this')
@@ -30,7 +30,7 @@ feature 'Progressive Tips', organization_workspace: :test do
30
30
  end
31
31
 
32
32
  scenario '5 failed submissions' do
33
- assignment.update! attemps_count: 5
33
+ assignment.update! attempts_count: 5
34
34
  visit "/exercises/#{problem.id}"
35
35
 
36
36
  expect(page).to_not have_text('Try this')
@@ -38,7 +38,7 @@ feature 'Progressive Tips', organization_workspace: :test do
38
38
  end
39
39
 
40
40
  scenario '10 failed submissions' do
41
- assignment.update! attemps_count: 10
41
+ assignment.update! attempts_count: 10
42
42
  visit "/exercises/#{problem.id}"
43
43
 
44
44
  expect(page).to_not have_text('Try this')
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe OrganizationListHelper, organization_workspace: :test do
4
+ helper OrganizationListHelper
5
+
6
+ context 'not not users path' do
7
+ let(:request) { struct path: '/guides/1' }
8
+
9
+ it { expect(organization_switch_url(Organization.current)).to eq 'http://test.localmumuki.io/guides/1' }
10
+ end
11
+
12
+ context 'on users path' do
13
+ let(:request) { struct path: '/users/' }
14
+ let(:controller_name) { 'users' }
15
+
16
+ it { expect(organization_switch_url(Organization.current)).to eq 'http://test.localmumuki.io/' }
17
+ end
18
+ end
19
+
20
+
@@ -52,11 +52,13 @@ describe Assignment, organization_workspace: :test do
52
52
  let(:failed_submission) { create(:assignment, status: :failed) }
53
53
  let(:passed_submission) { create(:assignment, status: :passed, expectation_results: []) }
54
54
  let(:passed_submission_with_visible_output_language) { create(:assignment, status: :passed, exercise: gobstones_exercise) }
55
+ let(:manual_evaluation_pending_submission) { create(:assignment, status: :manual_evaluation_pending) }
55
56
 
56
57
  it { expect(passed_submission.results_visible?).to be false }
57
58
  it { expect(failed_submission.should_retry?).to be true }
58
59
  it { expect(failed_submission.results_visible?).to be true }
59
60
  it { expect(passed_submission_with_visible_output_language.results_visible?).to be true }
61
+ it { expect(manual_evaluation_pending_submission.results_visible?).to be false }
60
62
  end
61
63
  describe '#expectation_results_visible?' do
62
64
  let(:haskell) { create(:language, visible_success_output: true) }
@@ -33,9 +33,9 @@ describe '#as_platform_json', organization_workspace: :test do
33
33
  expect(assignment.as_platform_json).to json_like(
34
34
  status: :passed,
35
35
  result: nil,
36
- expectation_results: nil,
36
+ expectation_results: [],
37
37
  queries: [],
38
- query_results: nil,
38
+ query_results: [],
39
39
  feedback: nil,
40
40
  test_results: nil,
41
41
  submissions_count: 2,
@@ -92,9 +92,9 @@ describe '#as_platform_json', organization_workspace: :test do
92
92
  expect(assignment.as_platform_json).to json_like(
93
93
  status: :passed,
94
94
  result: nil,
95
- expectation_results: nil,
95
+ expectation_results: [],
96
96
  queries: [],
97
- query_results: nil,
97
+ query_results: [],
98
98
  feedback: nil,
99
99
  test_results: nil,
100
100
  submissions_count: 2,
@@ -147,9 +147,9 @@ describe '#as_platform_json', organization_workspace: :test do
147
147
  expect(assignment.as_platform_json).to json_like(
148
148
  status: :passed,
149
149
  result: nil,
150
- expectation_results: nil,
150
+ expectation_results: [],
151
151
  queries: [],
152
- query_results: nil,
152
+ query_results: [],
153
153
  feedback: nil,
154
154
  test_results: nil,
155
155
  submissions_count: 2,
@@ -20,7 +20,7 @@ describe Exercise, organization_workspace: :test do
20
20
  context 'when there is no default content' do
21
21
  let(:exercise) { create(:exercise) }
22
22
 
23
- it { expect(exercise.new_solution.content).to be_nil }
23
+ it { expect(exercise.new_solution.content).to be_blank }
24
24
  end
25
25
  end
26
26
 
@@ -120,16 +120,16 @@ describe Exercise, organization_workspace: :test do
120
120
  language: haskell)]) }
121
121
  let(:exercise) { guide.exercises.first }
122
122
 
123
- it { expect(exercise.extra_preview(user)).to eq "```haskell\nf x = 1\ng y = y + 3\n```" }
123
+ it { expect(exercise.assignment_for(user).extra_preview).to eq "```haskell\nf x = 1\ng y = y + 3\n```" }
124
124
  end
125
125
 
126
126
  describe '#submit_solution!' do
127
127
  context 'when user did a submission' do
128
128
  before { exercise.submit_solution!(user) }
129
- it { expect(exercise.assignment_for(user)).to be_present }
129
+ it { expect(exercise.find_assignment_for(user)).to be_present }
130
130
  end
131
131
  context 'when user did no submission' do
132
- it { expect(exercise.assignment_for(user)).to be_blank }
132
+ it { expect(exercise.find_assignment_for(user)).to be_blank }
133
133
  end
134
134
  end
135
135
 
@@ -150,11 +150,11 @@ describe Exercise, organization_workspace: :test do
150
150
  context 'when user has a single submission for the exercise' do
151
151
  let!(:assignment) { exercise.submit_solution!(user, content: 'foo') }
152
152
 
153
- it { expect(exercise.current_content_for(user)).to eq assignment.solution }
153
+ it { expect(assignment.current_content).to eq assignment.solution }
154
154
  end
155
155
 
156
156
  context 'when user has no submissions for the exercise' do
157
- it { expect(exercise.current_content_for(user)).to eq '' }
157
+ it { expect(exercise.assignment_for(user).current_content).to eq '' }
158
158
  end
159
159
 
160
160
  context 'when using an interpolation' do
@@ -174,6 +174,8 @@ describe Exercise, organization_workspace: :test do
174
174
  before { reindex_current_organization! }
175
175
 
176
176
  context 'when interpolation is in default_content' do
177
+ let(:assignment) { exercise.assignment_for(user) }
178
+
177
179
  describe 'right previous content' do
178
180
  let(:exercise) { create(:exercise, default_content: interpolation) }
179
181
 
@@ -182,11 +184,11 @@ describe Exercise, organization_workspace: :test do
182
184
 
183
185
  context 'has previous submission' do
184
186
  before { previous_exercise.submit_solution!(user, content: 'foobar') }
185
- it { expect(exercise.current_content_for(user)).to eq 'foobar' }
187
+ it { expect(assignment.current_content).to eq 'foobar' }
186
188
  end
187
189
 
188
190
  context 'does not have previous submission' do
189
- it { expect(exercise.current_content_for(user)).to eq '' }
191
+ it { expect(assignment.current_content).to eq '' }
190
192
  end
191
193
  end
192
194
  context 'using previousSolution' do
@@ -194,11 +196,11 @@ describe Exercise, organization_workspace: :test do
194
196
 
195
197
  context 'has previous submission' do
196
198
  before { previous_exercise.submit_solution!(user, content: 'foobar') }
197
- it { expect(exercise.current_content_for(user)).to eq 'foobar' }
199
+ it { expect(assignment.current_content).to eq 'foobar' }
198
200
  end
199
201
 
200
202
  context 'does not have previous submission' do
201
- it { expect(exercise.current_content_for(user)).to eq '' }
203
+ it { expect(assignment.current_content).to eq '' }
202
204
  end
203
205
  end
204
206
  end
@@ -209,7 +211,7 @@ describe Exercise, organization_workspace: :test do
209
211
 
210
212
  context 'has previous submission' do
211
213
  before { second_exercise.submit_solution!(user, content: 'foobar') }
212
- it { expect(exercise.current_content_for(user)).to eq 'foobar' }
214
+ it { expect(assignment.current_content).to eq 'foobar' }
213
215
  end
214
216
  end
215
217
  context '-1 index' do
@@ -217,11 +219,11 @@ describe Exercise, organization_workspace: :test do
217
219
 
218
220
  context 'has previous submission' do
219
221
  before { previous_exercise.submit_solution!(user, content: 'foobar') }
220
- it { expect(exercise.current_content_for(user)).to eq 'foobar' }
222
+ it { expect(assignment.current_content).to eq 'foobar' }
221
223
  end
222
224
 
223
225
  context 'does not have previous submission' do
224
- it { expect(exercise.current_content_for(user)).to eq '' }
226
+ it { expect(assignment.current_content).to eq '' }
225
227
  end
226
228
  end
227
229
  context '1 index' do
@@ -229,7 +231,7 @@ describe Exercise, organization_workspace: :test do
229
231
 
230
232
  context 'has previous submission' do
231
233
  before { first_exercise.submit_solution!(user, content: 'foobar') }
232
- it { expect(exercise.current_content_for(user)).to eq 'foobar' }
234
+ it { expect(assignment.current_content).to eq 'foobar' }
233
235
  end
234
236
  end
235
237
  context '2 index' do
@@ -237,7 +239,7 @@ describe Exercise, organization_workspace: :test do
237
239
 
238
240
  context 'has previous submission' do
239
241
  before { second_exercise.submit_solution!(user, content: 'foobar') }
240
- it { expect(exercise.current_content_for(user)).to eq 'foobar' }
242
+ it { expect(assignment.current_content).to eq 'foobar' }
241
243
  end
242
244
  end
243
245
  context '3 index' do
@@ -245,26 +247,30 @@ describe Exercise, organization_workspace: :test do
245
247
 
246
248
  context 'has previous submission' do
247
249
  before { previous_exercise.submit_solution!(user, content: 'foobar') }
248
- it { expect(exercise.current_content_for(user)).to eq 'foobar' }
250
+ it { expect(assignment.current_content).to eq 'foobar' }
249
251
  end
250
252
  end
251
253
  end
252
254
  end
253
255
  context 'when interpolation is in test' do
256
+ let(:assignment) { exercise.assignment_for(user) }
257
+
254
258
  context 'using user_first_name' do
255
259
  let(:exercise) { create(:exercise, test: "<div>Hola #{interpolation}</div>") }
256
260
  let(:interpolation) { '/*...user_first_name...*/' }
257
261
 
258
- it { expect(exercise.test_for(user)).to eq "<div>Hola Orlo</div>" }
262
+ it { expect(assignment.test).to eq "<div>Hola Orlo</div>" }
259
263
  end
260
264
 
261
265
  context 'and test is nil' do
262
266
  let(:exercise) { create(:exercise, test: nil, expectations: [{}]) }
263
267
 
264
- it { expect(exercise.test_for(user)).to eq nil }
268
+ it { expect(assignment.test).to eq nil }
265
269
  end
266
270
  end
267
271
  context 'when interpolation is in extra' do
272
+ let(:assignment) { exercise.assignment_for(user) }
273
+
268
274
  describe 'right previous content' do
269
275
  let(:exercise) { create(:exercise, extra: interpolation) }
270
276
 
@@ -273,11 +279,11 @@ describe Exercise, organization_workspace: :test do
273
279
 
274
280
  context 'has previous submission' do
275
281
  before { previous_exercise.submit_solution!(user, content: 'foobar') }
276
- it { expect(exercise.extra_for(user)).to eq "foobar\n" }
282
+ it { expect(assignment.extra).to eq "foobar\n" }
277
283
  end
278
284
 
279
285
  context 'does not have previous submission' do
280
- it { expect(exercise.extra_for(user)).to eq "\n" }
286
+ it { expect(assignment.extra).to eq "\n" }
281
287
  end
282
288
  end
283
289
  context 'using previousSolution' do
@@ -285,11 +291,11 @@ describe Exercise, organization_workspace: :test do
285
291
 
286
292
  context 'has previous submission' do
287
293
  before { previous_exercise.submit_solution!(user, content: 'foobar') }
288
- it { expect(exercise.extra_for(user)).to eq "foobar\n" }
294
+ it { expect(assignment.extra).to eq "foobar\n" }
289
295
  end
290
296
 
291
297
  context 'does not have previous submission' do
292
- it { expect(exercise.extra_for(user)).to eq "\n" }
298
+ it { expect(assignment.extra).to eq "\n" }
293
299
  end
294
300
  end
295
301
  end
@@ -300,7 +306,7 @@ describe Exercise, organization_workspace: :test do
300
306
 
301
307
  context 'has previous submission' do
302
308
  before { second_exercise.submit_solution!(user, content: 'foobar') }
303
- it { expect(exercise.extra_for(user)).to eq "foobar\n" }
309
+ it { expect(assignment.extra).to eq "foobar\n" }
304
310
  end
305
311
  end
306
312
  context '-1 index' do
@@ -308,11 +314,11 @@ describe Exercise, organization_workspace: :test do
308
314
 
309
315
  context 'has previous submission' do
310
316
  before { previous_exercise.submit_solution!(user, content: 'foobar') }
311
- it { expect(exercise.extra_for(user)).to eq "foobar\n" }
317
+ it { expect(assignment.extra).to eq "foobar\n" }
312
318
  end
313
319
 
314
320
  context 'does not have previous submission' do
315
- it { expect(exercise.extra_for(user)).to eq "\n" }
321
+ it { expect(assignment.extra).to eq "\n" }
316
322
  end
317
323
  end
318
324
  context '1 index' do
@@ -320,7 +326,7 @@ describe Exercise, organization_workspace: :test do
320
326
 
321
327
  context 'has previous submission' do
322
328
  before { first_exercise.submit_solution!(user, content: 'foobar') }
323
- it { expect(exercise.extra_for(user)).to eq "foobar\n" }
329
+ it { expect(assignment.extra).to eq "foobar\n" }
324
330
  end
325
331
  end
326
332
  context '2 index' do
@@ -328,7 +334,7 @@ describe Exercise, organization_workspace: :test do
328
334
 
329
335
  context 'has previous submission' do
330
336
  before { second_exercise.submit_solution!(user, content: 'foobar') }
331
- it { expect(exercise.extra_for(user)).to eq "foobar\n" }
337
+ it { expect(assignment.extra).to eq "foobar\n" }
332
338
  end
333
339
  end
334
340
  context '3 index' do
@@ -336,7 +342,7 @@ describe Exercise, organization_workspace: :test do
336
342
 
337
343
  context 'has previous submission' do
338
344
  before { previous_exercise.submit_solution!(user, content: 'foobar') }
339
- it { expect(exercise.extra_for(user)).to eq "foobar\n" }
345
+ it { expect(assignment.extra).to eq "foobar\n" }
340
346
  end
341
347
  end
342
348
  end
@@ -344,16 +350,17 @@ describe Exercise, organization_workspace: :test do
344
350
  end
345
351
 
346
352
  context 'when user has multiple submission for the exercise' do
347
- let!(:assignments) { [exercise.submit_solution!(user, content: 'foo'),
348
- exercise.submit_solution!(user, content: 'bar')] }
353
+ before { exercise.submit_solution!(user, content: 'foo') }
354
+ let!(:assignment) { exercise.submit_solution!(user, content: 'bar') }
349
355
 
350
- it { expect(exercise.current_content_for(user)).to eq assignments.last.solution }
356
+ it { expect(assignment.current_content).to eq assignment.solution }
351
357
  end
352
358
 
353
359
  context 'when user has no solution and exercise has default content' do
354
360
  let(:exercise) { create(:exercise, default_content: '#write here...') }
361
+ let(:assignment) { exercise.assignment_for user }
355
362
 
356
- it { expect(exercise.current_content_for(user)).to eq '#write here...' }
363
+ it { expect(assignment.current_content).to eq '#write here...' }
357
364
  end
358
365
  end
359
366