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
cd1d7721
Commit
cd1d7721
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
fix for allowing special_type to be unset on a field. plus unit tests.
parent
979ae360
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/field.clj
+2
-2
2 additions, 2 deletions
src/metabase/api/field.clj
test/metabase/api/field_test.clj
+50
-24
50 additions, 24 deletions
test/metabase/api/field_test.clj
with
52 additions
and
26 deletions
src/metabase/api/field.clj
+
2
−
2
View file @
cd1d7721
...
...
@@ -39,13 +39,13 @@
(
defendpoint
PUT
"/:id"
"Update `Field` with ID."
[
id
:as
{{
:keys
[
special_type
visibility_type
description
display_name
]}
:body
}]
[
id
:as
{{
:keys
[
special_type
visibility_type
description
display_name
]
,
:as
body
}
:body
}]
{
special_type
FieldSpecialType
visibility_type
FieldVisibilityType
display_name
NonEmptyString
}
(
let-404
[
field
(
Field
id
)]
(
write-check
field
)
(
let
[
special_type
(
or
special_type
(
:special_type
field
))
(
let
[
special_type
(
if
(
contains?
body
:special_type
)
special_type
(
:special_type
field
))
visibility_type
(
or
visibility_type
(
:visibility_type
field
))]
(
check-400
(
field/valid-metadata?
(
:base_type
field
)
(
:field_type
field
)
special_type
visibility_type
))
;; update the Field. start with keys that may be set to NULL then conditionally add other keys if they have values
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/field_test.clj
+
50
−
24
View file @
cd1d7721
...
...
@@ -68,31 +68,57 @@
;; ## PUT /api/field/:id
;; Check that we can update a Field
;; TODO - this should NOT be modifying a field from our test data, we should create new data to mess with
(
tu/expect-eval-actual-first
(
tu/match-$
(
let
[
field
(
Field
(
id
:venues
:latitude
))]
;; this is sketchy. But return the Field back to its unmodified state so it won't affect other unit tests
(
db/upd
Field
(
id
:venues
:latitude
)
:special_type
"latitude"
)
;; match against the modified Field
field
)
{
:description
nil
:table_id
(
id
:venues
)
:special_type
"fk"
:name
"LATITUDE"
:display_name
"Latitude"
:updated_at
$
:active
true
:id
$
:field_type
"info"
:visibility_type
"normal"
:position
0
:preview_display
true
:created_at
$
:base_type
"FloatField"
:parent_id
nil
})
((
user->client
:crowberto
)
:put
200
(
format
"field/%d"
(
id
:venues
:latitude
))
{
:special_type
:fk
}))
(
defn
simple-field-details
[
field
]
(
select-keys
field
[
:name
:display_name
:description
:visibility_type
:special_type
]))
;; test that we can do basic field update work, including unsetting some fields such as special-type
(
expect
[{
:name
"Field Test"
:display_name
"Field test"
:description
nil
:special_type
nil
:visibility_type
:normal
}
{
:name
"Field Test"
:display_name
"yay"
:description
"foobar"
:special_type
:name
:visibility_type
:sensitive
}
{
:name
"Field Test"
:display_name
"yay"
:description
nil
:special_type
nil
:visibility_type
:sensitive
}]
(
tu/with-temp
Database
[{
database-id
:id
}
{
:name
"Field Test"
:engine
:yeehaw
:details
{}
:is_sample
false
}]
(
tu/with-temp
Table
[{
table-id
:id
}
{
:name
"Field Test"
:db_id
database-id
:active
true
}]
(
tu/with-temp
Field
[{
field-id
:id
}
{
:table_id
table-id
:name
"Field Test"
:base_type
:TextField
:field_type
:info
:special_type
nil
:active
true
:preview_display
true
:position
1
}]
(
let
[
original-val
(
simple-field-details
(
db/sel
:one
Field
:id
field-id
))]
;; set it
((
user->client
:crowberto
)
:put
200
(
format
"field/%d"
field-id
)
{
:name
"something else"
:display_name
"yay"
:description
"foobar"
:special_type
:name
:visibility_type
:sensitive
})
(
let
[
updated-val
(
simple-field-details
(
db/sel
:one
Field
:id
field-id
))]
;; unset it
((
user->client
:crowberto
)
:put
200
(
format
"field/%d"
field-id
)
{
:description
nil
:special_type
nil
})
[
original-val
updated-val
(
simple-field-details
(
db/sel
:one
Field
:id
field-id
))]))))))
;; check that you can't set a field to :timestamp_seconds if it's not of a proper base_type
(
expect
[
"Invalid Request."
nil
]
...
...
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