Sha256: 06de6b5c05847f5b78145fb5a642b273fba0d41c509d70520a5e13b96af06a76

Contents?: true

Size: 1.05 KB

Versions: 16

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

describe Base64Validator do

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

    subject { klass.new }

    it { should allow_value("YW55IGNhcm5hbCBwbGVhcw==").for(:code) }
    it { should allow_value("YW55IGNhcm5hbCBwbGVhc3U=").for(:code) }
    it { should allow_value("YW55IGNhcm5hbCBwbGVhc3Vy").for(:code) }
    it { should allow_value("YW55IGNhcm5hbCBwbGVhc3VyZQ==").for(:code) }
    it { should allow_value("YW55IGNhcm5hbCBwbGVhc3VyZS4=").for(:code) }

    it { should_not allow_value('').for(:code) }
    it { should_not allow_value(' ').for(:code) }
    it { should_not allow_value(nil).for(:code) }
    it { should_not allow_value("1a.b2").for(:code) }
    it { should_not allow_value("1a b2").for(:code) }
    it { should_not allow_value("1a.b2==").for(:code) }

    it { should ensure_valid_base64_format_of(:code) }
    it { should_not ensure_valid_base64_format_of(:name) }
  end

end

Version data entries

16 entries across 16 versions & 3 rubygems

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