Sha256: 4af58c383a2c4e5836f8490b85badeae329bb6f62f1e4eb2b9f8fb4ac0e3f527

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require 'init_tests'
require 'easy_key_value'
require 'test/unit'
require 'models/Foo'

load 'schema.rb'

class EayKeyValueTest < Test::Unit::TestCase


  def test_get_set_del
    foo = Foo.new
    foo.save

    assert_equal true, foo.add_key('foo', 'bar')
    assert_equal false, foo.add_key('foo', 'bar')

    assert_equal 'bar', foo.get_key('foo')
    assert_equal true, foo.del_key('foo')
    assert_equal false, foo.del_key('foo')
    assert_equal false, foo.del_key('bar')
    assert_equal nil, foo.get_key('foo')

    foo.add_key('toto', 'tata')

    foo = Foo.last

    assert_equal 'tata', foo.get_key('toto')

    assert_equal 'tata', foo.kv_store['toto']

    assert_equal true, foo.kv_store.frozen?

    assert_equal true, foo.update_key('toto', 'tutu')
    assert_equal false, foo.update_key('totu', 'tutu')

    assert_equal 'tutu', foo.get_key('toto')
    foo = Foo.last
    assert_equal 'tutu', foo.get_key('toto')

  end

  def test_key
    foo = Foo.new
    foo.save

    assert_equal nil, foo.key('foo')

    assert_equal true, foo.key('foo', 'bar')
    assert_equal 'bar', foo.key('foo')

    foo = Foo.last

    assert_equal 'bar', foo.key('foo')
    assert_equal true, foo.key('foo', 'baz')
    assert_equal 'baz', foo.key('foo')

    foo = Foo.last
    assert_equal 'baz', foo.key('foo')

  end

  def test_default_values
    foo = Foo.new
    foo.save

    assert_equal 'mia', foo.key('mama')

    foo.key('mama', 'nomia')

    assert_equal 'nomia', foo.key('mama')
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
easy_key_value-0.1.2 test/test_ekv.rb
easy_key_value-0.1.1 test/test_ekv.rb
easy_key_value-0.1.0 test/test_ekv.rb