Sha256: b4ac29be7c067f15e96a9792465577489ff00f7ee12e950960c5ff99edbef4d8

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require 'spec_helper'

describe PasswordValidator do

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

    subject { klass.new }

    it { should allow_value("password").for(:password) }
    it { should allow_value("password1234").for(:password) }
    it { should allow_value("pa$$word").for(:password) }
    it { should allow_value("pass-word").for(:password) }
    it { should allow_value("pass_word").for(:password) }
    it { should allow_value("password!").for(:password) }
    it { should allow_value("password@").for(:password) }
    it { should allow_value("password#").for(:password) }
    it { should allow_value("password%").for(:password) }
    it { should allow_value("password^").for(:password) }
    it { should allow_value("password&").for(:password) }
    it { should allow_value("password*").for(:password) }

    it { should_not allow_value('').for(:password) }
    it { should_not allow_value(' ').for(:password) }
    it { should_not allow_value(nil).for(:password) }
    it { should_not allow_value("pass").for(:password) }
    it { should_not allow_value(" password").for(:password) }
    it { should_not allow_value(" password ").for(:password) }
    it { should_not allow_value("password ").for(:password) }
    it { should_not allow_value("pass word").for(:password) }
    it { should_not allow_value("password-12345678910").for(:password) }
    it { should_not allow_value("! \#$%\`|").for(:password) }
    it { should_not allow_value("<>@[]\`|").for(:password) }

    it { should ensure_valid_password_format_of(:password) }
    it { should_not ensure_valid_password_format_of(:name) }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flash_validators-0.0.1 spec/lib/password_validator_spec.rb