mini_token 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/lib/mini_token.rb CHANGED
@@ -10,12 +10,23 @@ class MiniToken < Struct.new(:db, :token)
10
10
  def output(size = nil)
11
11
  generate { @token_size = size.nil? ? TOKEN_SIZE : size }
12
12
  end
13
-
13
+
14
14
  def truncate_tokens
15
15
  connection
16
16
  @db.truncate
17
17
  end
18
-
18
+
19
+ def delete_token(param)
20
+ connection
21
+ @db.filter(:token => param).delete
22
+ end
23
+
24
+ def find(param)
25
+ connection
26
+ t = @db.first(:token => param)
27
+ t[:token] unless t.nil?
28
+ end
29
+
19
30
  def all
20
31
  connection
21
32
  @db.all
@@ -28,21 +39,21 @@ class MiniToken < Struct.new(:db, :token)
28
39
  @token = TOKEN_CHARACTERS.sample(@token_size).join
29
40
  exist_token?
30
41
  end
31
-
42
+
32
43
  protected
33
-
44
+
34
45
  def exist_token?
35
46
  connection
36
47
  @db.first(:token => @token).nil? ? storing : generate unless @token.nil?
37
48
  end
38
-
49
+
39
50
  def storing
40
51
  @token if @db.insert(:token => @token)
41
52
  end
42
-
53
+
43
54
  def connection
44
55
  sequel = Sequel.sqlite(DB_PATH+(TOKEN_ENV=='production' ? '/mini_token.db' : '/mini_token_test.db' ))
45
- @db = sequel[:tokens]
56
+ @db = sequel[:tokens]
46
57
  end
47
58
  end
48
59
  end
data/mini_token.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mini_token}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Antonio Roberto Silva"]
12
- s.date = %q{2010-10-10}
12
+ s.date = %q{2010-10-16}
13
13
  s.description = %q{Generate simple tokens for short url and other things}
14
14
  s.email = %q{forevertonny@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -32,29 +32,50 @@ describe MiniToken do
32
32
  it 'should be return the token string with size' do
33
33
  assert_match /([a-zA-Z0-9]{10})/, MiniToken.output(10)
34
34
  end
35
-
35
+
36
36
  describe ".truncate_tokens" do
37
37
  before(:each) do
38
38
  4.times { MiniToken.output }
39
39
  end
40
-
40
+
41
41
  it "should have many tokens " do
42
42
  assert_equal MiniToken.all.size, 4
43
43
  end
44
-
44
+
45
45
  it "when call truncate then don't have more tokens storaged" do
46
46
  MiniToken.truncate_tokens
47
47
  assert_equal MiniToken.all.size, 0
48
48
  end
49
49
  end
50
-
50
+
51
+ describe ".delete_token" do
52
+ before(:each) do
53
+ @token = MiniToken.output
54
+ end
55
+
56
+ it "should not have token" do
57
+ MiniToken.delete_token(@token)
58
+ assert_equal nil, MiniToken.find(@token)
59
+ end
60
+ end
61
+
62
+ describe ".find" do
63
+ before(:each) do
64
+ @token = MiniToken.output
65
+ end
66
+
67
+ it "should return token" do
68
+ assert_equal @token, MiniToken.find(@token)
69
+ end
70
+ end
71
+
51
72
  describe ".all" do
52
73
  before(:each) do
53
74
  @token1 = MiniToken.output
54
75
  @token2 = MiniToken.output
55
- @token3 = MiniToken.output
56
- end
57
-
76
+ @token3 = MiniToken.output
77
+ end
78
+
58
79
  it "should return one hash with all tokens storaged" do
59
80
  assert_equal MiniToken.all, [{:id=>1, :token=>@token1}, {:id=>2, :token=>@token2}, {:id=>3, :token=>@token3}]
60
81
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Antonio Roberto Silva
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-10 00:00:00 -03:00
17
+ date: 2010-10-16 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency