(ns metabase.models.card-test
  (:require [expectations :refer :all]
            (metabase.api [card-test :refer [post-card]]
                          [dash-test :refer [create-dash]])
            [metabase.db :refer [ins]]
            (metabase.models [card :refer [Card]]
                             [dashboard-card :refer [DashboardCard]])
            [metabase.test.util :refer [random-name]]))

;; Check that the :dashboard_count delay returns the correct count of Dashboards a Card is in
(expect [0 1 2]
  (let [{card-id :id}       (post-card (random-name))
        get-dashboard-count (fn [] @(:dashboard_count (Card card-id)))]

    [(get-dashboard-count)
     (do (ins DashboardCard :card_id card-id, :dashboard_id (:id (create-dash (random-name))))
         (get-dashboard-count))
     (do (ins DashboardCard :card_id card-id, :dashboard_id (:id (create-dash (random-name))))
         (get-dashboard-count))]))

Add unit test for Card dashboard_count :sweat:
Add unit test for Card dashboard_count :sweat:

lukaswelte/metabase,dashkb/metabase,dashkb/metabase,dashkb/metabase,blueoceanideas/metabase,zoowii/metabase,blueoceanideas/metabase,zoowii/metabase,lukaswelte/metabase,Endika/metabase,lukaswelte/metabase,Endika/metabase,blueoceanideas/metabase,blueoceanideas/metabase,zoowii/metabase,jonasdiel/metabase-ptBR,lukaswelte/metabase,Endika/metabase,jonasdiel/metabase-ptBR,jonasdiel/metabase-ptBR,Endika/metabase,zoowii/metabase,jonasdiel/metabase-ptBR,Endika/metabase,blueoceanideas/metabase,jonasdiel/metabase-ptBR,lukaswelte/metabase,dashkb/metabase,dashkb/metabase,zoowii/metabase