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.

Files changed (68) hide show
  1. data/CHANGELOG.textile +12 -1
  2. data/README.textile +27 -44
  3. data/Rakefile +20 -36
  4. data/VERSION +1 -0
  5. data/app/controllers/clearance/confirmations_controller.rb +1 -1
  6. data/app/controllers/clearance/passwords_controller.rb +2 -2
  7. data/app/controllers/clearance/sessions_controller.rb +3 -3
  8. data/app/controllers/clearance/users_controller.rb +1 -1
  9. data/app/models/clearance_mailer.rb +2 -4
  10. data/app/views/sessions/new.html.erb +1 -1
  11. data/generators/clearance/clearance_generator.rb +6 -0
  12. data/generators/clearance/lib/insert_commands.rb +1 -1
  13. data/generators/clearance/templates/README +13 -11
  14. data/generators/clearance/templates/clearance.rb +3 -0
  15. data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +12 -8
  16. data/generators/clearance_features/templates/features/support/paths.rb +10 -9
  17. data/generators/clearance_views/templates/formtastic/sessions/new.html.erb +1 -1
  18. data/lib/clearance.rb +2 -1
  19. data/lib/clearance/authentication.rb +2 -2
  20. data/lib/clearance/configuration.rb +25 -0
  21. data/lib/clearance/routes.rb +49 -0
  22. data/lib/clearance/user.rb +0 -18
  23. data/shoulda_macros/clearance.rb +1 -1
  24. data/test/controllers/confirmations_controller_test.rb +100 -0
  25. data/test/controllers/passwords_controller_test.rb +183 -0
  26. data/test/controllers/sessions_controller_test.rb +141 -0
  27. data/test/controllers/users_controller_test.rb +65 -0
  28. data/test/models/clearance_mailer_test.rb +55 -0
  29. data/test/models/user_test.rb +227 -0
  30. data/test/rails_root/app/controllers/accounts_controller.rb +10 -0
  31. data/test/rails_root/app/controllers/application_controller.rb +5 -0
  32. data/test/rails_root/app/helpers/application_helper.rb +5 -0
  33. data/test/rails_root/app/helpers/confirmations_helper.rb +2 -0
  34. data/test/rails_root/app/helpers/passwords_helper.rb +2 -0
  35. data/test/rails_root/app/models/user.rb +3 -0
  36. data/test/rails_root/config/boot.rb +110 -0
  37. data/test/rails_root/config/environment.rb +17 -0
  38. data/test/rails_root/config/environments/development.rb +19 -0
  39. data/test/rails_root/config/environments/production.rb +1 -0
  40. data/test/rails_root/config/environments/test.rb +36 -0
  41. data/test/rails_root/config/initializers/clearance.rb +3 -0
  42. data/test/rails_root/config/initializers/clearance_loader.rb +8 -0
  43. data/test/rails_root/config/initializers/inflections.rb +10 -0
  44. data/test/rails_root/config/initializers/mime_types.rb +5 -0
  45. data/test/rails_root/config/initializers/requires.rb +13 -0
  46. data/test/rails_root/config/initializers/time_formats.rb +4 -0
  47. data/test/rails_root/config/routes.rb +6 -0
  48. data/test/rails_root/db/migrate/20100120045223_clearance_create_users.rb +21 -0
  49. data/test/rails_root/features/step_definitions/clearance_steps.rb +122 -0
  50. data/test/rails_root/features/step_definitions/factory_girl_steps.rb +5 -0
  51. data/test/rails_root/features/step_definitions/web_steps.rb +259 -0
  52. data/test/rails_root/features/support/env.rb +47 -0
  53. data/test/rails_root/features/support/paths.rb +23 -0
  54. data/test/rails_root/public/dispatch.rb +10 -0
  55. data/test/rails_root/script/create_project.rb +52 -0
  56. data/test/rails_root/test/factories/clearance.rb +13 -0
  57. data/test/rails_root/test/functional/accounts_controller_test.rb +23 -0
  58. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +21 -0
  59. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/formtastic.rb +1236 -0
  60. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/justin_french/formtastic.rb +10 -0
  61. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/rails/init.rb +3 -0
  62. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/formtastic_spec.rb +2900 -0
  63. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/test_helper.rb +14 -0
  64. data/test/test_helper.rb +19 -0
  65. metadata +60 -18
  66. data/TODO.textile +0 -6
  67. data/config/clearance_routes.rb +0 -30
  68. data/lib/clearance/extensions/routes.rb +0 -14
@@ -1,4 +1,15 @@
1
- h2. 0.8.4
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)
@@ -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. Please don't send pull requests.
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
- In config/environment.rb:
21
+ Install it as a gem however you like to install gems. Gem Bundler example:
26
22
 
27
23
  <pre>
28
- config.gem "clearance",
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
- A number of files will be created and instructions will be printed.
33
+ This:
48
34
 
