Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.manage_connection.refresh_schema_success'))
rescue StandardError => e
flash_message(:error, I18n.t('automated_tests.manage_connection.refresh_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
14 changes: 14 additions & 0 deletions app/views/courses/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@
<% if @current_course.persisted? && allowed_to?(:edit?, with: Admin::CoursePolicy) %>
<fieldset id="manage-connection" class="<%= @current_course.autotest_setting_id ? '' : 'no-display' %>">
<legend><span><%= t('automated_tests.manage_connection.title') %></span></legend>
<div>
<%= link_to t('automated_tests.manage_connection.refresh_schema_bottom'),
refresh_autotest_schema_admin_course_path(@current_course),
method: :post,
class: 'button',
data: { confirm: I18n.t('automated_tests.manage_connection.refresh_schema_confirm') } %>
<div class='inline-help'>
<p>
<%= I18n.t('automated_tests.manage_connection.refresh_schema_tooltip',
url: @current_course.autotest_setting&.url) %>
</p>
</div>
</div>
<br>
<div>
<%= link_to I18n.t('automated_tests.manage_connection.test'),
test_autotest_connection_admin_course_path(@current_course),
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 @@ -27,6 +27,11 @@ en:
Please try saving the settings again from the Automated Testing page.
manage_connection:
refresh: Refresh Settings
refresh_schema_bottom: Refresh autotest schema
refresh_schema_confirm: Do you want to refresh autotest schema now?
refresh_schema_failure: 'Refresh autotest schema failed with the following error: %{error}.'
refresh_schema_success: Refresh autotest schema was successful.
refresh_schema_tooltip: Fetch the latest autotest schema from %{url}.
refresh_tooltip: Resend all test settings to the automated tester at %{url}. This should be used when the automated tester has been reset.
test: Test Connection
test_failure: 'Connection to %{url} failed with the following error: %{error}'
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