thoughtbot-clearance 0.1.10 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/clearance.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "clearance"
3
- s.version = "0.1.10"
3
+ s.version = "0.2.0"
4
4
  s.date = "2008-10-11"
5
5
  s.summary = "Simple, complete Rails authentication."
6
6
  s.email = "dcroak@thoughtbot.com"
@@ -9,17 +9,42 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["thoughtbot, inc.", "Dan Croak", "Josh Nichols", "Mike Breen", "Mike Burns", "Jason Morrison"]
10
10
  s.files = ["README.textile",
11
11
  "clearance.gemspec",
12
+ "generators/clearance/clearance_generator.rb",
13
+ "generators/clearance/templates/app/.rb",
14
+ "generators/clearance/templates/app/controllers/confirmations_controller.rb",
15
+ "generators/clearance/templates/app/controllers/passwords_controller.rb",
16
+ "generators/clearance/templates/app/controllers/sessions_controller.rb",
17
+ "generators/clearance/templates/app/controllers/users_controller.rb",
18
+ "generators/clearance/templates/app/models/user.rb",
19
+ "generators/clearance/templates/app/models/user_mailer.rb",
20
+ "generators/clearance/templates/app/views/confirmations/new.html.erb",
21
+ "generators/clearance/templates/app/views/passwords/edit.html.erb",
22
+ "generators/clearance/templates/app/views/passwords/new.html.erb",
23
+ "generators/clearance/templates/app/views/sessions/new.htmlerb",
24
+ "generators/clearance/templates/app/views/user_mailer/change_password.htmlerb",
25
+ "generators/clearance/templates/app/views/user_mailer/confirmation.htmlerb",
26
+ "generators/clearance/templates/app/views/users/_form.htmlerb",
27
+ "generators/clearance/templates/app/views/users/edit.htmlerb",
28
+ "generators/clearance/templates/app/views/users/new.htmlerb",
29
+ "generators/clearance/templates/test/functional/confirmations_controller.rb",
30
+ "generators/clearance/templates/test/functional/passwords_controller.rb",
31
+ "generators/clearance/templates/test/functional/sessions_controller.rb",
32
+ "generators/clearance/templates/test/functional/users_controller_test.rb",
33
+ "generators/clearance/templates/test/unit/user_mailer_test.rb",
34
+ "generators/clearance/templates/test/unit/user_test.rb",
35
+ "generators/clearance/USAGE",
12
36
  "lib/clearance.rb",
13
37
  "lib/clearance/app/controllers/application_controller.rb",
38
+ "lib/clearance/app/controllers/confirmations_controller.rb",
39
+ "lib/clearance/app/controllers/passwords_controller.rb",
40
+ "lib/clearance/app/controllers/sessions_controller.rb",
41
+ "lib/clearance/app/controllers/users_controller.rb",
14
42
  "lib/clearance/app/models/user.rb",
15
43
  "lib/clearance/app/models/user_mailer.rb",
16
- "lib/clearance/app/controllers/sessions_controller.rb",
44
+ "lib/clearance/test/functionals/confirmations_controller_test.rb",
45
+ "lib/clearance/test/functionals/passwords_controller_test.rb",
17
46
  "lib/clearance/test/functionals/sessions_controller_test.rb",
18
47
  "lib/clearance/test/test_helper.rb",
19
48
  "lib/clearance/test/units/user_test.rb",
20
- "lib/clearance/test/units/user_mailer_test.rb",
21
- "lib/clearance/app/controllers/users_controller.rb",
22
- "lib/clearance/test/functionals/users_controller_test.rb",
23
- "lib/clearance/app/controllers/passwords_controller.rb",
24
- "lib/clearance/test/functionals/passwords_controller_test.rb"]
49
+ "lib/clearance/test/units/user_mailer_test.rb"]
25
50
  end
