Skip to content

Commit

Permalink
Merge pull request #4848 from dodona-edu/revert-4617-fix/series-witho…
Browse files Browse the repository at this point in the history
…ut-courseid

Prevent crash on series creation without course
  • Loading branch information
jorg-vr authored Aug 1, 2023
2 parents df940af + 42699af commit cd26776
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
8 changes: 2 additions & 6 deletions app/controllers/series_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,9 @@ def edit
# POST /series.json
def create
@series = Series.new(permitted_attributes(Series))
if @series.course.present?
authorize @series.course, :add_series?
else
@series.errors.add(:course_id, I18n.t('errors.messages.blank'))
end
authorize @series
respond_to do |format|
if @series.course.present? && @series.save
if @series.save
format.html { redirect_to edit_series_path(@series), notice: I18n.t('controllers.created', model: Series.model_name.human) }
format.json { render :show, status: :created, location: @series }
else
Expand Down
1 change: 0 additions & 1 deletion test/controllers/series_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class SeriesControllerTest < ActionDispatch::IntegrationTest
test 'create series with missing course_id should 422' do
post series_index_url, params: { series: { name: 'Test series' }, format: :json }
assert_response :unprocessable_entity
assert_includes assigns(:series).errors.messages[:course_id], I18n.t('errors.messages.blank')
end

test 'update series should redirect to course' do
Expand Down

0 comments on commit cd26776

Please sign in to comment.