Sha256: c53c2d36d262cd39c93bcd3b725dc4fc414465c196af2a0ac8159ef66f168e98

Contents?: true

Size: 1.29 KB

Versions: 17

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe UsernameValidator do

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

    subject { klass.new }

    it { should allow_value("username").for(:username) }
    it { should allow_value("username123").for(:username) }
    it { should allow_value("username_123").for(:username) }
    it { should allow_value("username-123").for(:username) }

    it { should_not allow_value('').for(:username) }
    it { should_not allow_value(' ').for(:username) }
    it { should_not allow_value(nil).for(:username) }
    it { should_not allow_value("u").for(:username) }
    it { should_not allow_value(" username").for(:username) }
    it { should_not allow_value(" username ").for(:username) }
    it { should_not allow_value("username ").for(:username) }
    it { should_not allow_value("user name").for(:username) }
    it { should_not allow_value("username-123456789").for(:username) }
    it { should_not allow_value("! \#$%\`|").for(:username) }
    it { should_not allow_value("<>@[]\`|").for(:username) }

    it { should ensure_valid_username_format_of(:username) }
    it { should_not ensure_valid_username_format_of(:name) }
  end

end

Version data entries

17 entries across 17 versions & 3 rubygems

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