Repository: codingedward/flask-sieve

Issue:
sometimes not working
sometimes rule not working with other rules. 

'zipCode': ['sometimes', 'numeric'],
'website': ['sometimes', 'url']

if we leave blank any of the field, it ask for valid integer and valid url.

Comments:

Patch:
diff --git a/flask_sieve/rules_processor.py b/flask_sieve/rules_processor.py
index 1fee1ba..a850531 100644
--- a/flask_sieve/rules_processor.py
+++ b/flask_sieve/rules_processor.py
@@ -547,7 +547,7 @@ class RulesProcessor:
             return True
         value = self._attribute_value(attribute)
         is_optional = self._has_rule(rules, 'sometimes')
-        if is_optional and value is not None:
+        if is_optional and value is None:
             return True
 
         attribute_conditional_rules = list(filter(lambda rule: rule['name'] in conditional_inclusion_rules, rules))
diff --git a/watch.sh b/watch.sh
index 340fb07..7c86b5b 100755
--- a/watch.sh
+++ b/watch.sh
@@ -1,3 +1,3 @@
 #!/bin/bash
 
-watchman-make -p "**/*.py" --run "nosetests --with-coverage --cover-package flask_sieve"
+watchman-make -p "**/*.py" --run "rm .coverage; nosetests --with-coverage --cover-package flask_sieve"


Test patch:
diff --git a/tests/test_rules_processor.py b/tests/test_rules_processor.py
index 167145c..eeafd0f 100644
--- a/tests/test_rules_processor.py
+++ b/tests/test_rules_processor.py
@@ -935,6 +935,45 @@ class TestRulesProcessor(unittest.TestCase):
             request={}
         )
 
+    def test_validates_sometimes(self):
+        self.assert_passes(
+            rules={'number': ['sometimes', 'max:5']},
+            request={}
+        )
+        self.assert_passes(
+            rules={'number': ['sometimes', 'max:5']},
+            request={'number': 2}
+        )
+        self.assert_fails(
+            rules={'number': ['sometimes', 'max:5']},
+            request={'number': ''}
+        )
+        self.assert_fails(
+            rules={'number': ['sometimes', 'max:5']},
+            request={'number': 10}
+        )
+        self.assert_passes(
+            rules={
+                'zipCode': ['sometimes', 'numeric'],
+                'website': ['sometimes', 'url']
+            },
+            request={}
+        )
+        self.assert_passes(
+            rules={
+                'zipCode': ['sometimes', 'numeric'],
+                'website': ['sometimes', 'url']
+            },
+            request={'website': 'https://google.com'}
+        )
+        self.assert_fails(
+            rules={
+                'zipCode': ['sometimes', 'numeric'],
+                'website': ['sometimes', 'url']
+            },
+            request={'website': 'ogle.com'}
+        )
+
 
     def test_validates_uuid(self):
         self.assert_passes(
diff --git a/tests/test_validator.py b/tests/test_validator.py
index fecfe45..9079d9d 100644
--- a/tests/test_validator.py
+++ b/tests/test_validator.py
@@ -184,41 +184,6 @@ class TestValidator(unittest.TestCase):
                 params_count=0
             )
 
-    def test_sometimes_request(self):
-        self.set_validator_params(
-            rules={'number': ['sometimes', 'max:5']},
-            request={}
-        )
-        self.assertTrue(self._validator.passes())
-
-        self.set_validator_params(
-            rules={'number': ['sometimes', 'max:5']},
-            request={'number': ''}
-        )
-        self.assertTrue(self._validator.fails())
-        self.assertDictEqual({
-            'number': [
-                'The number could not be validated since it is empty.'
-            ]
-        }, self._validator.messages())
-
-        self.set_validator_params(
-            rules={'number': ['sometimes', 'max:5']},
-            request={'number': 2}
-        )
-        self.assertTrue(self._validator.passes())
-
-        self.set_validator_params(
-            rules={'number': ['sometimes', 'max:5']},
-            request={'number': 10}
-        )
-        self.assertTrue(self._validator.fails())
-        self.assertDictEqual({
-            'number': [
-                'The number may not be greater than 5.'
-            ]
-        }, self._validator.messages())
-
     def set_validator_params(self, rules=None, request=None):
         rules = rules or {}
         request = request or {}