From 0d55c966b3bb6d28ef19486c04e37d96e0f6b248 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Fri, 14 Nov 2025 12:10:54 +0100 Subject: [PATCH] Fix: setting board entropy was changing the account entropy when not present --- app/controllers/boards/entropies_controller.rb | 2 +- test/controllers/boards/entropies_controller_test.rb | 8 +++++--- test/models/card/entropic_test.rb | 10 ++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/boards/entropies_controller.rb b/app/controllers/boards/entropies_controller.rb index e07272e9b..e42631eaf 100644 --- a/app/controllers/boards/entropies_controller.rb +++ b/app/controllers/boards/entropies_controller.rb @@ -4,7 +4,7 @@ class Boards::EntropiesController < ApplicationController before_action :ensure_permission_to_admin_board def update - @board.entropy.update!(entropy_params) + @board.update!(entropy_params) end private diff --git a/test/controllers/boards/entropies_controller_test.rb b/test/controllers/boards/entropies_controller_test.rb index 111fe1513..3d04f44dd 100644 --- a/test/controllers/boards/entropies_controller_test.rb +++ b/test/controllers/boards/entropies_controller_test.rb @@ -7,11 +7,13 @@ class Boards::EntropiesControllerTest < ActionDispatch::IntegrationTest end test "update" do - put board_entropy_path(@board, format: :turbo_stream), params: { board: { auto_postpone_period: 1.day } } + assert_no_difference -> { Account.sole.entropy.reload.auto_postpone_period } do + put board_entropy_path(@board, format: :turbo_stream), params: { board: { auto_postpone_period: 123.days } } - assert_equal 1.day, @board.entropy.reload.auto_postpone_period + assert_equal 123.days, @board.entropy.reload.auto_postpone_period - assert_turbo_stream action: :replace, target: dom_id(@board, :entropy) + assert_turbo_stream action: :replace, target: dom_id(@board, :entropy) + end end test "update requires board admin permission" do diff --git a/test/models/card/entropic_test.rb b/test/models/card/entropic_test.rb index 524efc340..c39d1df7f 100644 --- a/test/models/card/entropic_test.rb +++ b/test/models/card/entropic_test.rb @@ -22,6 +22,16 @@ class Card::EntropicTest < ActiveSupport::TestCase assert_equal (123 - 2).days.from_now, cards(:layout).entropy.auto_clean_at end + test "setting auto_postpone_period in the board without entropy will create it, without affecting the account entropy" do + account_entropy = entropies("37s_account") + original_period = account_entropy.auto_postpone_period + + entropies(:writebook_board).destroy + boards(:writebook).update! auto_postpone_period: 999.days + + assert_equal original_period, account_entropy.reload.auto_postpone_period + end + test "auto postpone all due using the default account entropy" do entropies(:writebook_board).destroy