Fix: setting board entropy was changing the account entropy when not present

This commit is contained in:
Jorge Manrubia
2025-11-14 12:10:54 +01:00
parent 73b739f128
commit 0d55c966b3
3 changed files with 16 additions and 4 deletions
@@ -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
@@ -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
+10
View File
@@ -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