@@ -0,0 +1 @@
1
+ script/generate clearance
@@ -0,0 +1,65 @@
1
+ class ClearanceGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ system `mkdir app/controllers`
6
+ ["app/controllers/confirmations_controller.rb",
7
+ "app/controllers/passwords_controller.rb",
8
+ "app/controllers/sessions_controller.rb",
9
+ "app/controllers/users_controller.rb"].each do |file|
10
+ m.file file, file
11
+ end
12
+
13
+ system `mkdir app/models`
14
+ ["app/models/user.rb",
15
+ "app/models/user_mailer.rb"].each do |file|
16
+ m.file file, file
17
+ end
18
+
19
+ system `mkdir app/views`
20
+ system `mkdir app/views/confirmations`
21
+ ["app/views/confirmations/new.html.erb"].each do |file|
22
+ m.file file, file
23
+ end
24
+
25
+ system `mkdir app/views/passwords`
26
+ ["app/views/passwords/new.html.erb",
27
+ "app/views/passwords/edit.html.erb"].each do |file|
28
+ m.file file, file
29
+ end
30
+
31
+ system `mkdir app/views/sessions`
32
+ ["app/views/sessions/new.html.erb"].each do |file|
33
+ m.file file, file
34
+ end
35
+
36
+ system `mkdir app/views/user_mailer`
37
+ ["app/views/user_mailer/change_password.html.erb",
38
+ "app/views/user_mailer/confirmation.html.erb"].each do |file|
39
+ m.file file, file
40
+ end
41
+
42
+ system `mkdir app/views/users`
43
+ ["app/views/users/_form.html.erb",
44
+ "app/views/users/edit.html.erb",
45
+ "app/views/users/new.html.erb"].each do |file|
46
+ m.file file, file
47
+ end
48
+
49
+ system `mkdir test/functional`
50
+ ["test/functional/confirmations_controller_test.rb",
51
+ "test/functional/passwords_controller_test.rb",
52
+ "test/functional/sessions_controller_test.rb",
53
+ "test/functional/users_controller_test.rb"].each do |file|
54
+ m.file file, file
55
+ end
56
+
57
+ system `mkdir test/unit`
58
+ ["test/unit/user_mailer_test.rb",
59
+ "test/unit/user_test.rb"].each do |file|
60
+ m.file file, file
61
+ end
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,3 @@
1
+ class ConfirmationsController < ApplicationController
2
+ include Clearance::ConfirmationsController
3
+ end
@@ -0,0 +1,3 @@
1
+ class PasswordsController < ApplicationController
2
+ include Clearance::PasswordsController
3
+ end
@@ -0,0 +1,3 @@
1
+ class SessionsController < ApplicationController
2
+ include Clearance::SessionsController
3
+ end
@@ -0,0 +1,3 @@
1
+ class UsersController < ApplicationController
2
+ include Clearance::UsersController
3
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ include Clearance::Models::User
3
+ end
@@ -0,0 +1,7 @@
1
+ class UserMailer < ActionMailer::Base
2
+
3
+ default_url_options[:host] = HOST
4
+
5
+ include Clearance::Mailers::User
6
+
7
+ end
@@ -0,0 +1,4 @@
1
+ <% form_for :user, :url => user_confirmation_path(:user_id => @user,
2
+ :salt => @user.salt) do |form| %>
3
+ <%= form.submit 'Confirm' %>
4
+ <% end %>
@@ -0,0 +1,28 @@
1
+ <div class="page">
2
+ <div class="plain">
3
+ <div class="page-header">
4
+ <h2 class="instructions">
5
+ Your password has been reset. Choose a new password below.
6
+ </h2>
7
+ </div>
8
+ <%= error_messages_for :user %>
9
+ <% form_for(:user,
10
+ :url => user_password_path(
11
+ @user,
12
+ :email => @user.email,
13
+ :password => @user.crypted_password),
14
+ :html => { :method => :put }) do |form| %>
15
+ <div class="text">
16
+ <%= form.label :password, 'Choose password' %>
17
+ <%= form.password_field :password %>
18
+ </div>
19
+ <div class="text">
20
+ <%= form.label :password_confirmation, 'Verify password' %>
21
+ <%= form.password_field :password_confirmation %>
22
+ </div>
23
+ <div class="buttons" id="password-submit">
24
+ <%= form.submit 'Save this password' %>
25
+ </div>
26
+ <% end %>
27
+ </div>
28
+ </div>
@@ -0,0 +1,13 @@
1
+ <h2>Change your password</h2>
2
+
3
+ <p class="help">We'll email you a link to change your password.</p>
4
+
5
+ <% form_for :password, :url => passwords_path do |form| %>
6
+ <div class="text">
7
+ <%= form.label :email, 'Email address' %>
8
+ <%= form.text_field :email %>
9
+ </div>
10
+ <div class="buttons" id="password-submit">
11
+ <%= form.submit 'Reset password' %>
12
+ </div>
13
+ <% end %>
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class UsersControllerTest < ActionController::TestCase
4
+ include Clearance::UsersControllerTest
5
+ end
@@ -0,0 +1,6 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class UserMailerTest < ActionMailer::TestCase
4
+ tests UserMailer
5
+ include Clearance::UserMailerTest
6
+ end
@@ -0,0 +1,38 @@
1
+ module Clearance
2
+ module ConfirmationsController
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+ before_filter :existing_user?, :only => [:new, :create]
7
+
8
+ include InstanceMethods
9
+
10
+ private
11
+ include PrivateInstanceMethods
12
+ end
13
+ end
14
+
15
+ module InstanceMethods
16
+ def new
17
+ @user = User.find_by_id_and_salt(params[:user_id], params[:salt])
18
+ end
19
+
20
+ def create
21
+ @user = User.find_by_id_and_salt(params[:user_id], params[:salt])
22
+ @user.confirm!
23
+ session[:user_id] = @user.id
24
+ redirect_to user_path(@user)
25
+ end
26
+ end
27
+
28
+ module PrivateInstanceMethods
29
+ def existing_user?
30
+ user = User.find_by_id_and_salt(params[:user_id], params[:salt])
31
+ if user.nil?
32
+ render :nothing => true, :status => :not_found
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,81 @@
1
+ module Clearance
2
+ module ConfirmationsControllerTest
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+
7
+ context 'A GET to #new' do
8
+ context "with the User with the given id's salt" do
9
+ setup do
10
+ @user = Factory :user
11
+ get :new, :user_id => @user.id, :salt => @user.salt
12
+ end
13
+
14
+ should 'find the User record with the given id and salt' do
15
+ assert_equal @user, assigns(:user)
16
+ end
17
+
18
+ should_respond_with :success
19
+ should_render_template :new
20
+ end
21
+
22
+ context "without the User with the given id's salt" do
23
+ setup do
24
+ user = Factory :user
25
+ salt = ''
26
+ assert_not_equal salt, user.salt
27
+
28
+ get :new, :user_id => user.id, :salt => ''
29
+ end
30
+
31
+ should_respond_with :not_found
32
+
33
+ should 'render nothing' do
34
+ assert @response.body.blank?
35
+ end
36
+ end
37
+ end
38
+
39
+ context 'A POST to #create' do
40
+ context "with the User with the given id's salt" do
41
+ setup do
42
+ @user = Factory :user
43
+ assert ! @user.confirmed?
44
+
45
+ post :create, :user_id => @user, :salt => @user.salt
46
+ @user.reload
47
+ end
48
+
49
+ should 'confirm the User record with the given id' do
50
+ assert @user.confirmed?
51
+ end
52
+
53
+ should 'log the User in' do
54
+ assert_equal @user.id, session[:user_id]
55
+ end
56
+
57
+ should_redirect_to "user_path(@user)"
58
+ end
59
+
60
+ context "without the User with the given id's salt" do
61
+ setup do
62
+ user = Factory :user
63
+ salt = ''
64
+ assert_not_equal salt, user.salt
65
+
66
+ post :create, :user_id => user.id, :salt => salt
67
+ end
68
+
69
+ should_respond_with :not_found
70
+
71
+ should 'render nothing' do
72
+ assert @response.body.blank?
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+ end
79
+
80
+ end
81
+ 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.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot, inc.
@@ -29,19 +29,44 @@ extra_rdoc_files: []
29
29
  files:
