Skip to content

Commit

Permalink
Ensure settings handles this nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
krschacht committed Jan 13, 2025
1 parent 5cca930 commit 7795188
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/assistant/slug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Assistant::Slug
included do
before_validation :set_default_slug
before_validation :clear_conflicting_deleted_assistant_slug
validates :slug, uniqueness: { scope: :user_id, message: "has already been taken" }
end

private
Expand Down
18 changes: 18 additions & 0 deletions test/controllers/settings/assistants_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ class Settings::AssistantsControllerTest < ActionDispatch::IntegrationTest
assert_equal params, Assistant.last.slice(:name, :description, :instructions, :language_model_id)
end

test "should show error when creating assistant with duplicate slug" do
existing_assistant = assistants(:samantha)
params = {
name: "New Assistant",
slug: existing_assistant.slug,
description: "A new description",
instructions: "New instructions",
language_model_id: language_models(:gpt_4o).id
}

assert_no_difference("Assistant.count") do
post settings_assistants_url, params: { assistant: params }
end

assert_response :unprocessable_entity
assert_contains_text "main", "Slug has already been taken"
end

test "should get edit" do
get edit_settings_assistant_url(@assistant)
assert_response :success
Expand Down

0 comments on commit 7795188

Please sign in to comment.