Sha256: d61b0739ad8eda7383a97c68aefebf57a0516c3ca5ad573e3b3ac690c63a4b77

Contents?: true

Size: 1.45 KB

Versions: 30

Compression:

Stored size: 1.45 KB

Contents

require 'helper'

class TestMongohash < Test::Unit::TestCase
  should "work with dot_get, dot_set, dot_delete" do
    h = Mongoo::Mongohash.new({
      "name" => "Ben", 
      "travel" => {},
      "location" => { "city" => "SF", "zip" => 94107, "demographics" => { "pop" => 120000 } }})
    assert_equal "Ben", h.dot_get("name")
    assert_equal "SF", h.dot_get("location.city")
    assert_equal 94107, h.dot_get("location.zip")
    assert_equal 120000, h.dot_get("location.demographics.pop")
    assert_equal nil, h.dot_get("foobar")
    assert_equal nil, h.dot_get("location.idontexist.andneitherdoi")
    h.dot_set("location.demographics.pop", 10000)
    assert_equal 10000, h.dot_get("location.demographics.pop")
    h.dot_set("interests", ["skydiving"])
    assert_equal ["skydiving"], h.dot_get("interests")
    h.dot_set("languages.fluent", ["english"])
    h.dot_set("languages.nonfluent", ["german"])
    assert_equal ["english"], h.dot_get("languages.fluent")
    assert_equal ["german"], h.dot_get("languages.nonfluent")
    h.dot_delete("languages.fluent")
    assert_equal nil, h.dot_get("languages.fluent")
    h.dot_delete("languages")
    assert_equal nil, h.dot_get("languages")
    assert_equal "Ben", h.dot_get("name")
    h.dot_delete("name")
    assert_equal nil, h.dot_get("name")
  end

  # should "not be able to initialize an object with undefined attributes" do
  #   assert_raise(Mongoo::UnknownAttributeError) { Person.new(:idontexist => "bah") }
  # end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
mongoo-0.5.7 test/test_mongohash.rb
mongoo-0.5.6 test/test_mongohash.rb
mongoo-0.5.5 test/test_mongohash.rb
mongoo-0.5.4 test/test_mongohash.rb
mongoo-0.5.3 test/test_mongohash.rb
mongoo-0.5.2 test/test_mongohash.rb
mongoo-0.5.1 test/test_mongohash.rb
mongoo-0.5.0 test/test_mongohash.rb
mongoo-0.4.10 test/test_mongohash.rb
mongoo-0.4.9 test/test_mongohash.rb
mongoo-0.4.8 test/test_mongohash.rb
mongoo-0.4.7 test/test_mongohash.rb
mongoo-0.4.6 test/test_mongohash.rb
mongoo-0.4.5 test/test_mongohash.rb
mongoo-0.4.4 test/test_mongohash.rb
mongoo-0.4.3 test/test_mongohash.rb
mongoo-0.4.2 test/test_mongohash.rb
mongoo-0.4.1 test/test_mongohash.rb
mongoo-0.4.0 test/test_mongohash.rb
mongoo-0.3.1 test/test_mongohash.rb