30
30
  - README.textile
31
31
  - clearance.gemspec
32
+ - generators/clearance/clearance_generator.rb
33
+ - generators/clearance/templates/app/.rb
34
+ - generators/clearance/templates/app/controllers/confirmations_controller.rb
35
+ - generators/clearance/templates/app/controllers/passwords_controller.rb
36
+ - generators/clearance/templates/app/controllers/sessions_controller.rb
37
+ - generators/clearance/templates/app/controllers/users_controller.rb
38
+ - generators/clearance/templates/app/models/user.rb
39
+ - generators/clearance/templates/app/models/user_mailer.rb
40
+ - generators/clearance/templates/app/views/confirmations/new.html.erb
41
+ - generators/clearance/templates/app/views/passwords/edit.html.erb
42
+ - generators/clearance/templates/app/views/passwords/new.html.erb
43
+ - generators/clearance/templates/app/views/sessions/new.htmlerb
44
+ - generators/clearance/templates/app/views/user_mailer/change_password.htmlerb
45
+ - generators/clearance/templates/app/views/user_mailer/confirmation.htmlerb
46
+ - generators/clearance/templates/app/views/users/_form.htmlerb
47
+ - generators/clearance/templates/app/views/users/edit.htmlerb
48
+ - generators/clearance/templates/app/views/users/new.htmlerb
49
+ - generators/clearance/templates/test/functional/confirmations_controller.rb
50
+ - generators/clearance/templates/test/functional/passwords_controller.rb
51
+ - generators/clearance/templates/test/functional/sessions_controller.rb
52
+ - generators/clearance/templates/test/functional/users_controller_test.rb
53
+ - generators/clearance/templates/test/unit/user_mailer_test.rb
54
+ - generators/clearance/templates/test/unit/user_test.rb
55
+ - generators/clearance/USAGE
32
56
  - lib/clearance.rb
