From aa1ee754c7fc63444c4bde7a5b26b522ee6ac463 Mon Sep 17 00:00:00 2001 From: melashu Date: Sun, 8 Oct 2023 15:50:18 +0300 Subject: [PATCH 1/2] Add complect pattern --- lib/liquid-validations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquid-validations.rb b/lib/liquid-validations.rb index 46941e0..0bb9a40 100644 --- a/lib/liquid-validations.rb +++ b/lib/liquid-validations.rb @@ -99,7 +99,7 @@ def check_occurance(patterns, value, max) def get_max_tag(tag, value, max) max_tag = "" tag.each do |ele| - if value.scan(/{% #{ele} %}/).size > max + if value.scan(/{%\s+#{ele}\s+(.*?)%}/).size > max max_tag << "{% #{ele} %}" end end From 83b719a7eef916b735d9330d013e56275bddacbf Mon Sep 17 00:00:00 2001 From: melashu Date: Sun, 8 Oct 2023 15:52:40 +0300 Subject: [PATCH 2/2] Add test for complex pattern --- spec/liquid_validations_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/liquid_validations_spec.rb b/spec/liquid_validations_spec.rb index 7a37a20..a7fb926 100644 --- a/spec/liquid_validations_spec.rb +++ b/spec/liquid_validations_spec.rb @@ -279,5 +279,19 @@ class Mixin < ActiveRecord::Base @mixin.errors.full_messages.any? { |e| e == "content must not have more than 2 {% josh_is_awesome %}" }.must_equal true end end + + describe "When tag contanis array of tag, complex pattern and presence is false" do + before do + Mixin.instance_eval do + validates_liquid_tag :content, tag: ['date_of_birth', 'national_id_no', 'street', 'postal_code', 'city', 'country_code', 'count', 'note'], max: 1, presence: false, :allow_blank => true + end + @mixin = Mixin.new + end + it "must be valid when the content is nil" do + @mixin.content = "{% name %} {% email %} {% street 'Adresse', 'data-required=true' %} {% street 'Sted', 'data-required=true' %}" + @mixin.valid? + @mixin.errors.full_messages.any? { |e| e == "content must not have more than 1 {% street %}" }.must_equal true + end + end end end