mirror of
https://github.com/we-promise/sure.git
synced 2026-04-14 01:24:06 +00:00
fix: Handle empty compound conditions on rules index (#965)
* fix: Handle empty compound conditions on rules index * fix: avoid contradictory rule condition summary on /rules * refactor: move rules condition display logic from view to model * fix: localize rule title fallback and preload conditions in rules index
This commit is contained in:
@@ -180,6 +180,36 @@ class RulesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to rules_url
|
||||
end
|
||||
|
||||
test "index renders when rule has empty compound condition" do
|
||||
malformed_rule = @user.family.rules.build(resource_type: "transaction")
|
||||
malformed_rule.conditions.build(condition_type: "compound", operator: "and")
|
||||
malformed_rule.actions.build(action_type: "exclude_transaction")
|
||||
malformed_rule.save!
|
||||
|
||||
get rules_url
|
||||
|
||||
assert_response :success
|
||||
assert_includes response.body, I18n.t("rules.no_condition")
|
||||
end
|
||||
|
||||
test "index uses next valid condition when first compound condition is empty" do
|
||||
rule = @user.family.rules.build(resource_type: "transaction")
|
||||
rule.conditions.build(condition_type: "compound", operator: "and")
|
||||
rule.conditions.build(condition_type: "transaction_name", operator: "like", value: "edge-case-name")
|
||||
rule.actions.build(action_type: "exclude_transaction")
|
||||
rule.save!
|
||||
|
||||
get rules_url
|
||||
|
||||
assert_response :success
|
||||
|
||||
assert_select "##{ActionView::RecordIdentifier.dom_id(rule)}" do
|
||||
assert_select "span", text: /edge-case-name/
|
||||
assert_select "span", text: /#{Regexp.escape(I18n.t("rules.no_condition"))}/, count: 0
|
||||
assert_select "p", text: /and 1 more condition/, count: 0
|
||||
end
|
||||
end
|
||||
|
||||
test "should get confirm_all" do
|
||||
get confirm_all_rules_url
|
||||
assert_response :success
|
||||
|
||||
Reference in New Issue
Block a user