Sha256: 29285f596682a6ed720874b7990a2a134d318bb0531d8205156408b22d40d7ac

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'
require 'spec/support/keys'
require 'spec/support/repos'
require 'donjon/database'
require 'donjon/user'

describe Donjon::Database do
  let_repo :repo

  let(:actor) {
    Donjon::User.new(name: 'alice', key: random_key, repo: repo).save
  }

  let(:other_user) {
    Donjon::User.new(name: 'bob', key: random_key, repo: repo).save
  }

  let(:options) {{
    actor: actor
  }}

  subject { described_class.new(**options) }

  describe '#initialize' do
    it 'passes with valid options' do
      expect { subject }.not_to raise_error
    end

    it 'requires :actor' do
      options.delete :actor
      expect { subject }.to raise_error
    end
  end

  describe '#[]=' do
    it 'passes' do
      expect {
        subject['foo'] = 'bar'
      }.not_to raise_error
    end
  end

  describe '#[]' do
    it 'returns nil is nothing saved' do
      expect( subject['foo1'] ).to be_nil
    end

    it 'returns nil if nil saved' do
      subject['foo2'] = nil
      expect( subject['foo2'] ).to be_nil
    end

    it 'returns previously save values' do
      subject['foo3'] = 'bar3'
      expect( subject['foo3'] ).to eq('bar3')
    end

    it 'returns nil when the key is not readable' do
      subject['foo4'] = 'bar4'
      other_db = described_class.new(actor: other_user)
      expect(other_db['foo4']).to be_nil
    end
  end

  describe '#update' do
    it 'makes keys reable for other users' do
      subject['foo'] = 'bar'
      other_db = described_class.new(actor: other_user)
      subject.update
      expect(other_db['foo']).to eq('bar')
    end
  end

  describe '#each' do
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
donjon-0.0.4 spec/donjon/database_spec.rb
donjon-0.0.3 spec/donjon/database_spec.rb
donjon-0.0.2 spec/donjon/database_spec.rb
donjon-0.0.1 spec/donjon/database_spec.rb