diff --git a/lib/diaspora_federation/validators/rules/tag_count.rb b/lib/diaspora_federation/validators/rules/tag_count.rb index e46fd7c..9a74c15 100644 --- a/lib/diaspora_federation/validators/rules/tag_count.rb +++ b/lib/diaspora_federation/validators/rules/tag_count.rb @@ -20,7 +20,7 @@ module Validation end def valid_value?(value) - value.count("#") <= params[:maximum] + value.nil? || value.count("#") <= params[:maximum] end end end diff --git a/spec/lib/diaspora_federation/validators/rules/tag_count_spec.rb b/spec/lib/diaspora_federation/validators/rules/tag_count_spec.rb index c301b41..e7a1ae7 100644 --- a/spec/lib/diaspora_federation/validators/rules/tag_count_spec.rb +++ b/spec/lib/diaspora_federation/validators/rules/tag_count_spec.rb @@ -41,5 +41,13 @@ describe Validation::Rule::TagCount do expect(validator).not_to be_valid expect(validator.errors).to include(:tags) end + + it "validates if tags are nil" do + validator = Validation::Validator.new(OpenStruct.new(tags: nil)) + validator.rule(:tags, tag_count: {maximum: 5}) + + expect(validator).to be_valid + expect(validator.errors).to be_empty + end end end