mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 19:44:09 +00:00
Sync hierarchy updates (#2087)
* Add parent sync orchestration * Pass sync object to dependents
This commit is contained in:
@@ -7,7 +7,7 @@ class SyncTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "runs successful sync" do
|
||||
@sync.syncable.expects(:sync_data).with(start_date: @sync.start_date).once
|
||||
@sync.syncable.expects(:sync_data).with(@sync, start_date: @sync.start_date).once
|
||||
|
||||
assert_equal "pending", @sync.status
|
||||
|
||||
@@ -20,7 +20,7 @@ class SyncTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "handles sync errors" do
|
||||
@sync.syncable.expects(:sync_data).with(start_date: @sync.start_date).raises(StandardError.new("test sync error"))
|
||||
@sync.syncable.expects(:sync_data).with(@sync, start_date: @sync.start_date).raises(StandardError.new("test sync error"))
|
||||
|
||||
assert_equal "pending", @sync.status
|
||||
previously_ran_at = @sync.last_ran_at
|
||||
@@ -31,4 +31,30 @@ class SyncTest < ActiveSupport::TestCase
|
||||
assert_equal "failed", @sync.status
|
||||
assert_equal "test sync error", @sync.error
|
||||
end
|
||||
|
||||
test "runs sync with child syncs" do
|
||||
family = families(:dylan_family)
|
||||
|
||||
parent = Sync.create!(syncable: family)
|
||||
child1 = Sync.create!(syncable: family.accounts.first, parent: parent)
|
||||
child2 = Sync.create!(syncable: family.accounts.last, parent: parent)
|
||||
|
||||
parent.syncable.expects(:sync_data).returns([]).once
|
||||
child1.syncable.expects(:sync_data).returns([]).once
|
||||
child2.syncable.expects(:sync_data).returns([]).once
|
||||
|
||||
parent.perform # no-op
|
||||
|
||||
assert_equal "syncing", parent.status
|
||||
assert_equal "pending", child1.status
|
||||
assert_equal "pending", child2.status
|
||||
|
||||
child1.perform
|
||||
assert_equal "completed", child1.status
|
||||
assert_equal "syncing", parent.status
|
||||
|
||||
child2.perform
|
||||
assert_equal "completed", child2.status
|
||||
assert_equal "completed", parent.status
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user