sparkly-auth 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/app/controllers/sparkly_accounts_controller.rb +59 -0
- data/app/controllers/sparkly_controller.rb +47 -0
- data/app/controllers/sparkly_sessions_controller.rb +52 -0
- data/app/models/password.rb +3 -0
- data/app/models/remembrance_token.rb +50 -0
- data/app/views/sparkly_accounts/edit.html.erb +24 -0
- data/app/views/sparkly_accounts/new.html.erb +24 -0
- data/app/views/sparkly_accounts/show.html.erb +0 -0
- data/app/views/sparkly_sessions/new.html.erb +22 -0
- data/dependencies.rb +1 -0
- data/generators/sparkly/USAGE +27 -0
- data/generators/sparkly/sparkly_generator.rb +76 -0
- data/generators/sparkly/templates/accounts_controller.rb +65 -0
- data/generators/sparkly/templates/accounts_helper.rb +2 -0
- data/generators/sparkly/templates/help_file.txt +56 -0
- data/generators/sparkly/templates/initializer.rb +30 -0
- data/generators/sparkly/templates/migrations/add_confirmed_to_sparkly_passwords.rb +9 -0
- data/generators/sparkly/templates/migrations/create_sparkly_passwords.rb +19 -0
- data/generators/sparkly/templates/migrations/create_sparkly_remembered_tokens.rb +15 -0
- data/generators/sparkly/templates/sessions_controller.rb +45 -0
- data/generators/sparkly/templates/sessions_helper.rb +2 -0
- data/generators/sparkly/templates/tasks/migrations.rb +1 -0
- data/generators/sparkly/templates/views/sparkly_accounts/edit.html.erb +24 -0
- data/generators/sparkly/templates/views/sparkly_accounts/new.html.erb +24 -0
- data/generators/sparkly/templates/views/sparkly_accounts/show.html.erb +0 -0
- data/generators/sparkly/templates/views/sparkly_sessions/new.html.erb +22 -0
- data/init.rb +44 -0
- data/lib/auth.rb +52 -0
- data/lib/auth/behavior/base.rb +64 -0
- data/lib/auth/behavior/core.rb +87 -0
- data/lib/auth/behavior/core/authenticated_model_methods.rb +52 -0
- data/lib/auth/behavior/core/controller_extensions.rb +52 -0
- data/lib/auth/behavior/core/controller_extensions/class_methods.rb +24 -0
- data/lib/auth/behavior/core/controller_extensions/current_user.rb +54 -0
- data/lib/auth/behavior/core/password_methods.rb +65 -0
- data/lib/auth/behavior/remember_me.rb +17 -0
- data/lib/auth/behavior/remember_me/configuration.rb +21 -0
- data/lib/auth/behavior/remember_me/controller_extensions.rb +66 -0
- data/lib/auth/behavior_lookup.rb +10 -0
- data/lib/auth/configuration.rb +328 -0
- data/lib/auth/encryptors/sha512.rb +20 -0
- data/lib/auth/generators/configuration_generator.rb +20 -0
- data/lib/auth/generators/controllers_generator.rb +34 -0
- data/lib/auth/generators/migration_generator.rb +32 -0
- data/lib/auth/generators/route_generator.rb +19 -0
- data/lib/auth/generators/views_generator.rb +26 -0
- data/lib/auth/model.rb +94 -0
- data/lib/auth/observer.rb +21 -0
- data/lib/auth/target_list.rb +5 -0
- data/lib/auth/tasks/migrations.rb +71 -0
- data/lib/auth/token.rb +10 -0
- data/lib/sparkly-auth.rb +1 -0
- data/rails/init.rb +17 -0
- data/rails/routes.rb +19 -0
- data/sparkly-auth.gemspec +143 -0
- data/spec/controllers/application_controller_spec.rb +13 -0
- data/spec/generators/sparkly_spec.rb +64 -0
- data/spec/lib/auth/behavior/core_spec.rb +184 -0
- data/spec/lib/auth/behavior/remember_me_spec.rb +127 -0
- data/spec/lib/auth/extensions/controller_spec.rb +32 -0
- data/spec/lib/auth/model_spec.rb +57 -0
- data/spec/lib/auth_spec.rb +32 -0
- data/spec/mocks/models/user.rb +3 -0
- data/spec/routes_spec.rb +24 -0
- data/spec/spec_helper.rb +61 -0
- data/spec/views_spec.rb +18 -0
- metadata +210 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Auth do
|
4
|
+
it "should be configurable" do
|
5
|
+
Auth.should respond_to(:configuration)
|
6
|
+
Auth.configure do |config|
|
7
|
+
config.path.should_not be_blank
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should provide a default encryptor" do
|
12
|
+
Auth.encryptor.should_not be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should allow classes to be designated 'authenticated models'" do
|
16
|
+
Auth.configure do |config|
|
17
|
+
config.authenticate :user
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should merge options for multiple entries as long as they resolve to the same class" do
|
22
|
+
Auth.configure do |config|
|
23
|
+
config.authenticate :user, :key => :login
|
24
|
+
config.authenticate :user, :with => :password
|
25
|
+
end
|
26
|
+
|
27
|
+
Auth.configuration.authenticated_models.find(:user).options.without(:behaviors).should == {
|
28
|
+
:key => :login,
|
29
|
+
:with => :password
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
data/spec/routes_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
describe 'routes' do
|
2
|
+
include ActionController::UrlWriter
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
Auth.configure do |config|
|
6
|
+
config.authenticate :user
|
7
|
+
end
|
8
|
+
|
9
|
+
Auth.kick!
|
10
|
+
ActionController::Routing::Routes.install_helpers([self.class])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should map new_user_path to /user/new" do
|
14
|
+
new_user_path.should == '/user/new'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should map edit_user_path to /user/edit" do
|
18
|
+
edit_user_path.should == '/user/edit'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should map user_path to /user" do
|
22
|
+
user_path.should == '/user'
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
|
3
|
+
require File.expand_path("../../../../../config/boot", __FILE__)
|
4
|
+
require File.expand_path("../../../../../config/environment", __FILE__)
|
5
|
+
require "email_spec"
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'genspec'
|
9
|
+
rescue LoadError
|
10
|
+
puts " >> Missing gem: 'genspec' <<"
|
11
|
+
puts
|
12
|
+
puts "These specs rely on gemspec, which tests the project's generators."
|
13
|
+
puts
|
14
|
+
raise
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_load_path(path)
|
18
|
+
path = File.expand_path(File.join("..", path), __FILE__)
|
19
|
+
$LOAD_PATH.unshift path
|
20
|
+
ActiveSupport::Dependencies.load_paths.unshift path
|
21
|
+
ActiveSupport::Dependencies.load_once_paths.delete path
|
22
|
+
end
|
23
|
+
|
24
|
+
# Add mock paths to load paths
|
25
|
+
add_load_path "mocks/models"
|
26
|
+
add_load_path "../app/models"
|
27
|
+
#add_load_path "../app/lib"
|
28
|
+
add_load_path "../app/controllers"
|
29
|
+
|
30
|
+
$LOAD_PATH.uniq!
|
31
|
+
ActiveSupport::Dependencies.load_paths.uniq!
|
32
|
+
ActiveSupport::Dependencies.load_once_paths.uniq!
|
33
|
+
|
34
|
+
undef add_load_path
|
35
|
+
|
36
|
+
def column(name)
|
37
|
+
ActiveRecord::ConnectionAdapters::Column.new(name, nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |fi| require fi }
|
41
|
+
|
42
|
+
Spec::Runner.configure do |config|
|
43
|
+
# Needed in order to reset configuration for each test. This should not happen in a real environment.
|
44
|
+
config.before(:each) do
|
45
|
+
Auth.reset_configuration!
|
46
|
+
Dispatcher.cleanup_application
|
47
|
+
Dispatcher.reload_application
|
48
|
+
end
|
49
|
+
|
50
|
+
config.include(EmailSpec::Helpers)
|
51
|
+
config.include(EmailSpec::Matchers)
|
52
|
+
end
|
53
|
+
|
54
|
+
def error_on(model, key, value = nil, options = {})
|
55
|
+
instance = model.new()
|
56
|
+
instance.send("#{key}=", value)
|
57
|
+
options.each { |k,v| instance.send("#{k}=", v) }
|
58
|
+
|
59
|
+
instance.valid?
|
60
|
+
instance.errors.on(key.to_s)
|
61
|
+
end
|
data/spec/views_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Sanity check to make sure generator views match the built-in views. I haven't figured out how to do this
|
2
|
+
# DRY-ly yet so this will remind me to copy changes to both locations.
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe 'the engine views' do
|
7
|
+
it "should match generator views" do
|
8
|
+
base = File.expand_path(File.join(File.dirname(__FILE__), "../app/"))
|
9
|
+
Dir[File.join(base, "views/**/*")].each do |file|
|
10
|
+
relative = file.sub(/^#{Regexp::escape base}/, '')
|
11
|
+
generated_file = File.expand_path(File.join(File.dirname(__FILE__), "../generators/sparkly/templates", relative))
|
12
|
+
raise "File #{generated_file} does not seem to exist" unless File.exist?(generated_file)
|
13
|
+
if File.file?(file)
|
14
|
+
raise "View #{relative} does not match generator version" unless File.read(file) == File.read(generated_file)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sparkly-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Colin MacKenzie IV
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-09 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: sc-core-ext
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
version: 1.2.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec-rails
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 3
|
44
|
+
- 2
|
45
|
+
version: 1.3.2
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: webrat
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 7
|
58
|
+
- 1
|
59
|
+
version: 0.7.1
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: genspec
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
- 1
|
72
|
+
- 1
|
73
|
+
version: 0.1.1
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: email_spec
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
- 6
|
86
|
+
- 2
|
87
|
+
version: 0.6.2
|
88
|
+
type: :development
|
89
|
+
version_requirements: *id005
|
90
|
+
description: As fate would have it, I found other authentication solutions unable to suit my needs. So I rolled my own.
|
91
|
+
email: sinisterchipmunk@gmail.com
|
92
|
+
executables: []
|
93
|
+
|
94
|
+
extensions: []
|
95
|
+
|
96
|
+
extra_rdoc_files:
|
97
|
+
- README.rdoc
|
98
|
+
files:
|
99
|
+
- LICENSE
|
100
|
+
- README.rdoc
|
101
|
+
- Rakefile
|
102
|
+
- VERSION
|
103
|
+
- app/controllers/sparkly_accounts_controller.rb
|
104
|
+
- app/controllers/sparkly_controller.rb
|
105
|
+
- app/controllers/sparkly_sessions_controller.rb
|
106
|
+
- app/models/password.rb
|
107
|
+
- app/models/remembrance_token.rb
|
108
|
+
- app/views/sparkly_accounts/edit.html.erb
|
109
|
+
- app/views/sparkly_accounts/new.html.erb
|
110
|
+
- app/views/sparkly_accounts/show.html.erb
|
111
|
+
- app/views/sparkly_sessions/new.html.erb
|
112
|
+
- dependencies.rb
|
113
|
+
- generators/sparkly/USAGE
|
114
|
+
- generators/sparkly/sparkly_generator.rb
|
115
|
+
- generators/sparkly/templates/accounts_controller.rb
|
116
|
+
- generators/sparkly/templates/accounts_helper.rb
|
117
|
+
- generators/sparkly/templates/help_file.txt
|
118
|
+
- generators/sparkly/templates/initializer.rb
|
119
|
+
- generators/sparkly/templates/migrations/add_confirmed_to_sparkly_passwords.rb
|
120
|
+
- generators/sparkly/templates/migrations/create_sparkly_passwords.rb
|
121
|
+
- generators/sparkly/templates/migrations/create_sparkly_remembered_tokens.rb
|
122
|
+
- generators/sparkly/templates/sessions_controller.rb
|
123
|
+
- generators/sparkly/templates/sessions_helper.rb
|
124
|
+
- generators/sparkly/templates/tasks/migrations.rb
|
125
|
+
- generators/sparkly/templates/views/sparkly_accounts/edit.html.erb
|
126
|
+
- generators/sparkly/templates/views/sparkly_accounts/new.html.erb
|
127
|
+
- generators/sparkly/templates/views/sparkly_accounts/show.html.erb
|
128
|
+
- generators/sparkly/templates/views/sparkly_sessions/new.html.erb
|
129
|
+
- init.rb
|
130
|
+
- lib/auth.rb
|
131
|
+
- lib/auth/behavior/base.rb
|
132
|
+
- lib/auth/behavior/core.rb
|
133
|
+
- lib/auth/behavior/core/authenticated_model_methods.rb
|
134
|
+
- lib/auth/behavior/core/controller_extensions.rb
|
135
|
+
- lib/auth/behavior/core/controller_extensions/class_methods.rb
|
136
|
+
- lib/auth/behavior/core/controller_extensions/current_user.rb
|
137
|
+
- lib/auth/behavior/core/password_methods.rb
|
138
|
+
- lib/auth/behavior/remember_me.rb
|
139
|
+
- lib/auth/behavior/remember_me/configuration.rb
|
140
|
+
- lib/auth/behavior/remember_me/controller_extensions.rb
|
141
|
+
- lib/auth/behavior_lookup.rb
|
142
|
+
- lib/auth/configuration.rb
|
143
|
+
- lib/auth/encryptors/sha512.rb
|
144
|
+
- lib/auth/generators/configuration_generator.rb
|
145
|
+
- lib/auth/generators/controllers_generator.rb
|
146
|
+
- lib/auth/generators/migration_generator.rb
|
147
|
+
- lib/auth/generators/route_generator.rb
|
148
|
+
- lib/auth/generators/views_generator.rb
|
149
|
+
- lib/auth/model.rb
|
150
|
+
- lib/auth/observer.rb
|
151
|
+
- lib/auth/target_list.rb
|
152
|
+
- lib/auth/tasks/migrations.rb
|
153
|
+
- lib/auth/token.rb
|
154
|
+
- lib/sparkly-auth.rb
|
155
|
+
- rails/init.rb
|
156
|
+
- rails/routes.rb
|
157
|
+
- sparkly-auth.gemspec
|
158
|
+
- spec/controllers/application_controller_spec.rb
|
159
|
+
- spec/generators/sparkly_spec.rb
|
160
|
+
- spec/lib/auth/behavior/core_spec.rb
|
161
|
+
- spec/lib/auth/behavior/remember_me_spec.rb
|
162
|
+
- spec/lib/auth/extensions/controller_spec.rb
|
163
|
+
- spec/lib/auth/model_spec.rb
|
164
|
+
- spec/lib/auth_spec.rb
|
165
|
+
- spec/mocks/models/user.rb
|
166
|
+
- spec/routes_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/views_spec.rb
|
169
|
+
has_rdoc: true
|
170
|
+
homepage: http://www.thoughtsincomputation.com
|
171
|
+
licenses: []
|
172
|
+
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options:
|
175
|
+
- --charset=UTF-8
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
segments:
|
183
|
+
- 0
|
184
|
+
version: "0"
|
185
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
segments:
|
190
|
+
- 0
|
191
|
+
version: "0"
|
192
|
+
requirements: []
|
193
|
+
|
194
|
+
rubyforge_project:
|
195
|
+
rubygems_version: 1.3.6
|
196
|
+
signing_key:
|
197
|
+
specification_version: 3
|
198
|
+
summary: User authentication with Sparkles!
|
199
|
+
test_files:
|
200
|
+
- spec/controllers/application_controller_spec.rb
|
201
|
+
- spec/generators/sparkly_spec.rb
|
202
|
+
- spec/lib/auth/behavior/core_spec.rb
|
203
|
+
- spec/lib/auth/behavior/remember_me_spec.rb
|
204
|
+
- spec/lib/auth/extensions/controller_spec.rb
|
205
|
+
- spec/lib/auth/model_spec.rb
|
206
|
+
- spec/lib/auth_spec.rb
|
207
|
+
- spec/mocks/models/user.rb
|
208
|
+
- spec/routes_spec.rb
|
209
|
+
- spec/spec_helper.rb
|
210
|
+
- spec/views_spec.rb
|