Sha256: 70bd12247892ce570176bf263f7a1afdf1dc5e00485c045cf0b93d5534c67072

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'

describe SlugValidator do

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

    subject { klass.new }

    it { should allow_value("slug").for(:slug) }
    it { should allow_value("slug1234").for(:slug) }
    it { should allow_value("slug-word").for(:slug) }
    it { should allow_value("slug-1234").for(:slug) }

    it { should_not allow_value('').for(:slug) }
    it { should_not allow_value(' ').for(:slug) }
    it { should_not allow_value(nil).for(:slug) }
    it { should_not allow_value(" slug").for(:slug) }
    it { should_not allow_value(" slug ").for(:slug) }
    it { should_not allow_value("slug ").for(:slug) }
    it { should_not allow_value(" 1234").for(:slug) }
    it { should_not allow_value(" 1234 ").for(:slug) }
    it { should_not allow_value("1234 ").for(:slug) }
    it { should_not allow_value("slug word").for(:slug) }
    it { should_not allow_value("slug 1234").for(:slug) }
    it { should_not allow_value("slug_word").for(:slug) }
    it { should_not allow_value("slug_1234").for(:slug) }
    it { should_not allow_value("! \#$%\`|").for(:slug) }
    it { should_not allow_value("<>@[]\`|").for(:slug) }

    it { should ensure_valid_slug_format_of(:slug) }
    it { should_not ensure_valid_slug_format_of(:name) }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flash_validators-1.0.0 spec/lib/slug_validator_spec.rb
flash_validators-0.0.1 spec/lib/slug_validator_spec.rb