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 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