mirror of
https://github.com/we-promise/sure.git
synced 2026-04-24 22:44:14 +00:00
Add protection indicator to entries and unlock functionality (#765)
* feat: add protection indicator to entries and unlock functionality - Introduced protection indicator component rendering on hover and in detail views. - Added support to unlock entries, clearing protection flags (`user_modified`, `import_locked`, and locked attributes). - Updated routes, controllers, and models to enable unlock functionality for trades and transactions. - Refactored views and localized content to support the new feature. - Added relevant tests for unlocking functionality and attribute handling. * feat: improve sync protection and turbo stream updates for entries - Added tests for turbo stream updates reflecting protection indicators. - Ensured user-modified entries lock specific attributes to prevent overwrites. - Updated controllers to mark entries as user-modified and reload for accurate rendering. - Enhanced protection indicator rendering using turbo frames. - Applied consistent lock state handling across trades and transactions. * Address PR review comments for protection indicator --------- Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
This commit is contained in:
@@ -283,4 +283,49 @@ end
|
||||
assert_redirected_to transactions_path
|
||||
assert_equal "An unexpected error occurred while creating the recurring transaction", flash[:alert]
|
||||
end
|
||||
|
||||
test "unlock clears protection flags on user-modified entry" do
|
||||
family = families(:empty)
|
||||
sign_in users(:empty)
|
||||
account = family.accounts.create! name: "Test", balance: 0, currency: "USD", accountable: Depository.new
|
||||
entry = create_transaction(account: account, amount: 100)
|
||||
transaction = entry.entryable
|
||||
|
||||
# Mark as protected with locked_attributes on both entry and entryable
|
||||
entry.update!(user_modified: true, locked_attributes: { "date" => Time.current.iso8601 })
|
||||
transaction.update!(locked_attributes: { "category_id" => Time.current.iso8601 })
|
||||
|
||||
assert entry.reload.protected_from_sync?
|
||||
|
||||
post unlock_transaction_path(transaction)
|
||||
|
||||
assert_redirected_to transactions_path
|
||||
assert_equal "Entry unlocked. It may be updated on next sync.", flash[:notice]
|
||||
|
||||
entry.reload
|
||||
assert_not entry.user_modified?
|
||||
assert_empty entry.locked_attributes, "Entry locked_attributes should be cleared"
|
||||
assert_empty entry.entryable.locked_attributes, "Transaction locked_attributes should be cleared"
|
||||
assert_not entry.protected_from_sync?
|
||||
end
|
||||
|
||||
test "unlock clears import_locked flag" do
|
||||
family = families(:empty)
|
||||
sign_in users(:empty)
|
||||
account = family.accounts.create! name: "Test", balance: 0, currency: "USD", accountable: Depository.new
|
||||
entry = create_transaction(account: account, amount: 100)
|
||||
transaction = entry.entryable
|
||||
|
||||
# Mark as import locked
|
||||
entry.update!(import_locked: true)
|
||||
|
||||
assert entry.reload.protected_from_sync?
|
||||
|
||||
post unlock_transaction_path(transaction)
|
||||
|
||||
assert_redirected_to transactions_path
|
||||
entry.reload
|
||||
assert_not entry.import_locked?
|
||||
assert_not entry.protected_from_sync?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user