clearance 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of clearance might be problematic. Click here for more details.
- data/CHANGELOG.textile +12 -1
- data/README.textile +27 -44
- data/Rakefile +20 -36
- data/VERSION +1 -0
- data/app/controllers/clearance/confirmations_controller.rb +1 -1
- data/app/controllers/clearance/passwords_controller.rb +2 -2
- data/app/controllers/clearance/sessions_controller.rb +3 -3
- data/app/controllers/clearance/users_controller.rb +1 -1
- data/app/models/clearance_mailer.rb +2 -4
- data/app/views/sessions/new.html.erb +1 -1
- data/generators/clearance/clearance_generator.rb +6 -0
- data/generators/clearance/lib/insert_commands.rb +1 -1
- data/generators/clearance/templates/README +13 -11
- data/generators/clearance/templates/clearance.rb +3 -0
- data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +12 -8
- data/generators/clearance_features/templates/features/support/paths.rb +10 -9
- data/generators/clearance_views/templates/formtastic/sessions/new.html.erb +1 -1
- data/lib/clearance.rb +2 -1
- data/lib/clearance/authentication.rb +2 -2
- data/lib/clearance/configuration.rb +25 -0
- data/lib/clearance/routes.rb +49 -0
- data/lib/clearance/user.rb +0 -18
- data/shoulda_macros/clearance.rb +1 -1
- data/test/controllers/confirmations_controller_test.rb +100 -0
- data/test/controllers/passwords_controller_test.rb +183 -0
- data/test/controllers/sessions_controller_test.rb +141 -0
- data/test/controllers/users_controller_test.rb +65 -0
- data/test/models/clearance_mailer_test.rb +55 -0
- data/test/models/user_test.rb +227 -0
- data/test/rails_root/app/controllers/accounts_controller.rb +10 -0
- data/test/rails_root/app/controllers/application_controller.rb +5 -0
- data/test/rails_root/app/helpers/application_helper.rb +5 -0
- data/test/rails_root/app/helpers/confirmations_helper.rb +2 -0
- data/test/rails_root/app/helpers/passwords_helper.rb +2 -0
- data/test/rails_root/app/models/user.rb +3 -0
- data/test/rails_root/config/boot.rb +110 -0
- data/test/rails_root/config/environment.rb +17 -0
- data/test/rails_root/config/environments/development.rb +19 -0
- data/test/rails_root/config/environments/production.rb +1 -0
- data/test/rails_root/config/environments/test.rb +36 -0
- data/test/rails_root/config/initializers/clearance.rb +3 -0
- data/test/rails_root/config/initializers/clearance_loader.rb +8 -0
- data/test/rails_root/config/initializers/inflections.rb +10 -0
- data/test/rails_root/config/initializers/mime_types.rb +5 -0
- data/test/rails_root/config/initializers/requires.rb +13 -0
- data/test/rails_root/config/initializers/time_formats.rb +4 -0
- data/test/rails_root/config/routes.rb +6 -0
- data/test/rails_root/db/migrate/20100120045223_clearance_create_users.rb +21 -0
- data/test/rails_root/features/step_definitions/clearance_steps.rb +122 -0
- data/test/rails_root/features/step_definitions/factory_girl_steps.rb +5 -0
- data/test/rails_root/features/step_definitions/web_steps.rb +259 -0
- data/test/rails_root/features/support/env.rb +47 -0
- data/test/rails_root/features/support/paths.rb +23 -0
- data/test/rails_root/public/dispatch.rb +10 -0
- data/test/rails_root/script/create_project.rb +52 -0
- data/test/rails_root/test/factories/clearance.rb +13 -0
- data/test/rails_root/test/functional/accounts_controller_test.rb +23 -0
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +21 -0
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/formtastic.rb +1236 -0
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/justin_french/formtastic.rb +10 -0
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/rails/init.rb +3 -0
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/formtastic_spec.rb +2900 -0
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/test_helper.rb +14 -0
- data/test/test_helper.rb +19 -0
- metadata +60 -18
- data/TODO.textile +0 -6
- data/config/clearance_routes.rb +0 -30
- data/lib/clearance/extensions/routes.rb +0 -14
data/CHANGELOG.textile
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
h2. 0.8.
|
1
|
+
h2. 0.8.5 (01/20/2009)
|
2
|
+
|
3
|
+
* replaced routing hack with Clearance::Routes.draw(map) to give
|
4
|
+
more control to the application developer. (Dan Croak)
|
5
|
+
* removed attr_accessible from Clearance::User. (Dan Croak)
|
6
|
+
* fixed bug in password reset feature. (Dan Croak)
|
7
|
+
* use Jeweler for gemming. (Dan Croak)
|
8
|
+
* remove dependency on root_path, use '/' instead. (Dan Croak)
|
9
|
+
* use Clearance.configure block to set mailer sender instead of
|
10
|
+
DO_NOT_REPLY constant. (Dan Croak)
|
11
|
+
|
12
|
+
h2. 0.8.4 (12/08/2009)
|
2
13
|
|
3
14
|
* [#48] remove unnecessary require 'factory_girl' in generator (Dan Croak)
|
4
15
|
* reference gemcutter (not github) as the gem source in README (Dan Croak)
|
data/README.textile
CHANGED
@@ -12,30 +12,16 @@ h2. Help
|
|
12
12
|
|
13
13
|
h2. Bugs, Patches
|
14
14
|
|
15
|
-
Fork away and create a "Github Issue":http://github.com/thoughtbot/clearance/issues.
|
16
|
-
|
17
|
-
h2. Suspenders
|
18
|
-
|
19
|
-
Clearance is included in "Suspenders":http://github.com/thoughtbot/suspenders, which thoughtbot uses on all of our apps. We highly recommend you try it. Suspenders is the "King Gem" in our ecosystem, representing what we think the current state-of-the-art is in Rails development.
|
15
|
+
Fork away and create a "Github Issue":http://github.com/thoughtbot/clearance/issues.
|
20
16
|
|
21
17
|
h2. Installation
|
22
18
|
|
23
19
|
Clearance is a Rails engine. It works with versions of Rails greater than 2.3.
|
24
20
|
|
25
|
-
|
21
|
+
Install it as a gem however you like to install gems. Gem Bundler example:
|
26
22
|
|
27
23
|
<pre>
|
28
|
-
|
29
|
-
:lib => 'clearance',
|
30
|
-
:source => 'http://gemcutter.org',
|
31
|
-
:version => '0.8.3'
|
32
|
-
</pre>
|
33
|
-
|
34
|
-
Vendor the gem:
|
35
|
-
|
36
|
-
<pre>
|
37
|
-
rake gems:install
|
38
|
-
rake gems:unpack
|
24
|
+
gem "clearance"
|
39
25
|
</pre>
|
40
26
|
|
41
27
|
Make sure the development database exists and run the generator:
|
@@ -44,41 +30,38 @@ Make sure the development database exists and run the generator:
|
|
44
30
|
script/generate clearance
|
45
31
|
</pre>
|
46
32
|
|
47
|
-
|
33
|
+
This:
|
48
34
|
|
49
|
-
|
35
|
+
* inserts Clearance::User into your User model
|
36
|
+
* inserts Clearance::Authentication into your ApplicationController
|
37
|
+
* inserts Clearance::Routes.draw(map) into your config.routes.rb
|
38
|
+
* created a migration that either creates a users table or adds only missing columns
|
39
|
+
* prints further instructions
|
50
40
|
|
51
|
-
|
41
|
+
h2. Usage
|
52
42
|
|
53
|
-
|
54
|
-
rake db:migrate
|
55
|
-
</pre>
|
43
|
+
If you want to authenticate users for a controller action, use the authenticate method in a before_filter.
|
56
44
|
|
57
|
-
|
45
|
+
class WidgetsController < ApplicationController
|
46
|
+
before_filter :authenticate
|
58
47
|
|
59
|
-
|
60
|
-
|
48
|
+
def index
|
49
|
+
@widgets = Widget.all
|
50
|
+
end
|
51
|
+
end
|
61
52
|
|
62
|
-
|
63
|
-
HOST = "localhost"
|
64
|
-
</pre>
|
65
|
-
|
66
|
-
In production.rb it must be the actual host your application is deployed to.
|
67
|
-
The constant is used by mailers to generate URLs in emails.
|
68
|
-
|
69
|
-
In config/environment.rb:
|
70
|
-
|
71
|
-
<pre>
|
72
|
-
DO_NOT_REPLY = "donotreply@example.com"
|
73
|
-
</pre>
|
53
|
+
Subclass and override any Clearance-provided controller as needed:
|
74
54
|
|
75
|
-
|
55
|
+
class SessionsController < Clearance::SessionsController
|
56
|
+
def url_after_create
|
57
|
+
new_blog_post_path
|
58
|
+
end
|
59
|
+
end
|
76
60
|
|
77
|
-
|
78
|
-
|
79
|
-
</pre>
|
61
|
+
Actions that redirect (create, update, and destroy) in Clearance controllers
|
62
|
+
can be overriden by re-defining url_after_(action) methods as seen above.
|
80
63
|
|
81
|
-
h2. Cucumber
|
64
|
+
h2. Optional Cucumber features
|
82
65
|
|
83
66
|
As your app evolves, you want to know that authentication still works. thoughtbot's opinion is that you should test its integration with your app using "Cucumber":http://cukes.info/.
|
84
67
|
|
@@ -105,7 +88,7 @@ def path_to(page_name)
|
|
105
88
|
end
|
106
89
|
</pre>
|
107
90
|
|
108
|
-
h2. Formtastic views
|
91
|
+
h2. Optional Formtastic views
|
109
92
|
|
110
93
|
We have begun standardizing our forms using "Formtastic":http://github.com/justinfrench/formtastic. We highly recommend trying it. It will make your Rails view life more interesting.
|
111
94
|
|
data/Rakefile
CHANGED
@@ -37,14 +37,7 @@ generators = %w(clearance clearance_features clearance_views)
|
|
37
37
|
namespace :generator do
|
38
38
|
desc "Cleans up the test app before running the generator"
|
39
39
|
task :cleanup do
|
40
|
-
|
41
|
-
FileList["generators/#{generator}/templates/**/*.*"].each do |each|
|
42
|
-
file = "test/rails_root/#{each.gsub("generators/#{generator}/templates/",'')}"
|
43
|
-
File.delete(file) if File.exists?(file)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
FileList["test/rails_root/db/**/*"].each do |each|
|
40
|
+
FileList["test/rails_root/db/**/*"].each do |each|
|
48
41
|
FileUtils.rm_rf(each)
|
49
42
|
end
|
50
43
|
|
@@ -52,25 +45,21 @@ namespace :generator do
|
|
52
45
|
FileUtils.mkdir_p("test/rails_root/vendor/plugins")
|
53
46
|
clearance_root = File.expand_path(File.dirname(__FILE__))
|
54
47
|
system("ln -s #{clearance_root} test/rails_root/vendor/plugins/clearance")
|
55
|
-
|
56
|
-
FileUtils.rm_rf("test/rails_root/app/views/passwords")
|
57
|
-
FileUtils.rm_rf("test/rails_root/app/views/sessions")
|
58
|
-
FileUtils.rm_rf("test/rails_root/app/views/users")
|
59
48
|
end
|
60
49
|
|
61
50
|
desc "Run the clearance generator"
|
62
51
|
task :clearance do
|
63
|
-
system "cd test/rails_root && ./script/generate clearance && rake db:migrate db:test:prepare"
|
52
|
+
system "cd test/rails_root && ./script/generate clearance -f && rake db:migrate db:test:prepare"
|
64
53
|
end
|
65
54
|
|
66
55
|
desc "Run the clearance features generator"
|
67
56
|
task :clearance_features do
|
68
|
-
system "cd test/rails_root && ./script/generate clearance_features"
|
57
|
+
system "cd test/rails_root && ./script/generate clearance_features -f"
|
69
58
|
end
|
70
59
|
|
71
60
|
desc "Run the clearance views generator"
|
72
61
|
task :clearance_views do
|
73
|
-
system "cd test/rails_root && ./script/generate clearance_views"
|
62
|
+
system "cd test/rails_root && ./script/generate clearance_views -f"
|
74
63
|
end
|
75
64
|
end
|
76
65
|
|
@@ -78,26 +67,21 @@ desc "Run the test suite"
|
|
78
67
|
task :default => ['test:basic', 'test:features',
|
79
68
|
'test:views', 'test:features_for_views']
|
80
69
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
desc "Generate a gemspec file"
|
98
|
-
task :gemspec do
|
99
|
-
File.open("#{gem_spec.name}.gemspec", 'w') do |f|
|
100
|
-
f.write gem_spec.to_yaml
|
101
|
-
end
|
70
|
+
require 'jeweler'
|
71
|
+
|
72
|
+
Jeweler::Tasks.new do |gem|
|
73
|
+
gem.name = "clearance"
|
74
|
+
gem.summary = "Rails authentication with email & password."
|
75
|
+
gem.description = "Rails authentication with email & password."
|
76
|
+
gem.email = "support@thoughtbot.com"
|
77
|
+
gem.homepage = "http://github.com/thoughtbot/clearance"
|
78
|
+
gem.authors = ["Dan Croak", "Mike Burns", "Jason Morrison",
|
79
|
+
"Joe Ferris", "Eugene Bolshakov", "Nick Quaranto",
|
80
|
+
"Josh Nichols", "Mike Breen", "Marcel Görner",
|
81
|
+
"Bence Nagy", "Ben Mabey", "Eloy Duran",
|
82
|
+
"Tim Pope", "Mihai Anca", "Mark Cornick",
|
83
|
+
"Shay Arnett", "Jon Yurek", "Chad Pytel"]
|
84
|
+
gem.files = FileList["[A-Z]*", "{app,config,generators,lib,shoulda_macros,rails}/**/*"]
|
102
85
|
end
|
103
86
|
|
87
|
+
Jeweler::GemcutterTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.8.5
|
@@ -71,7 +71,7 @@ class Clearance::PasswordsController < ApplicationController
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def url_after_create
|
74
|
-
|
74
|
+
sign_in_url
|
75
75
|
end
|
76
76
|
|
77
77
|
def flash_success_after_update
|
@@ -79,6 +79,6 @@ class Clearance::PasswordsController < ApplicationController
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def url_after_update
|
82
|
-
|
82
|
+
'/'
|
83
83
|
end
|
84
84
|
end
|
@@ -22,7 +22,7 @@ class Clearance::SessionsController < ApplicationController
|
|
22
22
|
else
|
23
23
|
::ClearanceMailer.deliver_confirmation(@user)
|
24
24
|
flash_notice_after_create
|
25
|
-
redirect_to(
|
25
|
+
redirect_to(sign_in_url)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -53,7 +53,7 @@ class Clearance::SessionsController < ApplicationController
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def url_after_create
|
56
|
-
|
56
|
+
'/'
|
57
57
|
end
|
58
58
|
|
59
59
|
def flash_success_after_destroy
|
@@ -61,6 +61,6 @@ class Clearance::SessionsController < ApplicationController
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def url_after_destroy
|
64
|
-
|
64
|
+
sign_in_url
|
65
65
|
end
|
66
66
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class ClearanceMailer < ActionMailer::Base
|
2
2
|
|
3
|
-
default_url_options[:host] = HOST
|
4
|
-
|
5
3
|
def change_password(user)
|
6
|
-
from
|
4
|
+
from Clearance.configuration.mailer_sender
|
7
5
|
recipients user.email
|
8
6
|
subject I18n.t(:change_password,
|
9
7
|
:scope => [:clearance, :models, :clearance_mailer],
|
@@ -12,7 +10,7 @@ class ClearanceMailer < ActionMailer::Base
|
|
12
10
|
end
|
13
11
|
|
14
12
|
def confirmation(user)
|
15
|
-
from
|
13
|
+
from Clearance.configuration.mailer_sender
|
16
14
|
recipients user.email
|
17
15
|
subject I18n.t(:confirmation,
|
18
16
|
:scope => [:clearance, :models, :clearance_mailer],
|
@@ -5,6 +5,9 @@ class ClearanceGenerator < Rails::Generator::Base
|
|
5
5
|
|
6
6
|
def manifest
|
7
7
|
record do |m|
|
8
|
+
m.directory File.join("config", "initializers")
|
9
|
+
m.file "clearance.rb", "config/initializers/clearance.rb"
|
10
|
+
|
8
11
|
m.insert_into "app/controllers/application_controller.rb",
|
9
12
|
"include Clearance::Authentication"
|
10
13
|
|
@@ -16,6 +19,9 @@ class ClearanceGenerator < Rails::Generator::Base
|
|
16
19
|
m.file "user.rb", user_model
|
17
20
|
end
|
18
21
|
|
22
|
+
m.insert_into "config/routes.rb",
|
23
|
+
"Clearance::Routes.draw(map)"
|
24
|
+
|
19
25
|
m.directory File.join("test", "factories")
|
20
26
|
m.file "factories.rb", "test/factories/clearance.rb"
|
21
27
|
|
@@ -10,7 +10,7 @@ Rails::Generator::Commands::Create.class_eval do
|
|
10
10
|
def insert_into(file, line)
|
11
11
|
logger.insert "#{line} into #{file}"
|
12
12
|
unless options[:pretend] || file_contains?(file, line)
|
13
|
-
gsub_file file, /^(class|module)
|
13
|
+
gsub_file file, /^(class|module|.*Routes).*$/ do |match|
|
14
14
|
"#{match}\n #{line}"
|
15
15
|
end
|
16
16
|
end
|
@@ -1,22 +1,24 @@
|
|
1
1
|
|
2
2
|
*******************************************************************************
|
3
3
|
|
4
|
-
|
4
|
+
Next:
|
5
5
|
|
6
|
-
1.
|
7
|
-
In
|
6
|
+
1. Configure default url options for the mailer to generate URLs in emails.
|
7
|
+
In production.rb it must be the actual host your application is deployed to.
|
8
|
+
In config/environments/test.rb and config/environments/development.rb:
|
8
9
|
|
9
|
-
|
10
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
10
11
|
|
11
|
-
|
12
|
-
The constant is used by mailers to generate URLs in emails.
|
12
|
+
2. Migrate:
|
13
13
|
|
14
|
-
|
14
|
+
rake db:migrate
|
15
15
|
|
16
|
-
|
16
|
+
4. Make sure you're displaying flashes somewhere. For instance, in a layout:
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
<div id="flash">
|
19
|
+
<% flash.each do |key, value| -%>
|
20
|
+
<div id="flash_<%= key %>"><%=h value %></div>
|
21
|
+
<% end -%>
|
22
|
+
</div>
|
21
23
|
|
22
24
|
*******************************************************************************
|
@@ -48,11 +48,14 @@ end
|
|
48
48
|
|
49
49
|
Then /^a confirmation message should be sent to "(.*)"$/ do |email|
|
50
50
|
user = User.find_by_email(email)
|
51
|
-
sent = ActionMailer::Base.deliveries.first
|
52
|
-
assert_equal [user.email], sent.to
|
53
|
-
assert_match /confirm/i, sent.subject
|
54
51
|
assert !user.confirmation_token.blank?
|
55
|
-
|
52
|
+
assert !ActionMailer::Base.deliveries.empty?
|
53
|
+
result = ActionMailer::Base.deliveries.any? do |email|
|
54
|
+
email.to == [user.email] &&
|
55
|
+
email.subject =~ /confirm/i &&
|
56
|
+
email.body =~ /#{user.confirmation_token}/
|
57
|
+
end
|
58
|
+
assert result
|
56
59
|
end
|
57
60
|
|
58
61
|
When /^I follow the confirmation link sent to "(.*)"$/ do |email|
|
@@ -63,13 +66,14 @@ end
|
|
63
66
|
|
64
67
|
Then /^a password reset message should be sent to "(.*)"$/ do |email|
|
65
68
|
user = User.find_by_email(email)
|
69
|
+
assert !user.confirmation_token.blank?
|
66
70
|
assert !ActionMailer::Base.deliveries.empty?
|
67
|
-
ActionMailer::Base.deliveries.any? do |email|
|
68
|
-
email.to == user.email &&
|
71
|
+
result = ActionMailer::Base.deliveries.any? do |email|
|
72
|
+
email.to == [user.email] &&
|
69
73
|
email.subject =~ /password/i &&
|
70
74
|
email.body =~ /#{user.confirmation_token}/
|
71
75
|
end
|
72
|
-
assert
|
76
|
+
assert result
|
73
77
|
end
|
74
78
|
|
75
79
|
When /^I follow the password reset link sent to "(.*)"$/ do |email|
|
@@ -97,7 +101,7 @@ When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
|
|
97
101
|
end
|
98
102
|
|
99
103
|
When /^I sign out$/ do
|
100
|
-
visit '/
|
104
|
+
visit '/sign_out'
|
101
105
|
end
|
102
106
|
|
103
107
|
When /^I request password reset link to be sent to "(.*)"$/ do |email|
|
@@ -1,22 +1,23 @@
|
|
1
1
|
module NavigationHelpers
|
2
2
|
def path_to(page_name)
|
3
3
|
case page_name
|
4
|
-
|
5
|
-
when /the
|
6
|
-
|
4
|
+
|
5
|
+
when /the home\s?page/
|
6
|
+
'/'
|
7
7
|
when /the sign up page/i
|
8
|
-
|
8
|
+
sign_up_path
|
9
9
|
when /the sign in page/i
|
10
|
-
|
10
|
+
sign_in_path
|
11
11
|
when /the password reset request page/i
|
12
12
|
new_password_path
|
13
|
-
|
13
|
+
|
14
14
|
# Add more page name => path mappings here
|
15
|
-
|
15
|
+
|
16
16
|
else
|
17
|
-
raise "Can't find mapping from \"#{page_name}\" to a path
|
17
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
18
|
+
"Now, go and add a mapping in #{__FILE__}"
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
World(NavigationHelpers)
|