@@ -213,4 +213,59 @@ class ShopkeeperTest < ActiveSupport::TestCase
213213 shopkeeper . destroy
214214 end
215215 end
216+
217+ test "should nullify item_tags references on destroy" do
218+ shopkeeper = shopkeepers ( :one )
219+ shopkeeper . create_default_account
220+ other_shopkeeper = shopkeepers ( :two )
221+ other_shopkeeper . create_default_account
222+ other_account = other_shopkeeper . accounts . first
223+
224+ item_tag = ActsAsTenant . with_tenant ( other_account ) do
225+ shop = other_account . shops . create! ( name : "Other Shop" , created_by : other_shopkeeper )
226+ shop . item_tags . create! (
227+ queue_number : "A1" ,
228+ account : other_account ,
229+ completed_by : shopkeeper
230+ )
231+ end
232+
233+ ActsAsTenant . without_tenant do
234+ shopkeeper . destroy
235+ end
236+
237+ ActsAsTenant . with_tenant ( other_account ) do
238+ item_tag . reload
239+ assert_nil item_tag . completed_by_id
240+ assert ItemTag . exists? ( item_tag . id )
241+ end
242+ end
243+
244+ test "should successfully destroy shopkeeper with item_tags in other accounts" do
245+ shopkeeper = shopkeepers ( :one )
246+ shopkeeper . create_default_account
247+ other_shopkeeper = shopkeepers ( :two )
248+ other_shopkeeper . create_default_account
249+ other_account = other_shopkeeper . accounts . first
250+
251+ item_tag = ActsAsTenant . with_tenant ( other_account ) do
252+ shop = other_account . shops . create! ( name : "Other Shop" , created_by : other_shopkeeper )
253+ shop . item_tags . create! (
254+ queue_number : "B1" ,
255+ account : other_account ,
256+ created_by : shopkeeper
257+ )
258+ end
259+
260+ ActsAsTenant . without_tenant do
261+ assert_nothing_raised do
262+ shopkeeper . destroy!
263+ end
264+ end
265+
266+ ActsAsTenant . with_tenant ( other_account ) do
267+ item_tag . reload
268+ assert_nil item_tag . created_by_id
269+ end
270+ end
216271end
0 commit comments