spec/admin_party/database_spec.rb in leanback-0.4.1 vs spec/admin_party/database_spec.rb in leanback-0.4.2

- old
+ new

@@ -35,18 +35,23 @@ data = {:firstname => 'John', :lastname =>'smith', :phone => '202-234-1234', :email =>'james@mail.com', - :age =>'34', - :gender =>'male'} + :age =>'34', + :gender =>'male'} doc = {:database => 'friends', :doc_id => 'john', :data => data} Couchdb.create_doc doc doc = {:database => 'friends', :doc_id => 'john'} hash = Couchdb.view doc hash["_id"].should == 'john' + + #view doc and return symbolized keys + doc = {:database => 'friends', :doc_id => 'john'} + hash = Couchdb.view(doc,'', {symbolize_keys: true}) + hash.should include(data) end it "should count the lastnames named smith" do count = Couchdb.count({:database => 'friends', :lastname => 'smith'}) count.should == 1 @@ -225,12 +230,12 @@ data = {:firstname => 'aaron', :gender =>'male', :age => '28', :salary => '50000'} doc = {:database => 'fishes', :doc_id => 'aaron', :data => data} Couchdb.create_doc doc - data = {:firstname => 'john', :gender =>'male', :age => '28', :salary => '60000'} - doc = {:database => 'fishes', :doc_id => 'john', :data => data} + data_c = {:firstname => 'john', :gender =>'male', :age => '28', :salary => '60000'} + doc = {:database => 'fishes', :doc_id => 'john', :data => data_c} Couchdb.create_doc doc data = {:firstname => 'peter', :gender =>'male', :age => '45', :salary => '78000'} doc = {:database => 'fishes', :doc_id => 'peter', :data => data} Couchdb.create_doc doc @@ -243,10 +248,14 @@ keys = {:age =>'28', :gender => 'male'} hash = Couchdb.find_by_keys({:database => 'fishes', :keys => keys},'', options = {:limit => 2, :skip => 1}) h = hash[0] h["firstname"].should == "john" hash.length.should == 2 + + #return hash in symbolized keys for find_by_keys + hash = Couchdb.find_by_keys({:database => 'fishes', :keys => keys},'', options = {:limit => 2, :skip => 1, :symbolize_keys => true}) + hash.first.should include(data_c) #create the design doc to be queryed in the test Couchdb.find_by({:database => 'fishes', :gender => 'male'}) @@ -256,17 +265,28 @@ hash = Couchdb.find view,"",key=nil, options = {:limit => 2, :skip => 1} h = hash[0] h["firstname"].should == "john" hash.length.should == 2 + + #return results in symbolized keys + hash = Couchdb.find view,'',key=nil, options = {:limit => 2, :skip => 1, :symbolize_keys => true} + hash.first.should include(data_c) + + #it should not return symbolized keys + hash = Couchdb.find view,'',key=nil, options = {:limit => 2, :skip => 1, :symbolize_keys => false} + hash.first.should_not include(data_c) + hash.first["firstname"].should == "john" Couchdb.find_by({:database => 'fishes', :gender => 'male'},"",options = {:limit => 2, :skip => 1}) h = hash[0] h["firstname"].should == "john" hash.length.should == 2 - + #return symbolized results + hash = Couchdb.find_by({:database => 'fishes', :gender => 'male'},'',options = {:limit => 2, :skip => 1, :symbolize_keys => true}) + hash.first.should include(data_c) hash = Couchdb.find view,"",key='male', options = {:descending => true} h = hash[0] h["firstname"].should == "sam" @@ -336,9 +356,15 @@ h0 = hash[0] h1 = hash[1] h0["firstname"].should == "john" h1["firstname"].should == "sam" hash.length.should == 2 + + + #return results as symbolized keys + options = {:startkey => ["28","male"], :endkey => ["28","male"], :skip => 1,:symbolize_keys => true} + hash = Couchdb.find_on_fly(view,'',key=nil, options) + hash.first.should include(data_c) options = {:startkey => ["28","male"], :endkey => ["28","male"]} hash = Couchdb.find_on_fly(view,"",key=nil, options)