Commit 11c454e6 authored by Drew Blessing's avatar Drew Blessing

Prevent 500 error when entering/uploading a license

Previously, if an admin clicked 'Upload license' without attaching
or entering a license, a 500 error would occur. Now, we check for
the right param. This also changed the render and return to a
redirect, which is more appropriate.
parent 9e5f3496
......@@ -17,11 +17,11 @@ class Admin::LicensesController < Admin::ApplicationController
end
def create
unless params[:license]
flash.now[:alert] = "No license was selected."
unless params[:license][:data].present? || params[:license][:data_file].present?
flash[:alert] = 'Please enter or upload a license.'
@license = License.new
render :new
redirect_to new_admin_license_path
return
end
......
---
title: Prevent 500 error when uploading/entering a blank license
merge_request: 1016
author:
require 'spec_helper'
describe Admin::LicensesController do
let(:admin) { create(:admin) }
before { sign_in(admin) }
describe 'Upload license' do
it 'redirects back when no license is entered/uploaded' do
post :create, license: { data: '' }
expect(response).to redirect_to new_admin_license_path
expect(flash[:alert]).to include 'Please enter or upload a license.'
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment