do not render the development environment for exercises without visible files

This commit is contained in:
Hauke Klement
2015-03-21 18:46:02 +01:00
parent 49f5ab061a
commit c294e3b499
5 changed files with 31 additions and 16 deletions

View File

@ -82,6 +82,7 @@ class ExercisesController < ApplicationController
private :handle_file_uploads private :handle_file_uploads
def implement def implement
redirect_to(@exercise, alert: t('exercises.implement.no_files')) unless @exercise.files.visible.exists?
@submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first @submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension) @files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension)
@paths = collect_paths(@files) @paths = collect_paths(@files)

View File

@ -1,3 +1,3 @@
#flash data-message-failure=t('shared.message_failure') #flash data-message-failure=t('shared.message_failure')
- %w[danger info notice success warning].each do |severity| - %w[alert danger info notice success warning].each do |severity|
p.alert.flash class="alert-#{severity == 'notice' ? 'success' : severity}" id="flash-#{severity}" = flash[severity] p.alert.flash class="alert-#{{'alert' => 'warning', 'notice' => 'success'}.fetch(severity, severity)}" id="flash-#{severity}" = flash[severity]

View File

@ -199,6 +199,7 @@ de:
feedback: Feedback feedback: Feedback
file: 'Test-Datei <span class="number">%{number}</span> (<span class="filename">%{filename}</span>)' file: 'Test-Datei <span class="number">%{number}</span> (<span class="filename">%{filename}</span>)'
hint: Tipp hint: Tipp
no_files: Die Aufgabe umfasst noch keine sichtbaren Dateien.
no_output: Die letzte Code-Ausführung hat keine Ausgabe erzeugt. no_output: Die letzte Code-Ausführung hat keine Ausgabe erzeugt.
no_output_yet: Bisher existiert noch keine Ausgabe. no_output_yet: Bisher existiert noch keine Ausgabe.
output: Programm-Ausgabe output: Programm-Ausgabe

View File

@ -199,6 +199,7 @@ en:
feedback: Feedback feedback: Feedback
file: 'Test File <span class="number">%{number}</span> (<span class="filename">%{filename}</span>)' file: 'Test File <span class="number">%{number}</span> (<span class="filename">%{filename}</span>)'
hint: Hint hint: Hint
no_files: The exercise does not comprise visible files yet.
no_output: The last code run has not generated any output. no_output: The last code run has not generated any output.
no_output_yet: There is no output yet. no_output_yet: There is no output yet.
output: Program Output output: Program Output

View File

@ -146,27 +146,39 @@ describe ExercisesController do
describe 'GET #implement' do describe 'GET #implement' do
let(:request) { proc { get :implement, id: exercise.id } } let(:request) { proc { get :implement, id: exercise.id } }
before(:each) { request.call }
expect_assigns(exercise: :exercise) context 'with an exercise with visible files' do
let(:exercise) { FactoryGirl.create(:fibonacci) }
before(:each) { request.call }
context 'with an existing submission' do expect_assigns(exercise: :exercise)
let!(:submission) { FactoryGirl.create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: InternalUser.class.name) }
it "populates the editors with the submission's files' content" do context 'with an existing submission' do
request.call let!(:submission) { FactoryGirl.create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: user.class.name) }
expect(assigns(:files)).to eq(submission.files)
it "populates the editors with the submission's files' content" do
request.call
expect(assigns(:files)).to eq(submission.files)
end
end end
context 'without an existing submission' do
it "populates the editors with the exercise's files' content" do
expect(assigns(:files)).to eq(exercise.files.visible)
end
end
expect_status(200)
expect_template(:implement)
end end
context 'without an existing submission' do context 'with an exercise without visible files' do
it "populates the editors with the exercise's files' content" do before(:each) { request.call }
expect(assigns(:files)).to eq(exercise.files.visible)
end
end
expect_status(200) expect_assigns(exercise: :exercise)
expect_template(:implement) expect_flash_message(:alert, :'exercises.implement.no_files')
expect_redirect(:exercise)
end
end end
describe 'GET #index' do describe 'GET #index' do