Sha256: 56b79c3b79dcb41c892efa474e1b285c4fed2fa77f6acb5b13b9569bf42b28dc
Contents?: true
Size: 1.62 KB
Versions: 4
Compression:
Stored size: 1.62 KB
Contents
require 'spec_helper' require 'slosilo/adapters/sequel_adapter' describe Slosilo::Adapters::SequelAdapter do let(:model) { double "model" } before { subject.stub create_model: model } describe "#get_key" do context "when given key does not exist" do before { model.stub :[] => nil } it "returns nil" do subject.get_key(:whatever).should_not be end end end describe "#put_key" do let(:id) { "id" } let(:key) { "key" } it "creates the key" do model.should_receive(:create).with id: id, key: key subject.put_key id, key end end let(:adapter) { subject } describe "#each" do let(:one) { double("one", id: :one, key: :onek) } let(:two) { double("two", id: :two, key: :twok) } before { model.stub(:each).and_yield(one).and_yield(two) } it "iterates over each key" do results = [] adapter.each { |id,k| results << { id => k } } results.should == [ { one: :onek}, {two: :twok } ] end end describe '#model' do let(:db) { Sequel.sqlite } before do Slosilo::encryption_key = Slosilo::Symmetric.new.random_key subject.unstub :create_model require 'sequel' Sequel::Model.db = db Sequel.extension :migration require 'slosilo/adapters/sequel_adapter/migration' Sequel::Migration::descendants.first.apply db, :up end let(:key) { 'fake key' } let(:id) { 'some id' } it "transforms (encrypts) the key" do subject.model.create id: id, key: key db[:slosilo_keystore][id: id][:key].should_not == key subject.model[id].key.should == key end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
slosilo-0.2.4 | spec/sequel_adapter_spec.rb |
slosilo-0.2.3 | spec/sequel_adapter_spec.rb |
slosilo-0.2.2 | spec/sequel_adapter_spec.rb |
slosilo-0.1.2 | spec/sequel_adapter_spec.rb |