Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Rules: Fix no action conditions (#447)

Dylan Corrales70b050e4a4f4
diff --git a/app/helpers/languages_helper.rb b/app/helpers/languages_helper.rb
index 29a3f62a8a..cd64c3cd29 100644
--- a/app/helpers/languages_helper.rb
+++ b/app/helpers/languages_helper.rb
@@ -155,14 +155,14 @@ module LanguagesHelper
# Locales with complete/extensive translations
SUPPORTED_LOCALES = [
- "en", # English - 61 translation files
+ "en", # English - 62 translation files
"de", # German - 62 translation files
- "es", # Spanish - 60 translation files
- "tr", # Turkish - 57 translation files
- "nb", # Norwegian Bokmål - 56 translation files
- "ca", # Catalan - 56 translation files
- "ro", # Romanian - 61 translation files
- "pt-BR" # Brazilian Portuguese - 60 translation files
+ "es", # Spanish - 61 translation files
+ "tr", # Turkish - 58 translation files
+ "nb", # Norwegian Bokmål - 57 translation files
+ "ca", # Catalan - 57 translation files
+ "ro", # Romanian - 62 translation files
+ "pt-BR" # Brazilian Portuguese - 60 translation files
].freeze
COUNTRY_MAPPING = {
diff --git a/app/models/rule.rb b/app/models/rule.rb
index 4ffb8caa2e..13087f93bc 100644
--- a/app/models/rule.rb
+++ b/app/models/rule.rb
@@ -101,7 +101,7 @@ class Rule < ApplicationRecord
end
def min_actions
- return if new_record? && actions.empty?
+ return if new_record? && !actions.empty?
if actions.reject(&:marked_for_destruction?).empty?
errors.add(:base, "must have at least one action")
diff --git a/app/views/rules/_rule.html.erb b/app/views/rules/_rule.html.erb
index 68630b7069..c0d59bea25 100644
--- a/app/views/rules/_rule.html.erb
+++ b/app/views/rules/_rule.html.erb
@@ -30,10 +30,14 @@
</div>
<p class="flex items-center flex-wrap gap-1.5 m-0">
<span class="px-2 py-1 border border-secondary rounded-full">
- <% if rule.actions.first.value && rule.actions.first.options %>
- <%= rule.actions.first.executor.label %> to <%= rule.actions.first.value_display %>
+ <% if rule.actions.first.nil? %>
+ <%= t("rules.no_action") %>
<% else %>
- <%= rule.actions.first.executor.label %>
+ <% if rule.actions.first.value && rule.actions.first.options %>
+ <%= rule.actions.first.executor.label %> to <%= rule.actions.first.value_display %>
+ <% else %>
+ <%= rule.actions.first.executor.label %>
+ <% end %>
<% end %>
</span>
<% if rule.actions.count > 1 %>
diff --git a/config/locales/views/rules/ca.yml b/config/locales/views/rules/ca.yml
index 33843b8f4a..c4864a9a7c 100644
--- a/config/locales/views/rules/ca.yml
+++ b/config/locales/views/rules/ca.yml
@@ -1,6 +1,7 @@
---
ca:
rules:
+ no_action: Sense acció
recent_runs:
title: Execucions Recents
description: Visualitza l'historial d'execució de les teves regles incloent l'estat d'èxit/fallada i els recomptes de transaccions.
diff --git a/config/locales/views/rules/de.yml b/config/locales/views/rules/de.yml
index d86ceebd55..a8a80bdff1 100644
--- a/config/locales/views/rules/de.yml
+++ b/config/locales/views/rules/de.yml
@@ -1,6 +1,7 @@
---
de:
rules:
+ no_action: Keine Aktion
recent_runs:
title: Letzte Ausführungen
description: Zeige die Ausführungsgeschichte deiner Regeln einschließlich Erfolgs-/Fehlerstatus und Transaktionsanzahlen.
diff --git a/config/locales/views/rules/en.yml b/config/locales/views/rules/en.yml
index 7a1837e454..c571eb0f69 100644
--- a/config/locales/views/rules/en.yml
+++ b/config/locales/views/rules/en.yml
@@ -1,6 +1,7 @@
---
en:
rules:
+ no_action: No Action
recent_runs:
title: Recent Runs
description: View the execution history of your rules including success/failure status and transaction counts.
diff --git a/config/locales/views/rules/es.yml b/config/locales/views/rules/es.yml
index 7010384798..472ed02403 100644
--- a/config/locales/views/rules/es.yml
+++ b/config/locales/views/rules/es.yml
@@ -1,6 +1,7 @@
---
es:
rules:
+ no_action: Sin acción
recent_runs:
title: Ejecuciones Recientes
description: Ver el historial de ejecución de tus reglas incluyendo el estado de éxito/fallo y los conteos de transacciones.
diff --git a/config/locales/views/rules/nb.yml b/config/locales/views/rules/nb.yml
index a1b7aeb068..1787cf18e6 100644
--- a/config/locales/views/rules/nb.yml
+++ b/config/locales/views/rules/nb.yml
@@ -1,6 +1,7 @@
---
nb:
rules:
+ no_action: Ingen handling
recent_runs:
title: Siste Kjøringer
description: Se kjøringsloggen for reglene dine inkludert suksess/feil-status og transaksjonsantall.
diff --git a/config/locales/views/rules/ro.yml b/config/locales/views/rules/ro.yml
index d4e7df3a5a..3f3ccb8c51 100644
--- a/config/locales/views/rules/ro.yml
+++ b/config/locales/views/rules/ro.yml
@@ -1,6 +1,7 @@
---
ro:
rules:
+ no_action: Nicio acțiune
recent_runs:
title: Rulări Recente
description: Vezi istoricul de execuție al regulilor tale incluzând statusul de succes/eșec și numărul de tranzacții.
diff --git a/config/locales/views/rules/tr.yml b/config/locales/views/rules/tr.yml
index 8318415b19..c2d50c11d0 100644
--- a/config/locales/views/rules/tr.yml
+++ b/config/locales/views/rules/tr.yml
@@ -1,6 +1,7 @@
---
tr:
rules:
+ no_action: İşlem yok
recent_runs:
title: Son Çalıştırmalar
description: Başarı/başarısızlık durumu ve işlem sayıları dahil olmak üzere kurallarınızın yürütme geçmişini görüntüleyin.
diff --git a/test/models/family/data_exporter_test.rb b/test/models/family/data_exporter_test.rb
index 2d5c3ad4a7..9f36e16bf8 100644
--- a/test/models/family/data_exporter_test.rb
+++ b/test/models/family/data_exporter_test.rb
@@ -24,20 +24,21 @@ class Family::DataExporterTest < ActiveSupport::TestCase
color: "#00FF00"
)
- @rule = @family.rules.create!(
+ @rule = @family.rules.build(
name: "Test Rule",
resource_type: "transaction",
active: true
)
- @rule.conditions.create!(
+ @rule.conditions.build(
condition_type: "transaction_name",
operator: "like",
value: "test"
)
- @rule.actions.create!(
+ @rule.actions.build(
action_type: "set_transaction_category",
value: @category.id
)
+ @rule.save!
end
test "generates a zip file with all required files" do
@@ -219,20 +220,21 @@ class Family::DataExporterTest < ActiveSupport::TestCase
test "exports rule actions and maps tag UUIDs to names" do
# Create a rule with a tag action
- tag_rule = @family.rules.create!(
+ tag_rule = @family.rules.build(
name: "Tag Rule",
resource_type: "transaction",
active: true
)
- tag_rule.conditions.create!(
+ tag_rule.conditions.build(
condition_type: "transaction_name",
operator: "like",
value: "test"
)
- tag_rule.actions.create!(
+ tag_rule.actions.build(
action_type: "set_transaction_tags",
value: @tag.id
)
+ tag_rule.save!
zip_data = @exporter.generate_export
@@ -259,28 +261,29 @@ class Family::DataExporterTest < ActiveSupport::TestCase
test "exports compound conditions with sub-conditions" do
# Create a rule with compound conditions
- compound_rule = @family.rules.create!(
+ compound_rule = @family.rules.build(
name: "Compound Rule",
resource_type: "transaction",
active: true
)
- parent_condition = compound_rule.conditions.create!(
+ parent_condition = compound_rule.conditions.build(
condition_type: "compound",
operator: "or"
)
- parent_condition.sub_conditions.create!(
+ parent_condition.sub_conditions.build(
condition_type: "transaction_name",
operator: "like",
value: "walmart"
)
- parent_condition.sub_conditions.create!(
+ parent_condition.sub_conditions.build(
condition_type: "transaction_name",
operator: "like",
value: "target"
)
- compound_rule.actions.create!(
+ compound_rule.actions.build(
action_type: "auto_categorize"
)
+ compound_rule.save!
zip_data = @exporter.generate_export
@@ -309,19 +312,20 @@ class Family::DataExporterTest < ActiveSupport::TestCase
test "only exports rules from the specified family" do
# Create a rule for another family that should NOT be exported
- other_rule = @other_family.rules.create!(
+ other_rule = @other_family.rules.build(
name: "Other Family Rule",
resource_type: "transaction",
active: true
)
- other_rule.conditions.create!(
+ other_rule.conditions.build(
condition_type: "transaction_name",
operator: "like",
value: "other"
)
- other_rule.actions.create!(
+ other_rule.actions.build(
action_type: "auto_categorize"
)
+ other_rule.save!
zip_data = @exporter.generate_export