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.rbindex 94e9bbe3..a0576b3a 100644--- a/app/controllers/accounts_controller.rb+++ b/app/controllers/accounts_controller.rb@@ -63,22 +63,11 @@ class AccountsController < ApplicationControllerenddef 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- endend++ redirect_to account_path(@account), notice: t(".success")endprivatediff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex d37580ac..500432af 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -2,20 +2,8 @@ class ApplicationController < ActionController::Baseinclude Authentication, Invitable, SelfHostableinclude 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- endenddiff --git a/config/locales/views/accounts/en.yml b/config/locales/views/accounts/en.ymlindex 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 accountsync:- cannot_sync: Account cannot be synced at the momentsuccess: Account sync startedupdate:success: Account updateddiff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rbindex 8e3af537..a2ceb6ba 100644--- a/test/controllers/accounts_controller_test.rb+++ b/test/controllers/accounts_controller_test.rb@@ -25,6 +25,11 @@ class AccountsControllerTest < ActionDispatch::IntegrationTestassert_response :okend+ test "can sync an account" do+ post sync_account_path(@account)+ assert_redirected_to account_url(@account)+ end+test "should update account" dopatch account_url(@account), params: {account: {