tokens 0.2.1 → 1.0.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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg
2
+ Gemfile.lock
3
+ .bundle
4
+ *.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/Gemfile CHANGED
@@ -1,9 +1,2 @@
1
- source :gemcutter
2
-
3
- gem "rspec-rails", "2.0.0.rc"
4
- gem "rails", "3.0.0"
5
- gem "sqlite3-ruby"
6
-
7
- platforms :mri_19 do
8
- gem "ruby-debug19", :require => "ruby-debug"
9
- end
1
+ source :rubygems
2
+ gemspec
data/Rakefile CHANGED
@@ -1,24 +1,5 @@
1
- require "rspec/core/rake_task"
2
- require "./lib/tokens/version"
3
-
4
- begin
5
- require "jeweler"
6
-
7
- JEWEL = Jeweler::Tasks.new do |gem|
8
- gem.name = "tokens"
9
- gem.email = "fnando.vieira@gmail.com"
10
- gem.homepage = "http://github.com/fnando/tokens"
11
- gem.authors = ["Nando Vieira"]
12
- gem.version = Tokens::Version::STRING
13
- gem.summary = "Generate named tokens on your ActiveRecord models."
14
- gem.files = FileList["{Rakefile,README.rdoc,Gemfile,Gemfile.lock,tokens.gemspec}", "{lib,spec,templates}/**/*"]
15
- end
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
16
3
 
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError => e
19
- puts "[JEWELER] You can't build a gem until you install jeweler with `gem install jeweler`"
20
- end
21
-
22
- RSpec::Core::RakeTask.new do |t|
23
- t.ruby_opts = %[ -Ilib -Ispec ]
24
- end
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new
data/lib/tokens.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "rails/railtie"
2
2
  require "active_record"
3
+ require "securerandom"
3
4
 
4
5
  require "tokens/active_record"
5
6
  require "tokens/token"
@@ -24,8 +24,8 @@ module Tokens
24
24
  validity = Proc.new {|token| Token.where(:token => token).first.nil?}
25
25
 
26
26
  begin
27
- seed = "--#{rand}--#{Time.now}--#{rand}--"
28
- token = Digest::SHA1.hexdigest(seed)[0, size]
27
+ token = SecureRandom.hex(40)[0, size]
28
+ token = token.encode("UTF-8") if token.respond_to?(:encoding)
29
29
  end while validity[token] == false
30
30
 
31
31
  token
@@ -88,7 +88,8 @@ module Tokens
88
88
  def find_token(name, token)
89
89
  self.class.find_token(
90
90
  :tokenizable_id => self.id,
91
- :name => name.to_s, :token => token
91
+ :name => name.to_s,
92
+ :token => token
92
93
  )
93
94
  end
94
95
 
data/lib/tokens/token.rb CHANGED
@@ -2,12 +2,8 @@ class Token < ActiveRecord::Base
2
2
  belongs_to :tokenizable, :polymorphic => true
3
3
  serialize :data
4
4
 
5
- def hash
6
- token
7
- end
8
-
9
5
  def to_s
10
- hash
6
+ token
11
7
  end
12
8
 
13
9
  def expired?
@@ -1,8 +1,8 @@
1
1
  module Tokens
2
2
  module Version
3
- MAJOR = 0
4
- MINOR = 2
5
- PATCH = 1
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,11 @@ require File.dirname(__FILE__) + "/support/config/boot"
4
4
  require "rspec/rails"
5
5
 
6
6
  # Load database schema
7
- load File.dirname(__FILE__) + "/schema.rb"
7
+ begin
8
+ load File.dirname(__FILE__) + "/schema.rb"
9
+ rescue Exception => e
10
+ p e
11
+ end
8
12
 
9
13
  require "support/models"
10
14
 
@@ -1,3 +1,3 @@
1
1
  test:
2
2
  adapter: sqlite3
3
- database: ":memory:"
3
+ database: ":memory:"
data/spec/tokens_spec.rb CHANGED
@@ -37,27 +37,27 @@ describe Tokens do
37
37
 
38
38
  it "should alias token method" do
39
39
  token = @user.add_token(:uid)
40
- token.hash.should == token.token
40
+ token.to_s.should == token.token
41
41
  end
