thoughtbot-clearance 0.6.9 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.textile CHANGED
@@ -1,3 +1,12 @@
1
+ h2. 0.7.0 (08/04/2009)
2
+
3
+ * Redirect signed in user who clicks confirmation link again. (Dan Croak)
4
+ * Redirect signed out user who clicks confirmation link again. (Dan Croak)
5
+ * Added signed_out? convenience method for controllers, helpers, views. (Dan
6
+ Croak)
7
+ * Added clearance_views generator. By default, creates formtastic views which
8
+ pass all tests and features. (Dan Croak)
9
+
1
10
  h2. 0.6.9 (07/04/2009)
2
11
 
3
12
  * Added timestamps to create users migration. (Dan Croak)
data/README.textile CHANGED
@@ -18,7 +18,7 @@ In config/environment.rb:
18
18
  config.gem "thoughtbot-clearance",
19
19
  :lib => 'clearance',
20
20
  :source => 'http://gems.github.com',
21
- :version => '0.6.6'
21
+ :version => '0.6.9'
22
22
  </pre>
23
23
 
24
24
  Vendor the gem:
data/Rakefile CHANGED
@@ -5,8 +5,16 @@ require 'rake/testtask'
5
5
  require 'cucumber/rake/task'
6
6
 
7
7
  namespace :test do
8
- Rake::TestTask.new(:all => ["generator:cleanup",
9
- "generator:generate"]) do |task|
8
+ Rake::TestTask.new(:basic => ["generator:cleanup",
9
+ "generator:clearance",
10
+ "generator:clearance_features"]) do |task|
11
+ task.libs << "lib"
12
+ task.libs << "test"
13
+ task.pattern = "test/**/*_test.rb"
14
+ task.verbose = false
15
+ end
16
+
17
+ Rake::TestTask.new(:views => ["generator:clearance_views"]) do |task|
10
18
  task.libs << "lib"
11
19
  task.libs << "test"
12
20
  task.pattern = "test/**/*_test.rb"
@@ -17,9 +25,14 @@ namespace :test do
17
25
  t.cucumber_opts = "--format progress"
18
26
  t.feature_pattern = "test/rails_root/features/*.feature"
19
27
  end
28
+
29
+ Cucumber::Rake::Task.new(:features_for_views) do |t|
30
+ t.cucumber_opts = "--format progress"
31
+ t.feature_pattern = "test/rails_root/features/*.feature"
32
+ end
20
33
  end
21
34
 
22
- generators = %w(clearance clearance_features)
35
+ generators = %w(clearance clearance_features clearance_views)
23
36
 
24
37
  namespace :generator do
25
38
  desc "Cleans up the test app before running the generator"
@@ -34,26 +47,40 @@ namespace :generator do
34
47
  FileList["test/rails_root/db/**/*"].each do |each|
35
48
  FileUtils.rm_rf(each)
36
49
  end
50
+
37
51
  FileUtils.rm_rf("test/rails_root/vendor/plugins/clearance")
38
52
  FileUtils.mkdir_p("test/rails_root/vendor/plugins")
39
53
  clearance_root = File.expand_path(File.dirname(__FILE__))
40
54
  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")
41
59
  end
42
60
 
43
- desc "Run the generator on the tests"
44
- task :generate do
45
- generators.each do |generator|
46
- system "cd test/rails_root && ./script/generate #{generator} && rake db:migrate db:test:prepare"
47
- end
61
+ desc "Run the clearance generator"
62
+ task :clearance do
63
+ system "cd test/rails_root && ./script/generate clearance && rake db:migrate db:test:prepare"
64
+ end
65
+
66
+ desc "Run the clearance features generator"
67
+ task :clearance_features do
68
+ system "cd test/rails_root && ./script/generate clearance_features"
69
+ end
70
+
71
+ desc "Run the clearance views generator"
72
+ task :clearance_views do
73
+ system "cd test/rails_root && ./script/generate clearance_views"
48
74
  end
49
75
  end
