-
-
Save minhajuddin/764729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "test/unit" | |
| require "rubygems" | |
| require "mongoid" | |
| Mongoid.configure do |config| | |
| name = "embed_hash_test" | |
| host = "localhost" | |
| config.master = Mongo::Connection.new.db(name) | |
| config.persist_in_safe_mode = false | |
| end | |
| class RootDoc | |
| include Mongoid::Document | |
| field :data, :type => Hash | |
| embeds_many :embedded_docs | |
| end | |
| class EmbeddedDoc | |
| include Mongoid::Document | |
| field :data, :type => Hash | |
| embedded_in :root_doc, :inverse_of => :embedded_docs | |
| end | |
| RootDoc.delete_all | |
| class EmbeddedHashSearch < Test::Unit::TestCase | |
| #passing test | |
| def test_root_doc_hash_search | |
| doc = RootDoc.create :data => {"test" => "this is a test" } | |
| assert_equal RootDoc.where("data.test" => "this is a test" ).first, doc | |
| end | |
| #failing test | |
| def test_embedded_hash_search | |
| root = RootDoc.new | |
| embed = EmbeddedDoc.new :data => {"test" => "this is a test" } | |
| root.embedded_docs << embed | |
| embed.save | |
| #root.save | |
| assert_equal RootDoc.where('embedded_docs.data.test' => "this is a test").first.embedded_docs.first, embed | |
| #assert_equal root.embedded_docs.where("data.test" => "this is a test" ).first, embed | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment