spec/validations_spec.rb in rasti-form-5.0.0 vs spec/validations_spec.rb in rasti-form-6.0.0
- old
+ new
@@ -101,11 +101,11 @@
def validate
assert_present :range
end
end
- assert_validation_error('range.max' => ['not present'], range: ['not present']) do
+ assert_validation_error('range.max' => ['not present']) do
form.new range: {min: 1}
end
end
it 'With default' do
@@ -160,11 +160,11 @@
form.new range: {min: 1, max: 2}
end
end
it 'Invalid nested cast' do
- assert_validation_error('range.max' => ['not present'], range: ['is present']) do
+ assert_validation_error('range.max' => ['not present']) do
form.new range: {min: 1}
end
end
end
@@ -294,8 +294,40 @@
proc { form.new range: {min: 1, max: 2} }.must_be_silent
assert_validation_error('range.min' => ['invalid range']) do
form.new range: {min: 2, max: 1}
end
+ end
+
+ describe 'Validations Precedence' do
+
+ let(:form) do
+ build_form do
+ attribute :limit, T::Integer
+
+ def validate
+ assert :limit, limit < 10, 'invalid limit'
+ end
+ end
+ end
+
+ it '1) Validate unexpected attributes' do
+ assert_validation_error(id: ["unexpected attribute"]) do
+ form.new id: '123'
+ end
+ end
+
+ it '2) Validate attributes casting' do
+ assert_validation_error(limit: ["Invalid cast: 'pepe' -> Rasti::Types::Integer"]) do
+ form.new limit: 'pepe'
+ end
+ end
+
+ it '3) Run custom validations' do
+ assert_validation_error(limit: ["invalid limit"]) do
+ form.new limit: 500
+ end
+ end
+
end
end
\ No newline at end of file