50
76
 
51
77
  desc "Run the test suite"
52
- task :default => ['test:all', 'test:features']
78
+ task :default => ['test:basic', 'test:features',
79
+ 'test:views', 'test:features_for_views']
53
80
 
54
81
  gem_spec = Gem::Specification.new do |gem_spec|
55
82
  gem_spec.name = "clearance"
56
- gem_spec.version = "0.6.9"
83
+ gem_spec.version = "0.7.0"
57
84
  gem_spec.summary = "Rails authentication with email & password."
58
85
  gem_spec.email = "support@thoughtbot.com"
59
86
  gem_spec.homepage = "http://github.com/thoughtbot/clearance"
@@ -1,9 +1,11 @@
1
1
  class Clearance::ConfirmationsController < ApplicationController
2
2
  unloadable
3
3
 
4
- before_filter :forbid_confirmed_user, :only => [:new, :create]
5
- before_filter :forbid_missing_token, :only => [:new, :create]
6
- before_filter :forbid_non_existent_user, :only => [:new, :create]
4
+ before_filter :redirect_signed_in_confirmed_user, :only => [:new, :create]
5
+ before_filter :redirect_signed_out_confirmed_user, :only => [:new, :create]
6
+ before_filter :forbid_missing_token, :only => [:new, :create]
7
+ before_filter :forbid_non_existent_user, :only => [:new, :create]
8
+
7
9
  filter_parameter_logging :token
8
10
 
9
11
  def new
@@ -21,10 +23,19 @@ class Clearance::ConfirmationsController < ApplicationController
21
23
 
22
24
  private
23
25
 
24
- def forbid_confirmed_user
26
+ def redirect_signed_in_confirmed_user
27
+ user = ::User.find_by_id(params[:user_id])
28
+ if user && user.email_confirmed? && current_user == user
29
+ flash_success_after_create
30
+ redirect_to(url_after_create)
31
+ end
32
+ end
33
+
34
+ def redirect_signed_out_confirmed_user
25
35
  user = ::User.find_by_id(params[:user_id])
26
- if user && user.email_confirmed?
27
- raise ActionController::Forbidden, "confirmed user"
36
+ if user && user.email_confirmed? && signed_out?
37
+ flash_already_confirmed
38
+ redirect_to(url_already_confirmed)
28
39
  end
29
40
  end
30
41
 
@@ -46,7 +57,17 @@ class Clearance::ConfirmationsController < ApplicationController
46
57
  :default => "Confirmed email and signed in.")
47
58
  end
48
59
 
60
+ def flash_already_confirmed
61
+ flash[:success] = translate(:already_confirmed_email,
62
+ :scope => [:clearance, :controllers, :confirmations],
63
+ :default => "Already confirmed email. Please sign in.")
64
+ end
65
+
49
66
  def url_after_create
50
67
  root_url
51
68
  end
69
+
70
+ def url_already_confirmed
71
+ sign_in_url
72
+ end
52
73
  end
@@ -1,10 +1,10 @@
1
1
  class ClearanceFeaturesGenerator < Rails::Generator::Base
2
-
2
+
3
3
  def manifest
4
4
  record do |m|
5
5
  m.directory File.join("features", "step_definitions")
6
6
  m.directory File.join("features", "support")
