Skip to content
Open
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Update autotest settings form UI (#7777)
- Store start and end date for courses (#7783)
- Split courses into Current and Past sections for all users (#7801)
- Add an administrator action on the course settings page to refresh autotest schema (#7828)

### 🐛 Bug fixes
- Prevent "No rows found" message from displaying in tables when data is loading (#7790)
Expand Down
17 changes: 17 additions & 0 deletions app/controllers/admin/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ def reset_autotest_connection
respond_with current_course, location: -> { edit_admin_course_path(current_course) }
end

def refresh_autotest_schema
settings = current_course.autotest_setting
if settings.nil?
flash_message(:error, I18n.t('automated_tests.no_autotest_settings'))
return respond_with current_course, location: -> { edit_admin_course_path(current_course) }
end

begin
schema_json = get_schema(settings)
settings.update!(schema: schema_json)
flash_message(:success, I18n.t('automated_tests.refresh_autotest_schema.success'))
rescue StandardError => e
flash_message(:error, I18n.t('automated_tests.refresh_autotest_schema.failure', error: e.message))
end
respond_with current_course, location: -> { edit_admin_course_path(current_course) }
end

def destroy_lti_deployment
deployment = LtiDeployment.find(params[:lti_deployment_id])
deployment.destroy!
Expand Down
9 changes: 9 additions & 0 deletions app/views/courses/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
placeholder: t('time.format_string.placeholder'),
readonly: !allowed_to?(:edit?, with: Admin::CoursePolicy) %>
</div>
<% if @current_course.persisted? && allowed_to?(:edit?, with: Admin::CoursePolicy) %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new button should go into the "Autotest Connection" section down below. Please also add help text, similar to the existing buttons, to give more information about what this action does.

<p>
<%= link_to t('automated_tests.refresh_autotest_schema.bottom'),
refresh_autotest_schema_admin_course_path(@current_course),
method: :post,
class: 'button',
data: { confirm: I18n.t('automated_tests.refresh_autotest_schema.confirm') } %>
</p>
<% end %>
<p>
<%= f.submit t(:save),
data: { disable_with: t('working') } %>
Expand Down
5 changes: 5 additions & 0 deletions config/locales/views/automated_tests/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ en:
no_instructor_runnable_tests: No tests are available for instructors to run.
no_results: No test results to display
no_student_runnable_tests: No tests are available for students to run.
refresh_autotest_schema:
bottom: Refresh autotest schema
confirm: Do you want to refresh autotest schema now?
failure: 'Refresh autotest schema failed with the following error: %{error}.'
success: Refresh autotest schema was successful.
requirements_file: Package requirements file
requirements_file_tooltip: Upload a requirements file along with the test files
results:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
member do
get 'test_autotest_connection'
put 'reset_autotest_connection'
post 'refresh_autotest_schema'
delete 'destroy_lti_deployment'
end
end
Expand Down
39 changes: 39 additions & 0 deletions spec/controllers/admin/courses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
expect(response).to have_http_status(:forbidden)
end
end

describe '#refresh_autotest_schema' do
it 'responds with 403' do
post_as user, :refresh_autotest_schema, params: { id: course.id }
expect(response).to have_http_status(:forbidden)
end
end
end

context 'Instructor' do
Expand Down Expand Up @@ -354,6 +361,38 @@
end
end

describe '#refresh_autotest_schema' do
subject { post_as admin, :refresh_autotest_schema, params: { id: course.id } }

context 'there is no autotest_setting set' do
it 'should flash an error message' do
subject
expect(response).to have_http_status(:found)
expect(flash[:error]).not_to be_empty
end
end

context 'there is an autotest_setting' do
include_context 'course with an autotest setting'
it 'should update the schema' do
schema_json = { 'schema' => 'data' }.to_json
allow(controller).to receive(:get_schema).and_return(schema_json)
subject
expect(autotest_setting.reload.schema).to eq(schema_json)
expect(flash[:success]).not_to be_empty
end

context 'when the refresh request fails' do
before { allow(controller).to receive(:get_schema).and_raise(StandardError) }

it 'should flash an error message' do
subject
expect(flash[:error]).not_to be_empty
end
end
end
end

describe '#reset_autotest_connection' do
subject { put_as admin, :reset_autotest_connection, params: { id: course.id } }

Expand Down