Sha256: 106729d42c68b8a1214ea48e6549e0eb81f8188db503cdb6486a3ffc531c7e8d

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

module Spreeference
  describe Spreeference::ScopedStore, type: :model do
    let(:scoped_store){ described_class.new(prefix, suffix) }
    subject{ scoped_store }
    let(:prefix){ nil }
    let(:suffix){ nil }

    describe '#store' do
      subject{ scoped_store.store }
      it{ is_expected.to be Spreeference::Store.instance }
    end

    context 'stubbed store' do
      let(:store){ double(:store) }
      before do
        allow(scoped_store).to receive(:store).and_return(store)
      end

      context "with a prefix" do
        let(:prefix){ 'my_class' }

        it "can fetch" do
          expect(store).to receive(:fetch).with('my_class/attr')
          scoped_store.fetch('attr'){ 'default' }
        end

        it "can assign" do
          expect(store).to receive(:[]=).with('my_class/attr', 'val')
          scoped_store['attr'] = 'val'
        end

        it "can delete" do
          expect(store).to receive(:delete).with('my_class/attr')
          scoped_store.delete('attr')
        end

        context "and suffix" do
          let(:suffix){ 123 }

          it "can fetch" do
            expect(store).to receive(:fetch).with('my_class/attr/123')
            scoped_store.fetch('attr'){ 'default' }
          end

          it "can assign" do
            expect(store).to receive(:[]=).with('my_class/attr/123', 'val')
            scoped_store['attr'] = 'val'
          end

          it "can delete" do
            expect(store).to receive(:delete).with('my_class/attr/123')
            scoped_store.delete('attr')
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spreeference-0.1.1 spec/lib/spreeference/scoped_store_spec.rb
spreeference-0.1.0 spec/lib/spreeference/scoped_store_spec.rb