thoughtbot-clearance 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile CHANGED
@@ -51,47 +51,21 @@ In test/test_helper.rb:
51
51
 
52
52
  In test/unit/user_test.rb:
53
53
 
54
- require File.dirname(__FILE__) + '/../test_helper'
55
-
56
54
  class UserTest < Test::Unit::TestCase
57
55
  include Clearance::UserTest
58
56
  end
59
57
 
60
58
  In test/functional/sessions_controller_test.rb:
61
59
 
62
- require File.dirname(__FILE__) + '/../test_helper'
63
-
64
- class SessionsControllerTest < ActionController::TestCase
65
- include Clearance::SessionsControllerTest
66
-
67
- private
68
-
69
- def url_after_create
70
- root_url # the default
60
+ class SessionsControllerTest < ActionController::TestCase
61
+ include Clearance::SessionsControllerTest
71
62
  end
72
-
73
- def url_after_destroy
74
- login_url # the default
75
- end
76
- end
77
63
 
78
64
  In test/functional/users_controller_test.rb:
79
65
 
80
- require File.dirname(__FILE__) + '/../test_helper'
81
-
82
- class UsersControllerTest < ActionController::TestCase
83
- include Clearance::UsersControllerTest
84
-
85
- private
86
-
87
- def url_after_create
88
- root_url # the default
89
- end
90
-
91
- def url_after_update
92
- root_url # the default
66
+ class UsersControllerTest < ActionController::TestCase
67
+ include Clearance::UsersControllerTest
93
68
  end
94
- end
95
69
 
96
70
  h2. Schema
97
71
 
@@ -130,12 +104,32 @@ In app/controllers/sessions_controller.rb:
130
104
 
131
105
  class SessionsController < ApplicationController
132
106
  include Clearance::SessionsController
107
+
108
+ private
109
+
110
+ def url_after_create
111
+ root_url # the default
112
+ end
113
+
114
+ def url_after_destroy
115
+ login_url # the default
116
+ end
133
117
  end
134
118
 
135
119
  In app/controllers/users_controller.rb:
136
120
 
137
121
  class UsersController < ApplicationController
138
122
  include Clearance::UsersController
123
+
124
+ private
125
+
126
+ def url_after_create
127
+ root_url # the default
128
+ end
129
+
130
+ def url_after_update
131
+ root_url # the default
132
+ end
139
133
  end
140
134
 
141
135
  h2. Routes
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.5"
4
- s.date = "2008-09-24"
3
+ s.version = "0.1.6"
4
+ s.date = "2008-09-26"
5
5
  s.summary = "Simple, complete Rails authentication."
6
6
  s.email = "dcroak@thoughtbot.com"
7
7
  s.homepage = "http://github.com/thoughtbot/clearance"
@@ -3,10 +3,8 @@ module Clearance
3
3
 
4
4
  def self.included(base)
5
5
  base.class_eval do
6
- before_filter :authenticate, :except => [:new, :create]
7
6
  before_filter :redirect_to_root, :only => [:new, :create], :if => :logged_in?
8
- before_filter :ensure_user_is_accessing_self, :only => [:edit, :update, :show]
9
-
7
+
10
8
  filter_parameter_logging :password
11
9
 
12
10
  include InstanceMethods
@@ -17,16 +15,8 @@ module Clearance
17
15
  end
18
16
 
19
17
  module InstanceMethods
20
- def index
21
- @users = User.find :all
22
- end
23
-
24
18
  def new
25
- @user = User.new
26
- end
27
-
28
- def show
29
- @user = User.find params[:id]
19
+ @user = User.new(params[:user])
30
20
  end
31
21
 
32
22
  def create
@@ -39,42 +29,12 @@ module Clearance
39
29
  render :action => "new"
40
30
  end
41
31
  end
42
-
43
- def edit
44
- @user = User.find params[:id]
45
- end
46
-
47
- def update
48
- @user = User.find params[:id]
49
-
50
- if @user.update_attributes params[:user]
51
- flash[:notice] = "User updated."
52
- redirect_back_or root_url
53
- else
54
- render :action => "edit"
55
- end
56
- end
57
-
58
- def destroy
59
- @user = User.find params[:id]
60
- @user.destroy
61
- redirect_to root_url
62
- end
63
32
  end
64
33
 
65
34
  module PrivateInstanceMethods
66
- def ensure_user_is_accessing_self
67
- return if current_user and current_user.respond_to?(:admin?) and current_user.admin?
68
- deny_access('You cannot edit that user.', :redirect => root_url) unless current_user.id.to_i == params[:id].to_i
69
- end
70
-
71
35
  def url_after_create
72
36
  root_url
73
37
  end
74
-
75
- def url_after_update
76
- root_url
77
- end
78
38
  end
79
39
 
80
40
  end
