Sha256: 7c6a947f176bda79bc3dbca97a4d77a51ea3fcea4ea8211350ff6bd432d091b5

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

require "spec_helper"

describe Vault::EncryptedModel do
  let(:klass) do
    Class.new(ActiveRecord::Base) do
      include Vault::EncryptedModel
    end
  end

  describe ".vault_attribute" do
    it "raises an exception if a serializer and :encode is given" do
      expect {
        klass.vault_attribute(:foo, serializer: :json, encode: ->(r) { r })
      }.to raise_error(Vault::Rails::ValidationFailedError)
    end

    it "raises an exception if a serializer and :decode is given" do
      expect {
        klass.vault_attribute(:foo, serializer: :json, decode: ->(r) { r })
      }.to raise_error(Vault::Rails::ValidationFailedError)
    end

    it "raises an exception if a proc is passed to :context without an arity of 1" do
      expect {
        klass.vault_attribute(:foo, context: ->() { })
      }.to raise_error(Vault::Rails::ValidationFailedError, /1 argument/i)
    end

    it "defines a getter" do
      klass.vault_attribute(:foo)
      expect(klass.instance_methods).to include(:foo)
    end

    it "defines a setter" do
      klass.vault_attribute(:foo)
      expect(klass.instance_methods).to include(:foo=)
    end

    it "defines a checker" do
      klass.vault_attribute(:foo)
      expect(klass.instance_methods).to include(:foo?)
    end

    it "defines dirty attribute methods" do
      expect(Person.new).to respond_to(:ssn_change)
      expect(Person.new).to respond_to(:ssn_changed?)
      expect(Person.new).to respond_to(:ssn_was)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vault-rails-0.9.0 spec/unit/encrypted_model_spec.rb