Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
364faf90
Unverified
Commit
364faf90
authored
2 years ago
by
Noah Moss
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Allow untranslated setting descriptions in tests (#28170)
* allow untranslated setting descriptions in tests * tweaks
parent
c1997793
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/models/setting.clj
+9
-3
9 additions, 3 deletions
src/metabase/models/setting.clj
test/metabase/models/setting_test.clj
+16
-4
16 additions, 4 deletions
test/metabase/models/setting_test.clj
with
25 additions
and
7 deletions
src/metabase/models/setting.clj
+
9
−
3
View file @
364faf90
...
...
@@ -878,14 +878,19 @@
[
description-form
]
(
when-not
(
valid-trs-or-tru?
description-form
)
;; this doesn't need to be i18n'ed because it's a compile-time error.
(
throw
(
ex-info
(
str
"defsetting docstrings must be a
n
*deferred* i18n form unless the Setting has"
" `:visibilty` `:internal`
or
`:setter` `:none`."
(
throw
(
ex-info
(
str
"defsetting docstrings must be a *deferred* i18n form unless the Setting has"
" `:visibilty` `:internal`
,
`:setter` `:none`
, or is defined in a test namespace
."
(
format
" Got: ^%s %s"
(
some->
description-form
class
(
.getCanonicalName
))
(
pr-str
description-form
)))
{
:description-form
description-form
})))
description-form
)
(
defn-
in-test?
"Is `defsetting` currently being used in a test namespace?"
[]
(
str/ends-with?
(
ns-name
*ns*
)
"-test"
))
(
defmacro
defsetting
"Defines a new Setting that will be added to the DB at some point in the future.
Conveniently can be used as a getter/setter as well
...
...
@@ -977,7 +982,8 @@
;; and `exciting!!` for the setter.
(
not
(
str/includes?
(
name
setting-symbol
)
"!"
))]}
(
let
[
description
(
if
(
or
(
=
(
:visibility
options
)
:internal
)
(
=
(
:setter
options
)
:none
))
(
=
(
:setter
options
)
:none
)
(
in-test?
))
description
(
validate-description-form
description
))
definition-form
(
assoc
options
...
...
This diff is collapsed.
Click to expand it.
test/metabase/models/setting_test.clj
+
16
−
4
View file @
364faf90
(
ns
metabase.models.setting-test
(
:require
[
clojure.test
:refer
:all
]
[
clojure.walk
:as
walk
]
[
environ.core
:as
env
]
[
medley.core
:as
m
]
[
metabase.db.query
:as
mdb.query
]
...
...
@@ -21,14 +22,14 @@
;; ## TEST SETTINGS DEFINITIONS
(
defsetting
test-setting-1
(
deferred-tru
"Test setting - this only shows up in dev (1)"
)
)
"Test setting - this only shows up in dev (1)"
)
(
defsetting
test-setting-2
(
deferred-tru
"Test setting - this only shows up in dev (2)"
)
"Test setting - this only shows up in dev (2)"
:default
"[Default Value]"
)
(
defsetting
test-setting-3
(
deferred-tru
"Test setting - this only shows up in dev (3)"
)
"Test setting - this only shows up in dev (3)"
:visibility
:internal
)
(
defsetting
test-boolean-setting
...
...
@@ -37,7 +38,7 @@
:type
:boolean
)
(
defsetting
test-json-setting
(
deferred-tru
"Test setting - this only shows up in dev (4)"
)
"Test setting - this only shows up in dev (4)"
:type
:json
)
(
defsetting
test-csv-setting
...
...
@@ -963,3 +964,14 @@
Exception
#
"Wrong :default type: got \^clojure\.lang\.Keyword :green-friend, but expected a java\.lang\.String"
(
validate
tag
value
)))))))))
(
deftest
validate-description-translation-test
(
with-redefs
[
metabase.models.setting/in-test?
(
constantly
false
)]
(
testing
"When not in a test, defsetting descriptions must be i18n'ed"
(
try
(
walk/macroexpand-all
`
(
defsetting
~
'test-asdf-asdf-asdf
"untranslated description"
))
(
catch
Exception
e
(
is
(
re-matches
#
"defsetting docstrings must be a \*deferred\* i18n form.*"
(
:cause
(
Throwable->map
e
)))))))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment