forked from technoweenie/guillotine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo_adapter_test.rb
56 lines (44 loc) · 1.24 KB
/
mongo_adapter_test.rb
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
require File.expand_path('../helper', __FILE__)
begin
require 'mongo'
class MongoAdapterTest < Guillotine::TestCase
def setup
@collection = Mongo::Connection.new.db('test').collection('guillotine')
@collection.drop
@db = Guillotine::MongoAdapter.new(@collection)
end
def test_adding_a_link_returns_code
code = @db.add 'abc'
assert_equal 'abc', @db.find(code)
end
def test_adding_duplicate_link_returns_same_code
code = @db.add 'abc'
assert_equal code, @db.add('abc')
end
def test_adds_url_with_custom_code
assert_equal 'code', @db.add('def', 'code')
assert_equal 'def', @db.find('code')
end
def test_clashing_urls_raises_error
code = @db.add 'abc'
assert_raises Guillotine::DuplicateCodeError do
@db.add 'def', code
end
end
def test_missing_code
assert_nil @db.find('missing')
end
def test_gets_code_for_url
code = @db.add 'abc'
assert_equal code, @db.code_for('abc')
end
def test_clears_code_for_url
code = @db.add 'abc'
assert_equal 'abc', @db.find(code)
@db.clear 'abc'
assert_nil @db.find(code)
end
end
rescue LoadError
puts "Skipping MongoDB tests: #{$!}"
end