Skip to content
Snippets Groups Projects
Commit eecbedde authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #737 from metabase/fix_human-readable-name

fix null pointer in human-readable-name function
parents 942b2a19 545ec1a3
No related branches found
No related tags found
No related merge requests found
......@@ -31,9 +31,10 @@
(name->human-readable-name \"admin_users\") -> \"Admin Users\""
[^String n]
(when (seq n)
(when-let [n (some-> n
(s/replace #"(?:-|_id)$" "") ; strip off any trailing _id or -id suffix
(s/split #"_|-"))] ; explode string on underscores and hyphens
(when-let [n (->> (some-> n
(s/replace #"(?:-|_id)$" "") ; strip off any trailing _id or -id suffix
(s/split #"_|-"))
(filterv not-empty)) ] ; explode string on underscores and hyphens
(->> (for [[first-letter & rest-letters] n] ; for each part of the string,
(apply str (s/upper-case first-letter) (map s/lower-case rest-letters))) ; upcase the first char and downcase the rest
(interpose " ") ; add a space between each part
......
(ns metabase.models.common-test
(:require [expectations :refer :all]
[metabase.db :refer :all]
[metabase.models.common :refer [name->human-readable-name]]
[metabase.test.data :refer :all]))
;; testing on `(name->human-readable-name)`
(expect nil (name->human-readable-name nil))
(expect nil (name->human-readable-name ""))
(expect "" (name->human-readable-name "_"))
(expect "" (name->human-readable-name "-"))
(expect "Agent Invite Migration" (name->human-readable-name "_agent_invite_migration"))
(expect "Agent Invite Migration" (name->human-readable-name "-agent-invite-migration"))
(expect "Foobar" (name->human-readable-name "fooBar"))
(expect "Foo Bar" (name->human-readable-name "foo-bar"))
(expect "Foo Bar" (name->human-readable-name "foo_bar"))
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