From 7e4d3e0a6070bbce5923548b2e92b8df58f1dbbd Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 12 Dec 2025 16:05:39 +0100 Subject: [PATCH] refactor: use sql_sandbox config instead of env for sync/async - Replace Application.get_env(:mv, :env) with :sql_sandbox config - Remove redundant :env config from test.exs - More explicit and less error-prone for test environment detection --- config/test.exs | 4 +--- lib/membership/member.ex | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/config/test.exs b/config/test.exs index 47e8a8d..326694e 100644 --- a/config/test.exs +++ b/config/test.exs @@ -47,7 +47,5 @@ config :mv, :session_identifier, :unsafe config :mv, :require_token_presence_for_authentication, false # Enable SQL Sandbox for async LiveView tests +# This flag controls sync vs async behavior in CycleGenerator after_action hooks config :mv, :sql_sandbox, true - -# Mark test environment for conditional behavior (e.g., sync vs async operations) -config :mv, :env, :test diff --git a/lib/membership/member.ex b/lib/membership/member.ex index d37abbc..702b436 100644 --- a/lib/membership/member.ex +++ b/lib/membership/member.ex @@ -112,7 +112,7 @@ defmodule Mv.Membership.Member do # but in test environment it runs synchronously for DB sandbox compatibility change after_action(fn _changeset, member, _context -> if member.membership_fee_type_id && member.join_date do - if Application.get_env(:mv, :env) == :test do + if Application.get_env(:mv, :sql_sandbox, false) do # Run synchronously in test environment for DB sandbox compatibility Mv.MembershipFees.CycleGenerator.generate_cycles_for_member(member.id) else @@ -180,7 +180,7 @@ defmodule Mv.Membership.Member do Ash.Changeset.changing_attribute?(changeset, :membership_fee_type_id) if fee_type_changed && member.membership_fee_type_id && member.join_date do - if Application.get_env(:mv, :env) == :test do + if Application.get_env(:mv, :sql_sandbox, false) do # Run synchronously in test environment for DB sandbox compatibility Mv.MembershipFees.CycleGenerator.generate_cycles_for_member(member.id) else