42
42
 
43
43
  it "should find user by token" do
44
44
  token = @user.add_token(:uid)
45
- User.find_by_token(:uid, token.hash).should == @user
45
+ User.find_by_token(:uid, token.to_s).should == @user
46
46
  end
47
47
 
48
48
  it "should return user by its valid token without expiration time" do
49
49
  token = @user.add_token(:uid)
50
- User.find_by_valid_token(:uid, token.hash).should == @user
50
+ User.find_by_valid_token(:uid, token.to_s).should == @user
51
51
  end
52
52
 
53
53
  it "should return user by its valid token with expiration time" do
54
54
  token = @user.add_token(:uid, :expires_at => @expire)
55
- User.find_by_valid_token(:uid, token.hash).should == @user
55
+ User.find_by_valid_token(:uid, token.to_s).should == @user
56
56
  end
57
57
 
58
58
  it "should find token using class method with one argument (hash only)" do
59
59
  token = @user.add_token(:uid)
60
- User.find_token(:name => :uid, :token => token.hash).should == token
60
+ User.find_token(:name => :uid, :token => token.to_s).should == token
61
61
  end
62
62
 
63
63
  it "should not conflict with other models" do
@@ -70,7 +70,7 @@ describe Tokens do
70
70
 
71
71
  it "to_s should return hash" do
72
72
  token = @user.add_token(:uid)
73
- token.to_s.should == token.hash
73
+ token.to_s.should == token.to_s
74
74
  end
75
75
 
76
76
  describe Token do
@@ -98,7 +98,7 @@ describe Tokens do
98
98
  end
99
99
 
100
100
  it "should be created with custom size" do
101
- @user.add_token(:uid, :size => 6).hash.size.should == 6
101
+ @user.add_token(:uid, :size => 6).to_s.size.should == 6
102
102
  end
103
103
 
104
104
  it "should find token by its name" do
@@ -113,7 +113,7 @@ describe Tokens do
113
113
 
114
114
  it "should be a valid token" do
115
115
  token = @user.add_token(:uid)
116
- @user.valid_token?(:uid, token.hash).should be_true
116
+ @user.valid_token?(:uid, token.to_s).should be_true
117
117
  end
118
118
 
119
119
  it "should not be a valid token" do
@@ -122,7 +122,7 @@ describe Tokens do
122
122
 
123
123
  it "should find token by its name and hash" do
124
124
  token = @user.add_token(:uid)
125
- @user.find_token(:uid, token.hash).should == token
125
+ @user.find_token(:uid, token.to_s).should == token
126
126
  end
127
127
 
128
128
  it "should not be expired when have no expiration date" do
