thoughtbot-clearance 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -4,13 +4,6 @@ Simple, complete Ruby web app authentication.
4
4
 
5
5
  "We have clearance, Clarence.":http://www.youtube.com/v/mNRXJEE3Nz8
6
6
 
7
- h2. Features
8
-
9
- * email & password
10
- * modules, not a generator
11
- * gem, not a plugin
12
- * tests included using "shoulda":http://thoughtbot.com/projects/shoulda & "factory_girl":http://thoughtbot.com/projects/factory_girl
13
-
14
7
  h2. Gem installation (Rails 2.1+)
15
8
 
16
9
  Specify the gem dependency in your config/environment.rb file:
@@ -27,6 +20,46 @@ Then:
27
20
  rake gems:install
28
21
  rake gems:unpack
29
22
 
23
+ h2. Generator
24
+
25
+ In a greenfield application, just run the generator:
26
+
27
+ script/generate clearance
28
+
29
+ This will create:
30
+
31
+ app/controllers/confirmations_controller.rb
32
+ app/controllers/passwords_controller.rb
33
+ app/controllers/sessions_controller.rb
34
+ app/controllers/users_controller.rb
35
+ app/models/user.rb
36
+ app/models/user_mailer.rb
37
+ app/views/confirmations/new.html.erb
38
+ app/views/passwords/edit.html.erb
39
+ app/views/passwords/new.html.erb
40
+ app/views/sessions/new.html.erb
41
+ app/views/user_mailer/change_password.html.erb
42
+ app/views/user_mailer/confirmation.html.erb
43
+ app/views/users/_form.html.erb
44
+ app/views/users/edit.html.erb
45
+ app/views/users/new.html.erb
46
+ test/functional/confirmations_controller_test.rb
47
+ test/functional/passwords_controller_test.rb
48
+ test/functional/sessions_controller_test.rb
49
+ test/functional/users_controller_test.rb
50
+ test/unit/user_mailer_test.rb
51
+ test/unit/user_test.rb
52
+
53
+ If you already have some of these files created, the generator will:
54
+
55
+ # NOT overwrite your files
56
+ # print out instructions to include Clearance modules in those files manually
57
+
58
+ For example:
59
+
60
+ app/models/user.rb already exists. Add this line to it:
61
+ include Clearance::Models::User
62
+
30
63
  h2. Tests
31
64
 
32
65
  The tests use "Shoulda":http://thoughtbot.com/projects/shoulda >= 2.0.4 and "Factory Girl":http://thoughtbot.com/projects/factory_girl. You should create a User Factory:
@@ -37,8 +70,8 @@ The tests use "Shoulda":http://thoughtbot.com/projects/shoulda >= 2.0.4 and "Fac
37
70
 
38
71
  Factory.define :user do |user|
39
72
  user.email { Factory.next :email }
40
- user.password 'sekrit'
41
- user.password_confirmation 'sekrit'
73
+ user.password "password"
74
+ user.password_confirmation "password"
42
75
  end
43
76
 
44
77
  In test/test_helper.rb:
@@ -49,71 +82,6 @@ In test/test_helper.rb:
49
82
  include Clearance::TestHelper
50
83
  end
51
84
 
52
- In test/unit/user_test.rb:
53
-
54
- class UserTest < Test::Unit::TestCase
55
- include Clearance::UserTest
56
- end
57
-
58
- In test/unit/user_mailer_test.rb:
59
-
60
- class UserMailerTest < Test::Unit::TestCase
61
- include Clearance::UserMailerTest
62
- end
63
-
64
- In test/functional/sessions_controller_test.rb:
65
-
66
- class SessionsControllerTest < ActionController::TestCase
67
- include Clearance::SessionsControllerTest
68
- end
69
-
70
- In test/functional/users_controller_test.rb:
71
-
72
- class UsersControllerTest < ActionController::TestCase
73
- include Clearance::UsersControllerTest
74
- end
75
-
76
- In test/functional/passwords_controller_test.rb:
77
-
78
- class PasswordsControllerTest < ActionController::TestCase
79
- include Clearance::PasswordsControllerTest
80
- end
81
-
82
- h2. Schema
83
-
84
- Change your User model so it has these attributes:
85
-
86
- change_table(:users) do |t|
87
- t.column :email, :string
88
- t.column :crypted_password, :string, :limit => 40
89
- t.column :salt, :string, :limit => 40
90
- t.column :remember_token, :string
91
- t.column :remember_token_expires_at, :datetime
92
- end
93
-
94
- add_index :users, :email
95
- add_index :users, :remember_token
96
-
97
- h2. User Model
98
-
99
- In app/models/user.rb:
100
-
101
- class User < ActiveRecord::Base
102
- include Clearance::Models::User
103
- end
104
-
105
- h2. User Mailer
106
-
107
- In app/models/user_mailer.rb:
108
-
109
- class UserMailer < ActionMailer::Base
110
-
111
- default_url_options[:host] = HOST
112
-
113
- include Clearance::Mailers::User
114
-
115
- end
116
-
117
85
  h2. Controllers
