spec/integration/form/predicates/array_spec.rb in dry-validation-0.9.1 vs spec/integration/form/predicates/array_spec.rb in dry-validation-0.9.2
- old
+ new
@@ -238,6 +238,50 @@
expect(result).to be_failing 0 => ['must be an integer']
end
end
end
end
+
+ context 'with maybe macro' do
+ subject(:schema) { Dry::Validation.Form { required(:foo).maybe(:array?) } }
+
+ context 'with empty string' do
+ let(:input) { { 'foo' => '' } }
+
+ it 'is successful' do
+ expect(result).to be_successful
+ end
+ end
+
+ context 'with nil' do
+ let(:input) { { 'foo' => nil } }
+
+ it 'is successful' do
+ expect(result).to be_successful
+ end
+ end
+
+ context 'with empty array' do
+ let(:input) { { 'foo' => [] } }
+
+ it 'is successful' do
+ expect(result).to be_successful
+ end
+ end
+
+ context 'with filled array' do
+ let(:input) { { 'foo' => [1, 2, 3] } }
+
+ it 'is successful' do
+ expect(result).to be_successful
+ end
+ end
+
+ context 'with invalid value' do
+ let(:input) { { 'foo' => 'oops' } }
+
+ it 'is not successful' do
+ expect(result).to be_failing(['must be an array'])
+ end
+ end
+ end
end