Sha256: 0eae2c65381cc759adc675b8a1c7924f47f54b5801eecf62f3f843cc3aaad850

Contents?: true

Size: 1.54 KB

Versions: 32

Compression:

Stored size: 1.54 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 "uses the global preferences instance" do
      is_expected.to be Spree::Preferences::Store.instance
    end
  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

32 entries across 32 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.2.2 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.1.1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.0.3 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-1.4.2 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-1.3.2 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.3.0 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.0.2 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-1.4.1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.2.1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.2.0 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.1.0 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/preferences/scoped_store_spec.rb
solidus_core-2.0.1 spec/models/spree/preferences/scoped_store_spec.rb