Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Clean up sync logic (#871)

Zach Gollwitzer957584b69c78
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 94e9bbe3..a0576b3a 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -63,22 +63,11 @@ class AccountsController < ApplicationController
end
def sync
- if @account.can_sync?
+ unless @account.syncing?
@account.sync_later
- respond_to do |format|
- format.html { redirect_to account_path(@account), notice: t(".success") }
- format.turbo_stream do
- render turbo_stream: turbo_stream.append("notification-tray", partial: "shared/notification", locals: { type: "success", content: { body: t(".success") } })
- end
- end
- else
- respond_to do |format|
- format.html { redirect_to account_path(@account), notice: t(".cannot_sync") }
- format.turbo_stream do
- render turbo_stream: turbo_stream.append("notification-tray", partial: "shared/notification", locals: { type: "error", content: { body: t(".cannot_sync") } })
- end
- end
end
+
+ redirect_to account_path(@account), notice: t(".success")
end
private
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index d37580ac..500432af 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,20 +2,8 @@ class ApplicationController < ActionController::Base
include Authentication, Invitable, SelfHostable
include Pagy::Backend
- before_action :sync_accounts
-
default_form_builder ApplicationFormBuilder
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
-
- private
-
- def sync_accounts
- return if Current.user.blank?
-
- if Current.user.last_login_at.nil? || Current.user.last_login_at.before?(Date.current.beginning_of_day)
- Current.family.sync_accounts
- end
- end
end
diff --git a/config/locales/views/accounts/en.yml b/config/locales/views/accounts/en.yml
index 7b4d04e5..eaf049f1 100644
--- a/config/locales/views/accounts/en.yml
+++ b/config/locales/views/accounts/en.yml
@@ -71,7 +71,6 @@ en:
summary:
new: New account
sync:
- cannot_sync: Account cannot be synced at the moment
success: Account sync started
update:
success: Account updated
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
index 8e3af537..a2ceb6ba 100644
--- a/test/controllers/accounts_controller_test.rb
+++ b/test/controllers/accounts_controller_test.rb
@@ -25,6 +25,11 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_response :ok
end
+ test "can sync an account" do
+ post sync_account_path(@account)
+ assert_redirected_to account_url(@account)
+ end
+
test "should update account" do
patch account_url(@account), params: {
account: {