clearance 0.9.1 → 0.10.0
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.
- data/CHANGELOG.md +20 -1
- data/README.md +20 -20
- data/VERSION +1 -1
- data/app/controllers/clearance/passwords_controller.rb +0 -1
- data/app/controllers/clearance/sessions_controller.rb +3 -16
- data/app/controllers/clearance/users_controller.rb +2 -2
- data/app/models/clearance_mailer.rb +0 -11
- data/app/views/passwords/edit.html.erb +1 -1
- data/app/views/passwords/new.html.erb +1 -1
- data/app/views/sessions/new.html.erb +1 -1
- data/app/views/users/new.html.erb +1 -1
- data/clearance.gemspec +2 -10
- data/config/routes.rb +0 -4
- data/lib/clearance/shoulda_macros.rb +1 -9
- data/lib/clearance/user.rb +2 -18
- data/lib/rails/generators/clearance_features_templates/features/password_reset.feature +6 -0
- data/lib/rails/generators/clearance_features_templates/features/sign_in.feature +2 -10
- data/lib/rails/generators/clearance_features_templates/features/sign_out.feature +1 -1
- data/lib/rails/generators/clearance_features_templates/features/sign_up.feature +1 -26
- data/lib/rails/generators/clearance_features_templates/features/step_definitions/clearance_steps.rb +7 -28
- data/lib/rails/generators/clearance_templates/factories.rb +1 -1
- data/lib/rails/generators/clearance_templates/migrations/create_users.rb +0 -1
- data/lib/rails/generators/clearance_templates/migrations/update_users.rb +1 -2
- data/test/controllers/sessions_controller_test.rb +7 -40
- data/test/controllers/users_controller_test.rb +2 -4
- data/test/models/clearance_mailer_test.rb +1 -27
- data/test/models/user_test.rb +10 -46
- data/test/rails_root/test/factories/clearance.rb +1 -1
- metadata +23 -23
- data/app/controllers/clearance/confirmations_controller.rb +0 -74
- data/app/views/clearance_mailer/confirmation.html.erb +0 -5
- data/spec/rails_root/db/schema.rb +0 -29
- data/spec/rails_root/features/password_reset.feature +0 -33
- data/spec/rails_root/features/sign_in.feature +0 -35
- data/spec/rails_root/features/sign_out.feature +0 -15
- data/spec/rails_root/features/sign_up.feature +0 -45
- data/spec/rails_root/features/step_definitions/clearance_steps.rb +0 -138
- data/test/controllers/confirmations_controller_test.rb +0 -107
@@ -1,29 +0,0 @@
|
|
1
|
-
# This file is auto-generated from the current state of the database. Instead
|
2
|
-
# of editing this file, please use the migrations feature of Active Record to
|
3
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
-
#
|
5
|
-
# Note that this schema.rb definition is the authoritative source for your
|
6
|
-
# database schema. If you need to create the application database on another
|
7
|
-
# system, you should be using db:schema:load, not running all the migrations
|
8
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
-
#
|
11
|
-
# It's strongly recommended to check this file into your version control system.
|
12
|
-
|
13
|
-
ActiveRecord::Schema.define(:version => 20101220185807) do
|
14
|
-
|
15
|
-
create_table "users", :force => true do |t|
|
16
|
-
t.string "email"
|
17
|
-
t.string "encrypted_password", :limit => 128
|
18
|
-
t.string "salt", :limit => 128
|
19
|
-
t.string "confirmation_token", :limit => 128
|
20
|
-
t.string "remember_token", :limit => 128
|
21
|
-
t.boolean "email_confirmed", :default => false, :null => false
|
22
|
-
t.datetime "created_at"
|
23
|
-
t.datetime "updated_at"
|
24
|
-
end
|
25
|
-
|
26
|
-
add_index "users", ["email"], :name => "index_users_on_email"
|
27
|
-
add_index "users", ["remember_token"], :name => "index_users_on_remember_token"
|
28
|
-
|
29
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
Feature: Password reset
|
2
|
-
In order to sign in even if user forgot their password
|
3
|
-
A user
|
4
|
-
Should be able to reset it
|
5
|
-
|
6
|
-
Scenario: User is not signed up
|
7
|
-
Given no user exists with an email of "email@person.com"
|
8
|
-
When I request password reset link to be sent to "email@person.com"
|
9
|
-
Then I should see "Unknown email"
|
10
|
-
|
11
|
-
Scenario: User is signed up and requests password reset
|
12
|
-
Given I signed up with "email@person.com/password"
|
13
|
-
When I request password reset link to be sent to "email@person.com"
|
14
|
-
Then I should see "instructions for changing your password"
|
15
|
-
And a password reset message should be sent to "email@person.com"
|
16
|
-
|
17
|
-
Scenario: User is signed up updated his password and types wrong confirmation
|
18
|
-
Given I signed up with "email@person.com/password"
|
19
|
-
When I follow the password reset link sent to "email@person.com"
|
20
|
-
And I update my password with "newpassword/wrongconfirmation"
|
21
|
-
Then I should see an error message
|
22
|
-
And I should be signed out
|
23
|
-
|
24
|
-
Scenario: User is signed up and updates his password
|
25
|
-
Given I signed up with "email@person.com/password"
|
26
|
-
When I follow the password reset link sent to "email@person.com"
|
27
|
-
And I update my password with "newpassword/newpassword"
|
28
|
-
Then I should be signed in
|
29
|
-
When I sign out
|
30
|
-
Then I should be signed out
|
31
|
-
And I sign in as "email@person.com/newpassword"
|
32
|
-
Then I should be signed in
|
33
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
Feature: Sign in
|
2
|
-
In order to get access to protected sections of the site
|
3
|
-
A user
|
4
|
-
Should be able to sign in
|
5
|
-
|
6
|
-
Scenario: User is not signed up
|
7
|
-
Given no user exists with an email of "email@person.com"
|
8
|
-
When I go to the sign in page
|
9
|
-
And I sign in as "email@person.com/password"
|
10
|
-
Then I should see "Bad email or password"
|
11
|
-
And I should be signed out
|
12
|
-
|
13
|
-
Scenario: User is not confirmed
|
14
|
-
Given I signed up with "email@person.com/password"
|
15
|
-
When I go to the sign in page
|
16
|
-
And I sign in as "email@person.com/password"
|
17
|
-
Then I should see "User has not confirmed email"
|
18
|
-
And I should be signed out
|
19
|
-
|
20
|
-
Scenario: User enters wrong password
|
21
|
-
Given I am signed up and confirmed as "email@person.com/password"
|
22
|
-
When I go to the sign in page
|
23
|
-
And I sign in as "email@person.com/wrongpassword"
|
24
|
-
Then I should see "Bad email or password"
|
25
|
-
And I should be signed out
|
26
|
-
|
27
|
-
Scenario: User signs in successfully
|
28
|
-
Given I am signed up and confirmed as "email@person.com/password"
|
29
|
-
When I go to the sign in page
|
30
|
-
And I sign in as "email@person.com/password"
|
31
|
-
Then I should see "Signed in"
|
32
|
-
And I should be signed in
|
33
|
-
When I return next time
|
34
|
-
Then I should be signed in
|
35
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
Feature: Sign out
|
2
|
-
To protect my account from unauthorized access
|
3
|
-
A signed in user
|
4
|
-
Should be able to sign out
|
5
|
-
|
6
|
-
Scenario: User signs out
|
7
|
-
Given I am signed up and confirmed as "email@person.com/password"
|
8
|
-
When I sign in as "email@person.com/password"
|
9
|
-
Then I should be signed in
|
10
|
-
And I sign out
|
11
|
-
Then I should see "Signed out"
|
12
|
-
And I should be signed out
|
13
|
-
When I return next time
|
14
|
-
Then I should be signed out
|
15
|
-
|
@@ -1,45 +0,0 @@
|
|
1
|
-
Feature: Sign up
|
2
|
-
In order to get access to protected sections of the site
|
3
|
-
A user
|
4
|
-
Should be able to sign up
|
5
|
-
|
6
|
-
Scenario: User signs up with invalid data
|
7
|
-
When I go to the sign up page
|
8
|
-
And I fill in "Email" with "invalidemail"
|
9
|
-
And I fill in "Password" with "password"
|
10
|
-
And I fill in "Confirm password" with ""
|
11
|
-
And I press "Sign up"
|
12
|
-
Then I should see error messages
|
13
|
-
|
14
|
-
Scenario: User signs up with valid data
|
15
|
-
When I go to the sign up page
|
16
|
-
And I fill in "Email" with "email@person.com"
|
17
|
-
And I fill in "Password" with "password"
|
18
|
-
And I fill in "Confirm password" with "password"
|
19
|
-
And I press "Sign up"
|
20
|
-
Then I should see "instructions for confirming"
|
21
|
-
And a confirmation message should be sent to "email@person.com"
|
22
|
-
|
23
|
-
Scenario: User confirms his account
|
24
|
-
Given I signed up with "email@person.com/password"
|
25
|
-
When I follow the confirmation link sent to "email@person.com"
|
26
|
-
Then I should see "Confirmed email and signed in"
|
27
|
-
And I should be signed in
|
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
|
-
|
@@ -1,138 +0,0 @@
|
|
1
|
-
# General
|
2
|
-
|
3
|
-
Then /^I should see error messages$/ do
|
4
|
-
Then %{I should see "errors prohibited"}
|
5
|
-
end
|
6
|
-
|
7
|
-
Then /^I should see an error message$/ do
|
8
|
-
Then %{I should see "error prohibited"}
|
9
|
-
end
|
10
|
-
|
11
|
-
# Database
|
12
|
-
|
13
|
-
Given /^no user exists with an email of "(.*)"$/ do |email|
|
14
|
-
assert_nil User.find_by_email(email)
|
15
|
-
end
|
16
|
-
|
17
|
-
Given /^I signed up with "(.*)\/(.*)"$/ do |email, password|
|
18
|
-
user = Factory :user,
|
19
|
-
:email => email,
|
20
|
-
:password => password,
|
21
|
-
:password_confirmation => password
|
22
|
-
end
|
23
|
-
|
24
|
-
Given /^I am signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
|
25
|
-
user = Factory :email_confirmed_user,
|
26
|
-
:email => email,
|
27
|
-
:password => password,
|
28
|
-
:password_confirmation => password
|
29
|
-
end
|
30
|
-
|
31
|
-
# Session
|
32
|
-
|
33
|
-
Then /^I should be signed in$/ do
|
34
|
-
Given %{I am on the homepage}
|
35
|
-
Then %{I should see "Sign out"}
|
36
|
-
end
|
37
|
-
|
38
|
-
Then /^I should be signed out$/ do
|
39
|
-
Given %{I am on the homepage}
|
40
|
-
Then %{I should see "Sign in"}
|
41
|
-
end
|
42
|
-
|
43
|
-
When /^session is cleared$/ do
|
44
|
-
# TODO: This doesn't work with Capybara
|
45
|
-
# TODO: I tried Capybara.reset_sessions! but that didn't work
|
46
|
-
#request.reset_session
|
47
|
-
#controller.instance_variable_set(:@_current_user, nil)
|
48
|
-
end
|
49
|
-
|
50
|
-
Given /^I have signed in with "(.*)\/(.*)"$/ do |email, password|
|
51
|
-
Given %{I am signed up and confirmed as "#{email}/#{password}"}
|
52
|
-
And %{I sign in as "#{email}/#{password}"}
|
53
|
-
end
|
54
|
-
|
55
|
-
Given /^I sign in$/ do
|
56
|
-
email = Factory.next(:email)
|
57
|
-
Given %{I have signed in with "#{email}/password"}
|
58
|
-
end
|
59
|
-
|
60
|
-
# Emails
|
61
|
-
|
62
|
-
Then /^a confirmation message should be sent to "(.*)"$/ do |email|
|
63
|
-
user = User.find_by_email(email)
|
64
|
-
assert !user.confirmation_token.blank?
|
65
|
-
assert !ActionMailer::Base.deliveries.empty?
|
66
|
-
result = ActionMailer::Base.deliveries.any? do |email|
|
67
|
-
email.to == [user.email] &&
|
68
|
-
email.subject =~ /confirm/i &&
|
69
|
-
email.body =~ /#{user.confirmation_token}/
|
70
|
-
end
|
71
|
-
assert result
|
72
|
-
end
|
73
|
-
|
74
|
-
When /^I follow the confirmation link sent to "(.*)"$/ do |email|
|
75
|
-
user = User.find_by_email(email)
|
76
|
-
visit new_user_confirmation_path(:user_id => user,
|
77
|
-
:token => user.confirmation_token)
|
78
|
-
end
|
79
|
-
|
80
|
-
Then /^a password reset message should be sent to "(.*)"$/ do |email|
|
81
|
-
user = User.find_by_email(email)
|
82
|
-
assert !user.confirmation_token.blank?
|
83
|
-
assert !ActionMailer::Base.deliveries.empty?
|
84
|
-
result = ActionMailer::Base.deliveries.any? do |email|
|
85
|
-
email.to == [user.email] &&
|
86
|
-
email.subject =~ /password/i &&
|
87
|
-
email.body =~ /#{user.confirmation_token}/
|
88
|
-
end
|
89
|
-
assert result
|
90
|
-
end
|
91
|
-
|
92
|
-
When /^I follow the password reset link sent to "(.*)"$/ do |email|
|
93
|
-
user = User.find_by_email(email)
|
94
|
-
visit edit_user_password_path(:user_id => user,
|
95
|
-
:token => user.confirmation_token)
|
96
|
-
end
|
97
|
-
|
98
|
-
When /^I try to change the password of "(.*)" without token$/ do |email|
|
99
|
-
user = User.find_by_email(email)
|
100
|
-
visit edit_user_password_path(:user_id => user)
|
101
|
-
end
|
102
|
-
|
103
|
-
Then /^I should be forbidden$/ do
|
104
|
-
assert_response :forbidden
|
105
|
-
end
|
106
|
-
|
107
|
-
# Actions
|
108
|
-
|
109
|
-
When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
|
110
|
-
When %{I go to the sign in page}
|
111
|
-
And %{I fill in "Email" with "#{email}"}
|
112
|
-
And %{I fill in "Password" with "#{password}"}
|
113
|
-
And %{I press "Sign in"}
|
114
|
-
end
|
115
|
-
|
116
|
-
When "I sign out" do
|
117
|
-
steps %{
|
118
|
-
When I go to the homepage
|
119
|
-
And I follow "Sign out"
|
120
|
-
}
|
121
|
-
end
|
122
|
-
|
123
|
-
When /^I request password reset link to be sent to "(.*)"$/ do |email|
|
124
|
-
When %{I go to the password reset request page}
|
125
|
-
And %{I fill in "Email address" with "#{email}"}
|
126
|
-
And %{I press "Reset password"}
|
127
|
-
end
|
128
|
-
|
129
|
-
When /^I update my password with "(.*)\/(.*)"$/ do |password, confirmation|
|
130
|
-
And %{I fill in "Choose password" with "#{password}"}
|
131
|
-
And %{I fill in "Confirm password" with "#{confirmation}"}
|
132
|
-
And %{I press "Save this password"}
|
133
|
-
end
|
134
|
-
|
135
|
-
When /^I return next time$/ do
|
136
|
-
When %{session is cleared}
|
137
|
-
And %{I go to the homepage}
|
138
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ConfirmationsControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
tests Clearance::ConfirmationsController
|
6
|
-
|
7
|
-
should filter_param(:token)
|
8
|
-
|
9
|
-
context "a user whose email has not been confirmed" do
|
10
|
-
setup { @user = Factory(:user) }
|
11
|
-
|
12
|
-
should "have a token" do
|
13
|
-
assert_not_nil @user.confirmation_token
|
14
|
-
assert_not_equal "", @user.confirmation_token
|
15
|
-
end
|
16
|
-
|
17
|
-
context "on GET to #new with correct id and token" do
|
18
|
-
setup do
|
19
|
-
get :new, :user_id => @user.to_param,
|
20
|
-
:token => @user.confirmation_token
|
21
|
-
end
|
22
|
-
|
23
|
-
should set_the_flash.to(/confirmed email/i)
|
24
|
-
should set_the_flash.to(/signed in/i)
|
25
|
-
should_redirect_to_url_after_create
|
26
|
-
|
27
|
-
should "set the current user" do
|
28
|
-
assert_equal @user, @controller.current_user
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "with an incorrect token" do
|
33
|
-
setup do
|
34
|
-
@bad_token = "bad token"
|
35
|
-
assert_not_equal @bad_token, @user.confirmation_token
|
36
|
-
end
|
37
|
-
|
38
|
-
should_forbid "on GET to #new with incorrect token" do
|
39
|
-
get :new, :user_id => @user.to_param,
|
40
|
-
:token => @bad_token
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
should_forbid "on GET to #new with blank token" do
|
45
|
-
get :new, :user_id => @user.to_param, :token => ""
|
46
|
-
end
|
47
|
-
|
48
|
-
should_forbid "on GET to #new with no token" do
|
49
|
-
get :new, :user_id => @user.to_param
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "a signed in confirmed user on GET to #new with token" do
|
54
|
-
setup do
|
55
|
-
@user = Factory(:user)
|
56
|
-
@token = @user.confirmation_token
|
57
|
-
@user.confirm_email!
|
58
|
-
sign_in_as @user
|
59
|
-
|
60
|
-
get :new, :user_id => @user.to_param, :token => @token
|
61
|
-
end
|
62
|
-
|
63
|
-
should set_the_flash.to(/confirmed email/i)
|
64
|
-
should_redirect_to_url_after_create
|
65
|
-
end
|
66
|
-
|
67
|
-
context "a bad user" do
|
68
|
-
setup do
|
69
|
-
@user = Factory(:user)
|
70
|
-
@token = @user.confirmation_token
|
71
|
-
@user.confirm_email!
|
72
|
-
|
73
|
-
@bad_user = Factory(:email_confirmed_user)
|
74
|
-
sign_in_as @bad_user
|
75
|
-
end
|
76
|
-
|
77
|
-
should_forbid "on GET to #new with token for another user" do
|
78
|
-
get :new, :user_id => @user.to_param, :token => @token
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "a signed out confirmed user on GET to #new with token" do
|
83
|
-
setup do
|
84
|
-
@user = Factory(:user)
|
85
|
-
@token = @user.confirmation_token
|
86
|
-
@user.confirm_email!
|
87
|
-
get :new, :user_id => @user.to_param, :token => @token
|
88
|
-
end
|
89
|
-
|
90
|
-
should set_the_flash.to(/already confirmed/i)
|
91
|
-
should set_the_flash.to(/sign in/i)
|
92
|
-
should_redirect_to_url_already_confirmed
|
93
|
-
|
94
|
-
should "not be signed in" do
|
95
|
-
assert_nil cookies[:remember_token]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "no users" do
|
100
|
-
setup { assert_equal 0, ::User.count }
|
101
|
-
|
102
|
-
should_forbid "on GET to #new with nonexistent id and token" do
|
103
|
-
get :new, :user_id => '123', :token => '123'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|