Sha256: 2909bff8ab9a46dfa13a76b281c2815eeb3086a91704ba9fe70c6d864e927b18

Contents?: true

Size: 1.86 KB

Versions: 17

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

describe MacAddressValidator do

  context "has valid format" do
    let(:klass) do
      Class.new do
        include ActiveModel::Validations
        attr_accessor :mac, :name
        validates :mac, mac_address: true
      end
    end

    subject { klass.new }

    # Valid formats
    it { should allow_value("08:00:2b:01:02:03").for(:mac) }
    it { should allow_value("08-00-2b-01-02-03").for(:mac) }
    it { should allow_value("08.00.2b.01.02.03").for(:mac) }
    it { should allow_value("08 00 2b 01 02 03").for(:mac) }
    it { should allow_value("08002b:010203").for(:mac) }
    it { should allow_value("08002b.010203").for(:mac) }
    it { should allow_value("08002b-010203").for(:mac) }
    it { should allow_value("0800.2b01.0203").for(:mac) }
    it { should allow_value("0800-2b01-0203").for(:mac) }
    it { should allow_value("0800 2b01 0203").for(:mac) }
    it { should allow_value("08002b010203").for(:mac) }

    # Mixed Separators
    it { should_not allow_value("08-00:2b:01:02:03").for(:mac) }
    it { should_not allow_value("08.00:2b:01:02:03").for(:mac) }
    it { should_not allow_value("08 00:2b:01:02:03").for(:mac) }
    it { should_not allow_value("0800-2b01:0203").for(:mac) }
    it { should_not allow_value("0800 2b01:0203").for(:mac) }

    # Too Short
    it { should_not allow_value("08:00:2b:01:02").for(:mac) }
    it { should_not allow_value("08-00-2b-01-02").for(:mac) }

    # Too Long
    it { should_not allow_value("08:00:2b:01:02:03:04").for(:mac) }

    # Non-Hex Characters
    it { should_not allow_value("qq:00:00:00:00:00").for(:mac) }

    it { should_not allow_value(' ').for(:mac) }
    it { should_not allow_value(nil).for(:mac) }
    it { should_not allow_value("invalid").for(:mac) }

    it { should ensure_valid_mac_address_format_of(:mac) }
    it { should_not ensure_valid_mac_address_format_of(:name) }
  end

end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
active_validation-1.0.0 spec/lib/mac_address_validator_spec.rb
yukonisuru-1.0.0 spec/lib/mac_address_validator_spec.rb
yukonisuru-0.0.1 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.12 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.11 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.10 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.9 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.8 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.7 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.6 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.5 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.4 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.3 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.2 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.1 spec/lib/mac_address_validator_spec.rb
flash_validators-3.0.0 spec/lib/mac_address_validator_spec.rb
flash_validators-1.1.0 spec/lib/mac_address_validator_spec.rb