Sha256: 96a27ef8a36558bbf1a8e6c7197a85348790a87abd9b7cbb2c21700bdfb265ee

Contents?: true

Size: 1.46 KB

Versions: 17

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

describe IsbnValidator do

  context "has a valid value" do
    let(:klass) do
      Class.new do
        include ActiveModel::Validations
        attr_accessor :isbn, :name
        validates :isbn, isbn: true
      end
    end

    subject { klass.new }

    it { should allow_value("9519854894").for(:isbn) }
    it { should allow_value("951 98548 9 4").for(:isbn) }
    it { should allow_value("951-98548-9-4").for(:isbn) }
    it { should allow_value("951-98548 9 4").for(:isbn) }
    it { should allow_value("0-9722051-1-X").for(:isbn) }
    it { should allow_value("0-9722051-1-x").for(:isbn) }
    it { should allow_value("9781590599938").for(:isbn) }
    it { should allow_value("978 159059 9938").for(:isbn) }
    it { should allow_value("978-159059-9938").for(:isbn) }
    it { should allow_value("978-159059 9938").for(:isbn) }

    it { should_not allow_value('').for(:isbn) }
    it { should_not allow_value(' ').for(:isbn) }
    it { should_not allow_value(nil).for(:isbn) }
    it { should_not allow_value("951-98548-9-p").for(:isbn) }
    it { should_not allow_value("abc123ab3344").for(:isbn) }
    it { should_not allow_value("12345678901234").for(:isbn) }
    it { should_not allow_value("9991a9010599938").for(:isbn) }
    it { should_not allow_value("! \#$%\`|").for(:isbn) }
    it { should_not allow_value("<>@[]\`|").for(:isbn) }

    it { should ensure_valid_isbn_format_of(:isbn) }
    it { should_not ensure_valid_isbn_format_of(:name) }
  end

end

Version data entries

17 entries across 17 versions & 3 rubygems

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