Sha256: 91d93039f8b7073a8b54b2e1658add236c0c9f569b388e70ea285efdb3398622

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

describe ImeiValidator do
  context "IMEI has valid format" do
    let(:klass) do
      Class.new do
        include ActiveModel::Validations
        attr_accessor :imei, :name
        validates :imei, imei: true
      end
    end

    subject { klass.new }

    it { should ensure_valid_imei_format_of(:imei) }
    it { should_not ensure_valid_imei_format_of(:name) }

    it { should allow_value(356843052637512).for(:imei) }
    it { should allow_value("356843052637512").for(:imei) }
    it { should allow_value("35-684305-2637512").for(:imei) }
    it { should allow_value("35-684305.263.7512").for(:imei) }

    context "value too short" do
      it { should_not allow_value("3568430537512").for(:imei) }
      it { should_not allow_value("3").for(:imei) }
    end

    it "can't be too long" do
      should_not allow_value("35684305263751233").for(:imei)
    end

    context "checksum doesn't match" do
      it { should_not allow_value("356843052637513").for(:imei) }
      it { should_not allow_value("156843052637512").for(:imei) }
    end

    it { should_not allow_value("invalid").for(:imei) }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
missing_validators-1.1.0 spec/validators/imei_spec.rb
missing_validators-1.0.1 spec/validators/imei_spec.rb
missing_validators-0.9.1 spec/validators/imei_spec.rb
missing_validators-0.9 spec/validators/imei_spec.rb