Skip to content

Commit

Permalink
adds a rediect and move permanently status for old talks url
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly committed Aug 16, 2023
1 parent c2773e0 commit aa65d44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def update

# Use callbacks to share common setup or constraints between actions.
def set_talk
@talk = Talk.includes(:speakers, :event).find_by!(slug: params[:slug])
@talk = Talk.includes(:speakers, :event).find_by(slug: params[:slug])

redirect_to talks_path, status: :moved_permanently if @talk.blank?
end

# Only allow a list of trusted parameters through.
Expand Down
5 changes: 5 additions & 0 deletions test/controllers/talks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class TalksControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end

test "should redirect to talks for wrong slugs" do
get talk_url("wrong-slug")
assert_response :moved_permanently
end

test "should get edit" do
get edit_talk_url(@talk)
assert_response :success
Expand Down

0 comments on commit aa65d44

Please sign in to comment.