49
- You may already have some of these files. Don't worry. You'll be asked if you want to overwrite them.
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
- Run the migration:
41
+ h2. Usage
52
42
 
53
- <pre>
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
- h2. If you aren't on Suspenders, you aren't done
45
+ class WidgetsController < ApplicationController
46
+ before_filter :authenticate
58
47
 
59
- Define a HOST constant in your environment files.
60
- In config/environments/test.rb and config/environments/development.rb it can be:
48
+ def index
49
+ @widgets = Widget.all
50
+ end
51
+ end
61
52
 
62
- <pre>
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
- Define root_url to *something* in your config/routes.rb:
55
+ class SessionsController < Clearance::SessionsController
56
+ def url_after_create
57
+ new_blog_post_path
58
+ end
59
+ end
76
60
 
77
- <pre>
78
- map.root :controller => 'home'
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 Features
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
- generators.each do |generator|
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
- gem_spec = Gem::Specification.new do |gem_spec|
82
- gem_spec.name = "clearance"
83
- gem_spec.version = "0.8.4"
84
- gem_spec.summary = "Rails authentication with email & password."
85
- gem_spec.email = "support@thoughtbot.com"
86
- gem_spec.homepage = "http://github.com/thoughtbot/clearance"
87
- gem_spec.description = "Rails authentication with email & password."
88
- gem_spec.authors = ["Dan Croak", "Mike Burns", "Jason Morrison",
89
- "Joe Ferris", "Eugene Bolshakov", "Nick Quaranto",
90
- "Josh Nichols", "Mike Breen", "Marcel Görner",
91
- "Bence Nagy", "Ben Mabey", "Eloy Duran",
92
- "Tim Pope", "Mihai Anca", "Mark Cornick",
93
- "Shay Arnett", "Jon Yurek", "Chad Pytel"]
94
- gem_spec.files = FileList["[A-Z]*", "{app,config,generators,lib,shoulda_macros,rails}/**/*"]
95
- end
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
@@ -66,7 +66,7 @@ class Clearance::ConfirmationsController < ApplicationController
66
66
  end
67
67
 
68
68
  def url_after_create
69
- root_url
69
+ '/'
70
70
  end
71
71
 
72
72
  def url_already_confirmed
@@ -71,7 +71,7 @@ class Clearance::PasswordsController < ApplicationController
71
71
  end
72
72
 
73
73
  def url_after_create
74
- new_session_url
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
- root_url
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(new_session_url)
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
- root_url
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
- new_session_url
64
+ sign_in_url
65
65
  end
66
66
  end
@@ -29,6 +29,6 @@ class Clearance::UsersController < ApplicationController
29
29
  end
30
30
 
31
31
  def url_after_create
32
- new_session_url
32
+ sign_in_url
33
33
  end
34
34
  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 DO_NOT_REPLY
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 DO_NOT_REPLY
13
+ from Clearance.configuration.mailer_sender
16
14
  recipients user.email
17
15
  subject I18n.t(:confirmation,
18
16
  :scope => [:clearance, :models, :clearance_mailer],
@@ -16,7 +16,7 @@
16
16
 
17
17
  <ul>
18
18
  <li>
19
- <%= link_to "Sign up", new_user_path %>
19
+ <%= link_to "Sign up", sign_up_path %>
20
20
  </li>
21
21
  <li>
22
22
  <%= link_to "Forgot password?", new_password_path %>
@@ -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) .+$/ do |match|
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
- Ok, enough fancy automatic stuff. Time for some old school monkey copy-pasting.
4
+ Next:
5
5
 
6
- 1. Define a HOST constant in your environments files.
7
- In config/environments/test.rb and config/environments/development.rb it can be:
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
- HOST = "localhost"
10
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
10
11
 
11
- In production.rb it must be the actual host your application is deployed to.
12
- The constant is used by mailers to generate URLs in emails.
12
+ 2. Migrate:
13
13
 
14
- 2. In config/environment.rb:
14
+ rake db:migrate
15
15
 
16
- DO_NOT_REPLY = "donotreply@example.com"
16
+ 4. Make sure you're displaying flashes somewhere. For instance, in a layout:
17
17
 
18
- 3. Define root_url to *something* in your config/routes.rb:
19
-
20
- map.root :controller => 'home'
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
  *******************************************************************************
@@ -0,0 +1,3 @@
1
+ Clearance.configure do |config|
2
+ config.mailer_sender = 'donotreply@example.com'
3
+ end
@@ -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
- assert_match /#{user.confirmation_token}/, sent.body
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 !user.confirmation_token.blank?
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 '/session', :delete
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 homepage/i
6
- root_path
4
+
5
+ when /the home\s?page/
6
+ '/'
7
7
  when /the sign up page/i
8
- new_user_path
8
+ sign_up_path
9
9
  when /the sign in page/i
10
- new_session_path
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)