Sha256: 53c18ce194a39774c439f81f0e964cb84661e5abae170da4e1cbdd0973edf223

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

if defined?(ActiveModel)

  class DutchVehicle < ModelBase
    validates :number, license_plate: { country: :nl }
  end

  class DutchMethodVehicle < ModelBase
    validates :number, license_plate: { country: Proc.new { |dmv| dmv.country } }
  end

  class UnknownVehicle < ModelBase
    validates :number, license_plate: true
  end

  RSpec.describe "Ruby on Rails ActiveModel support" do
    context DutchVehicle do
      it "accepts Dutch plates only" do
        obj = DutchVehicle.new(number: "60-NFH-1")
        expect(obj).to be_valid

        obj = DutchVehicle.new(number: "SBA5226")
        expect(obj).not_to be_valid
      end
    end

    context DutchMethodVehicle do
      it "accepts Dutch plates only" do
        obj = DutchMethodVehicle.new(number: "60-NFH-1", country: "nl")
        expect(obj).to be_valid

        obj = DutchMethodVehicle.new(number: "SBA5226", country: "nl")
        expect(obj).not_to be_valid
      end
    end

    context UnknownVehicle do
      it "accepts both Dutch and German plates" do
        obj = UnknownVehicle.new(number: "60-NFH-1")
        expect(obj).to be_valid

        obj = UnknownVehicle.new(number: "SBA5226")
        expect(obj).to be_valid
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
license_plate_validator-2.0.0 spec/license_plate_validator/active_model_spec.rb