Sha256: 17e6421d3a8aa4a8b714744a674b2296698116b076f73028d5a7c04788ee1362

Contents?: true

Size: 1.49 KB

Versions: 21

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'

describe Spree::Preferences::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 Spree::Preferences::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

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
solidus_core-1.0.7 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.5 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.4 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.3 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.2 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.0.10 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.1 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.0 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.0.rc4 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.0.9 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.0.rc3 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.0.rc2 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.1.0.rc1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-1.0.6 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.0.8 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.0.7 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-1.0.5 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.0.6.1 spec/models/spree/preferences/scoped_store_spec.rb
spree_core-3.0.6 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-1.0.4 spec/models/spree/preferences/scoped_store_spec.rb