summaryrefslogtreecommitdiff
path: root/rbejdb
diff options
context:
space:
mode:
authorFedor Yudanov <fedwiz@academ.org>2013-04-04 20:20:55 +0700
committerFedor Yudanov <fedwiz@academ.org>2013-04-04 20:20:55 +0700
commit76dd9f13298ce7fc0f32b160ee76db4a76156c6d (patch)
treea5142c6eebb96efc23d2e41cf488963bf0cf51aa /rbejdb
parentdde2a9da88c7fb3a636166296f16793d32eef3f3 (diff)
downloadejdb-76dd9f13298ce7fc0f32b160ee76db4a76156c6d.tar.gz
ejdb-76dd9f13298ce7fc0f32b160ee76db4a76156c6d.tar.bz2
ejdb-76dd9f13298ce7fc0f32b160ee76db4a76156c6d.zip
#50 - advanced tests (test 11)
Diffstat (limited to 'rbejdb')
-rw-r--r--rbejdb/src/rbejdb.c19
-rw-r--r--rbejdb/test/t2.rb18
2 files changed, 37 insertions, 0 deletions
diff --git a/rbejdb/src/rbejdb.c b/rbejdb/src/rbejdb.c
index 1c4f6ab..00cf9e4 100644
--- a/rbejdb/src/rbejdb.c
+++ b/rbejdb/src/rbejdb.c
@@ -320,6 +320,24 @@ VALUE EJDB_update(int argc, VALUE* argv, VALUE self) {
}
+void EJDB_remove(VALUE self, VALUE collName, VALUE rboid) {
+ SafeStringValue(collName);
+ SafeStringValue(rboid);
+
+ EJDB* ejdb = getEJDB(self);
+
+ EJCOLL *coll = ejdbgetcoll(ejdb, StringValuePtr(collName));
+ if (!coll) {
+ raise_ejdb_error(ejdb);
+ }
+
+ bson_oid_t oid = ruby_to_bson_oid(rboid);
+ if (!ejdbrmbson(coll, &oid)) {
+ raise_ejdb_error(ejdb);
+ }
+}
+
+
void EJDB_set_index_internal(VALUE self, VALUE collName, VALUE fpath, int flags) {
SafeStringValue(collName);
SafeStringValue(fpath);
@@ -561,6 +579,7 @@ Init_rbejdb() {
rb_define_method(ejdbClass, "find", RUBY_METHOD_FUNC(EJDB_find), -1);
rb_define_method(ejdbClass, "find_one", RUBY_METHOD_FUNC(EJDB_find_one), -1);
rb_define_method(ejdbClass, "update", RUBY_METHOD_FUNC(EJDB_update), -1);
+ rb_define_method(ejdbClass, "remove", RUBY_METHOD_FUNC(EJDB_remove), 2);
rb_define_method(ejdbClass, "drop_collection", RUBY_METHOD_FUNC(EJDB_drop_collection), 2);
rb_define_method(ejdbClass, "ensure_collection", RUBY_METHOD_FUNC(EJDB_ensure_collection), -1);
diff --git a/rbejdb/test/t2.rb b/rbejdb/test/t2.rb
index b52ae09..f2d2379 100644
--- a/rbejdb/test/t2.rb
+++ b/rbejdb/test/t2.rb
@@ -316,4 +316,22 @@ class EJDBTestUnit < Test::Unit::TestCase
puts "test_ejdba_id_nin has passed successfull"
end
+ def test_ejdbb_test_remove
+ assert_not_nil $jb
+ assert $jb.is_open?
+
+ obj = $jb.find_one("birds", {"name" => "Molly"})
+ assert_not_nil obj
+ assert_not_nil obj["_id"]
+ assert_equal("Very angry", obj["mood"])
+
+ #Bye bye Molly!
+ $jb.remove("birds", obj["_id"])
+
+ obj = $jb.find_one("birds", {"name" => "Molly"})
+ assert_nil obj
+
+ puts "test_ejdbb_test_remove has passed successfull"
+ end
+
end