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

with-temp* macro :unamused:

parent e3abd529
No related branches found
No related tags found
No related merge requests found
Showing
with 583 additions and 686 deletions
......@@ -16,7 +16,7 @@
definition [Required Dict]}
(check-superuser)
(checkp #(db/exists? Table :id table_id) "table_id" "Table does not exist.")
(check-500 (metric/create-metric table_id name description *current-user-id* definition)))
(check-500 (metric/create-metric! table_id name description *current-user-id* definition)))
(defendpoint GET "/:id"
......@@ -34,7 +34,7 @@
definition [Required Dict]}
(check-superuser)
(check-404 (metric/exists-metric? id))
(metric/update-metric
(metric/update-metric!
{:id id
:name name
:description description
......@@ -49,7 +49,7 @@
{revision_message [Required NonEmptyString]}
(check-superuser)
(check-404 (metric/exists-metric? id))
(metric/delete-metric id *current-user-id* revision_message)
(metric/delete-metric! id *current-user-id* revision_message)
{:success true})
......
......@@ -65,7 +65,7 @@
;; ## Persistence Functions
(defn create-metric
(defn create-metric!
"Create a new `Metric`.
Returns the newly created `Metric` or throws an Exception."
......@@ -111,7 +111,7 @@
(db/sel :many Metric :table_id table-id, :is_active (if (= :active state) true false), (k/order :name :ASC)))
(hydrate :creator))))
(defn update-metric
(defn update-metric!
"Update an existing `Metric`.
Returns the updated `Metric` or throws an Exception."
......@@ -129,7 +129,7 @@
(u/prog1 (retrieve-metric id)
(events/publish-event :metric-update (assoc <> :actor_id user-id, :revision_message revision_message))))
(defn delete-metric
(defn delete-metric!
"Delete a `Metric`.
This does a soft delete and simply marks the `Metric` as deleted but does not actually remove the
......
......@@ -10,7 +10,7 @@
[table :refer [Table]])
[metabase.test.data :refer :all]
[metabase.test.data.users :refer :all]
[metabase.test.util :refer [match-$ expect-eval-actual-first random-name with-temp obj->json->obj]]))
[metabase.test.util :refer [match-$ expect-eval-actual-first random-name with-temp with-temp* obj->json->obj]]))
;; # CARD LIFECYCLE
......@@ -32,37 +32,38 @@
[true
false
true]
(with-temp Database [{db-id :id}]
(with-temp Card [{card-1-id :id} {:database_id (id)}]
(with-temp Card [{card-2-id :id} {:database_id db-id}]
(let [card-returned? (fn [database-id card-id]
(contains? (set (for [card ((user->client :rasta) :get 200 "card", :f :database, :model_id database-id)]
(:id card)))
card-id))]
[(card-returned? (id) card-1-id)
(card-returned? db-id card-1-id)
(card-returned? db-id card-2-id)])))))
(with-temp* [Database [{db-id :id}]
Card [{card-1-id :id} {:database_id (id)}]
Card [{card-2-id :id} {:database_id db-id}]]
(let [card-returned? (fn [database-id card-id]
(contains? (set (for [card ((user->client :rasta) :get 200 "card", :f :database, :model_id database-id)]
(:id card)))
card-id))]
[(card-returned? (id) card-1-id)
(card-returned? db-id card-1-id)
(card-returned? db-id card-2-id)])))
;; Make sure `id` is required when `f` is :database
(expect {:errors {:id "id is required parameter when filter mode is 'database'"}}
((user->client :crowberto) :get 400 "card" :f :database))
;; Filter cards by table
(expect [true
false
true]
(with-temp Database [{database-id :id}]
(with-temp Table [{table-1-id :id} {:db_id database-id}]
(with-temp Table [{table-2-id :id} {:db_id database-id}]
(with-temp Card [{card-1-id :id} {:table_id table-1-id}]
(with-temp Card [{card-2-id :id} {:table_id table-2-id}]
(let [card-returned? (fn [table-id card-id]
(contains? (set (for [card ((user->client :rasta) :get 200 "card", :f :table, :model_id table-id)]
(:id card)))
card-id))]
[(card-returned? table-1-id card-1-id)
(card-returned? table-2-id card-1-id)
(card-returned? table-2-id card-2-id)])))))))
(expect
[true
false
true]
(with-temp* [Database [{database-id :id}]
Table [{table-1-id :id} {:db_id database-id}]
Table [{table-2-id :id} {:db_id database-id}]
Card [{card-1-id :id} {:table_id table-1-id}]
Card [{card-2-id :id} {:table_id table-2-id}]]
(let [card-returned? (fn [table-id card-id]
(contains? (set (for [card ((user->client :rasta) :get 200 "card", :f :table, :model_id table-id)]
(:id card)))
card-id))]
[(card-returned? table-1-id card-1-id)
(card-returned? table-2-id card-1-id)
(card-returned? table-2-id card-2-id)])))
;; Make sure `id` is required when `f` is :table
(expect {:errors {:id "id is required parameter when filter mode is 'table'"}}
......
......@@ -120,11 +120,10 @@
:series []}]
:organization_id nil}
;; fetch a dashboard WITH a dashboard card on it
(tu/with-temp Dashboard [{dashboard-id :id} {:name "Test Dashboard"}]
(tu/with-temp Card [{card-id :id} {:name "Dashboard Test Card"}]
(tu/with-temp DashboardCard [_ {:dashboard_id dashboard-id
:card_id card-id}]
(dashboard-response ((user->client :rasta) :get 200 (format "dashboard/%d" dashboard-id)))))))
(tu/with-temp* [Dashboard [{dashboard-id :id} {:name "Test Dashboard"}]
Card [{card-id :id} {:name "Dashboard Test Card"}]
DashboardCard [_ {:dashboard_id dashboard-id, :card_id card-id}]]
(dashboard-response ((user->client :rasta) :get 200 (format "dashboard/%d" dashboard-id)))))
;; ## PUT /api/dashboard/:id
......@@ -185,15 +184,15 @@
:sizeY 2
:col 4
:row 4}]]
(tu/with-temp Dashboard [{dashboard-id :id}]
(tu/with-temp Card [{card-id :id}]
[(-> ((user->client :rasta) :post 200 (format "dashboard/%d/cards" dashboard-id) {:cardId card-id
:row 4
:col 4})
(dissoc :id :dashboard_id :card_id)
(update :created_at #(not (nil? %)))
(update :updated_at #(not (nil? %))))
(db/sel :many :fields [DashboardCard :sizeX :sizeY :col :row] :dashboard_id dashboard-id)])))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Card [{card-id :id}]]
[(-> ((user->client :rasta) :post 200 (format "dashboard/%d/cards" dashboard-id) {:cardId card-id
:row 4
:col 4})
(dissoc :id :dashboard_id :card_id)
(update :created_at #(not (nil? %)))
(update :updated_at #(not (nil? %))))
(db/sel :many :fields [DashboardCard :sizeX :sizeY :col :row] :dashboard_id dashboard-id)]))
;; new dashboard card w/ additional series
(expect
......@@ -213,16 +212,16 @@
:col 4
:row 4}]
[0]]
(tu/with-temp Dashboard [{dashboard-id :id}]
(tu/with-temp Card [{card-id :id}]
(tu/with-temp Card [{series-id-1 :id} {:name "Series Card"}]
(let [dashboard-card ((user->client :rasta) :post 200 (format "dashboard/%d/cards" dashboard-id) {:cardId card-id
:row 4
:col 4
:series [{:id series-id-1}]})]
[(remove-ids-and-boolean-timestamps dashboard-card)
(db/sel :many :fields [DashboardCard :sizeX :sizeY :col :row] :dashboard_id dashboard-id)
(db/sel :many :field [DashboardCardSeries :position] :dashboardcard_id (:id dashboard-card))])))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Card [{card-id :id}]
Card [{series-id-1 :id} {:name "Series Card"}]]
(let [dashboard-card ((user->client :rasta) :post 200 (format "dashboard/%d/cards" dashboard-id) {:cardId card-id
:row 4
:col 4
:series [{:id series-id-1}]})]
[(remove-ids-and-boolean-timestamps dashboard-card)
(db/sel :many :fields [DashboardCard :sizeX :sizeY :col :row] :dashboard_id dashboard-id)
(db/sel :many :field [DashboardCardSeries :position] :dashboardcard_id (:id dashboard-card))])))
;; ## DELETE /api/dashboard/:id/cards
......@@ -231,16 +230,16 @@
{:success true}
0]
;; fetch a dashboard WITH a dashboard card on it
(tu/with-temp Dashboard [{dashboard-id :id}]
(tu/with-temp Card [{card-id :id}]
(tu/with-temp Card [{series-id-1 :id}]
(tu/with-temp Card [{series-id-2 :id}]
(tu/with-temp DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-1, :position 0}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-2, :position 1}]
[(count (db/sel :many :field [DashboardCard :id] :dashboard_id dashboard-id))
((user->client :rasta) :delete 200 (format "dashboard/%d/cards" dashboard-id) :dashcardId dashcard-id)
(count (db/sel :many :field [DashboardCard :id] :dashboard_id dashboard-id))]))))))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Card [{card-id :id}]
Card [{series-id-1 :id}]
Card [{series-id-2 :id}]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-1, :position 0}]
DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-2, :position 1}]]
[(count (db/sel :many :field [DashboardCard :id] :dashboard_id dashboard-id))
((user->client :rasta) :delete 200 (format "dashboard/%d/cards" dashboard-id) :dashcardId dashcard-id)
(count (db/sel :many :field [DashboardCard :id] :dashboard_id dashboard-id))]))
;; ## PUT /api/dashboard/:id/cards
......@@ -280,26 +279,26 @@
:created_at true
:updated_at true}]]
;; fetch a dashboard WITH a dashboard card on it
(tu/with-temp Dashboard [{dashboard-id :id}]
(tu/with-temp Card [{card-id :id}]
(tu/with-temp DashboardCard [{dashcard-id-1 :id} {:dashboard_id dashboard-id, :card_id card-id}]
(tu/with-temp DashboardCard [{dashcard-id-2 :id} {:dashboard_id dashboard-id, :card_id card-id}]
(tu/with-temp Card [{series-id-1 :id} {:name "Series Card"}]
[[(remove-ids-and-boolean-timestamps (retrieve-dashboard-card dashcard-id-1))
(remove-ids-and-boolean-timestamps (retrieve-dashboard-card dashcard-id-2))]
((user->client :rasta) :put 200 (format "dashboard/%d/cards" dashboard-id) {:cards [{:id dashcard-id-1
:sizeX 4
:sizeY 2
:col 0
:row 0
:series [{:id series-id-1}]}
{:id dashcard-id-2
:sizeX 1
:sizeY 1
:col 1
:row 3}]})
[(remove-ids-and-boolean-timestamps (retrieve-dashboard-card dashcard-id-1))
(remove-ids-and-boolean-timestamps (retrieve-dashboard-card dashcard-id-2))]]))))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Card [{card-id :id}]
DashboardCard [{dashcard-id-1 :id} {:dashboard_id dashboard-id, :card_id card-id}]
DashboardCard [{dashcard-id-2 :id} {:dashboard_id dashboard-id, :card_id card-id}]
Card [{series-id-1 :id} {:name "Series Card"}]]
[[(remove-ids-and-boolean-timestamps (retrieve-dashboard-card dashcard-id-1))
(remove-ids-and-boolean-timestamps (retrieve-dashboard-card dashcard-id-2))]
((user->client :rasta) :put 200 (format "dashboard/%d/cards" dashboard-id) {:cards [{:id dashcard-id-1
:sizeX 4
:sizeY 2
:col 0
:row 0
:series [{:id series-id-1}]}
{:id dashcard-id-2
:sizeX 1
:sizeY 1
:col 1
:row 3}]})
[(remove-ids-and-boolean-timestamps (retrieve-dashboard-card dashcard-id-1))
(remove-ids-and-boolean-timestamps (retrieve-dashboard-card dashcard-id-2))]]))
......@@ -325,38 +324,34 @@
(dissoc :email :date_joined :last_login :is_superuser :is_qbnewb))
:diff nil
:description nil}]
(tu/with-temp Dashboard [{:keys [id]}]
(tu/with-temp Revision [_ {:model "Dashboard"
:model_id id
:user_id (user->id :rasta)
:object {:name "b"
:description nil
:public_perms 0
:cards [{:sizeX 2
:sizeY 2
:row nil
:col nil
:card_id 123
:series []}]}
:is_creation true
:is_reversion false}]
(tu/with-temp Revision [_ {:model "Dashboard"
:model_id id
:user_id (user->id :crowberto)
:object {:name "c"
:description "something"
:public_perms 0
:cards [{:sizeX 4
:sizeY 3
:row 0
:col 0
:card_id 123
:series [8 9]}]}
:is_creation false
:is_reversion false
:message "updated"}]
(->> ((user->client :crowberto) :get 200 (format "dashboard/%d/revisions" id))
(mapv #(dissoc % :timestamp :id)))))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Revision [_ {:model "Dashboard"
:model_id dashboard-id
:object {:name "b"
:description nil
:public_perms 0
:cards [{:sizeX 2
:sizeY 2
:row nil
:col nil
:card_id 123
:series []}]}
:is_creation true}]
Revision [_ {:model "Dashboard"
:model_id dashboard-id
:user_id (user->id :crowberto)
:object {:name "c"
:description "something"
:public_perms 0
:cards [{:sizeX 4
:sizeY 3
:row 0
:col 0
:card_id 123
:series [8 9]}]}
:message "updated"}]]
(doall (for [revision ((user->client :crowberto) :get 200 (format "dashboard/%d/revisions" dashboard-id))]
(dissoc revision :timestamp :id)))))
;; ## POST /api/dashboard/:id/revert
......@@ -369,7 +364,7 @@
(expect
[;; the api response
[ ;; the api response
{:is_reversion true
:is_creation false
:message nil
......@@ -402,27 +397,22 @@
(dissoc :email :date_joined :last_login :is_superuser :is_qbnewb))
:diff nil
:description nil}]]
(tu/with-temp Dashboard [{:keys [id]}]
(tu/with-temp Revision [{revision-id :id} {:model "Dashboard"
:model_id id
:user_id (user->id :rasta)
:object {:name "a"
:description nil
:public_perms 0
:cards []}
:is_creation true
:is_reversion false}]
(tu/with-temp Revision [_ {:model "Dashboard"
:model_id id
:user_id (user->id :crowberto)
:object {:name "b"
:description nil
:public_perms 0
:cards []}
:is_creation false
:is_reversion false
:message "updated"}]
[(-> ((user->client :crowberto) :post 200 (format "dashboard/%d/revert" id) {:revision_id revision-id})
(dissoc :id :timestamp))
(->> ((user->client :crowberto) :get 200 (format "dashboard/%d/revisions" id))
(mapv #(dissoc % :timestamp :id)))]))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Revision [{revision-id :id} {:model "Dashboard"
:model_id dashboard-id
:object {:name "a"
:description nil
:public_perms 0
:cards []}
:is_creation true}]
Revision [_ {:model "Dashboard"
:model_id dashboard-id
:user_id (user->id :crowberto)
:object {:name "b"
:description nil
:public_perms 0
:cards []}
:message "updated"}]]
[(dissoc ((user->client :crowberto) :post 200 (format "dashboard/%d/revert" dashboard-id) {:revision_id revision-id}) :id :timestamp)
(doall (for [revision ((user->client :crowberto) :get 200 (format "dashboard/%d/revisions" dashboard-id))]
(dissoc revision :timestamp :id)))]))
......@@ -158,11 +158,11 @@
(expect
["Invalid Request."
nil]
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Field [{field-id :id} {:table_id table-id}]
[((user->client :crowberto) :put 400 (str "field/" field-id) {:special_type :timestamp_seconds})
(db/sel :one :field [Field :special_type], :id field-id)]))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Field [{field-id :id} {:table_id table-id}]]
[((user->client :crowberto) :put 400 (str "field/" field-id) {:special_type :timestamp_seconds})
(db/sel :one :field [Field :special_type], :id field-id)]))
(defn- field->field-values
......
......@@ -30,11 +30,11 @@
(expect
[{:success true}
nil]
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Field [{field-id :id} {:table_id table-id}]
(tu/with-temp ForeignKey [{:keys [id]} {:destination_id field-id
:origin_id field-id
:relationship "whoot"}]
[((user->client :crowberto) :delete 200 (format "foreignkey/%d" id))
(db/sel :one ForeignKey :id id)])))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Field [{field-id :id} {:table_id table-id}]
ForeignKey [{:keys [id]} {:destination_id field-id
:origin_id field-id
:relationship "whoot"}]]
[((user->client :crowberto) :delete 200 (format "foreignkey/%d" id))
(db/sel :one ForeignKey :id id)]))
......@@ -81,13 +81,13 @@
:is_active true
:definition {:database 21
:query {:filter ["abc"]}}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{:keys [id]} {:db_id database-id}]
(metric-response ((user->client :crowberto) :post 200 "metric" {:name "A Metric"
:description "I did it!"
:table_id id
:definition {:database 21
:query {:filter ["abc"]}}})))))
(tu/with-temp* [Database [{database-id :id}]
Table [{:keys [id]} {:db_id database-id}]]
(metric-response ((user->client :crowberto) :post 200 "metric" {:name "A Metric"
:description "I did it!"
:table_id id
:definition {:database 21
:query {:filter ["abc"]}}}))))
;; ## PUT /api/metric
......@@ -128,20 +128,16 @@
:is_active true
:definition {:database 2
:query {:filter ["not" "the toucans you're looking for"]}}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [{:keys [id]} {:creator_id (user->id :rasta)
:table_id table-id
:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:definition {}}]
(metric-response ((user->client :crowberto) :put 200 (format "metric/%d" id) {:id id
:name "Costa Rica"
:description nil
:table_id 456
:revision_message "I got me some revisions"
:definition {:database 2
:query {:filter ["not" "the toucans you're looking for"]}}}))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [{:keys [id]} {:table_id table-id}]]
(metric-response ((user->client :crowberto) :put 200 (format "metric/%d" id) {:id id
:name "Costa Rica"
:description nil
:table_id 456
:revision_message "I got me some revisions"
:definition {:database 2
:query {:filter ["not" "the toucans you're looking for"]}}}))))
;; ## DELETE /api/metric/:id
......@@ -168,18 +164,11 @@
:updated_at true
:is_active false
:definition {}}]
(tu/with-temp Database [{database-id :id} {:name "Hillbilly"
:engine :yeehaw
:details {}
:is_sample false}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [{:keys [id]} {:creator_id (user->id :rasta)
:table_id table-id
:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:definition {}}]
[((user->client :crowberto) :delete 200 (format "metric/%d" id) :revision_message "carryon")
(metric-response (metric/retrieve-metric id))]))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [{:keys [id]} {:table_id table-id}]]
[((user->client :crowberto) :delete 200 (format "metric/%d" id) :revision_message "carryon")
(metric-response (metric/retrieve-metric id))]))
;; ## GET /api/metric/:id
......@@ -190,24 +179,19 @@
(expect
{:name "One Metric to rule them all, one metric to define them"
:description "One metric to bring them all, and in the DataModel bind them"
{:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:creator_id (user->id :crowberto)
:creator (user-details (fetch-user :crowberto))
:created_at true
:updated_at true
:is_active true
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Metric to rule them all, one metric to define them"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}]
(metric-response ((user->client :crowberto) :get 200 (format "metric/%d" id)))))))
:definition {}}
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id}]]
(metric-response ((user->client :crowberto) :get 200 (format "metric/%d" id)))))
;; ## GET /api/metric/:id/revisions
......@@ -233,31 +217,27 @@
:diff {:name {:after "b"}
:definition {:after {:filter ["AND" [">" 1 25]]}}}
:description nil}]
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Metric to rule them all, one metric to define them"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}]
(tu/with-temp Revision [_ {:model "Metric"
:model_id id
:user_id (user->id :rasta)
:object {:name "b"
:definition {:filter ["AND" [">" 1 25]]}}
:is_creation true
:is_reversion false}]
(tu/with-temp Revision [_ {:model "Metric"
:model_id id
:user_id (user->id :crowberto)
:object {:name "c"
:definition {:filter ["AND" [">" 1 25]]}}
:is_creation false
:is_reversion false
:message "updated"}]
(->> ((user->client :crowberto) :get 200 (format "metric/%d/revisions" id))
(mapv #(dissoc % :timestamp :id)))))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Metric to rule them all, one metric to define them"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}]
Revision [_ {:model "Metric"
:model_id id
:object {:name "b"
:definition {:filter ["AND" [">" 1 25]]}}
:is_creation true}]
Revision [_ {:model "Metric"
:model_id id
:user_id (user->id :crowberto)
:object {:name "c"
:definition {:filter ["AND" [">" 1 25]]}}
:message "updated"}]]
(doall (for [revision ((user->client :crowberto) :get 200 (format "metric/%d/revisions" id))]
(dissoc revision :timestamp :id)))))
;; ## POST /api/metric/:id/revert
......@@ -275,12 +255,11 @@
(expect
[;; the api response
[ ;; the api response
{:is_reversion true
:is_creation false
:message nil
:user (-> (user-details (fetch-user :crowberto))
(dissoc :email :date_joined :last_login :is_superuser :is_qbnewb))
:user (dissoc (user-details (fetch-user :crowberto)) :email :date_joined :last_login :is_superuser :is_qbnewb)
:diff {:name {:before "Changed Metric Name"
:after "One Metric to rule them all, one metric to define them"}}
:description "renamed this Metric from \"Changed Metric Name\" to \"One Metric to rule them all, one metric to define them\"."}
......@@ -288,65 +267,57 @@
[{:is_reversion true
:is_creation false
:message nil
:user (-> (user-details (fetch-user :crowberto))
(dissoc :email :date_joined :last_login :is_superuser :is_qbnewb))
:user (dissoc (user-details (fetch-user :crowberto)) :email :date_joined :last_login :is_superuser :is_qbnewb)
:diff {:name {:before "Changed Metric Name"
:after "One Metric to rule them all, one metric to define them"}}
:description "renamed this Metric from \"Changed Metric Name\" to \"One Metric to rule them all, one metric to define them\"."}
{:is_reversion false
:is_creation false
:message "updated"
:user (-> (user-details (fetch-user :crowberto))
(dissoc :email :date_joined :last_login :is_superuser :is_qbnewb))
:user (dissoc (user-details (fetch-user :crowberto)) :email :date_joined :last_login :is_superuser :is_qbnewb)
:diff {:name {:after "Changed Metric Name"
:before "One Metric to rule them all, one metric to define them"}}
:description "renamed this Metric from \"One Metric to rule them all, one metric to define them\" to \"Changed Metric Name\"."}
{:is_reversion false
:is_creation true
:message nil
:user (-> (user-details (fetch-user :rasta))
(dissoc :email :date_joined :last_login :is_superuser :is_qbnewb))
:user (dissoc (user-details (fetch-user :rasta)) :email :date_joined :last_login :is_superuser :is_qbnewb)
:diff {:name {:after "One Metric to rule them all, one metric to define them"}
:description {:after "One metric to bring them all, and in the DataModel bind them"}
:definition {:after {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}}
:description nil}]]
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Metric to rule them all, one metric to define them"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:creator_id (user->id :crowberto)
:table_id table-id
:name "Reverted Metric Name"
:description nil
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}}]
(tu/with-temp Revision [{revision-id :id} {:model "Metric"
:model_id id
:user_id (user->id :rasta)
:object {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Metric to rule them all, one metric to define them"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
:is_creation true
:is_reversion false}]
(tu/with-temp Revision [_ {:model "Metric"
:model_id id
:user_id (user->id :crowberto)
:object {:creator_id (user->id :crowberto)
:table_id table-id
:name "Changed Metric Name"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
:is_creation false
:is_reversion false
:message "updated"}]
[(-> ((user->client :crowberto) :post 200 (format "metric/%d/revert" id) {:revision_id revision-id})
(dissoc :id :timestamp))
(->> ((user->client :crowberto) :get 200 (format "metric/%d/revisions" id))
(mapv #(dissoc % :timestamp :id)))]))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Metric to rule them all, one metric to define them"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:creator_id (user->id :crowberto)
:table_id table-id
:name "Reverted Metric Name"
:description nil
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}}]
Revision [{revision-id :id} {:model "Metric"
:model_id id
:object {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Metric to rule them all, one metric to define them"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
:is_creation true}]
Revision [_ {:model "Metric"
:model_id id
:user_id (user->id :crowberto)
:object {:creator_id (user->id :crowberto)
:table_id table-id
:name "Changed Metric Name"
:description "One metric to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
:message "updated"}]]
[(dissoc ((user->client :crowberto) :post 200 (format "metric/%d/revert" id) {:revision_id revision-id}) :id :timestamp)
(doall (for [revision ((user->client :crowberto) :get 200 (format "metric/%d/revisions" id))]
(dissoc revision :timestamp :id)))]))
......@@ -9,7 +9,7 @@
[revision-test :refer [with-fake-card]])
[metabase.test.data :refer :all]
[metabase.test.data.users :refer :all]
[metabase.test.util :refer [expect-eval-actual-first with-temp random-name]]))
[metabase.test.util :refer [expect-eval-actual-first random-name]]))
(def ^:private rasta-revision-info
(delay {:id (user->id :rasta) :common_name "Rasta Toucan", :first_name "Rasta", :last_name "Toucan"}))
......
......@@ -81,13 +81,13 @@
:is_active true
:definition {:database 21
:query {:filter ["abc"]}}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{:keys [id]} {:db_id database-id}]
(segment-response ((user->client :crowberto) :post 200 "segment" {:name "A Segment"
:description "I did it!"
:table_id id
:definition {:database 21
:query {:filter ["abc"]}}})))))
(tu/with-temp* [Database [{database-id :id}]
Table [{:keys [id]} {:db_id database-id}]]
(segment-response ((user->client :crowberto) :post 200 "segment" {:name "A Segment"
:description "I did it!"
:table_id id
:definition {:database 21
:query {:filter ["abc"]}}}))))
;; ## PUT /api/segment
......@@ -128,20 +128,16 @@
:is_active true
:definition {:database 2
:query {:filter ["not" "the toucans you're looking for"]}}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Segment [{:keys [id]} {:creator_id (user->id :rasta)
:table_id table-id
:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:definition {}}]
(segment-response ((user->client :crowberto) :put 200 (format "segment/%d" id) {:id id
:name "Costa Rica"
:description nil
:table_id 456
:revision_message "I got me some revisions"
:definition {:database 2
:query {:filter ["not" "the toucans you're looking for"]}}}))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Segment [{:keys [id]} {:table_id table-id}]]
(segment-response ((user->client :crowberto) :put 200 (format "segment/%d" id) {:id id
:name "Costa Rica"
:description nil
:table_id 456
:revision_message "I got me some revisions"
:definition {:database 2
:query {:filter ["not" "the toucans you're looking for"]}}}))))
;; ## DELETE /api/segment/:id
......@@ -168,15 +164,11 @@
:updated_at true
:is_active false
:definition {}}]
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Segment [{:keys [id]} {:creator_id (user->id :rasta)
:table_id table-id
:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:definition {}}]
[((user->client :crowberto) :delete 200 (format "segment/%d" id) :revision_message "carryon")
(segment-response (segment/retrieve-segment id))]))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Segment [{:keys [id]} {:table_id table-id}]]
[((user->client :crowberto) :delete 200 (format "segment/%d" id) :revision_message "carryon")
(segment-response (segment/retrieve-segment id))]))
;; ## GET /api/segment/:id
......@@ -187,8 +179,8 @@
(expect
{:name "One Segment to rule them all, one segment to define them"
:description "One segment to bring them all, and in the DataModel bind them"
{:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:creator_id (user->id :crowberto)
:creator (user-details (fetch-user :crowberto))
:created_at true
......@@ -196,15 +188,13 @@
:is_active true
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Segment [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Segment to rule them all, one segment to define them"
:description "One segment to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}]
(segment-response ((user->client :crowberto) :get 200 (format "segment/%d" id)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Segment [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}]]
(segment-response ((user->client :crowberto) :get 200 (format "segment/%d" id)))))
;; ## GET /api/segment/:id/revisions
......@@ -230,31 +220,25 @@
:diff {:name {:after "b"}
:definition {:after {:filter ["AND" [">" 1 25]]}}}
:description nil}]
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Segment [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Segment to rule them all, one segment to define them"
:description "One segment to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}]
(tu/with-temp Revision [_ {:model "Segment"
:model_id id
:user_id (user->id :rasta)
:object {:name "b"
:definition {:filter ["AND" [">" 1 25]]}}
:is_creation true
:is_reversion false}]
(tu/with-temp Revision [_ {:model "Segment"
:model_id id
:user_id (user->id :crowberto)
:object {:name "c"
:definition {:filter ["AND" [">" 1 25]]}}
:is_creation false
:is_reversion false
:message "updated"}]
(->> ((user->client :crowberto) :get 200 (format "segment/%d/revisions" id))
(mapv #(dissoc % :timestamp :id)))))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Segment [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}]
Revision [_ {:model "Segment"
:model_id id
:object {:name "b"
:definition {:filter ["AND" [">" 1 25]]}}
:is_creation true}]
Revision [_ {:model "Segment"
:model_id id
:user_id (user->id :crowberto)
:object {:name "c"
:definition {:filter ["AND" [">" 1 25]]}}
:message "updated"}]]
(doall (for [revision ((user->client :crowberto) :get 200 (format "segment/%d/revisions" id))]
(dissoc revision :timestamp :id)))))
;; ## POST /api/segment/:id/revert
......@@ -272,7 +256,7 @@
(expect
[;; the api response
[ ;; the api response
{:is_reversion true
:is_creation false
:message nil
......@@ -308,42 +292,37 @@
:definition {:after {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}}
:description nil}]]
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Segment [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Segment to rule them all, one segment to define them"
:description "One segment to bring them all, and in the DataModel bind them"
:definition {:creator_id (user->id :crowberto)
:table_id table-id
:name "Reverted Segment Name"
:description nil
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}}]
(tu/with-temp Revision [{revision-id :id} {:model "Segment"
:model_id id
:user_id (user->id :rasta)
:object {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Segment to rule them all, one segment to define them"
:description "One segment to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
:is_creation true
:is_reversion false}]
(tu/with-temp Revision [_ {:model "Segment"
:model_id id
:user_id (user->id :crowberto)
:object {:creator_id (user->id :crowberto)
:table_id table-id
:name "Changed Segment Name"
:description "One segment to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
:is_creation false
:is_reversion false
:message "updated"}]
[(-> ((user->client :crowberto) :post 200 (format "segment/%d/revert" id) {:revision_id revision-id})
(dissoc :id :timestamp))
(->> ((user->client :crowberto) :get 200 (format "segment/%d/revisions" id))
(mapv #(dissoc % :timestamp :id)))]))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Segment [{:keys [id]} {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Segment to rule them all, one segment to define them"
:description "One segment to bring them all, and in the DataModel bind them"
:definition {:creator_id (user->id :crowberto)
:table_id table-id
:name "Reverted Segment Name"
:description nil
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}}]
Revision [{revision-id :id} {:model "Segment"
:model_id id
:object {:creator_id (user->id :crowberto)
:table_id table-id
:name "One Segment to rule them all, one segment to define them"
:description "One segment to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
:is_creation true}]
Revision [_ {:model "Segment"
:model_id id
:user_id (user->id :crowberto)
:object {:creator_id (user->id :crowberto)
:table_id table-id
:name "Changed Segment Name"
:description "One segment to bring them all, and in the DataModel bind them"
:definition {:database 123
:query {:filter ["In the Land of Metabase where the Datas lie"]}}}
:message "updated"}]]
[(dissoc ((user->client :crowberto) :post 200 (format "segment/%d/revert" id) {:revision_id revision-id}) :id :timestamp)
(doall (for [revision ((user->client :crowberto) :get 200 (format "segment/%d/revisions" id))]
(dissoc revision :timestamp :id)))]))
......@@ -30,21 +30,17 @@
:query {:aggregation ["rows"]
:filter ["AND" ["AND" ["=" 5 "abc"]] ["OR" ["AND" ["IS_NULL" 7]] [">" 4 1]]]
:breakout [17]}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Segment [{segment1 :id} {:creator_id (user->id :crowberto)
:table_id table-id
:name "Test Segment"
:definition {:filter ["AND" ["=" 5 "abc"]]}}]
(tu/with-temp Segment [{segment2 :id} {:creator_id (user->id :crowberto)
:table_id table-id
:name "Test Segment"
:definition {:filter ["AND" ["IS_NULL" 7]]}}]
(expand-macros {:database 1
:type :query
:query {:aggregation ["rows"]
:filter ["AND" ["SEGMENT" segment1] ["OR" ["SEGMENT" segment2] [">" 4 1]]]
:breakout [17]}}))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Segment [{segment-1-id :id} {:table_id table-id
:definition {:filter ["AND" ["=" 5 "abc"]]}}]
Segment [{segment-2-id :id} {:table_id table-id
:definition {:filter ["AND" ["IS_NULL" 7]]}}]]
(expand-macros {:database 1
:type :query
:query {:aggregation ["rows"]
:filter ["AND" ["SEGMENT" segment-1-id] ["OR" ["SEGMENT" segment-2-id] [">" 4 1]]]
:breakout [17]}})))
;; just a metric (w/out nested segments)
(expect
......@@ -54,19 +50,17 @@
:filter ["AND" ["AND" [">" 4 1]] ["AND" ["=" 5 "abc"]]]
:breakout [17]
:order_by [[1 "ASC"]]}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [{metric1 :id} {:creator_id (user->id :crowberto)
:table_id table-id
:name "Test Metric"
:definition {:aggregation ["count"]
:filter ["AND" ["=" 5 "abc"]]}}]
(expand-macros {:database 1
:type :query
:query {:aggregation ["METRIC" metric1]
:filter ["AND" [">" 4 1]]
:breakout [17]
:order_by [[1 "ASC"]]}})))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [{metric-1-id :id} {:table_id table-id
:definition {:aggregation ["count"]
:filter ["AND" ["=" 5 "abc"]]}}]]
(expand-macros {:database 1
:type :query
:query {:aggregation ["METRIC" metric-1-id]
:filter ["AND" [">" 4 1]]
:breakout [17]
:order_by [[1 "ASC"]]}})))
;; check that when the original filter is empty we simply use our metric filter definition instead
(expect
......@@ -76,19 +70,17 @@
:filter ["AND" ["=" 5 "abc"]]
:breakout [17]
:order_by [[1 "ASC"]]}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [{metric1 :id} {:creator_id (user->id :crowberto)
:table_id table-id
:name "Test Metric"
:definition {:aggregation ["count"]
:filter ["AND" ["=" 5 "abc"]]}}]
(expand-macros {:database 1
:type :query
:query {:aggregation ["METRIC" metric1]
:filter []
:breakout [17]
:order_by [[1 "ASC"]]}})))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [{metric-1-id :id} {:table_id table-id
:definition {:aggregation ["count"]
:filter ["AND" ["=" 5 "abc"]]}}]]
(expand-macros {:database 1
:type :query
:query {:aggregation ["METRIC" metric-1-id]
:filter []
:breakout [17]
:order_by [[1 "ASC"]]}})))
;; metric w/ no filter definition
(expect
......@@ -98,18 +90,16 @@
:filter ["AND" ["=" 5 "abc"]]
:breakout [17]
:order_by [[1 "ASC"]]}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [{metric1 :id} {:creator_id (user->id :crowberto)
:table_id table-id
:name "Test Metric"
:definition {:aggregation ["count"]}}]
(expand-macros {:database 1
:type :query
:query {:aggregation ["METRIC" metric1]
:filter ["AND" ["=" 5 "abc"]]
:breakout [17]
:order_by [[1 "ASC"]]}})))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [{metric-1-id :id} {:table_id table-id
:definition {:aggregation ["count"]}}]]
(expand-macros {:database 1
:type :query
:query {:aggregation ["METRIC" metric-1-id]
:filter ["AND" ["=" 5 "abc"]]
:breakout [17]
:order_by [[1 "ASC"]]}})))
;; a metric w/ nested segments
(expect
......@@ -119,24 +109,18 @@
:filter ["AND" ["AND" [">" 4 1] ["AND" ["IS_NULL" 7]]] ["AND" ["=" 5 "abc"] ["AND" ["BETWEEN" 9 0 25]]]]
:breakout [17]
:order_by [[1 "ASC"]]}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Segment [{segment1 :id} {:creator_id (user->id :crowberto)
:table_id table-id
:name "Test Segment"
:definition {:filter ["AND" ["BETWEEN" 9 0 25]]}}]
(tu/with-temp Segment [{segment2 :id} {:creator_id (user->id :crowberto)
:table_id table-id
:name "Test Segment"
:definition {:filter ["AND" ["IS_NULL" 7]]}}]
(tu/with-temp Metric [{metric1 :id} {:creator_id (user->id :crowberto)
:table_id table-id
:name "Test Metric"
:definition {:aggregation ["sum" 18]
:filter ["AND" ["=" 5 "abc"] ["SEGMENT" segment1]]}}]
(expand-macros {:database 1
:type :query
:query {:aggregation ["METRIC" metric1]
:filter ["AND" [">" 4 1] ["SEGMENT" segment2]]
:breakout [17]
:order_by [[1 "ASC"]]}})))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Segment [{segment-1-id :id} {:table_id table-id
:definition {:filter ["AND" ["BETWEEN" 9 0 25]]}}]
Segment [{segment-2-id :id} {:table_id table-id
:definition {:filter ["AND" ["IS_NULL" 7]]}}]
Metric [{metric-1-id :id} {:table_id table-id
:definition {:aggregation ["sum" 18]
:filter ["AND" ["=" 5 "abc"] ["SEGMENT" segment-1-id]]}}]]
(expand-macros {:database 1
:type :query
:query {:aggregation ["METRIC" metric-1-id]
:filter ["AND" [">" 4 1] ["SEGMENT" segment-2-id]]
:breakout [17]
:order_by [[1 "ASC"]]}})))
......@@ -82,7 +82,7 @@
:display_name "Id"
:base_type :IntegerField
:visibility_type :normal
:fk_target_field_id nil
:fk_target_field_id nil}
{:description nil
:special_type nil
:name "studio"
......@@ -95,7 +95,7 @@
:base_type :TextField
:visibility_type :normal
:fk_target_field_id nil}
{:description nil
{:description nil
:special_type nil
:name "title"
:active true
......@@ -196,12 +196,13 @@
:base_type :TextField
:visibility_type :normal
:fk_target_field_id nil}]}
(tu/with-temp Database [fake-db]
(tu/with-temp Table [fake-table {:name "movie"
:schema "default"
:db_id (:id fake-db)}]
(sync/sync-table! (SyncTestDriver.) fake-table)
(table-details (sel :one Table, :id (:id fake-table))))))
(tu/with-temp* [Database [fake-db]
Table [fake-table {:name "movie"
:schema "default"
:db_id (:id fake-db)}]]
(sync/sync-table! (SyncTestDriver.) fake-table)
(table-details (sel :one Table, :id (:id fake-table)))))
;; ## Test that we will remove field-values when they aren't appropriate
......@@ -209,16 +210,16 @@
(expect
[[1 2 3]
[1 2 3]]
(tu/with-temp Database [fake-db]
(tu/with-temp Table [fake-table {:db_id (:id fake-db), :name "movie", :schema "default"}]
(sync/sync-table! (SyncTestDriver.) fake-table)
(let [field-id (sel :one :id Field, :table_id (:id fake-table), :name "title")]
(tu/with-temp FieldValues [_ {:field_id field-id
:values "[1,2,3]"}]
(let [initial-field-values (sel :one :field [FieldValues :values], :field_id field-id)]
(sync/sync-table! (SyncTestDriver.) fake-table)
[initial-field-values
(sel :one :field [FieldValues :values], :field_id field-id)]))))))
(tu/with-temp* [Database [fake-db]
Table [fake-table {:db_id (:id fake-db), :name "movie", :schema "default"}]]
(sync/sync-table! (SyncTestDriver.) fake-table)
(let [field-id (sel :one :id Field, :table_id (:id fake-table), :name "title")]
(tu/with-temp FieldValues [_ {:field_id field-id
:values "[1,2,3]"}]
(let [initial-field-values (sel :one :field [FieldValues :values], :field_id field-id)]
(sync/sync-table! (SyncTestDriver.) fake-table)
[initial-field-values
(sel :one :field [FieldValues :values], :field_id field-id)])))))
;; ## Individual Helper Fns
......
......@@ -15,7 +15,7 @@
[table :refer [Table]]
[user :refer [User]])
[metabase.test.data :refer :all]
[metabase.test.util :refer [expect-eval-actual-first with-temp random-name]]
[metabase.test.util :refer [expect-eval-actual-first random-name]]
[metabase.test-setup :refer :all]))
......
......@@ -44,16 +44,14 @@
:dependent_on_id 18}
{:dependent_on_model "Segment"
:dependent_on_id 35}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [metric {:creator_id (user->id :rasta)
:table_id table-id
:name "Dependencies Test"
:definition {:aggregation ["count"]
:filter ["AND" ["SEGMENT" 18] ["SEGMENT" 35]]}}]
(process-dependencies-event {:topic :metric-create
:item metric})
(set (db/sel :many :fields [Dependency :dependent_on_model :dependent_on_id], :model "Metric", :model_id (:id metric)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [metric {:table_id table-id
:definition {:aggregation ["count"]
:filter ["AND" ["SEGMENT" 18] ["SEGMENT" 35]]}}]]
(process-dependencies-event {:topic :metric-create
:item metric})
(set (db/sel :many :fields [Dependency :dependent_on_model :dependent_on_id], :model "Metric", :model_id (:id metric)))))
;; `:card-update` event
(expect
......@@ -61,13 +59,11 @@
:dependent_on_id 18}
{:dependent_on_model "Segment"
:dependent_on_id 35}}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Metric [metric {:creator_id (user->id :rasta)
:table_id table-id
:name "Dependencies Test"
:definition {:aggregation ["count"]
:filter ["AND" ["SEGMENT" 18] ["SEGMENT" 35]]}}]
(process-dependencies-event {:topic :metric-update
:item metric})
(set (db/sel :many :fields [Dependency :dependent_on_model :dependent_on_id], :model "Metric", :model_id (:id metric)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Metric [metric {:table_id table-id
:definition {:aggregation ["count"]
:filter ["AND" ["SEGMENT" 18] ["SEGMENT" 35]]}}]]
(process-dependencies-event {:topic :metric-update
:item metric})
(set (db/sel :many :fields [Dependency :dependent_on_model :dependent_on_id], :model "Metric", :model_id (:id metric)))))
......@@ -4,7 +4,7 @@
[metabase.events.last-login :refer :all]
(metabase.models [user :refer [User]])
[metabase.test.data :refer :all]
[metabase.test.util :refer [expect-eval-actual-first with-temp random-name]]
[metabase.test.util :refer [expect-eval-actual-first random-name]]
[metabase.test-setup :refer :all]))
......
......@@ -14,9 +14,10 @@
[table :refer [Table]])
[metabase.test.data :refer :all]
[metabase.test.data.users :refer :all]
[metabase.test.util :refer [expect-eval-actual-first with-temp random-name]]
[metabase.test.util :refer [expect-eval-actual-first random-name]]
[metabase.test-setup :refer :all]
[metabase.test.util :as tu]))
[metabase.test.util :as tu]
[metabase.util :as u]))
(defn- create-test-card []
(let [rand-name (random-name)]
......@@ -183,153 +184,129 @@
(expect
{:model "Metric"
:user_id (user->id :rasta)
:object {:name "ABC"
:description "DEF"
:object {:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:is_active true
:creator_id (user->id :rasta)
:definition {:a "b"}}
:is_reversion false
:is_creation true
:message nil}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{:keys [id]} {:db_id database-id}]
(tu/with-temp Metric [metric {:creator_id (user->id :rasta)
:table_id id
:name "ABC"
:description "DEF"
:definition {:a "b"}}]
(process-revision-event {:topic :metric-create
:item metric})
(let [revision (db/sel :one :fields [Revision :model :user_id :object :is_reversion :is_creation :message], :model "Metric", :model_id (:id metric))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{:keys [id]} {:db_id database-id}]
Metric [metric {:table_id id, :definition {:a "b"}}]]
(process-revision-event {:topic :metric-create
:item metric})
(let [revision (db/sel :one :fields [Revision :model :user_id :object :is_reversion :is_creation :message], :model "Metric", :model_id (:id metric))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))
;; :metric-update
(expect
{:model "Metric"
:user_id (user->id :crowberto)
:object {:name "ABC"
:description "DEF"
:object {:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:is_active true
:creator_id (user->id :rasta)
:definition {:a "b"}}
:is_reversion false
:is_creation false
:message "updated"}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{:keys [id]} {:db_id database-id}]
(tu/with-temp Metric [metric {:creator_id (user->id :rasta)
:table_id id
:name "ABC"
:description "DEF"
:definition {:a "b"}}]
(process-revision-event {:topic :metric-update
:item (assoc metric
:actor_id (user->id :crowberto)
:revision_message "updated")})
(let [revision (db/sel :one :fields [Revision :model :user_id :object :is_reversion :is_creation :message], :model "Metric", :model_id (:id metric))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{:keys [id]} {:db_id database-id}]
Metric [metric {:table_id id, :definition {:a "b"}}]]
(process-revision-event {:topic :metric-update
:item (assoc metric
:actor_id (user->id :crowberto)
:revision_message "updated")})
(let [revision (db/sel :one :fields [Revision :model :user_id :object :is_reversion :is_creation :message], :model "Metric", :model_id (:id metric))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))
;; :metric-delete
(expect
{:model "Metric"
:user_id (user->id :rasta)
:object {:name "ABC"
:description "DEF"
:object {:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:is_active false
:creator_id (user->id :rasta)
:definition {:a "b"}}
:is_reversion false
:is_creation false
:message nil}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{:keys [id]} {:db_id database-id}]
(tu/with-temp Metric [metric {:creator_id (user->id :rasta)
:table_id id
:name "ABC"
:description "DEF"
:definition {:a "b"}
:is_active false}]
(process-revision-event {:topic :metric-delete
:item metric})
(let [revision (-> (db/sel :one Revision :model "Metric" :model_id (:id metric))
(select-keys [:model :user_id :object :is_reversion :is_creation :message]))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{:keys [id]} {:db_id database-id}]
Metric [metric {:table_id id, :definition {:a "b"}, :is_active false}]]
(process-revision-event {:topic :metric-delete
:item metric})
(let [revision (db/sel :one :fields [Revision :model :user_id :object :is_reversion :is_creation :message], :model "Metric", :model_id (:id metric))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))
;; :segment-create
(expect
{:model "Segment"
:user_id (user->id :rasta)
:object {:name "ABC"
:description "DEF"
:object {:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:is_active true
:creator_id (user->id :rasta)
:definition {:a "b"}}
:is_reversion false
:is_creation true
:message nil}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{:keys [id]} {:db_id database-id}]
(tu/with-temp Segment [segment {:creator_id (user->id :rasta)
:table_id id
:name "ABC"
:description "DEF"
:definition {:a "b"}}]
(process-revision-event {:topic :segment-create
:item segment})
(let [revision (-> (db/sel :one Revision :model "Segment" :model_id (:id segment))
(select-keys [:model :user_id :object :is_reversion :is_creation :message]))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{:keys [id]} {:db_id database-id}]
Segment [segment {:table_id id
:definition {:a "b"}}]]
(process-revision-event {:topic :segment-create
:item segment})
(let [revision (-> (db/sel :one Revision :model "Segment" :model_id (:id segment))
(select-keys [:model :user_id :object :is_reversion :is_creation :message]))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))
;; :segment-update
(expect
{:model "Segment"
:user_id (user->id :crowberto)
:object {:name "ABC"
:description "DEF"
:object {:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:is_active true
:creator_id (user->id :rasta)
:definition {:a "b"}}
:is_reversion false
:is_creation false
:message "updated"}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{:keys [id]} {:db_id database-id}]
(tu/with-temp Segment [segment {:creator_id (user->id :rasta)
:table_id id
:name "ABC"
:description "DEF"
:definition {:a "b"}}]
(process-revision-event {:topic :segment-update
:item (assoc segment
:actor_id (user->id :crowberto)
:revision_message "updated")})
(let [revision (-> (db/sel :one Revision :model "Segment" :model_id (:id segment))
(select-keys [:model :user_id :object :is_reversion :is_creation :message]))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{:keys [id]} {:db_id database-id}]
Segment [segment {:table_id id
:definition {:a "b"}}]]
(process-revision-event {:topic :segment-update
:item (assoc segment
:actor_id (user->id :crowberto)
:revision_message "updated")})
(update (db/sel :one :fields [Revision :model :user_id :object :is_reversion :is_creation :message], :model "Segment", :model_id (:id segment))
:object (u/rpartial dissoc :id :table_id))))
;; :segment-delete
(expect
{:model "Segment"
:user_id (user->id :rasta)
:object {:name "ABC"
:description "DEF"
:object {:name "Toucans in the rainforest"
:description "Lookin' for a blueberry"
:is_active false
:creator_id (user->id :rasta)
:definition {:a "b"}}
:is_reversion false
:is_creation false
:message nil}
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{:keys [id]} {:db_id database-id}]
(tu/with-temp Segment [segment {:creator_id (user->id :rasta)
:table_id id
:name "ABC"
:description "DEF"
:definition {:a "b"}
:is_active false}]
(process-revision-event {:topic :segment-delete
:item segment})
(let [revision (-> (db/sel :one Revision :model "Segment" :model_id (:id segment))
(select-keys [:model :user_id :object :is_reversion :is_creation :message]))]
(assoc revision :object (dissoc (:object revision) :id :table_id)))))))
(tu/with-temp* [Database [{database-id :id}]
Table [{:keys [id]} {:db_id database-id}]
Segment [segment {:table_id id
:definition {:a "b"}
:is_active false}]]
(process-revision-event {:topic :segment-delete
:item segment})
(update (db/sel :one :fields [Revision :model :user_id :object :is_reversion :is_creation :message], :model "Segment", :model_id (:id segment))
:object (u/rpartial dissoc :id :table_id))))
......@@ -6,7 +6,7 @@
(metabase.models [user :refer [User]]
[view-log :refer [ViewLog]])
[metabase.test.data :refer :all]
[metabase.test.util :refer [expect-eval-actual-first with-temp random-name]]
[metabase.test.util :refer [expect-eval-actual-first random-name]]
[metabase.test-setup :refer :all]))
......
......@@ -33,11 +33,10 @@
:col nil
:row nil
:series []}
(tu/with-temp Dashboard [{dashboard-id :id}]
(tu/with-temp Card [{card-id :id}]
(tu/with-temp DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id
:card_id card-id}]
(remove-ids-and-timestamps (retrieve-dashboard-card dashcard-id))))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Card [{card-id :id}]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]]
(remove-ids-and-timestamps (retrieve-dashboard-card dashcard-id))))
;; retrieve-dashboard-card
;; dashcard w/ additional series
......@@ -56,14 +55,14 @@
:display :table
:dataset_query {}
:visualization_settings {}}]}
(tu/with-temp Dashboard [{dashboard-id :id}]
(tu/with-temp Card [{card-id :id}]
(tu/with-temp Card [{series-id-1 :id} {:name "Additional Series Card 1"}]
(tu/with-temp Card [{series-id-2 :id} {:name "Additional Series Card 2"}]
(tu/with-temp DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-1, :position 0}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-2, :position 1}]
(remove-ids-and-timestamps (retrieve-dashboard-card dashcard-id))))))))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Card [{card-id :id}]
Card [{series-id-1 :id} {:name "Additional Series Card 1"}]
Card [{series-id-2 :id} {:name "Additional Series Card 2"}]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-1, :position 0}]
DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-2, :position 1}]]
(remove-ids-and-timestamps (retrieve-dashboard-card dashcard-id))))
;; update-dashboard-card-series
......@@ -114,19 +113,19 @@
:display :table
:dataset_query {}
:visualization_settings {}}]}]
(tu/with-temp Dashboard [{dashboard-id :id}]
(tu/with-temp Card [{card-id :id} {:name "Test Card"}]
(let [dashboard-card (create-dashboard-card {:creator_id (user->id :rasta)
:dashboard_id dashboard-id
:card_id card-id
:sizeX 4
:sizeY 3
:row 1
:col 1
:series [card-id]})]
;; first result is return value from function, second is to validate db captured everything
[(remove-ids-and-timestamps dashboard-card)
(remove-ids-and-timestamps (retrieve-dashboard-card (:id dashboard-card)))]))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Card [{card-id :id} {:name "Test Card"}]]
(let [dashboard-card (create-dashboard-card {:creator_id (user->id :rasta)
:dashboard_id dashboard-id
:card_id card-id
:sizeX 4
:sizeY 3
:row 1
:col 1
:series [card-id]})]
;; first result is return value from function, second is to validate db captured everything
[(remove-ids-and-timestamps dashboard-card)
(remove-ids-and-timestamps (retrieve-dashboard-card (:id dashboard-card)))])))
;; update-dashboard-card
;; basic update. we are testing multiple things here
......@@ -168,22 +167,22 @@
:display :table
:dataset_query {}
:visualization_settings {}}]}]
(tu/with-temp Dashboard [{dashboard-id :id}]
(tu/with-temp Card [{card-id :id}]
(tu/with-temp DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
(tu/with-temp Card [{card-id-1 :id} {:name "Test Card 1"}]
(tu/with-temp Card [{card-id-2 :id} {:name "Test Card 2"}]
;; first result is the unmodified dashcard
;; second is the return value from the update call
;; third is to validate db captured everything
[(remove-ids-and-timestamps (retrieve-dashboard-card dashcard-id))
(remove-ids-and-timestamps (update-dashboard-card {:id dashcard-id
:actor_id (user->id :rasta)
:dashboard_id nil
:card_id nil
:sizeX 4
:sizeY 3
:row 1
:col 1
:series [card-id-2 card-id-1]}))
(remove-ids-and-timestamps (retrieve-dashboard-card dashcard-id))]))))))
(tu/with-temp* [Dashboard [{dashboard-id :id}]
Card [{card-id :id}]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
Card [{card-id-1 :id} {:name "Test Card 1"}]
Card [{card-id-2 :id} {:name "Test Card 2"}]]
;; first result is the unmodified dashcard
;; second is the return value from the update call
;; third is to validate db captured everything
[(remove-ids-and-timestamps (retrieve-dashboard-card dashcard-id))
(remove-ids-and-timestamps (update-dashboard-card {:id dashcard-id
:actor_id (user->id :rasta)
:dashboard_id nil
:card_id nil
:sizeX 4
:sizeY 3
:row 1
:col 1
:series [card-id-2 card-id-1]}))
(remove-ids-and-timestamps (retrieve-dashboard-card dashcard-id))]))
......@@ -24,18 +24,18 @@
:id true
:card_id true
:series true}]}
(tu/with-temp Dashboard [{dashboard-id :id :as dashboard} {:name "Test Dashboard"}]
(tu/with-temp Card [{card-id :id}]
(tu/with-temp Card [{series-id-1 :id}]
(tu/with-temp Card [{series-id-2 :id}]
(tu/with-temp DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-1, :position 0}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-2, :position 1}]
(update (serialize-dashboard dashboard) :cards (fn [[{:keys [id card_id series], :as card}]]
[(assoc card
:id (= dashcard-id id)
:card_id (= card-id card_id)
:series (= [series-id-1 series-id-2] series))]))))))))))
(tu/with-temp* [Dashboard [{dashboard-id :id :as dashboard} {:name "Test Dashboard"}]
Card [{card-id :id}]
Card [{series-id-1 :id}]
Card [{series-id-2 :id}]
DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id, :card_id card-id}]
DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-1, :position 0}]
DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-2, :position 1}]]
(update (serialize-dashboard dashboard) :cards (fn [[{:keys [id card_id series], :as card}]]
[(assoc card
:id (= dashcard-id id)
:card_id (= card-id card_id)
:series (= [series-id-1 series-id-2] series))]))))
;; diff-dashboards-str
......@@ -134,29 +134,29 @@
:id false
:card_id true
:series true}]}]
(tu/with-temp Dashboard [{dashboard-id :id, :as dashboard} {:name "Test Dashboard"}]
(tu/with-temp Card [{card-id :id}]
(tu/with-temp Card [{series-id-1 :id}]
(tu/with-temp Card [{series-id-2 :id}]
(tu/with-temp DashboardCard [{dashcard-id :id :as dashboard-card} {:dashboard_id dashboard-id, :card_id card-id}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-1, :position 0}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-2, :position 1}]
(let [check-ids (fn [[{:keys [id card_id series] :as card}]]
[(assoc card
:id (= dashcard-id id)
:card_id (= card-id card_id)
:series (= [series-id-1 series-id-2] series))])
serialized-dashboard (serialize-dashboard dashboard)]
;; delete the dashcard and modify the dash attributes
(dashboard-card/delete-dashboard-card dashboard-card (user->id :rasta))
(db/upd Dashboard dashboard-id
:name "Revert Test"
:description "something")
;; capture our updated dashboard state
(let [serialized-dashboard2 (serialize-dashboard (Dashboard dashboard-id))]
;; now do the reversion
(revert-dashboard dashboard-id (user->id :crowberto) serialized-dashboard)
;; final output is original-state, updated-state, reverted-state
[(update serialized-dashboard :cards check-ids)
serialized-dashboard2
(update (serialize-dashboard (Dashboard dashboard-id)) :cards check-ids)]))))))))))
(tu/with-temp* [Dashboard [{dashboard-id :id, :as dashboard} {:name "Test Dashboard"}]
Card [{card-id :id}]
Card [{series-id-1 :id}]
Card [{series-id-2 :id}]
DashboardCard [{dashcard-id :id :as dashboard-card} {:dashboard_id dashboard-id, :card_id card-id}]
DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-1, :position 0}]
DashboardCardSeries [_ {:dashboardcard_id dashcard-id, :card_id series-id-2, :position 1}]]
(let [check-ids (fn [[{:keys [id card_id series] :as card}]]
[(assoc card
:id (= dashcard-id id)
:card_id (= card-id card_id)
:series (= [series-id-1 series-id-2] series))])
serialized-dashboard (serialize-dashboard dashboard)]
;; delete the dashcard and modify the dash attributes
(dashboard-card/delete-dashboard-card dashboard-card (user->id :rasta))
(db/upd Dashboard dashboard-id
:name "Revert Test"
:description "something")
;; capture our updated dashboard state
(let [serialized-dashboard2 (serialize-dashboard (Dashboard dashboard-id))]
;; now do the reversion
(revert-dashboard dashboard-id (user->id :crowberto) serialized-dashboard)
;; final output is original-state, updated-state, reverted-state
[(update serialized-dashboard :cards check-ids)
serialized-dashboard2
(update (serialize-dashboard (Dashboard dashboard-id)) :cards check-ids)]))))
......@@ -46,17 +46,17 @@
:model_id 4
:dependent_on_model "foobar"
:dependent_on_id 13}}
(tu/with-temp Dependency [_ {:model "Mock"
:model_id 4
:dependent_on_model "test"
:dependent_on_id 1
:created_at (u/new-sql-timestamp)}]
(tu/with-temp Dependency [_ {:model "Mock"
(tu/with-temp* [Dependency [_ {:model "Mock"
:model_id 4
:dependent_on_model "test"
:dependent_on_id 1
:created_at (u/new-sql-timestamp)}]
Dependency [_ {:model "Mock"
:model_id 4
:dependent_on_model "foobar"
:dependent_on_id 13
:created_at (u/new-sql-timestamp)}]
(format-dependencies (retrieve-dependencies Mock 4)))))
:created_at (u/new-sql-timestamp)}]]
(format-dependencies (retrieve-dependencies Mock 4))))
;; update-dependencies
......
......@@ -47,11 +47,10 @@
[[1,2,3]
{:status 204, :body nil}
nil]
(tu/with-temp Database [{database-id :id}]
(tu/with-temp Table [{table-id :id} {:db_id database-id}]
(tu/with-temp Field [{field-id :id} {:table_id table-id}]
(tu/with-temp FieldValues [_ {:field_id field-id
:values "[1,2,3]"}]
[(db/sel :one :field [FieldValues :values] :field_id field-id)
(clear-field-values field-id)
(db/sel :one :field [FieldValues :values] :field_id field-id)])))))
(tu/with-temp* [Database [{database-id :id}]
Table [{table-id :id} {:db_id database-id}]
Field [{field-id :id} {:table_id table-id}]
FieldValues [_ {:field_id field-id, :values "[1,2,3]"}]]
[(db/sel :one :field [FieldValues :values] :field_id field-id)
(clear-field-values field-id)
(db/sel :one :field [FieldValues :values] :field_id field-id)]))
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