118
86
 
119
87
  In app/controllers/application_controller.rb:
@@ -124,74 +92,27 @@ In app/controllers/application_controller.rb:
124
92
  include Clearance::ApplicationController
125
93
  end
126
94
 
127
- In app/controllers/sessions_controller.rb:
128
-
129
- class SessionsController < ApplicationController
130
- include Clearance::SessionsController
131
-
132
- private
133
-
134
- def url_after_create
135
- root_url # the default
136
- end
137
-
138
- def url_after_destroy
139
- login_url # the default
140
- end
141
- end
142
-
143
- In app/controllers/users_controller.rb:
144
-
145
- class UsersController < ApplicationController
146
- include Clearance::UsersController
147
-
148
- private
149
-
150
- def url_after_create
151
- root_url # the default
152
- end
153
-
154
- def url_after_update
155
- root_url # the default
156
- end
157
- end
158
-
159
- In app/controllers/passwords_controller.rb:
160
-
161
- class PasswordsController < ApplicationController
162
- include Clearance::PasswordsController
163
- end
164
-
165
- h2. Routes
166
-
167
- map.with_options :controller => 'sessions' do |m|
168
- m.login '/login', :action => 'new'
169
- m.logout '/logout', :action => 'destroy'
170
- end
171
- map.resource :session
172
- map.resources :users, :has_one => :password
173
-
174
95
  h2. Views
175
96
 
176
97
  In app/views/sessions/new.html.erb
177
98
 
178
- <% form_for :session, :url => session_path do |f| %>
179
- <div class="group">
180
- <%= f.label :email %>
181
- <%= f.text_field :email %>
182
- </div>
183
- <div class="group">
184
- <%= f.label :password %>
185
- <%= f.password_field :password %>
186
- </div>
187
- <div class="checkbox">
188
- <%= f.check_box :remember_me %>
189
- <%= f.label :remember_me %>
190
- </div>
191
- <div class="group buttons">
192
- <%= f.submit 'Login', :disable_with => 'Please wait...' %>
193
- </div>
194
- <% end %>
99
+ <% form_for :session, :url => session_path do |f| %>
100
+ <div class="group">
101
+ <%= f.label :email %>
102
+ <%= f.text_field :email %>
103
+ </div>
104
+ <div class="group">
105
+ <%= f.label :password %>
106
+ <%= f.password_field :password %>
107
+ </div>
108
+ <div class="checkbox">
109
+ <%= f.check_box :remember_me %>
110
+ <%= f.label :remember_me %>
111
+ </div>
112
+ <div class="group buttons">
113
+ <%= f.submit 'Login', :disable_with => 'Please wait...' %>
114
+ </div>
115
+ <% end %>
195
116
 
196
117
  h2. Authors
197
118
 
@@ -200,4 +121,4 @@ h2. Authors
200
121
  * Jason Morrison
201
122
  * Mike Burns
202
123
  * Josh Nichols
203
- * Mike Breen
124
+ * Mike Breen
data/clearance.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "clearance"
3
- s.version = "0.1.9"
4
- s.date = "2008-10-10"
3
+ s.version = "0.1.10"
4
+ s.date = "2008-10-11"
5
5
  s.summary = "Simple, complete Rails authentication."
6
6
  s.email = "dcroak@thoughtbot.com"
7
7
  s.homepage = "http://github.com/thoughtbot/clearance"
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  "lib/clearance/test/functionals/sessions_controller_test.rb",
18
18
  "lib/clearance/test/test_helper.rb",
19
19
  "lib/clearance/test/units/user_test.rb",
20
+ "lib/clearance/test/units/user_mailer_test.rb",
20
21
  "lib/clearance/app/controllers/users_controller.rb",
21
22
  "lib/clearance/test/functionals/users_controller_test.rb",
22
23
  "lib/clearance/app/controllers/passwords_controller.rb",
