Sha256: 551aa83593a6cff49301cbcf65602f560a4ee82fdc23738b952785022b0d8b9c

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require "spec_helper"

describe HungryForm::Validator do
  let(:resolver) { HungryForm::Resolver.new() }
  let(:group) { HungryForm::Elements::Group.new(:group, nil, resolver, {}) {} }

  let(:element_options) { {} }
  let(:element) { HungryForm::Elements::TextField.new(:element_name, group, resolver, element_options) {} }

  describe "required" do
    it "should return nil when the element's value is present" do
      element_options[:value] = "value"
      expect(HungryForm::Validator.required(element, true)).to be nil
    end

    it "should return error when the element's value is not present" do
      element_options[:value] = ""
      expect(HungryForm::Validator.required(element, true)).to eq "is required"
    end

    it "should return the result of the custom required validation" do
      element_options[:value] = "value"
      expect(HungryForm::Validator.required(element, ->(el) { "not ok" if el.value != "custom" })).to eq "not ok"
    end
  end

  describe "validation" do
    it "should return the result of the custom validation" do
      element_options[:value] = "value"
      expect(HungryForm::Validator.validation(element, ->(el) { "not ok" if el.value != "custom" })).to eq "not ok"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hungryform-0.0.11 spec/validator_spec.rb
hungryform-0.0.10 spec/validator_spec.rb
hungryform-0.0.9 spec/validator_spec.rb
hungryform-0.0.8 spec/validator_spec.rb
hungryform-0.0.7 spec/validator_spec.rb
hungryform-0.0.6 spec/validator_spec.rb
hungryform-0.0.4 spec/validator_spec.rb