From 2f114c165167b7ec3cc9df7d35260f46e3d3c5e7 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 30 Sep 2019 16:44:24 +0500 Subject: [PATCH] Add GoodSmallTextValidator --- app/validators/good_small_text_validator.rb | 14 ++++++++++++++ spec/validators/good_small_text_validator_spec.rb | 7 +++++++ 2 files changed, 21 insertions(+) create mode 100644 app/validators/good_small_text_validator.rb create mode 100644 spec/validators/good_small_text_validator_spec.rb diff --git a/app/validators/good_small_text_validator.rb b/app/validators/good_small_text_validator.rb new file mode 100644 index 0000000..46fa4e9 --- /dev/null +++ b/app/validators/good_small_text_validator.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class GoodSmallTextValidator < GoodTextValidator + class Validation < Validation + MIN = 1 + MAX = 255 + + def perform + super + error! :too_short, count: MIN if value.to_s.length < MIN + error! :too_long, count: MAX if value.to_s.length > MAX + end + end +end diff --git a/spec/validators/good_small_text_validator_spec.rb b/spec/validators/good_small_text_validator_spec.rb new file mode 100644 index 0000000..a85ae89 --- /dev/null +++ b/spec/validators/good_small_text_validator_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe GoodSmallTextValidator do + pending "add some examples to (or delete) #{__FILE__}" +end