mirror of
https://github.com/we-promise/sure.git
synced 2026-06-02 17:29:01 +00:00
Rules: Fix no action conditions (#447)
* Fix Rules page when no action on rule * Reject new rules without actions * Rule with no action translation * Easy one to keep translations going * Fix tests * Learn something new every day --------- Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user