33
57
  - lib/clearance/app/controllers/application_controller.rb
58
+ - lib/clearance/app/controllers/confirmations_controller.rb
59
+ - lib/clearance/app/controllers/passwords_controller.rb
60
+ - lib/clearance/app/controllers/sessions_controller.rb
61
+ - lib/clearance/app/controllers/users_controller.rb
34
62
  - lib/clearance/app/models/user.rb
35
63
  - lib/clearance/app/models/user_mailer.rb
36
- - lib/clearance/app/controllers/sessions_controller.rb
64
+ - lib/clearance/test/functionals/confirmations_controller_test.rb
65
+ - lib/clearance/test/functionals/passwords_controller_test.rb
37
66
  - lib/clearance/test/functionals/sessions_controller_test.rb
38
67
  - lib/clearance/test/test_helper.rb
39
68
  - lib/clearance/test/units/user_test.rb
40
69
  - lib/clearance/test/units/user_mailer_test.rb
41
- - lib/clearance/app/controllers/users_controller.rb
42
- - lib/clearance/test/functionals/users_controller_test.rb
43
- - lib/clearance/app/controllers/passwords_controller.rb
44
- - lib/clearance/test/functionals/passwords_controller_test.rb
45
70
  has_rdoc: false
46
71
  homepage: http://github.com/thoughtbot/clearance
47
72
  post_install_message:
@@ -1,60 +0,0 @@
1
- module Clearance
2
- module UsersControllerTest
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- public_context do
7
-
8
- context "on GET to /users/new" do
9
- setup { get :new }
10
- should_respond_with :success
11
- should_render_template :new
12
- should_not_set_the_flash
13
- should_have_form :action => "users_path",
14
- :method => :post,
15
- :fields => { :email => :text,
16
- :password => :password,
17
- :password_confirmation => :password }
18
-
19
- context "with params" do
20
- setup do
21
- @email = 'a@example.com'
22
- get :new, :user => {:email => @email}
23
- end
24
-
25
- should_assign_to :user
26
- should "set the @user's params" do
27
- assert_equal @email, assigns(:user).email
28
- end
29
- end
30
- end
31
-
32
- context "on POST to /users" do
33
- setup do
34
- post :create, :user => {
35
- :email => Factory.next(:email),
36
- :password => 'skerit',
37
- :password_confirmation => 'skerit'
38
- }
39
- end
40
-
41
- should_set_the_flash_to /created/i
42
- should_redirect_to "@controller.send(:url_after_create)"
43
- should_assign_to :user
44
- should_change 'User.count', :by => 1
45
- end
46
-
47
- end
48
-
49
- logged_in_user_context do
50
-
51
- should_deny_access_on "get :new"
52
- should_deny_access_on "post :create, :user => {}"
53
- should_filter_params :password
54
-
55
- end
56
- end
57
- end
58
-
59
- end
60
- end