simplest_auth 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -4,6 +4,15 @@ simplest_auth is a gem to be used with Rails applications where RESTful Authenti
4
4
 
5
5
  simplest_auth is now compatible with both ActiveRecord and DataMapper (the README displays examples for AR)
6
6
 
7
+ h2. Changes!
8
+
9
+ Version 0.2.0 has a change to handle multiple Model session keys. If you are using User as your model class then you shouldn't have a problem. However, if you're using another
10
+ class, you will either need to override the <pre><code>session_key</code></pre> method to return <pre><code>:user_id</code></pre> or just accept that a few sessions will be lost.
11
+
12
+ If you don't care about losing sessions, just go ahead and ignore this message.
13
+
14
+ If you use this gem in Rails (like most, I suspect), the session_key method will return the model class underscored plus "_id" as a symbol. Otherwise, it's just #downcased (lame).
15
+
7
16
  h2. Installation
8
17
 
9
18
  SimplestAuth depends (for now) on the BCrypt gem, so install that first:
@@ -1,11 +1,15 @@
1
1
  module SimplestAuth
2
2
  class UndefinedMethodError < StandardError; end
3
-
3
+
4
4
  module Controller
5
5
  def user_class
6
6
  User
7
7
  end
8
8
 
9
+ def session_key
10
+ user_class.session_key
11
+ end
12
+
9
13
  def authorized?
10
14
  logged_in?
11
15
  end
@@ -55,12 +55,20 @@ module SimplestAuth
55
55
  EOM
56
56
  end
57
57
  end
58
+
59
+ def session_key
60
+ if name.to_s.respond_to?(:underscore)
61
+ "#{name.underscore}_id".to_sym
62
+ else
63
+ "#{name.downcase}_id".to_sym
64
+ end
65
+ end
58
66
  end
59
67
 
60
68
  module InstanceMethods
61
69
  include BCrypt
62
70
 
63
- RecordNotFound = Class.new(StandardError)
71
+ RecordNotFound = Class.new(StandardError) unless defined?(RecordNotFound)
64
72
 
65
73
  def authentic?(password)
66
74
  Password.new(self.crypted_password) == password
@@ -2,12 +2,12 @@ module SimplestAuth
2
2
  module Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 1
6
- TINY = 3
5
+ MINOR = 2
6
+ TINY = 0
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
10
10
  end
11
11
 
12
12
  end
13
- end
13
+ end
@@ -146,6 +146,11 @@ class ControllerTest < Test::Unit::TestCase
146
146
 
147
147
  assert_equal "user", current_user
148
148
  end
149
+
150
+ should "adapt the session key for the user class" do
151
+ stubs(:user_class).returns(mock(:session_key => :user_id))
152
+ assert_equal :user_id, session_key
153
+ end
149
154
  end
150
155
 
151
156
  end
@@ -17,7 +17,13 @@ class UserTest < Test::Unit::TestCase
17
17
  end
18
18
  end
19
19
 
20
- context "an instance of the User class" do
20
+ context "The User class" do
21
+ should "define a session key" do
22
+ assert_equal :user_id, User.session_key
23
+ end
24
+ end
25
+
26
+ context "An instance of the User class" do
21
27
  setup do
22
28
  User.send(:include, SimplestAuth::Model)
23
29
  @user = User.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplest_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-09 00:00:00 -04:00
12
+ date: 2009-07-07 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,6 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - README.textile
35
35
  - Rakefile
36
- - lib/simplest_auth
37
36
  - lib/simplest_auth/controller.rb
38
37
  - lib/simplest_auth/model.rb
39
38
  - lib/simplest_auth/version.rb
@@ -42,8 +41,10 @@ files:
42
41
  - test/unit/simplest_auth/controller_test.rb
43
42
  - test/unit/simplest_auth/dm_model_test.rb
44
43
  - test/unit/simplest_auth/model_test.rb
45
- has_rdoc: false
44
+ has_rdoc: true
46
45
  homepage: http://viget.com/extend
46
+ licenses: []
47
+
47
48
  post_install_message:
48
49
  rdoc_options: []
49
50
 
@@ -64,9 +65,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  requirements: []
65
66
 
66
67
  rubyforge_project:
67
- rubygems_version: 1.3.1
68
+ rubygems_version: 1.3.4
68
69
  signing_key:
69
- specification_version: 2
70
+ specification_version: 3
70
71
  summary: Simple implementation of authentication for Rails
71
72
  test_files:
72
73
  - test/unit/simplest_auth/ar_model_test.rb