-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tonto.rb
More file actions
74 lines (55 loc) · 1.53 KB
/
Copy pathtest_tonto.rb
File metadata and controls
74 lines (55 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'digest/md5'
require 'fileutils'
require File.expand_path(File.dirname(__FILE__) + '/helper')
context "Tonto" do
setup do
@db = Tonto::Repo.new("example", "mydb")
end
context "database" do
setup do
@repo = Tonto::Repo.new("repo", "db")
end
test "is the real db" do
assert_equal "db", @repo.db
end
test "create a db" do
assert @db.open("tonto")
assert_equal "tonto", @repo.db
end
end
test "repo path" do
assert_equal "example", @db.path
end
test "git repo" do
assert_equal Grit::Repo, @db.db.class
end
test "put a new document with id" do
assert @db.put({:id => 12, :name => "tonto", :says => "i'm not stupid :("})
end
test "get a document by id" do
assert @db.get(12)
assert_equal "tonto", @db.get(12)["name"]
end
test "ask if a key exists" do
assert @db.exist?(12)
assert @db.exists?(12)
end
test "update a document" do
assert @db.put :id => 12, :nick => "git"
assert_equal "git", @db.get(12)["nick"]
assert @db.put :id => 12, :nick => "tonto"
assert_equal "git", @db.get(12)["nick"]
end
test "remove a document" do
assert @db.remove(12)
assert_equal nil, @db.get(12)
end
test "add a blob" do
assert @db.put :id => 3, :name => "logo", :blobs => {'octocat' => "octocat.png"}
digest = Digest::MD5.hexdigest(File.read("octocat.png"))
assert_equal digest, Digest::MD5.hexdigest(@db.get(3)["blobs"]["octocat"])
end
#teardown do
# FileUtils.rm_rf(@db.path)
#end
end