guillotine 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/guillotine.gemspec +2 -2
- data/lib/guillotine/adapters/riak_adapter.rb +18 -11
- data/lib/guillotine.rb +1 -1
- data/test/riak_adapter_test.rb +18 -2
- metadata +9 -9
data/guillotine.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'guillotine'
|
16
|
-
s.version = '1.0.
|
17
|
-
s.date = '2011-
|
16
|
+
s.version = '1.0.1'
|
17
|
+
s.date = '2011-09-29'
|
18
18
|
s.rubyforge_project = 'guillotine'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -26,19 +26,26 @@ module Guillotine
|
|
26
26
|
def add(url, code = nil)
|
27
27
|
sha = url_key url
|
28
28
|
url_obj = @url_bucket.get_or_new sha, :r => 1
|
29
|
-
url_obj.data
|
30
|
-
code
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
if url_obj.data
|
30
|
+
code = url_obj.data
|
31
|
+
end
|
32
|
+
|
33
|
+
code ||= shorten url
|
34
|
+
code_obj = @code_bucket.get_or_new code
|
35
|
+
|
36
|
+
if existing_url = code_obj.data # key exists
|
37
|
+
raise DuplicateCodeError.new(existing_url, url, code) if existing_url != url
|
38
|
+
end
|
39
|
+
|
40
|
+
if !url_obj.data # unsaved
|
41
|
+
url_obj.data = code
|
39
42
|
url_obj.store
|
40
|
-
code
|
41
43
|
end
|
44
|
+
|
45
|
+
code_obj.content_type = url_obj.content_type = 'text/plain'
|
46
|
+
code_obj.data = url
|
47
|
+
code_obj.store
|
48
|
+
code
|
42
49
|
end
|
43
50
|
|
44
51
|
# Public: Retrieves a URL from the code.
|
data/lib/guillotine.rb
CHANGED
data/test/riak_adapter_test.rb
CHANGED
@@ -12,8 +12,8 @@ begin
|
|
12
12
|
# http://localhost:8091/riak/guillotine-test
|
13
13
|
class RiakAdapterTest < Guillotine::TestCase
|
14
14
|
client = Riak::Client.new(:http_port => 8091)
|
15
|
-
CODE_BUCKET = client[
|
16
|
-
URL_BUCKET = client[
|
15
|
+
CODE_BUCKET = client["guillotine-code-test-#{Process.pid}"]
|
16
|
+
URL_BUCKET = client["guillotine-url-test-#{Process.pid}"]
|
17
17
|
ADAPTER = Guillotine::Adapters::RiakAdapter.new CODE_BUCKET, URL_BUCKET
|
18
18
|
|
19
19
|
def setup
|
@@ -44,6 +44,22 @@ begin
|
|
44
44
|
CODE_BUCKET.delete 'code'
|
45
45
|
end
|
46
46
|
|
47
|
+
def test_adds_url_with_missing_url_key
|
48
|
+
url = 'inconsistent'
|
49
|
+
code = "#{url}_code"
|
50
|
+
sha = @db.url_key url
|
51
|
+
url_obj = URL_BUCKET.new sha
|
52
|
+
url_obj.data = code
|
53
|
+
url_obj.store
|
54
|
+
|
55
|
+
assert_nil @db.find(code)
|
56
|
+
|
57
|
+
added_code = @db.add url
|
58
|
+
|
59
|
+
assert_equal code, added_code
|
60
|
+
assert_equal url, @db.find(code)
|
61
|
+
end
|
62
|
+
|
47
63
|
def test_clashing_urls_raises_error
|
48
64
|
code = @db.add 'abc'
|
49
65
|
assert_raises Guillotine::DuplicateCodeError do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guillotine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
16
|
-
requirement: &
|
16
|
+
requirement: &70118940049540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.2.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70118940049540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: addressable
|
27
|
-
requirement: &
|
27
|
+
requirement: &70118940049020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.2.6
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70118940049020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack-test
|
38
|
-
requirement: &
|
38
|
+
requirement: &70118940048460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70118940048460
|
47
47
|
description: Adaptable private URL shortener
|
48
48
|
email: technoweenie@gmail.com
|
49
49
|
executables: []
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project: guillotine
|
91
|
-
rubygems_version: 1.8.
|
91
|
+
rubygems_version: 1.8.10
|
92
92
|
signing_key:
|
93
93
|
specification_version: 2
|
94
94
|
summary: Adaptable private URL shortener
|