Sha256: 2463839647b51ddfed54e56f9ae84d3d3aeabfce42c1beff7b599248f65aa162

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

require "test_helper"

class BitsTest < Minitest::Test
  let(:model) { Class.new {
    def self.name
      "User"
    end

    include ActiveModel::Model
    validates_ssh_private_key :key, bits: 2048
    attr_accessor :key
  } }

  test "accepts bits equals to required" do
    record = model.new(key: SSHKey.generate(bits: 2048).private_key)
    record.valid?

    assert record.errors[:key].empty?
  end

  test "accepts bits greater than required" do
    record = model.new(key: SSHKey.generate(bits: 4096).private_key)
    record.valid?

    assert record.errors[:key].empty?
  end

  test "rejects invalid bits" do
    record = model.new(key: SSHKey.generate(bits: 1024).private_key)
    record.valid?

    refute record.errors[:key].empty?
  end

  test "sets translated error message" do
    I18n.locale = "pt-BR"
    message = "precisa ter pelo menos 2048 bits; a sua chave tem 1024 bits"

    record = model.new(key: SSHKey.generate(bits: 1024).private_key)
    record.valid?

    assert_includes record.errors[:key], message
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
validators-2.8.1 test/validators/validates_ssh_private_key/bits_test.rb
validators-2.8.0 test/validators/validates_ssh_private_key/bits_test.rb
validators-2.7.0 test/validators/validates_ssh_private_key/bits_test.rb
validators-2.6.0 test/validators/validates_ssh_private_key/bits_test.rb
validators-2.5.4 test/validators/validates_ssh_private_key/bits_test.rb