data/tokens.gemspec CHANGED
@@ -1,61 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tokens/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{tokens}
8
- s.version = "0.2.1"
6
+ s.name = "tokens"
7
+ s.version = Tokens::Version::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nando Vieira"]
10
+ s.email = ["fnando.vieira@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/tokens"
12
+ s.summary = "Generate named tokens on your ActiveRecord models."
13
+ s.description = s.summary
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Nando Vieira"]
12
- s.date = %q{2010-10-06}
13
- s.email = %q{fnando.vieira@gmail.com}
14
- s.extra_rdoc_files = [
15
- "README.rdoc"
16
- ]
17
- s.files = [
18
- "Gemfile",
19
- "Gemfile.lock",
20
- "README.rdoc",
21
- "Rakefile",
22
- "lib/tokens.rb",
23
- "lib/tokens/active_record.rb",
24
- "lib/tokens/generator.rb",
25
- "lib/tokens/railtie.rb",
26
- "lib/tokens/token.rb",
27
- "lib/tokens/version.rb",
28
- "spec/schema.rb",
29
- "spec/spec_helper.rb",
30
- "spec/support/config/boot.rb",
31
- "spec/support/config/database.yml",
32
- "spec/support/log/test.log",
33
- "spec/support/models.rb",
34
- "spec/tokens_spec.rb",
35
- "templates/tokens.rb",
36
- "tokens.gemspec"
37
- ]
38
- s.homepage = %q{http://github.com/fnando/tokens}
39
- s.rdoc_options = ["--charset=UTF-8"]
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
40
18
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.7}
42
- s.summary = %q{Generate named tokens on your ActiveRecord models.}
43
- s.test_files = [
44
- "spec/schema.rb",
45
- "spec/spec_helper.rb",
46
- "spec/support/config/boot.rb",
47
- "spec/support/models.rb",
48
- "spec/tokens_spec.rb"
49
- ]
50
19
 
51
- if s.respond_to? :specification_version then
52
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
- s.specification_version = 3
54
-
55
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
- else
57
- end
58
- else
59
- end
20
+ s.add_development_dependency "rails" , "~> 3.1"
21
+ s.add_development_dependency "rake" , "~> 0.9"
22
+ s.add_development_dependency "rspec-rails" , "~> 2.6"
23
+ s.add_development_dependency "sqlite3" , "~> 1.3.4"
24
+ s.add_development_dependency "ruby-debug19" if RUBY_VERSION >= "1.9"
60
25
  end
61
-
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokens
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 23
5
+ prerelease:
5
6
  segments:
6
- - 0
7
- - 2
8
7
  - 1
9
- version: 0.2.1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Nando Vieira
@@ -14,21 +15,82 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-10-06 00:00:00 -03:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description:
22
- email: fnando.vieira@gmail.com
18
+ date: 2011-08-31 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :development
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 5
28
+ segments:
29
+ - 3
30
+ - 1
31
+ version: "3.1"
32
+ prerelease: false
33
+ requirement: *id001
34
+ name: rails
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 25
43
+ segments:
44
+ - 0
45
+ - 9
46
+ version: "0.9"
47
+ prerelease: false
48
+ requirement: *id002
49
+ name: rake
50
+ - !ruby/object:Gem::Dependency
51
+ type: :development
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 15
58
+ segments:
59
+ - 2
60
+ - 6
61
+ version: "2.6"
62
+ prerelease: false
63
+ requirement: *id003
64
+ name: rspec-rails
65
+ - !ruby/object:Gem::Dependency
66
+ type: :development
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ hash: 19
73
+ segments:
74
+ - 1
75
+ - 3
76
+ - 4
77
+ version: 1.3.4
78
+ prerelease: false
79
+ requirement: *id004
80
+ name: sqlite3
81
+ description: Generate named tokens on your ActiveRecord models.
82
+ email:
83
+ - fnando.vieira@gmail.com
23
84
  executables: []
24
85
 
25
86
  extensions: []
26
87
 
27
- extra_rdoc_files:
28
- - README.rdoc
88
+ extra_rdoc_files: []
89
+
29
90
  files:
91
+ - .gitignore
92
+ - .rspec
30
93
  - Gemfile
31
- - Gemfile.lock
32
94
  - README.rdoc
33
95
  - Rakefile
34
96
  - lib/tokens.rb
@@ -41,18 +103,16 @@ files:
41
103
  - spec/spec_helper.rb
42
104
  - spec/support/config/boot.rb
43
105
  - spec/support/config/database.yml
44
- - spec/support/log/test.log
45
106
  - spec/support/models.rb
46
107
  - spec/tokens_spec.rb
47
108
  - templates/tokens.rb
48
109
  - tokens.gemspec
49
- has_rdoc: true
50
- homepage: http://github.com/fnando/tokens
110
+ homepage: http://rubygems.org/gems/tokens
51
111
  licenses: []
52
112
 
53
113
  post_install_message:
54
- rdoc_options:
55
- - --charset=UTF-8
114
+ rdoc_options: []
115
+
56
116
  require_paths:
57
117
  - lib
58
118
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -60,6 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
120
  requirements:
61
121
  - - ">="
62
122
  - !ruby/object:Gem::Version
123
+ hash: 3
63
124
  segments:
64
125
  - 0
65
126
  version: "0"
@@ -68,13 +129,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
129
  requirements:
69
130
  - - ">="
70
131
  - !ruby/object:Gem::Version
132
+ hash: 3
71
133
  segments:
72
134
  - 0
73
135
  version: "0"
74
136
  requirements: []
75
137
 
76
138
  rubyforge_project:
77
- rubygems_version: 1.3.7
139
+ rubygems_version: 1.8.10
78
140
  signing_key:
79
141
  specification_version: 3
80
142
  summary: Generate named tokens on your ActiveRecord models.
@@ -82,5 +144,6 @@ test_files:
82
144
  - spec/schema.rb
83
145
  - spec/spec_helper.rb
84
146
  - spec/support/config/boot.rb
147
+ - spec/support/config/database.yml
85
148
  - spec/support/models.rb
86
149
  - spec/tokens_spec.rb
data/Gemfile.lock DELETED
@@ -1,102 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.0)
6
- actionpack (= 3.0.0)
7
- mail (~> 2.2.5)
8
- actionpack (3.0.0)
9
- activemodel (= 3.0.0)
10
- activesupport (= 3.0.0)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.4.1)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.12)
16
- rack-test (~> 0.5.4)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.0)
19
- activesupport (= 3.0.0)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.4.1)
22
- activerecord (3.0.0)
23
- activemodel (= 3.0.0)
24
- activesupport (= 3.0.0)
25
- arel (~> 1.0.0)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.0)
28
- activemodel (= 3.0.0)
29
- activesupport (= 3.0.0)
30
- activesupport (3.0.0)
31
- archive-tar-minitar (0.5.2)
32
- arel (1.0.1)
33
- activesupport (~> 3.0.0)
34
- builder (2.1.2)
35
- columnize (0.3.1)
36
- diff-lcs (1.1.2)
37
- erubis (2.6.6)
38
- abstract (>= 1.0.0)
39
- i18n (0.4.1)
40
- linecache19 (0.5.11)
41
- ruby_core_source (>= 0.1.4)
42
- mail (2.2.6.1)
43
- activesupport (>= 2.3.6)
44
- mime-types
45
- treetop (>= 1.4.5)
46
- mime-types (1.16)
47
- polyglot (0.3.1)
48
- rack (1.2.1)
49
- rack-mount (0.6.13)
50
- rack (>= 1.0.0)
51
- rack-test (0.5.6)
52
- rack (>= 1.0)
53
- rails (3.0.0)
54
- actionmailer (= 3.0.0)
55
- actionpack (= 3.0.0)
56
- activerecord (= 3.0.0)
57
- activeresource (= 3.0.0)
58
- activesupport (= 3.0.0)
59
- bundler (~> 1.0.0)
60
- railties (= 3.0.0)
61
- railties (3.0.0)
62
- actionpack (= 3.0.0)
63
- activesupport (= 3.0.0)
64
- rake (>= 0.8.4)
65
- thor (~> 0.14.0)
66
- rake (0.8.7)
67
- rspec (2.0.0.rc)
68
- rspec-core (= 2.0.0.rc)
69
- rspec-expectations (= 2.0.0.rc)
70
- rspec-mocks (= 2.0.0.rc)
71
- rspec-core (2.0.0.rc)
72
- rspec-expectations (2.0.0.rc)
73
- diff-lcs (>= 1.1.2)
74
- rspec-mocks (2.0.0.rc)
75
- rspec-core (= 2.0.0.rc)
76
- rspec-expectations (= 2.0.0.rc)
77
- rspec-rails (2.0.0.rc)
78
- rspec (= 2.0.0.rc)
79
- ruby-debug-base19 (0.11.24)
80
- columnize (>= 0.3.1)
81
- linecache19 (>= 0.5.11)
82
- ruby_core_source (>= 0.1.4)
83
- ruby-debug19 (0.11.6)
84
- columnize (>= 0.3.1)
85
- linecache19 (>= 0.5.11)
86
- ruby-debug-base19 (>= 0.11.19)
87
- ruby_core_source (0.1.4)
88
- archive-tar-minitar (>= 0.5.2)
89
- sqlite3-ruby (1.3.1)
90
- thor (0.14.3)
91
- treetop (1.4.8)
92
- polyglot (>= 0.3.1)
93
- tzinfo (0.3.23)
94
-
95
- PLATFORMS
96
- ruby
97
-
98
- DEPENDENCIES
99
- rails (= 3.0.0)
100
- rspec-rails (= 2.0.0.rc)
101
- ruby-debug19
102
- sqlite3-ruby