spec/validations_spec.rb in va-0.3.0 vs spec/validations_spec.rb in va-0.4.0
- old
+ new
@@ -1,10 +1,10 @@
require "./spec/spec_helper"
scope "basic validations" do
scope "non-blank" do
- class ANonBlankAttribute < Va::Model
+ class ANonBlankAttribute < Va::Validator
attribute :name
attribute :age
validate_present(:name, :age)
end
@@ -26,6 +26,40 @@
spec "both empty" do
@va = ANonBlankAttribute.new(name: nil, age: "")
! @va.valid?
end
end
+
+ scope "non-nil" do
+ class ANotNilAttribute < Va::Validator
+ attribute :name
+ attribute :age
+ validate_not_nil(:name, :age)
+ end
+
+ spec "passing" do
+ @va = ANotNilAttribute.new(name: "Fede", age: :of_ultron)
+ @va.valid?
+ end
+
+ spec "one empty string" do
+ @va = ANotNilAttribute.new(name: "", age: :of_ultron)
+ @va.valid?
+ end
+
+ spec "one nil" do
+ @va = ANotNilAttribute.new(name: "Fede", age: nil)
+ ! @va.valid?
+ end
+
+ spec "both empty" do
+ @va = ANotNilAttribute.new(name: nil, age: "")
+ ! @va.valid?
+ end
+
+ spec "both nil" do
+ @va = ANotNilAttribute.new(name: nil, age: nil)
+ ! @va.valid?
+ end
+ end
+
end