data/lib/clearance.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  require 'clearance/app/controllers/application_controller'
2
+ require 'clearance/app/controllers/confirmations_controller'
3
+ require 'clearance/app/controllers/passwords_controller'
2
4
  require 'clearance/app/controllers/sessions_controller'
3
5
  require 'clearance/app/controllers/users_controller'
4
- require 'clearance/app/controllers/passwords_controller'
5
6
  require 'clearance/app/models/user'
6
7
  require 'clearance/app/models/user_mailer'
7
- require 'clearance/test/test_helper'
8
+ require 'clearance/test/functionals/confirmations_controller_test'
8
9
  require 'clearance/test/functionals/sessions_controller_test'
9
10
  require 'clearance/test/functionals/users_controller_test'
10
11
  require 'clearance/test/functionals/passwords_controller_test'
12
+ require 'clearance/test/test_helper'
11
13
  require 'clearance/test/units/user_test'
12
14
  require 'clearance/test/units/user_mailer_test'
@@ -58,6 +58,10 @@ module Clearance
58
58
  self.update_attribute :remember_token_expires_at, nil
59
59
  self.update_attribute :remember_token, nil
60
60
  end
61
+
62
+ def confirm!
63
+ update_attribute :confirmed, true
64
+ end
61
65
  end
62
66
 
63
67
  module ProtectedInstanceMethods
@@ -17,6 +17,13 @@ module Clearance
17
17
  subject "[YOUR APP] Request to change your password"
18
18
  body :user => user
19
19
  end
20
+
21
+ def confirmation(user)
22
+ recipients user.email
23
+ from "donotreply@example.com"
24
+ subject 'Account Confirmation'
25
+ body :user => user
26
+ end
20
27
  end
21
28
  end
22
29
  end
@@ -0,0 +1,34 @@
1
+ module Clearance
2
+ module UserMailerTest
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+ context "A change password email" do
7
+ setup do
8
+ @user = Factory :user
9
+ @email = UserMailer.create_change_password @user
10
+ end
11
+
12
+ should "set its from address to 'donotreply@example.com'" do
13
+ assert_equal 'donotreply@example.com', @email.from[0]
14
+ end
15
+
16
+ should "contain a link to edit the user's password" do
17
+ host = ActionMailer::Base.default_url_options[:host]
18
+ regexp = %r{http://#{host}/users/#{@user.id}/password/edit\?email=#{@user.email.gsub("@", "%40")}&amp;password=#{@user.crypted_password}}
19
+ assert_match regexp, @email.body
20
+ end
21
+
22
+ should "be sent to the user" do
23
+ assert_equal [@user.email], @email.to
24
+ end
25
+
26
+ should "have a subject of '[YOUR APP] Request to change your password'" do
27
+ assert_equal "[YOUR APP] Request to change your password", @email.subject
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -35,10 +35,10 @@ module Clearance
35
35
 
36
36
  context 'A user' do
37
37
  setup do
38
- @password = 'mysekrit'
39
38
  @salt = 'salt'
40
39
  User.any_instance.stubs(:initialize_salt)
41
- @user = Factory(:user, :password => @password, :password_confirmation => @password, :salt => @salt)
40
+ @user = Factory :user, :salt => @salt
41
+ @password = @user.password
42
42
  end
43
43
 
44
44
  should "require password validation on update" do
@@ -180,6 +180,23 @@ module Clearance
180
180
  end
181
181
  end
182
182
 
183
+ context "A user" do
184
+ setup do
185
+ @user = Factory :user
186
+ end
187
+
188
+ context 'when sent #confirm!' do
189
+ setup do
190
+ assert ! @user.confirmed?
191
+ assert @user.confirm!
192
+ @user.reload
193
+ end
194
+
195
+ should 'mark the User record as confirmed' do
196
+ assert @user.confirmed?
197
+ end
198
+ end
199
+ end
183
200
  end
184
201
  end
185
202
  end
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.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot, inc.
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2008-10-10 00:00:00 -07:00
17
+ date: 2008-10-11 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -37,6 +37,7 @@ files:
37
37
  - lib/clearance/test/functionals/sessions_controller_test.rb
38
38
  - lib/clearance/test/test_helper.rb
39
39
  - lib/clearance/test/units/user_test.rb
40
+ - lib/clearance/test/units/user_mailer_test.rb
40
41
  - lib/clearance/app/controllers/users_controller.rb
41
42
  - lib/clearance/test/functionals/users_controller_test.rb
42
43
  - lib/clearance/app/controllers/passwords_controller.rb