@@ -44,10 +44,9 @@ module Clearance
44
44
  should_set_the_flash_to /bad/i
45
45
  should_render_template :new
46
46
  #should_return_from_session(:user_id, 'nil')
47
- should "return the correct value from the session for key :user_id" do
47
+ should "return nil from the session for key :user_id" do
48
48
  instantiate_variables_from_assigns do
49
- expected_value = @user.id
50
- assert_equal expected_value, session[:user_id], "Expected #{expected_value.inspect} but was #{session[:user_id]}"
49
+ assert_nil session[:user_id], "Expected nil but was #{session[:user_id]}"
51
50
  end
52
51
  end
53
52
  end
@@ -15,6 +15,18 @@ module Clearance
15
15
  :fields => { :email => :text,
16
16
  :password => :password,
17
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
18
30
  end
19
31
 
20
32
  context "on POST to /users" do
@@ -32,11 +44,6 @@ module Clearance
32
44
  should_change 'User.count', :by => 1
33
45
  end
34
46
 
35
- should_deny_access_on "get :edit, :id => 1", :redirect => "login_url"
36
- should_deny_access_on "put :update, :id => 1", :redirect => "login_url"
37
- should_deny_access_on "get :show, :id => 1", :redirect => "login_url"
38
- should_deny_access_on "delete :destroy, :id => 1", :redirect => "login_url"
39
-
40
47
  end
41
48
 
42
49
  logged_in_user_context do
@@ -45,66 +52,6 @@ module Clearance
45
52
  should_deny_access_on "post :create, :user => {}"
46
53
  should_filter :password
47
54
 
48
- context "viewing their account" do
49
- context "on GET to /users/:id/show" do
50
- setup { get :show, :id => @user.to_param }
51
- should_respond_with :success
52
- should_render_template :show
53
- should_not_set_the_flash
54
-
55
- should 'assign to @user' do
56
- assert_equal @user, assigns(:user)
57
- end
58
- end
59
-
60
- should_deny_access_on "delete :destroy, :id => @user.to_param"
61
-
62
- context "on GET to /users/:id/edit" do
63
- setup { get :edit, :id => @user.to_param }
64
-
65
- should_respond_with :success
66
- should_render_template :edit
67
- should_not_set_the_flash
68
- should_assign_to :user
69
- should_have_form :action => "user_path(@user)",
70
- :method => :put,
71
- :fields => { :email => :text,
72
- :password => :password,
73
- :password_confirmation => :password }
74
- end
75
-
76
- context "on PUT to /users/:id" do
77
- setup do
78
- put :update,
79
- :id => @user.to_param,
80
- :user => { :email => "none@example.com" }
81
- end
82
- should_set_the_flash_to /updated/i
83
- should_redirect_to "@controller.send(:url_after_update)"
84
- should_assign_to :user
85
- should "update the user's attributes" do
86
- assert_equal "none@example.com", assigns(:user).email
87
- end
88
- end
89
-
90
- context "on PUT to /users/:id with invalid attributes" do
91
- setup { put :update, :id => @user.to_param, :user => {:email => ''} }
92
- should_not_set_the_flash
93
- should_assign_to :user
94
- should_render_template 'edit'
95
- should "display errors" do
96
- assert_select '#errorExplanation'
97
- end
98
- end
99
- end
100
-
101
- context "trying to access another user's account" do
102
- setup { @user = Factory :user }
103
-
104
- should_deny_access_on "get :show, :id => @user.to_param", :flash => /cannot edit/i
105
- should_deny_access_on "get :edit, :id => @user.to_param", :flash => /cannot edit/i
106
- should_deny_access_on "put :update, :id => @user.to_param, :user => {}", :flash => /cannot edit/i
107
- end
108
55
  end
109
56
  end
110
57
  end
@@ -35,10 +35,10 @@ module Clearance
35
35
 
36
36
  context 'A user' do
37
37
  setup do
38
- @password = 'sekrit'
38
+ @password = 'mysekrit'
39
39
  @salt = 'salt'
40
40
  User.any_instance.stubs(:initialize_salt)
41
- @user = Factory(:user, :password => @password, :salt => @salt)
41
+ @user = Factory(:user, :password => @password, :password_confirmation => @password, :salt => @salt)
42
42
  end
43
43
 
44
44
  should "require password validation on update" do
@@ -52,7 +52,7 @@ module Clearance
52
52
  context 'authenticating a user' do
53
53
  context 'with good credentials' do
54
54
  setup do
55
- @result = User.authenticate @user.email, 'sekrit'
55
+ @result = User.authenticate @user.email, @password
56
56
  end
57
57
 
58
58
  should 'return true' do
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.5
4
+ version: 0.1.6
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-09-24 00:00:00 -07:00
17
+ date: 2008-09-26 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20