Sha256: 1009209a752ed4978f248e0f5b0e62244fa701bfc7c595ab6571af57f3ccb76b

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper.rb'

RSpec.describe "auto_trim" do

  let(:validator) do
    LIVR::Validator.new({
      code: "required",
      password: [ "required", { "min_length" => 3 }],
      address:  { "nested_object" => {
          street: { "min_length" => 5 },
        }
      }
    }, true)
  end

  it "NEGATIVE: Validate data with automatic trim" do
    output = validator.validate({
        code: '  ',
        password: ' 12  ',
        address: {
            street: '  hell '
        }
      })
    # expect(output).to eq(false), 'should return false due to validation errors fot trimmed values'
    expect(output).to eq(false)

    expect(validator.get_errors).to eq({
                                        code: 'REQUIRED',
                                        password: 'TOO_SHORT',
                                        address: {
                                          street: 'TOO_SHORT',
                                        }
                                      })

  end

  it "POSITIVE: Validate data with automatic trim" do
    clean_data = validator.validate({
        code: ' A ',
        password: ' 123  ',
        address: {
            street: '  hello '
        }
    })

    expect(clean_data).to be_truthy, 'should return clean data'
    expect(clean_data).to eq({
                              code: 'A',
                              password: '123',
                              address: {
                                street: 'hello',
                              }
                             }), 'Should contain error codes'
  end

end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
ruby-livr-2.0.0 spec/03-auto_trim_spec.rb
livr2-2.0.0 spec/03-auto_trim_spec.rb