Sha256: 04e8a1788e01535b634809be2260a2b2706fe7593078555e7d05c7a2b8ecedd2

Contents?: true

Size: 1.92 KB

Versions: 7

Compression:

Stored size: 1.92 KB

Contents

describe BubbleWrap::Persistence do

  describe '.app_key' do

    it "caches the @app_key" do
      BubbleWrap::Persistence.instance_variable_get(:@app_key).should.equal nil
      BubbleWrap::Persistence.app_key
      BubbleWrap::Persistence.instance_variable_get(:@app_key).should.not.equal nil
    end

    it 'delegates to BubbleWrap::App.idenfitier' do
      BubbleWrap::Persistence.app_key.should == BubbleWrap::App.identifier
    end

  end


  describe "storing objects" do
    it 'can persist simple objects' do
      lambda do
        BubbleWrap::Persistence['arbitraryNumber'] = 42
      end.
        should.not.raise(Exception)
    end

    it "must call synchronize" do
      storage = NSUserDefaults.standardUserDefaults
      def storage.synchronize; @sync_was_called = true; end

      BubbleWrap::Persistence['arbitraryNumber'] = 42
      storage.instance_variable_get(:@sync_was_called).should.equal true
    end
  end

  describe "storing multiple objects" do
    it 'can persist multiple objects' do
      lambda do
        BubbleWrap::Persistence.merge({
          :anotherArbitraryNumber => 9001,
          :arbitraryString => 'test string'
        })
      end.
        should.not.raise(Exception)
    end

    it 'must call synchronize' do
      storage = NSUserDefaults.standardUserDefaults
      def storage.synchronize; @sync_was_called = true; end

      BubbleWrap::Persistence.merge({
        :anotherArbitraryNumber => 9001,
        :arbitraryString => 'test string'
      })
      storage.instance_variable_get(:@sync_was_called).should.equal true
    end
  end

  describe "retrieving objects" do
    it 'can retrieve persisted objects' do
      BubbleWrap::Persistence['arbitraryNumber'].should == 42
      BubbleWrap::Persistence[:arbitraryString].should == 'test string'
    end

    it 'returns fully functional strings' do
      BubbleWrap::Persistence[:arbitraryString].methods.should == 'test string'.methods
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bubble-wrap-1.3.0 spec/motion/core/persistence_spec.rb
bubble-wrap-1.3.0.osx spec/motion/core/persistence_spec.rb
bubble-wrap-1.2.0 spec/motion/core/persistence_spec.rb
bubble-wrap-1.2.0.pre spec/motion/core/persistence_spec.rb
bubble-wrap-1.1.5 spec/motion/core/persistence_spec.rb
bubble-wrap-1.1.4 spec/motion/core/persistence_spec.rb
bubble-wrap-1.1.3 spec/motion/core/persistence_spec.rb