7
-
7
+
8
8
  ["features/step_definitions/clearance_steps.rb",
9
9
  "features/step_definitions/factory_girl_steps.rb",
10
10
  "features/support/paths.rb",
@@ -16,5 +16,5 @@ class ClearanceFeaturesGenerator < Rails::Generator::Base
16
16
  end
17
17
  end
18
18
  end
19
-
19
+
20
20
  end
@@ -26,3 +26,20 @@ Feature: Sign up
26
26
  Then I should see "Confirmed email and signed in"
27
27
  And I should be signed in
28
28
 
29
+ Scenario: Signed in user clicks confirmation link again
30
+ Given I signed up with "email@person.com/password"
31
+ When I follow the confirmation link sent to "email@person.com"
32
+ Then I should be signed in
33
+ When I follow the confirmation link sent to "email@person.com"
34
+ Then I should see "Confirmed email and signed in"
35
+ And I should be signed in
36
+
37
+ Scenario: Signed out user clicks confirmation link again
38
+ Given I signed up with "email@person.com/password"
39
+ When I follow the confirmation link sent to "email@person.com"
40
+ Then I should be signed in
41
+ When I sign out
42
+ And I follow the confirmation link sent to "email@person.com"
43
+ Then I should see "Already confirmed email. Please sign in."
44
+ And I should be signed out
45
+
File without changes
@@ -0,0 +1,27 @@
1
+ class ClearanceViewsGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ strategy = "formtastic"
6
+ template_strategy = "erb"
7
+
8
+ m.directory File.join("app", "views", "users")
9
+ m.file "#{strategy}/users/new.html.#{template_strategy}",
10
+ "app/views/users/new.html.#{template_strategy}"
11
+ m.file "#{strategy}/users/_inputs.html.#{template_strategy}",
12
+ "app/views/users/_inputs.html.#{template_strategy}"
13
+
14
+ m.directory File.join("app", "views", "sessions")
15
+ m.file "#{strategy}/sessions/new.html.#{template_strategy}",
16
+ "app/views/sessions/new.html.#{template_strategy}"
17
+
18
+ m.directory File.join("app", "views", "passwords")
19
+ m.file "#{strategy}/passwords/new.html.#{template_strategy}",
20
+ "app/views/passwords/new.html.#{template_strategy}"
21
+ m.file "#{strategy}/passwords/edit.html.#{template_strategy}",
22
+ "app/views/passwords/edit.html.#{template_strategy}"
23
+ end
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,21 @@
1
+ <h2>Change your password</h2>
2
+
3
+ <p>
4
+ Your password has been reset. Choose a new password below.
5
+ </p>
6
+
7
+ <% semantic_form_for(:user,
8
+ :url => user_password_path(@user, :token => @user.token),
9
+ :html => { :method => :put }) do |form| %>
10
+ <%= form.error_messages %>
11
+ <% form.inputs do -%>
12
+ <%= form.input :password, :as => :password,
13
+ :label => "Choose password" %>
14
+ <%= form.input :password_confirmation, :as => :password,
15
+ :label => "Confirm password" %>
16
+ <% end -%>
17
+ <% form.buttons do -%>
18
+ <%= form.commit_button "Save this password" %>
19
+ <% end -%>
20
+ <% end %>
21
+
@@ -0,0 +1,15 @@
1
+ <h2>Reset your password</h2>
2
+
3
+ <p>
4
+ We will email you a link to reset your password.
5
+ </p>
6
+
7
+ <% semantic_form_for :password, :url => passwords_path do |form| -%>
8
+ <% form.inputs do -%>
9
+ <%= form.input :email, :label => "Email address" %>
10
+ <% end -%>
11
+ <% form.buttons do -%>
12
+ <%= form.commit_button "Reset password" %>
13
+ <% end -%>
14
+ <% end -%>
15
+
@@ -0,0 +1,22 @@
1
+ <h2>Sign in</h2>
2
+
3
+ <% semantic_form_for :session, :url => session_path do |form| %>
4
+ <% form.inputs do %>
5
+ <%= form.input :email %>
6
+ <%= form.input :password, :as => :password %>
7
+ <%= form.input :remember_me, :as => :boolean, :required => false %>
8
+ <% end %>
9
+ <% form.buttons do %>
10
+ <%= form.commit_button "Sign in" %>
11
+ <% end %>
12
+ <% end %>
13
+
14
+ <ul>
15
+ <li>
16
+ <%= link_to "Sign up", new_user_path %>
17
+ </li>
18
+ <li>
19
+ <%= link_to "Forgot password?", new_password_path %>
20
+ </li>
21
+ </ul>
22
+
@@ -0,0 +1,6 @@
1
+ <% form.inputs do %>
2
+ <%= form.input :email %>
3
+ <%= form.input :password %>
4
+ <%= form.input :password_confirmation, :label => "Confirm password" %>
5
+ <% end %>
6
+
@@ -0,0 +1,10 @@
1
+ <h2>Sign up</h2>
2
+
3
+ <% semantic_form_for @user do |form| %>
4
+ <%= form.error_messages %>
5
+ <%= render :partial => "/users/inputs", :locals => { :form => form } %>
6
+ <% form.buttons do %>
7
+ <%= form.commit_button "Sign up" %>
8
+ <% end %>
9
+ <% end %>
10
+
@@ -5,10 +5,8 @@ module Clearance
5
5
  controller.send(:include, InstanceMethods)
6
6
 
7
7
  controller.class_eval do
8
- helper_method :current_user
9
- helper_method :signed_in?
10
-
11
- hide_action :current_user, :signed_in?
8
+ helper_method :current_user, :signed_in?, :signed_out?
9
+ hide_action :current_user, :signed_in?, :signed_out?
12
10
  end
13
11
  end
14
12
 
@@ -21,6 +19,10 @@ module Clearance
21
19
  ! current_user.nil?
22
20
  end
23
21
 
22
+ def signed_out?
23
+ current_user.nil?
24
+ end
25
+
24
26
  protected
25
27
 
26
28
  def authenticate
@@ -132,6 +132,12 @@ module Clearance
132
132
  end
133
133
  end
134
134
 
135
+ def should_redirect_to_url_already_confirmed
136
+ should_redirect_to("the already confirmed url") do
137
+ @controller.send(:url_already_confirmed)
138
+ end
139
+ end
140
+
135
141
  # VALIDATIONS
136
142
 
137
143
  def should_validate_confirmation_of(attribute, opts = {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thoughtbot-clearance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
@@ -24,7 +24,7 @@ autorequire:
24
24
  bindir: bin
25
25
  cert_chain: []
26
26
 
27
- date: 2009-07-03 21:00:00 -07:00
27
+ date: 2009-08-03 21:00:00 -07:00
28
28
  default_executable:
29
29
  dependencies: []
30
30
 
@@ -90,6 +90,19 @@ files:
90
90
  - generators/clearance_features/templates/features/support
91
91
  - generators/clearance_features/templates/features/support/paths.rb
92
92
  - generators/clearance_features/USAGE
93
+ - generators/clearance_views
94
+ - generators/clearance_views/clearance_views_generator.rb
95
+ - generators/clearance_views/templates
96
+ - generators/clearance_views/templates/formtastic
97
+ - generators/clearance_views/templates/formtastic/passwords
98
+ - generators/clearance_views/templates/formtastic/passwords/edit.html.erb
99
+ - generators/clearance_views/templates/formtastic/passwords/new.html.erb
100
+ - generators/clearance_views/templates/formtastic/sessions
101
+ - generators/clearance_views/templates/formtastic/sessions/new.html.erb
102
+ - generators/clearance_views/templates/formtastic/users
103
+ - generators/clearance_views/templates/formtastic/users/_inputs.html.erb
104
+ - generators/clearance_views/templates/formtastic/users/new.html.erb
105
+ - generators/clearance_views/USAGE
93
106
  - lib/clearance
94
107
  - lib/clearance/authentication.rb
95
108
  - lib/clearance/extensions
@@ -102,6 +115,8 @@ files:
102
115
  - rails/init.rb
103
116
  has_rdoc: true
104
117
  homepage: http://github.com/thoughtbot/clearance
118
+ licenses: []
119
+
105
120
  post_install_message:
106
121
  rdoc_options: []
107
122
 
@@ -122,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
137
  requirements: []
123
138
 
124
139
  rubyforge_project:
125
- rubygems_version: 1.2.0
140
+ rubygems_version: 1.3.5
126
141
  signing_key:
127
142
  specification_version: 3
128
143
  summary: Rails authentication with email & password.