fix tag count validator
This commit is contained in:
parent
ed52108cc7
commit
ce39616265
2 changed files with 9 additions and 1 deletions
|
|
@ -20,7 +20,7 @@ module Validation
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_value?(value)
|
def valid_value?(value)
|
||||||
value.count("#") <= params[:maximum]
|
value.nil? || value.count("#") <= params[:maximum]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,5 +41,13 @@ describe Validation::Rule::TagCount do
|
||||||
expect(validator).not_to be_valid
|
expect(validator).not_to be_valid
|
||||||
expect(validator.errors).to include(:tags)
|
expect(validator.errors).to include(:tags)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue