mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-18 20:59:39 +02:00
Fix attribute locking namespace conflict, duplicate syncs
This commit is contained in:
parent
ab5bce3462
commit
137219c121
11 changed files with 87 additions and 28 deletions
|
@ -20,7 +20,7 @@ class AutoSyncTest < ActionDispatch::IntegrationTest
|
|||
travel_to Time.current.beginning_of_day
|
||||
last_sync_datetime = 1.hour.ago
|
||||
|
||||
Sync.create!(syncable: @family, created_at: last_sync_datetime)
|
||||
Sync.create!(syncable: @family, created_at: last_sync_datetime, status: "completed")
|
||||
|
||||
assert_difference "Sync.count", 1 do
|
||||
get root_path
|
||||
|
@ -32,7 +32,7 @@ class AutoSyncTest < ActionDispatch::IntegrationTest
|
|||
|
||||
last_created_sync_at = 23.hours.ago
|
||||
|
||||
Sync.create!(syncable: @family, created_at: last_created_sync_at)
|
||||
Sync.create!(syncable: @family, created_at: last_created_sync_at, status: "completed")
|
||||
|
||||
assert_no_difference "Sync.count" do
|
||||
get root_path
|
||||
|
|
|
@ -18,11 +18,19 @@ module SyncableInterfaceTest
|
|||
@syncable.perform_sync(mock_sync)
|
||||
end
|
||||
|
||||
test "any prior syncs for the same syncable entity are marked stale when new sync is requested" do
|
||||
stale_sync = @syncable.sync_later
|
||||
new_sync = @syncable.sync_later
|
||||
test "second sync request widens existing pending window" do
|
||||
later_start = 2.days.ago.to_date
|
||||
first_sync = @syncable.sync_later(window_start_date: later_start, window_end_date: later_start)
|
||||
|
||||
assert_equal "stale", stale_sync.reload.status
|
||||
assert_equal "pending", new_sync.reload.status
|
||||
earlier_start = 5.days.ago.to_date
|
||||
wider_end = Date.current
|
||||
|
||||
assert_no_difference "@syncable.syncs.count" do
|
||||
@syncable.sync_later(window_start_date: earlier_start, window_end_date: wider_end)
|
||||
end
|
||||
|
||||
first_sync.reload
|
||||
assert_equal earlier_start, first_sync.window_start_date
|
||||
assert_equal wider_end, first_sync.window_end_date
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ class Rule::ActionTest < ActiveSupport::TestCase
|
|||
|
||||
test "set_transaction_category" do
|
||||
# Does not modify transactions that are locked (user edited them)
|
||||
@txn1.lock!(:category_id)
|
||||
@txn1.lock_attr!(:category_id)
|
||||
|
||||
action = Rule::Action.new(
|
||||
rule: @transaction_rule,
|
||||
|
@ -42,7 +42,7 @@ class Rule::ActionTest < ActiveSupport::TestCase
|
|||
tag = @family.tags.create!(name: "Rule test tag")
|
||||
|
||||
# Does not modify transactions that are locked (user edited them)
|
||||
@txn1.lock!(:tag_ids)
|
||||
@txn1.lock_attr!(:tag_ids)
|
||||
|
||||
action = Rule::Action.new(
|
||||
rule: @transaction_rule,
|
||||
|
@ -63,7 +63,7 @@ class Rule::ActionTest < ActiveSupport::TestCase
|
|||
merchant = @family.merchants.create!(name: "Rule test merchant")
|
||||
|
||||
# Does not modify transactions that are locked (user edited them)
|
||||
@txn1.lock!(:merchant_id)
|
||||
@txn1.lock_attr!(:merchant_id)
|
||||
|
||||
action = Rule::Action.new(
|
||||
rule: @transaction_rule,
|
||||
|
@ -84,7 +84,7 @@ class Rule::ActionTest < ActiveSupport::TestCase
|
|||
new_name = "Renamed Transaction"
|
||||
|
||||
# Does not modify transactions that are locked (user edited them)
|
||||
@txn1.lock!(:name)
|
||||
@txn1.lock_attr!(:name)
|
||||
|
||||
action = Rule::Action.new(
|
||||
rule: @transaction_rule,
|
||||
|
|
|
@ -188,4 +188,24 @@ class SyncTest < ActiveSupport::TestCase
|
|||
assert_equal "stale", stale_pending.reload.status
|
||||
assert_equal "stale", stale_syncing.reload.status
|
||||
end
|
||||
|
||||
test "expand_window_if_needed widens start and end dates on a pending sync" do
|
||||
initial_start = 1.day.ago.to_date
|
||||
initial_end = 1.day.ago.to_date
|
||||
|
||||
sync = Sync.create!(
|
||||
syncable: accounts(:depository),
|
||||
window_start_date: initial_start,
|
||||
window_end_date: initial_end
|
||||
)
|
||||
|
||||
new_start = 5.days.ago.to_date
|
||||
new_end = Date.current
|
||||
|
||||
sync.expand_window_if_needed(new_start, new_end)
|
||||
sync.reload
|
||||
|
||||
assert_equal new_start, sync.window_start_date
|
||||
assert_equal new_end, sync.window_end_date
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue