Skip to content

Commit

Permalink
Merge pull request #4617 from dodona-edu/fix/series-without-courseid
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Jul 28, 2023
2 parents 35b85e8 + be8a401 commit ae1dac1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/controllers/series_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ def edit
# POST /series.json
def create
@series = Series.new(permitted_attributes(Series))
authorize @series.course, :add_series?
if @series.course.present?
authorize @series.course, :add_series?
else
@series.errors.add(:course_id, I18n.t('errors.messages.blank'))
end
respond_to do |format|
if @series.save
if @series.course.present? && @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
6 changes: 6 additions & 0 deletions test/controllers/series_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class SeriesControllerTest < ActionDispatch::IntegrationTest
end
end

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
instance = update_request_expect(attr_hash: { series: { description: 'new description' } })
assert_redirected_to course_url(instance.course, series: instance, anchor: instance.anchor)
Expand Down

0 comments on commit ae1dac1

Please sign in to comment.