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

Additional re-humanization tests :yum:

parent 31597a70
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,7 @@ const SECTIONS = [
},
{
key: "enable-advanced-humanization",
display_name: "Friendly Table Names",
display_name: "Friendly Table and Field Names",
type: "boolean"
}
]
......
......@@ -53,7 +53,7 @@
name->human-readable-name:simple) s))
(defn- re-humanize-table-names!
(defn- re-humanize-table-and-field-names!
"Update the display names of all tables in the database using new values obtained from the (obstensibly toggled implementation of) `name->human-readable-name`."
[]
(doseq [{id :id, table-name :name, display-name :display_name} (db/select ['Table :id :name :display_name])]
......@@ -67,11 +67,11 @@
(defn- set-enable-advanced-humanization! [^Boolean new-value]
(setting/set-boolean! :enable-advanced-humanization new-value)
(log/info (format "Now using %s table name humanization." (if (enable-advanced-humanization) "ADVANCED" "SIMPLE")))
(re-humanize-table-names!))
(re-humanize-table-and-field-names!))
(defsetting enable-advanced-humanization
"Metabase can attempt to transform your table names into more sensible human readable versions, e.g. \"somehorriblename\" becomes \"Some Horrible Name\".
This doesn’t work all that well if your table names are in a language other than English, however. Do you want us to take a guess?"
"Metabase can attempt to transform your table and field names into more sensible human readable versions, e.g. \"somehorriblename\" becomes \"Some Horrible Name\".
This doesn’t work all that well if the names are in a language other than English, however. Do you want us to take a guess?"
:type :boolean
:default true
:setter set-enable-advanced-humanization!)
(ns metabase.models.humanization-test
(:require [expectations :refer :all]
(metabase.models [humanization :refer :all]
(metabase.models [field :refer [Field]]
[humanization :refer :all]
[table :refer [Table]])
[metabase.test.util :as tu]
[metabase.db :as db]))
......@@ -48,26 +49,89 @@
(expect
"Toucans Are Cool"
(tu/with-temporary-setting-values [enable-advanced-humanization true]
(tu/with-temp* [Table [{table-id :id} {:name "toucansare_cool"}]]
(tu/with-temp Table [{table-id :id} {:name "toucansare_cool"}]
(db/select-one-field :display_name Table, :id table-id))))
(expect
"Fussy Bird Sightings"
(tu/with-temporary-setting-values [enable-advanced-humanization true]
(tu/with-temp Field [{field-id :id} {:name "fussybird_sightings"}]
(db/select-one-field :display_name Field, :id field-id))))
;; check that we get the expected :display_name with advanced humanization *disabled*
(expect
"Toucansare Cool"
(tu/with-temporary-setting-values [enable-advanced-humanization false]
(tu/with-temp* [Table [{table-id :id} {:name "toucansare_cool"}]]
(tu/with-temp Table [{table-id :id} {:name "toucansare_cool"}]
(db/select-one-field :display_name Table, :id table-id))))
(expect
"Fussybird Sightings"
(tu/with-temporary-setting-values [enable-advanced-humanization false]
(tu/with-temp Field [{field-id :id} {:name "fussybird_sightings"}]
(db/select-one-field :display_name Field, :id field-id))))
;; now check that existing tables have their :display_names updated appropriately when the setting `enabled-advanced-humanization` is toggled
(expect
["Toucans Are Cool"
"Toucansare Cool"
"Toucans Are Cool"]
(tu/with-temporary-setting-values [enable-advanced-humanization true]
(tu/with-temp* [Table [{table-id :id} {:name "toucansare_cool"}]]
(tu/with-temp Table [{table-id :id} {:name "toucansare_cool"}]
(let [display-name #(db/select-one-field :display_name Table, :id table-id)]
[(display-name)
(do (enable-advanced-humanization false)
(display-name))
(do (enable-advanced-humanization true)
(display-name))]))))
(expect
["Fussy Bird Sightings"
"Fussybird Sightings"
"Fussy Bird Sightings"]
(tu/with-temporary-setting-values [enable-advanced-humanization true]
(tu/with-temp Field [{field-id :id} {:name "fussybird_sightings"}]
(let [display-name #(db/select-one-field :display_name Field, :id field-id)]
[(display-name)
(do (enable-advanced-humanization false)
(display-name))
(do (enable-advanced-humanization true)
(display-name))]))))
;; check that if we give a field a custom display_name that re-humanization doesn't overwrite it
(expect
"My Favorite Table"
(tu/with-temporary-setting-values [enable-advanced-humanization true]
(tu/with-temp Table [{table-id :id} {:name "toucansare_cool"}]
(db/update! Table table-id
:display_name "My Favorite Table")
(enable-advanced-humanization false)
(db/select-one-field :display_name Table, :id table-id))))
(expect
"My Favorite Field"
(tu/with-temporary-setting-values [enable-advanced-humanization true]
(tu/with-temp Field [{field-id :id} {:name "fussybird_sightings"}]
(db/update! Field field-id
:display_name "My Favorite Field")
(enable-advanced-humanization false)
(db/select-one-field :display_name Field, :id field-id))))
;; make sure switching in the other direction doesn't stomp all over custom names either
(expect
"My Favorite Table"
(tu/with-temporary-setting-values [enable-advanced-humanization false]
(tu/with-temp Table [{table-id :id} {:name "toucansare_cool"}]
(db/update! Table table-id
:display_name "My Favorite Table")
(enable-advanced-humanization true)
(db/select-one-field :display_name Table, :id table-id))))
(expect
"My Favorite Field"
(tu/with-temporary-setting-values [enable-advanced-humanization false]
(tu/with-temp Field [{field-id :id} {:name "fussybird_sightings"}]
(db/update! Field field-id
:display_name "My Favorite Field")
(enable-advanced-humanization true)
(db/select-one-field :display_name Field, :id field-id))))
......@@ -150,7 +150,8 @@
:field_type :info
:name (random-name)
:position 1
:preview_display true})})
:preview_display true
:table_id (data/id :venues)})})
(u/strict-extend (class Metric)
WithTempDefaults
......
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