Sha256: f79e11bdd134c3e96024370d3c33cf0fc903a0a0b45f9f8c8243fc892f7e04cf

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "test_helper"

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

      include ActiveModel::Model
      validates_ssh_private_key :key
      attr_accessor :key
    end
  end

  test "fails when gem is not available" do
    assert_raises do
      Class.new do
        expects(:require).with("sshkey").raises(LoadError)

        include ActiveModel::Model
        validates_ssh_private_key :key
      end
    end
  end

  test "requires valid key" do
    record = model.new(key: "invalid")
    record.valid?

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

  test "accepts valid key" do
    record = model.new(key: SSHKey.generate.private_key)
    record.valid?

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

  test "sets translated error message" do
    I18n.locale = "pt-BR"
    message = "não é uma chave privada de SSH válida"

    record = model.new(key: "invalid")
    record.valid?

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
validators-3.4.0 test/validators/validates_ssh_private_key/common_test.rb
validators-3.3.0 test/validators/validates_ssh_private_key/common_test.rb
validators-3.2.1 test/validators/validates_ssh_private_key/common_test.rb
validators-3.2.0 test/validators/validates_ssh_private_key/common_test.rb
validators-3.1.1 test/validators/validates_ssh_private_key/common_test.rb
validators-3.1.0 test/validators/validates_ssh_private_key/common_test.rb
validators-3.0.5 test/validators/validates_ssh_private_key/common_test.rb
validators-3.0.4 test/validators/validates_ssh_private_key/common_test.rb
validators-3.0.3 test/validators/validates_ssh_private_key/common_test.rb
validators-3.0.2 test/validators/validates_ssh_private_key/common_test.rb
validators-3.0.1 test/validators/validates_ssh_private_key/common_test.rb
validators-3.0.0 test/validators/validates_ssh_private_key/common_test.rb