Skip to content
Snippets Groups Projects
Commit 2621e099 authored by Cam Saül's avatar Cam Saül
Browse files

Merge pull request #2437 from metabase/fix-updating-label-name

Fix updating a label name :unamused:
parents 5898c9c5 67533b4d
No related branches found
No related tags found
No related merge requests found
......@@ -14,11 +14,12 @@
(assoc label :slug (u/prog1 (u/slugify label-name)
(assert-unique-slug <>))))
(defn- pre-update [{label-name :name, :as label}]
(defn- pre-update [{label-name :name, id :id, :as label}]
(if-not label-name
label
(assoc label :slug (u/prog1 (u/slugify label-name)
(assert-unique-slug <>)))))
(or (db/exists? Label, :slug <>, :id id) ; if slug hasn't changed no need to check for uniqueness
(assert-unique-slug <>)))))) ; otherwise check to make sure the new slug is unique
(defn- pre-cascade-delete [{:keys [id]}]
(db/cascade-delete 'CardLabel :label_id id))
......
(ns metabase.models.label-test
(:require [expectations :refer :all]
[metabase.db :as db]
[metabase.models.label :refer [Label]]
[metabase.test.util :refer [with-temp with-temp*]]))
;; Check that we can create a label with the name "Cam" (slug "cam")
;; and update the name to something that will produce the same slug ("cam") without getting a "name already taken" exception
(expect
(with-temp Label [{:keys [id]} {:name "Cam"}]
(db/upd Label id, :name "cam")))
;; We SHOULD still see an exception if we try to give something a name that produces a slug that's already been taken
(expect
clojure.lang.ExceptionInfo
(with-temp* [Label [{:keys [id]} {:name "Cam"}]
Label [_ {:name "Rasta"}]]
(db/upd Label id, :name "rasta")))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment