Sha256: e1e5c9114cd601e0adf02beac99c8bdad699d27a20c409a2e90a087d43f56766

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

require 'minitest_helper'

describe Asynchronic::DataStore::Key do

  Key = Asynchronic::DataStore::Key

  it 'Return the namespace' do
    key = Key['foo']
    key.must_equal 'foo'
  end

  it 'Prepend the namespace' do
    key = Key['foo']
    key['bar'].must_equal 'foo|bar'
  end

  it 'Work in more than one level' do
    key_1 = Key['foo']
    key_2 = Key[key_1['bar']]
    key_2['baz'].must_equal 'foo|bar|baz'
  end

  it 'Be chainable' do
    key = Key['foo']
    key['bar']['baz'].must_equal 'foo|bar|baz'
  end

  it 'Accept symbols' do
    key = Key[:foo]
    key[:bar].must_equal 'foo|bar'
  end

  it 'Accept numbers' do
    key = Key['foo']
    key[3].must_equal 'foo|3'
  end

  it 'Split in sections' do
    key = Key[:foo][:bar][:buz]
    key.sections.must_equal %w(foo bar buz)
  end

  it 'Detect nested sections' do
    Key[:foo].wont_be :nested?
    Key[:foo][:bar].must_be :nested?
  end

  it 'Remove first sections' do
    key = Key[:foo][:bar][:buz]
    key.remove_first.must_equal 'bar|buz'
    key.remove_first(2).must_equal 'buz'
  end

  it 'Remove last sections' do
    key = Key[:foo][:bar][:buz]
    key.remove_last.must_equal 'foo|bar'
    key.remove_last(2).must_equal 'foo'
  end
  
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
asynchronic-3.0.3 spec/data_store/key_spec.rb
asynchronic-3.0.2 spec/data_store/key_spec.rb
asynchronic-3.0.1 spec/data_store/key_spec.rb
asynchronic-3.0.0 spec/data_store/key_spec.rb
asynchronic-2.0.1 spec/data_store/key_spec.rb
asynchronic-2.0.0 spec/data_store/key_spec.rb
asynchronic-1.6.3 spec/data_store/key_spec.rb
asynchronic-1.6.2 spec/data_store/key_spec.rb
asynchronic-1.6.1 spec/data_store/key_spec.rb
asynchronic-1.6.0 spec/data_store/key_spec.rb
asynchronic-1.5.2 spec/data_store/key_spec.rb
asynchronic-1.5.1 spec/data_store/key_spec.rb
asynchronic-1.5.0 spec/data_store/key_spec.rb