Permalink
Browse files

check if xapian database exists before removing - closes #28

  • Loading branch information...
1 parent b7c78e7 commit f2f6eaaf6bbbb1051976f0c4897a0bab5c0e8216 @ryanb committed Jul 6, 2009
Showing with 18 additions and 2 deletions.
  1. +2 −0 CHANGELOG
  2. +2 −2 lib/xapit/config.rb
  3. +14 −0 spec/xapit/config_spec.rb
View
@@ -1,3 +1,5 @@
+* check if xapian database exists before removing
+
* search multiple conditions with OR by passing an array
:conditions => [{ :category_id => 1 }, { :priority => 2 }]
View
@@ -65,8 +65,8 @@ def writable_database
end
# Removes the configured database file and clears the stored one in memory.
- def remove_database # this can be a bit dangers, maybe do some checking here first?
- FileUtils.rm_rf(path) if File.exist? path
+ def remove_database
+ FileUtils.rm_rf(path) if File.exist? File.join(path, "iamflint")
@database = nil
@writable_database = nil
end
View
@@ -45,4 +45,18 @@
Xapit::Config.setup(:stemming => "german")
Xapit::Config.stemming == "german"
end
+
+ it "should remove the database if it is a true xapian database" do
+ Xapit::Config.writable_database # load the database
+ Xapit::Config.remove_database
+ File.exist?(Xapit::Config.path).should be_false
+ end
+
+ it "should NOT remove the database if it is not a xapian database" do
+ path = Xapit::Config.path + "/testing"
+ FileUtils.mkdir_p(path)
+ Xapit::Config.remove_database
+ File.exist?(Xapit::Config.path).should be_true
+ FileUtils.rm_rf(Xapit::Config.path)
+ end
end

0 comments on commit f2f6eaa

Please sign in to comment.