simple_auth 1.0.2 → 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/Gemfile +1 -12
- data/Gemfile.lock +68 -66
- data/README.markdown +28 -1
- data/Rakefile +3 -25
- data/lib/simple_auth/action_controller.rb +2 -4
- data/lib/simple_auth/active_record.rb +4 -0
- data/lib/simple_auth/session.rb +4 -3
- data/lib/simple_auth/version.rb +2 -2
- data/{config/locales → locales}/en.yml +0 -0
- data/{config/locales/pt.yml → locales/pt-BR.yml} +1 -7
- data/simple_auth.gemspec +17 -82
- data/spec/controllers/require_logged_user_spec.rb +9 -2
- data/spec/simple_auth/session_spec.rb +18 -4
- data/spec/spec_helper.rb +2 -0
- data/spec/support/config/boot.rb +1 -1
- metadata +51 -26
data/Gemfile
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
1
|
source :rubygems
|
|
2
|
-
|
|
3
|
-
gem "rspec-rails", "2.0.0"
|
|
4
|
-
gem "rails", "3.0.0"
|
|
5
|
-
gem "sqlite3-ruby", :require => "sqlite3"
|
|
6
|
-
|
|
7
|
-
platforms :mri_18 do
|
|
8
|
-
gem "ruby-debug"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
platforms :mri_19 do
|
|
12
|
-
gem "ruby-debug19", :require => "ruby-debug"
|
|
13
|
-
end
|
|
2
|
+
gemspec
|
data/Gemfile.lock
CHANGED
|
@@ -1,87 +1,88 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
simple_auth (1.1.0)
|
|
5
|
+
rails (~> 3.0.0)
|
|
6
|
+
|
|
1
7
|
GEM
|
|
2
8
|
remote: http://rubygems.org/
|
|
3
9
|
specs:
|
|
4
10
|
abstract (1.0.0)
|
|
5
|
-
actionmailer (3.0.
|
|
6
|
-
actionpack (= 3.0.
|
|
7
|
-
mail (~> 2.2.
|
|
8
|
-
actionpack (3.0.
|
|
9
|
-
activemodel (= 3.0.
|
|
10
|
-
activesupport (= 3.0.
|
|
11
|
+
actionmailer (3.0.3)
|
|
12
|
+
actionpack (= 3.0.3)
|
|
13
|
+
mail (~> 2.2.9)
|
|
14
|
+
actionpack (3.0.3)
|
|
15
|
+
activemodel (= 3.0.3)
|
|
16
|
+
activesupport (= 3.0.3)
|
|
11
17
|
builder (~> 2.1.2)
|
|
12
18
|
erubis (~> 2.6.6)
|
|
13
|
-
i18n (~> 0.4
|
|
19
|
+
i18n (~> 0.4)
|
|
14
20
|
rack (~> 1.2.1)
|
|
15
|
-
rack-mount (~> 0.6.
|
|
16
|
-
rack-test (~> 0.5.
|
|
21
|
+
rack-mount (~> 0.6.13)
|
|
22
|
+
rack-test (~> 0.5.6)
|
|
17
23
|
tzinfo (~> 0.3.23)
|
|
18
|
-
activemodel (3.0.
|
|
19
|
-
activesupport (= 3.0.
|
|
24
|
+
activemodel (3.0.3)
|
|
25
|
+
activesupport (= 3.0.3)
|
|
20
26
|
builder (~> 2.1.2)
|
|
21
|
-
i18n (~> 0.4
|
|
22
|
-
activerecord (3.0.
|
|
23
|
-
activemodel (= 3.0.
|
|
24
|
-
activesupport (= 3.0.
|
|
25
|
-
arel (~>
|
|
27
|
+
i18n (~> 0.4)
|
|
28
|
+
activerecord (3.0.3)
|
|
29
|
+
activemodel (= 3.0.3)
|
|
30
|
+
activesupport (= 3.0.3)
|
|
31
|
+
arel (~> 2.0.2)
|
|
26
32
|
tzinfo (~> 0.3.23)
|
|
27
|
-
activeresource (3.0.
|
|
28
|
-
activemodel (= 3.0.
|
|
29
|
-
activesupport (= 3.0.
|
|
30
|
-
activesupport (3.0.
|
|
33
|
+
activeresource (3.0.3)
|
|
34
|
+
activemodel (= 3.0.3)
|
|
35
|
+
activesupport (= 3.0.3)
|
|
36
|
+
activesupport (3.0.3)
|
|
31
37
|
archive-tar-minitar (0.5.2)
|
|
32
|
-
arel (
|
|
33
|
-
activesupport (~> 3.0.0)
|
|
38
|
+
arel (2.0.8)
|
|
34
39
|
builder (2.1.2)
|
|
35
|
-
columnize (0.3.
|
|
40
|
+
columnize (0.3.2)
|
|
36
41
|
diff-lcs (1.1.2)
|
|
37
42
|
erubis (2.6.6)
|
|
38
43
|
abstract (>= 1.0.0)
|
|
39
|
-
i18n (0.
|
|
40
|
-
linecache (0.43)
|
|
44
|
+
i18n (0.5.0)
|
|
41
45
|
linecache19 (0.5.11)
|
|
42
46
|
ruby_core_source (>= 0.1.4)
|
|
43
|
-
mail (2.2.
|
|
47
|
+
mail (2.2.15)
|
|
44
48
|
activesupport (>= 2.3.6)
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
i18n (>= 0.4.0)
|
|
50
|
+
mime-types (~> 1.16)
|
|
51
|
+
treetop (~> 1.4.8)
|
|
47
52
|
mime-types (1.16)
|
|
48
53
|
polyglot (0.3.1)
|
|
49
54
|
rack (1.2.1)
|
|
50
55
|
rack-mount (0.6.13)
|
|
51
56
|
rack (>= 1.0.0)
|
|
52
|
-
rack-test (0.5.
|
|
57
|
+
rack-test (0.5.7)
|
|
53
58
|
rack (>= 1.0)
|
|
54
|
-
rails (3.0.
|
|
55
|
-
actionmailer (= 3.0.
|
|
56
|
-
actionpack (= 3.0.
|
|
57
|
-
activerecord (= 3.0.
|
|
58
|
-
activeresource (= 3.0.
|
|
59
|
-
activesupport (= 3.0.
|
|
60
|
-
bundler (~> 1.0
|
|
61
|
-
railties (= 3.0.
|
|
62
|
-
railties (3.0.
|
|
63
|
-
actionpack (= 3.0.
|
|
64
|
-
activesupport (= 3.0.
|
|
65
|
-
rake (>= 0.8.
|
|
66
|
-
thor (~> 0.14.
|
|
59
|
+
rails (3.0.3)
|
|
60
|
+
actionmailer (= 3.0.3)
|
|
61
|
+
actionpack (= 3.0.3)
|
|
62
|
+
activerecord (= 3.0.3)
|
|
63
|
+
activeresource (= 3.0.3)
|
|
64
|
+
activesupport (= 3.0.3)
|
|
65
|
+
bundler (~> 1.0)
|
|
66
|
+
railties (= 3.0.3)
|
|
67
|
+
railties (3.0.3)
|
|
68
|
+
actionpack (= 3.0.3)
|
|
69
|
+
activesupport (= 3.0.3)
|
|
70
|
+
rake (>= 0.8.7)
|
|
71
|
+
thor (~> 0.14.4)
|
|
67
72
|
rake (0.8.7)
|
|
68
|
-
rspec (2.
|
|
69
|
-
rspec-core (
|
|
70
|
-
rspec-expectations (
|
|
71
|
-
rspec-mocks (
|
|
72
|
-
rspec-core (2.
|
|
73
|
-
rspec-expectations (2.
|
|
74
|
-
diff-lcs (
|
|
75
|
-
rspec-mocks (2.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
columnize (>= 0.1)
|
|
82
|
-
ruby-debug-base (~> 0.10.3.0)
|
|
83
|
-
ruby-debug-base (0.10.3)
|
|
84
|
-
linecache (>= 0.3)
|
|
73
|
+
rspec (2.5.0)
|
|
74
|
+
rspec-core (~> 2.5.0)
|
|
75
|
+
rspec-expectations (~> 2.5.0)
|
|
76
|
+
rspec-mocks (~> 2.5.0)
|
|
77
|
+
rspec-core (2.5.1)
|
|
78
|
+
rspec-expectations (2.5.0)
|
|
79
|
+
diff-lcs (~> 1.1.2)
|
|
80
|
+
rspec-mocks (2.5.0)
|
|
81
|
+
rspec-rails (2.5.0)
|
|
82
|
+
actionpack (~> 3.0)
|
|
83
|
+
activesupport (~> 3.0)
|
|
84
|
+
railties (~> 3.0)
|
|
85
|
+
rspec (~> 2.5.0)
|
|
85
86
|
ruby-debug-base19 (0.11.24)
|
|
86
87
|
columnize (>= 0.3.1)
|
|
87
88
|
linecache19 (>= 0.5.11)
|
|
@@ -92,18 +93,19 @@ GEM
|
|
|
92
93
|
ruby-debug-base19 (>= 0.11.19)
|
|
93
94
|
ruby_core_source (0.1.4)
|
|
94
95
|
archive-tar-minitar (>= 0.5.2)
|
|
95
|
-
sqlite3
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
sqlite3 (1.3.3)
|
|
97
|
+
sqlite3-ruby (1.3.3)
|
|
98
|
+
sqlite3 (>= 1.3.3)
|
|
99
|
+
thor (0.14.6)
|
|
100
|
+
treetop (1.4.9)
|
|
98
101
|
polyglot (>= 0.3.1)
|
|
99
|
-
tzinfo (0.3.
|
|
102
|
+
tzinfo (0.3.24)
|
|
100
103
|
|
|
101
104
|
PLATFORMS
|
|
102
105
|
ruby
|
|
103
106
|
|
|
104
107
|
DEPENDENCIES
|
|
105
|
-
rails (
|
|
106
|
-
rspec-rails (= 2.0.0)
|
|
107
|
-
ruby-debug
|
|
108
|
+
rspec-rails (~> 2.5.0)
|
|
108
109
|
ruby-debug19
|
|
110
|
+
simple_auth!
|
|
109
111
|
sqlite3-ruby
|
data/README.markdown
CHANGED
|
@@ -46,6 +46,23 @@ In your model, use the `authentication` macro.
|
|
|
46
46
|
|
|
47
47
|
This will add some callbacks and password validations. It will also inject helper methods like `Model.authenticate`.
|
|
48
48
|
|
|
49
|
+
Session is valid only when both `Model#authorized?` and `Controller#authorized?` methods return `true`, which is the default behavior. You can override these methods with your own rules:
|
|
50
|
+
|
|
51
|
+
class User < ActiveRecord::Base
|
|
52
|
+
authentication
|
|
53
|
+
|
|
54
|
+
def authorized?
|
|
55
|
+
deleted_at.nil?
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class Admin::DashboardController < ApplicationController
|
|
60
|
+
private
|
|
61
|
+
def authorized?
|
|
62
|
+
current_user.admin?
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
49
66
|
After you set up the model, you can go to the controller.
|
|
50
67
|
|
|
51
68
|
class SessionsController < ApplicationController
|
|
@@ -117,12 +134,22 @@ There are some helpers:
|
|
|
117
134
|
find_by_credential # model
|
|
118
135
|
find_by_credential! # model
|
|
119
136
|
|
|
120
|
-
If you're having problems to use any helper, include the module
|
|
137
|
+
If you're having problems to use any helper, include the module `SimpleAuth::Helper` on your `ApplicationHelper`.
|
|
121
138
|
|
|
122
139
|
module ApplicationHelper
|
|
123
140
|
include SimpleAuth::Helper
|
|
124
141
|
end
|
|
125
142
|
|
|
143
|
+
### Translations
|
|
144
|
+
|
|
145
|
+
These are the translations you'll need:
|
|
146
|
+
|
|
147
|
+
en:
|
|
148
|
+
simple_auth:
|
|
149
|
+
sessions:
|
|
150
|
+
need_to_be_logged: "You need to be logged"
|
|
151
|
+
invalid_credentials: "Invalid username or password"
|
|
152
|
+
|
|
126
153
|
Troubleshooting
|
|
127
154
|
---------------
|
|
128
155
|
|
data/Rakefile
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
require "
|
|
2
|
-
|
|
1
|
+
require "bundler"
|
|
2
|
+
Bundler::GemHelper.install_tasks
|
|
3
3
|
|
|
4
|
+
require "rspec/core/rake_task"
|
|
4
5
|
RSpec::Core::RakeTask.new
|
|
5
|
-
|
|
6
|
-
desc "Default: run specs."
|
|
7
|
-
task :default => :spec
|
|
8
|
-
|
|
9
|
-
begin
|
|
10
|
-
require "jeweler"
|
|
11
|
-
|
|
12
|
-
JEWEL = Jeweler::Tasks.new do |gem|
|
|
13
|
-
gem.name = "simple_auth"
|
|
14
|
-
gem.version = SimpleAuth::Version::STRING
|
|
15
|
-
gem.summary = "A simple authentication system for Rails apps"
|
|
16
|
-
gem.description = "When Authlogic & Devise are just too much."
|
|
17
|
-
gem.authors = ["Nando Vieira"]
|
|
18
|
-
gem.email = "fnando.vieira@gmail.com"
|
|
19
|
-
gem.homepage = "http://github.com/fnando/simple_auth"
|
|
20
|
-
gem.has_rdoc = true
|
|
21
|
-
gem.add_dependency "rails", ">= 3.0.0"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
Jeweler::GemcutterTasks.new
|
|
25
|
-
rescue LoadError => e
|
|
26
|
-
puts "You don't Jeweler installed, so you won't be able to build gems."
|
|
27
|
-
end
|
|
@@ -58,9 +58,7 @@ module SimpleAuth
|
|
|
58
58
|
def require_logged_user(options = {})
|
|
59
59
|
before_filter options.except(:to) do |controller|
|
|
60
60
|
controller.instance_eval do
|
|
61
|
-
unless
|
|
62
|
-
flash[:alert] = I18n.translate("simple_auth.sessions.need_to_be_logged")
|
|
63
|
-
|
|
61
|
+
unless current_session && current_session.valid? && authorized?
|
|
64
62
|
if request.respond_to?(:fullpath)
|
|
65
63
|
return_to = request.fullpath
|
|
66
64
|
else
|
|
@@ -68,7 +66,7 @@ module SimpleAuth
|
|
|
68
66
|
end
|
|
69
67
|
|
|
70
68
|
session[:return_to] = return_to if request.get?
|
|
71
|
-
redirect_to simple_auth_url_for(:login_url, controller, options[:to])
|
|
69
|
+
redirect_to simple_auth_url_for(:login_url, controller, options[:to]), :alert => t("simple_auth.sessions.need_to_be_logged")
|
|
72
70
|
end
|
|
73
71
|
end
|
|
74
72
|
end
|
data/lib/simple_auth/session.rb
CHANGED
|
@@ -37,6 +37,7 @@ module SimpleAuth
|
|
|
37
37
|
|
|
38
38
|
def self.find
|
|
39
39
|
session = new
|
|
40
|
+
return unless session.controller && session.controller.session[:record_id]
|
|
40
41
|
session.record = session.model.find_by_id(session.controller.session[:record_id])
|
|
41
42
|
|
|
42
43
|
if session.record
|
|
@@ -47,13 +48,13 @@ module SimpleAuth
|
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
def self.create(options = {})
|
|
50
|
-
|
|
51
|
+
new(options).tap do |session|
|
|
51
52
|
session.save
|
|
52
53
|
end
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
def self.create!(options = {})
|
|
56
|
-
|
|
57
|
+
new(options).tap do |session|
|
|
57
58
|
session.save!
|
|
58
59
|
end
|
|
59
60
|
end
|
|
@@ -93,7 +94,7 @@ module SimpleAuth
|
|
|
93
94
|
end
|
|
94
95
|
|
|
95
96
|
def valid?
|
|
96
|
-
if record
|
|
97
|
+
if record && record.authorized?
|
|
97
98
|
true
|
|
98
99
|
else
|
|
99
100
|
errors.add_to_base I18n.translate("simple_auth.sessions.invalid_credentials")
|
data/lib/simple_auth/version.rb
CHANGED
|
File without changes
|
data/simple_auth.gemspec
CHANGED
|
@@ -1,89 +1,24 @@
|
|
|
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 "simple_auth/version"
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name
|
|
8
|
-
s.version
|
|
6
|
+
s.name = "simple_auth"
|
|
7
|
+
s.version = SimpleAuth::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/simple_auth"
|
|
12
|
+
s.summary = "A simple authentication system for Rails apps"
|
|
13
|
+
s.description = s.summary
|
|
9
14
|
|
|
10
|
-
s.
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
s.description = %q{When Authlogic & Devise are just too much.}
|
|
14
|
-
s.email = %q{fnando.vieira@gmail.com}
|
|
15
|
-
s.extra_rdoc_files = [
|
|
16
|
-
"README.markdown"
|
|
17
|
-
]
|
|
18
|
-
s.files = [
|
|
19
|
-
".gitignore",
|
|
20
|
-
".rspec",
|
|
21
|
-
"Gemfile",
|
|
22
|
-
"Gemfile.lock",
|
|
23
|
-
"README.markdown",
|
|
24
|
-
"Rakefile",
|
|
25
|
-
"config/locales/en.yml",
|
|
26
|
-
"config/locales/pt.yml",
|
|
27
|
-
"lib/simple_auth.rb",
|
|
28
|
-
"lib/simple_auth/action_controller.rb",
|
|
29
|
-
"lib/simple_auth/active_record.rb",
|
|
30
|
-
"lib/simple_auth/config.rb",
|
|
31
|
-
"lib/simple_auth/generator.rb",
|
|
32
|
-
"lib/simple_auth/helper.rb",
|
|
33
|
-
"lib/simple_auth/railtie.rb",
|
|
34
|
-
"lib/simple_auth/session.rb",
|
|
35
|
-
"lib/simple_auth/version.rb",
|
|
36
|
-
"simple_auth.gemspec",
|
|
37
|
-
"spec/controllers/redirect_logged_user_spec.rb",
|
|
38
|
-
"spec/controllers/require_logged_user_spec.rb",
|
|
39
|
-
"spec/schema.rb",
|
|
40
|
-
"spec/simple_auth/active_record_spec.rb",
|
|
41
|
-
"spec/simple_auth/config_spec.rb",
|
|
42
|
-
"spec/simple_auth/helper_spec.rb",
|
|
43
|
-
"spec/simple_auth/session_spec.rb",
|
|
44
|
-
"spec/spec_helper.rb",
|
|
45
|
-
"spec/support/app/controllers/application_controller.rb",
|
|
46
|
-
"spec/support/app/models/account.rb",
|
|
47
|
-
"spec/support/app/models/user.rb",
|
|
48
|
-
"spec/support/app/views/dashboard/index.erb",
|
|
49
|
-
"spec/support/app/views/session/new.erb",
|
|
50
|
-
"spec/support/config/boot.rb",
|
|
51
|
-
"spec/support/config/database.yml",
|
|
52
|
-
"spec/support/config/routes.rb",
|
|
53
|
-
"templates/initializer.rb"
|
|
54
|
-
]
|
|
55
|
-
s.homepage = %q{http://github.com/fnando/simple_auth}
|
|
56
|
-
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) }
|
|
57
18
|
s.require_paths = ["lib"]
|
|
58
|
-
s.rubygems_version = %q{1.3.7}
|
|
59
|
-
s.summary = %q{A simple authentication system for Rails apps}
|
|
60
|
-
s.test_files = [
|
|
61
|
-
"spec/controllers/redirect_logged_user_spec.rb",
|
|
62
|
-
"spec/controllers/require_logged_user_spec.rb",
|
|
63
|
-
"spec/schema.rb",
|
|
64
|
-
"spec/simple_auth/active_record_spec.rb",
|
|
65
|
-
"spec/simple_auth/config_spec.rb",
|
|
66
|
-
"spec/simple_auth/helper_spec.rb",
|
|
67
|
-
"spec/simple_auth/session_spec.rb",
|
|
68
|
-
"spec/spec_helper.rb",
|
|
69
|
-
"spec/support/app/controllers/application_controller.rb",
|
|
70
|
-
"spec/support/app/models/account.rb",
|
|
71
|
-
"spec/support/app/models/user.rb",
|
|
72
|
-
"spec/support/config/boot.rb",
|
|
73
|
-
"spec/support/config/routes.rb"
|
|
74
|
-
]
|
|
75
19
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
81
|
-
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
|
|
82
|
-
else
|
|
83
|
-
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
|
84
|
-
end
|
|
85
|
-
else
|
|
86
|
-
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
|
87
|
-
end
|
|
20
|
+
s.add_dependency "rails", "~> 3.0.0"
|
|
21
|
+
s.add_development_dependency "sqlite3-ruby"
|
|
22
|
+
s.add_development_dependency "rspec-rails", "~> 2.5.0"
|
|
23
|
+
s.add_development_dependency "ruby-debug19"
|
|
88
24
|
end
|
|
89
|
-
|
|
@@ -38,14 +38,21 @@ describe ApplicationController do
|
|
|
38
38
|
flash[:alert].should == "You need to be logged"
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
it "should redirect when user is not authorized" do
|
|
42
|
-
|
|
41
|
+
it "should redirect when user is not authorized on controller level" do
|
|
42
|
+
session[:record_id] = user.id
|
|
43
43
|
@controller.should_receive(:authorized?).and_return(false)
|
|
44
44
|
|
|
45
45
|
get :index
|
|
46
46
|
response.should redirect_to("/login")
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
it "should redirect when session is not valid" do
|
|
50
|
+
session[:record_id] = "invalid"
|
|
51
|
+
|
|
52
|
+
get :index
|
|
53
|
+
response.should redirect_to("/login")
|
|
54
|
+
end
|
|
55
|
+
|
|
49
56
|
context "using hash" do
|
|
50
57
|
controller do
|
|
51
58
|
require_logged_user :to => {:controller => "session", :action => "new"}
|
|
@@ -13,12 +13,20 @@ describe SimpleAuth::Session do
|
|
|
13
13
|
|
|
14
14
|
@session = Hash.new
|
|
15
15
|
@controller = ActionController::Base.new
|
|
16
|
-
@controller.stub
|
|
16
|
+
@controller.stub :session => @session
|
|
17
17
|
|
|
18
18
|
SimpleAuth::Config.controller = @controller
|
|
19
19
|
@user_session = SimpleAuth::Session.new(:credential => "johndoe", :password => "test")
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
it "should not raise when trying to find a session without activating controller" do
|
|
23
|
+
SimpleAuth::Config.controller = nil
|
|
24
|
+
|
|
25
|
+
expect {
|
|
26
|
+
SimpleAuth::Session.find.should be_nil
|
|
27
|
+
}.to_not raise_error
|
|
28
|
+
end
|
|
29
|
+
|
|
22
30
|
context "with valid credentials" do
|
|
23
31
|
before do
|
|
24
32
|
@user_session.save!
|
|
@@ -34,14 +42,20 @@ describe SimpleAuth::Session do
|
|
|
34
42
|
@user_session.should_not be_new_record
|
|
35
43
|
end
|
|
36
44
|
|
|
37
|
-
it "should
|
|
38
|
-
@user_session.record.
|
|
45
|
+
it "should be invalid when record is not authorized" do
|
|
46
|
+
@user_session.record.stub :authorized? => false
|
|
47
|
+
@user_session.should_not be_valid
|
|
39
48
|
end
|
|
40
49
|
|
|
41
|
-
it "should be
|
|
50
|
+
it "should be valid when record is authorized" do
|
|
51
|
+
@user_session.record.stub :authorized? => true
|
|
42
52
|
@user_session.should be_valid
|
|
43
53
|
end
|
|
44
54
|
|
|
55
|
+
it "should find record" do
|
|
56
|
+
@user_session.record.should == @user
|
|
57
|
+
end
|
|
58
|
+
|
|
45
59
|
it "should set record_id on session" do
|
|
46
60
|
@session[:record_id].should == @user.id
|
|
47
61
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/config/boot.rb
CHANGED
metadata
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_auth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
prerelease:
|
|
5
|
-
|
|
6
|
-
- 1
|
|
7
|
-
- 0
|
|
8
|
-
- 2
|
|
9
|
-
version: 1.0.2
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 1.1.0
|
|
10
6
|
platform: ruby
|
|
11
7
|
authors:
|
|
12
8
|
- Nando Vieira
|
|
@@ -14,7 +10,7 @@ autorequire:
|
|
|
14
10
|
bindir: bin
|
|
15
11
|
cert_chain: []
|
|
16
12
|
|
|
17
|
-
date:
|
|
13
|
+
date: 2011-02-08 00:00:00 -02:00
|
|
18
14
|
default_executable:
|
|
19
15
|
dependencies:
|
|
20
16
|
- !ruby/object:Gem::Dependency
|
|
@@ -23,23 +19,53 @@ dependencies:
|
|
|
23
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
20
|
none: false
|
|
25
21
|
requirements:
|
|
26
|
-
- -
|
|
22
|
+
- - ~>
|
|
27
23
|
- !ruby/object:Gem::Version
|
|
28
|
-
segments:
|
|
29
|
-
- 3
|
|
30
|
-
- 0
|
|
31
|
-
- 0
|
|
32
24
|
version: 3.0.0
|
|
33
25
|
type: :runtime
|
|
34
26
|
version_requirements: *id001
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: sqlite3-ruby
|
|
29
|
+
prerelease: false
|
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
31
|
+
none: false
|
|
32
|
+
requirements:
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: "0"
|
|
36
|
+
type: :development
|
|
37
|
+
version_requirements: *id002
|
|
38
|
+
- !ruby/object:Gem::Dependency
|
|
39
|
+
name: rspec-rails
|
|
40
|
+
prerelease: false
|
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ~>
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 2.5.0
|
|
47
|
+
type: :development
|
|
48
|
+
version_requirements: *id003
|
|
49
|
+
- !ruby/object:Gem::Dependency
|
|
50
|
+
name: ruby-debug19
|
|
51
|
+
prerelease: false
|
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
53
|
+
none: false
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: "0"
|
|
58
|
+
type: :development
|
|
59
|
+
version_requirements: *id004
|
|
60
|
+
description: A simple authentication system for Rails apps
|
|
61
|
+
email:
|
|
62
|
+
- fnando.vieira@gmail.com
|
|
37
63
|
executables: []
|
|
38
64
|
|
|
39
65
|
extensions: []
|
|
40
66
|
|
|
41
|
-
extra_rdoc_files:
|
|
42
|
-
|
|
67
|
+
extra_rdoc_files: []
|
|
68
|
+
|
|
43
69
|
files:
|
|
44
70
|
- .gitignore
|
|
45
71
|
- .rspec
|
|
@@ -47,8 +73,6 @@ files:
|
|
|
47
73
|
- Gemfile.lock
|
|
48
74
|
- README.markdown
|
|
49
75
|
- Rakefile
|
|
50
|
-
- config/locales/en.yml
|
|
51
|
-
- config/locales/pt.yml
|
|
52
76
|
- lib/simple_auth.rb
|
|
53
77
|
- lib/simple_auth/action_controller.rb
|
|
54
78
|
- lib/simple_auth/active_record.rb
|
|
@@ -58,6 +82,8 @@ files:
|
|
|
58
82
|
- lib/simple_auth/railtie.rb
|
|
59
83
|
- lib/simple_auth/session.rb
|
|
60
84
|
- lib/simple_auth/version.rb
|
|
85
|
+
- locales/en.yml
|
|
86
|
+
- locales/pt-BR.yml
|
|
61
87
|
- simple_auth.gemspec
|
|
62
88
|
- spec/controllers/redirect_logged_user_spec.rb
|
|
63
89
|
- spec/controllers/require_logged_user_spec.rb
|
|
@@ -77,12 +103,12 @@ files:
|
|
|
77
103
|
- spec/support/config/routes.rb
|
|
78
104
|
- templates/initializer.rb
|
|
79
105
|
has_rdoc: true
|
|
80
|
-
homepage: http://
|
|
106
|
+
homepage: http://rubygems.org/gems/simple_auth
|
|
81
107
|
licenses: []
|
|
82
108
|
|
|
83
109
|
post_install_message:
|
|
84
|
-
rdoc_options:
|
|
85
|
-
|
|
110
|
+
rdoc_options: []
|
|
111
|
+
|
|
86
112
|
require_paths:
|
|
87
113
|
- lib
|
|
88
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
@@ -90,21 +116,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
90
116
|
requirements:
|
|
91
117
|
- - ">="
|
|
92
118
|
- !ruby/object:Gem::Version
|
|
93
|
-
segments:
|
|
94
|
-
- 0
|
|
95
119
|
version: "0"
|
|
96
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
121
|
none: false
|
|
98
122
|
requirements:
|
|
99
123
|
- - ">="
|
|
100
124
|
- !ruby/object:Gem::Version
|
|
101
|
-
segments:
|
|
102
|
-
- 0
|
|
103
125
|
version: "0"
|
|
104
126
|
requirements: []
|
|
105
127
|
|
|
106
128
|
rubyforge_project:
|
|
107
|
-
rubygems_version: 1.
|
|
129
|
+
rubygems_version: 1.5.0
|
|
108
130
|
signing_key:
|
|
109
131
|
specification_version: 3
|
|
110
132
|
summary: A simple authentication system for Rails apps
|
|
@@ -120,5 +142,8 @@ test_files:
|
|
|
120
142
|
- spec/support/app/controllers/application_controller.rb
|
|
121
143
|
- spec/support/app/models/account.rb
|
|
122
144
|
- spec/support/app/models/user.rb
|
|
145
|
+
- spec/support/app/views/dashboard/index.erb
|
|
146
|
+
- spec/support/app/views/session/new.erb
|
|
123
147
|
- spec/support/config/boot.rb
|
|
148
|
+
- spec/support/config/database.yml
|
|
124
149
|
- spec/support/config/routes.rb
|