Created
September 3, 2017 14:45
-
-
Save cmrd-senya/24f28a6e02852fb89ffeb32d7c0a5d3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/diaspora_federation/validators/photo_validator.rb b/lib/diaspora_federation/validators/photo_validator.rb | |
index 9c7bbb3..6c34914 100644 | |
--- a/lib/diaspora_federation/validators/photo_validator.rb | |
+++ b/lib/diaspora_federation/validators/photo_validator.rb | |
@@ -1,7 +1,19 @@ | |
module DiasporaFederation | |
module Validators | |
+ class Validator2 < Validation::Validator | |
+ def rules | |
+ super.reject do |field, _rules| | |
+ optional_nil_value?(field, @obj.send(field)) | |
+ end | |
+ end | |
+ | |
+ def optional_nil_value?(name, value) | |
+ value.nil? && optional_props.include?(name) | |
+ end | |
+ end | |
+ | |
# This validates a {Entities::Photo}. | |
- class PhotoValidator < Validation::Validator | |
+ class PhotoValidator < Validator2 | |
include Validation | |
rule :guid, :guid | |
@@ -18,9 +30,13 @@ module DiasporaFederation | |
rule :text, length: {maximum: 65_535} | |
- rule :height, :number | |
+ rule :height, :numeric | |
+ | |
+ rule :width, :numeric | |
- rule :width, :number | |
+ def optional_props | |
+ DiasporaFederation::Entities::Photo.optional_props | |
+ end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment