hero_generator 0.0.1.alpha5 → 0.0.1.alpha6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/generators/hero/authentication/USAGE +8 -0
- data/lib/generators/hero/authentication/authentication_generator.rb +107 -0
- data/lib/generators/hero/authentication/templates/config/config.yml +22 -0
- data/lib/generators/hero/authentication/templates/config/initializers/action_mailer.rb +60 -0
- data/lib/generators/hero/authentication/templates/config/initializers/load_config.rb +3 -0
- data/lib/generators/hero/authentication/templates/config/locales/en.yml +52 -0
- data/lib/generators/hero/authentication/templates/config/routes.rb +29 -0
- data/lib/generators/hero/authentication/templates/controllers/application_controller.rb +9 -0
- data/lib/generators/hero/authentication/templates/controllers/confirmation_controller.rb +80 -0
- data/lib/generators/hero/authentication/templates/controllers/sessions_controller.rb +24 -0
- data/lib/generators/hero/authentication/templates/controllers/settings_controller.rb +33 -0
- data/lib/generators/hero/authentication/templates/controllers/users_controller.rb +32 -0
- data/lib/generators/hero/authentication/templates/mailers/confirmation_mailer.rb +30 -0
- data/lib/generators/hero/authentication/templates/migrations/20120213162337_create_users.rb +15 -0
- data/lib/generators/hero/authentication/templates/models/authentication.rb +33 -0
- data/lib/generators/hero/authentication/templates/models/user.rb +144 -0
- data/lib/generators/hero/authentication/templates/tests/spec/controllers/sessions_controller_spec.rb +6 -0
- data/lib/generators/hero/authentication/templates/tests/spec/controllers/users_controller_spec.rb +6 -0
- data/lib/generators/hero/authentication/templates/tests/spec/factories.rb +20 -0
- data/lib/generators/hero/authentication/templates/tests/spec/models/user_spec.rb +154 -0
- data/lib/generators/hero/authentication/templates/tests/spec/requests/new_email_request_spec.rb +69 -0
- data/lib/generators/hero/authentication/templates/tests/spec/requests/password_resets_spec.rb +58 -0
- data/lib/generators/hero/authentication/templates/tests/spec/requests/user_confirmation_spec.rb +61 -0
- data/lib/generators/hero/authentication/templates/tests/spec/requests/user_sign_in_spec.rb +13 -0
- data/lib/generators/hero/authentication/templates/tests/spec/requests/user_sign_up_spec.rb +55 -0
- data/lib/generators/hero/authentication/templates/tests/spec/routing/confirmation_mailer_spec.rb +49 -0
- data/lib/generators/hero/authentication/templates/tests/spec/spec_helper.rb +34 -0
- data/lib/generators/hero/authentication/templates/tests/spec/support/mailer_macros.rb +10 -0
- data/lib/generators/hero/authentication/templates/views/confirmation/new_email_token.html.haml +11 -0
- data/lib/generators/hero/authentication/templates/views/confirmation/order_new_password.html.haml +11 -0
- data/lib/generators/hero/authentication/templates/views/confirmation/password_token.html.haml +11 -0
- data/lib/generators/hero/authentication/templates/views/confirmation/recover_password.html.haml +15 -0
- data/lib/generators/hero/authentication/templates/views/confirmation/registration.html.haml +10 -0
- data/lib/generators/hero/authentication/templates/views/confirmation/resend_signup_token.html.haml +13 -0
- data/lib/generators/hero/authentication/templates/views/confirmation/user_email.html.haml +0 -0
- data/lib/generators/hero/authentication/templates/views/confirmation_mailer/new_email_request.text.haml +9 -0
- data/lib/generators/hero/authentication/templates/views/confirmation_mailer/registration.text.haml +11 -0
- data/lib/generators/hero/authentication/templates/views/confirmation_mailer/resend_signup_token.text.haml +11 -0
- data/lib/generators/hero/authentication/templates/views/confirmation_mailer/send_password_reset.text.haml +9 -0
- data/lib/generators/hero/authentication/templates/views/sessions/new.html.haml +16 -0
- data/lib/generators/hero/authentication/templates/views/settings/index.html.haml +28 -0
- data/lib/generators/hero/authentication/templates/views/users/new.html.haml +35 -0
- data/lib/generators/hero/hero.rb +28 -0
- data/lib/hero_generator/engine.rb +6 -0
- data/lib/hero_generator/version.rb +1 -1
- metadata +53 -11
- data/.gitignore +0 -4
- data/hero_generator.gemspec +0 -28
@@ -0,0 +1,144 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
attr_accessible :email, :password, :password_confirmation, :new_email_confirmation, :set_new_email
|
3
|
+
|
4
|
+
attr_accessor :password, :password_confirmation, :update_password, :new_email_confirmation, :set_new_email
|
5
|
+
before_save :encrypt_password
|
6
|
+
|
7
|
+
validates_format_of :email, :with => /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i
|
8
|
+
validates_presence_of :email
|
9
|
+
validates_uniqueness_of :email, :unless => :confirmed_duplicate
|
10
|
+
|
11
|
+
validates_presence_of :password, :if => :should_validate_password?
|
12
|
+
validates_length_of :password, :if => :should_validate_password?,
|
13
|
+
:within => 3..30,
|
14
|
+
:too_short => 'too short message',
|
15
|
+
:too_long => 'too long message'
|
16
|
+
|
17
|
+
validates_confirmation_of :password, :if => :should_validate_password?
|
18
|
+
|
19
|
+
#set new email
|
20
|
+
validates_presence_of :new_email, :if => :should_validate_new_email?
|
21
|
+
validates_format_of :new_email, :with => /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i,
|
22
|
+
:if => :should_validate_new_email?
|
23
|
+
|
24
|
+
validates_presence_of :new_email_confirmation, :if => :should_validate_new_email?
|
25
|
+
validates_confirmation_of :new_email, :if => :should_validate_new_email?
|
26
|
+
|
27
|
+
|
28
|
+
def new_email=(new_email)
|
29
|
+
self[:new_email] = new_email if self.set_new_email.present?
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def confirm_signup!
|
34
|
+
update_attribute(:confirmed, Time.now)
|
35
|
+
update_attribute(:signup_token, nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
def confirm_password!(password)
|
39
|
+
update_attribute(:password, password)
|
40
|
+
update_attribute(:password_token, nil)
|
41
|
+
end
|
42
|
+
|
43
|
+
def confirm_new_email!
|
44
|
+
update_attribute(:email, new_email)
|
45
|
+
update_attribute(:new_email_token, nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
def confirmed?
|
49
|
+
!self.confirmed.nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.confirmed
|
53
|
+
where("confirmed IS NOT NULL")
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.with_email(email)
|
57
|
+
where(:email => email)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Wenn der User sich registriert, dann wird ein signup_token für ihn hinterlegt.
|
61
|
+
# Dieser Token wird per Mail verschickt. Der User kann sich nun per Klick auf den
|
62
|
+
# Tokenlink verifizieren. Sollte die Mail nicht mehr erreichbar sein, so kann der User
|
63
|
+
# unter Angabe seiner Email einen neuen signup_Token anfordern. Der alte Token ist
|
64
|
+
# ab diesem Zeitpunkt ungültig.
|
65
|
+
|
66
|
+
# Nach erfolgreicher Verifizierung der Email-Adresse) wird das
|
67
|
+
# Feld confirmed mit einem Datum gefüllt. Ab diesem Zeitpunkt kann keine neuer
|
68
|
+
# Confirmation-Token generiert und verschickt werden.
|
69
|
+
|
70
|
+
def confirmed_duplicate
|
71
|
+
if ((User.confirmed.with_email(self.email).count == 0) || (User.with_email(self.email).count == 0))
|
72
|
+
true
|
73
|
+
else
|
74
|
+
self.id = User.confirmed.with_email(self.email).first.id
|
75
|
+
false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def should_validate_new_email?
|
80
|
+
set_new_email.present?
|
81
|
+
end
|
82
|
+
|
83
|
+
def should_validate_password?
|
84
|
+
update_password || new_record?
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.authenticate(email, password)
|
88
|
+
user = find_by_email(email)
|
89
|
+
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
|
90
|
+
user
|
91
|
+
else
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def encrypt_password
|
97
|
+
if password.present?
|
98
|
+
self.password_salt = BCrypt::Engine.generate_salt
|
99
|
+
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def send_password_reset
|
105
|
+
if generate_token(:password_token)
|
106
|
+
ConfirmationMailer.send_password_reset( self ).deliver
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def send_registration
|
111
|
+
if generate_token(:signup_token)
|
112
|
+
ConfirmationMailer.registration( self ).deliver
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def resend_signup_token
|
117
|
+
if !confirmed? && generate_token(:signup_token)
|
118
|
+
ConfirmationMailer.resend_signup_token( self ).deliver
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def send_new_email_request
|
123
|
+
if generate_token(:new_email_token)
|
124
|
+
ConfirmationMailer.new_email_request( self ).deliver
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def send_new_email( new_email )
|
129
|
+
if self.set_new_email.present?
|
130
|
+
if self.save
|
131
|
+
send_new_email_request
|
132
|
+
self.set_new_email = false
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def generate_token( token )
|
140
|
+
(defined?( token ) && update_attribute( token, SecureRandom.hex(13) ))? true : false
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#Factory.define :propertyname do |f|
|
2
|
+
# f.p0 "eins"
|
3
|
+
# f.p1 ""
|
4
|
+
# f.p2 ""
|
5
|
+
# f.p3 ""
|
6
|
+
#end
|
7
|
+
|
8
|
+
|
9
|
+
Factory.define :user do |u|
|
10
|
+
|
11
|
+
u.email { Factory.next(:email) }
|
12
|
+
u.password 'secret'
|
13
|
+
#u.password_confirmation 'secret'
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
Factory.sequence :email do |n|
|
18
|
+
names = %w[ joe bob sue ]
|
19
|
+
"#{names[rand names.count]}#{n}@somewhere.com"
|
20
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@user = Factory.build(:user)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have an email field" do
|
10
|
+
@user.should respond_to(:email)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be valid when created by factory" do
|
14
|
+
@user.should be_valid
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be invalid without email" do
|
18
|
+
@user.email = nil
|
19
|
+
@user.should_not be_valid
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be invalid without password" do
|
23
|
+
@user.password = nil
|
24
|
+
@user.should_not be_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should only accept real emails" do
|
28
|
+
@user.email = nil
|
29
|
+
|
30
|
+
[ 'foo', 'foo.org', 'foo@.org', 'foo@', 'foo@@bar.org', '@bar.org' ].each do |email|
|
31
|
+
@user.email = email
|
32
|
+
@user.should_not be_valid
|
33
|
+
end
|
34
|
+
|
35
|
+
@user.email = 'foo@bar.org'
|
36
|
+
@user.should be_valid
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
it "email address should only exist once" do
|
41
|
+
same_email = 'foo@bar.org'
|
42
|
+
|
43
|
+
@user.email = same_email
|
44
|
+
@user.confirmed = Time.now
|
45
|
+
@user.save
|
46
|
+
|
47
|
+
@other_user = Factory.build( :user, :email => same_email )
|
48
|
+
@other_user.should_not be_valid
|
49
|
+
|
50
|
+
@other_user.email = 'foo@otherbar.org'
|
51
|
+
@other_user.should be_valid
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'saves same passwords with different salts' do
|
55
|
+
same_password = 'secret'
|
56
|
+
@user.password = same_password
|
57
|
+
@user.save
|
58
|
+
|
59
|
+
@other_user = Factory.build( :user, :password => same_password )
|
60
|
+
@other_user.save
|
61
|
+
|
62
|
+
@user.password_hash.should_not == @other_user.password_hash
|
63
|
+
@user.password_salt.should_not == @other_user.password_salt
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should authenticate valid user' do
|
67
|
+
@user.save
|
68
|
+
@user.should == User.authenticate( @user.email, @user.password )
|
69
|
+
|
70
|
+
User.authenticate( '', @user.password ).should == nil
|
71
|
+
User.authenticate( @user.email, '' ).should == nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should be confirmable' do
|
75
|
+
@user.should respond_to( :confirm_signup! )
|
76
|
+
@user.should respond_to( :confirmed? )
|
77
|
+
|
78
|
+
@user.confirmed?.should be false
|
79
|
+
@user.confirm_signup!
|
80
|
+
@user.confirmed?.should be true
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'has confirmation token' do
|
84
|
+
@user.save
|
85
|
+
@user.send_registration
|
86
|
+
@user.signup_token.should match /^[\da-z]{26}$/
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#send_password_reset" do
|
90
|
+
let(:user) { Factory(:user) }
|
91
|
+
|
92
|
+
it "generate a unique password_token each time" do
|
93
|
+
user.send_password_reset
|
94
|
+
last_token = user.password_token
|
95
|
+
user.send_password_reset
|
96
|
+
user.password_token.should_not eq(last_token)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "delivers email to user" do
|
100
|
+
user.send_password_reset
|
101
|
+
last_email.to.should include(user.email)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#send_password_reset" do
|
106
|
+
|
107
|
+
it "should not set false emails" do
|
108
|
+
@user.email = "hallo@mail.de"
|
109
|
+
@user.set_new_email = true
|
110
|
+
[ 'foo', 'foo.org', 'foo@.org', 'foo@', 'foo@@bar.org', '@bar.org' ].each do |email|
|
111
|
+
@user.new_email = email
|
112
|
+
@user.new_email_confirmation = email
|
113
|
+
@user.should_not be_valid
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should set true emails" do
|
118
|
+
@user.set_new_email = true
|
119
|
+
@user.new_email = 'foo@bar.org'
|
120
|
+
@user.new_email_confirmation = 'foo@bar.org'
|
121
|
+
@user.should be_valid
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should not set new emails without confirmation" do
|
125
|
+
@user.set_new_email = true
|
126
|
+
@user.new_email = 'foo@bar.org'
|
127
|
+
@user.new_email_confirmation = nil
|
128
|
+
@user.should_not be_valid
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should not set new emails with false confirmation" do
|
132
|
+
@user.set_new_email = true
|
133
|
+
@user.new_email = 'foo@bar.org'
|
134
|
+
@user.new_email_confirmation = 'ups@bar.org'
|
135
|
+
@user.should_not be_valid
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not set new emails without set_new_email flag" do
|
139
|
+
@user.set_new_email = nil
|
140
|
+
@user.new_email = 'foo@bar.org'
|
141
|
+
@user.new_email_confirmation = 'foo@bar.org'
|
142
|
+
@user.should be_valid
|
143
|
+
@user.save
|
144
|
+
@user2 = User.find(@user.id)
|
145
|
+
@user2.new_email.should be_blank
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should not set new_email to a confirmed email address" do
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
data/lib/generators/hero/authentication/templates/tests/spec/requests/new_email_request_spec.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "send new email" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@user = Factory(:user, :confirmed => Time.now)
|
7
|
+
visit log_in_path
|
8
|
+
fill_in "email", :with => @user.email
|
9
|
+
fill_in "password", :with => @user.password
|
10
|
+
click_button "log_in_button"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "GET index" do
|
14
|
+
it "send new email request" do
|
15
|
+
visit "/settings/index"
|
16
|
+
new_email = "neue@example.com"
|
17
|
+
fill_in "user_new_email", :with => new_email
|
18
|
+
fill_in "user_new_email_confirmation", :with => new_email
|
19
|
+
fill_in "user_password", :with => @user.password
|
20
|
+
click_button "change_email_button"
|
21
|
+
@user = User.find(@user.id)
|
22
|
+
@user.new_email.should eq(new_email)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
it "set new email with link" do
|
28
|
+
@user.set_new_email = true
|
29
|
+
@user.new_email = "new@email.de"
|
30
|
+
@user.new_email_confirmation = "new@email.de"
|
31
|
+
@user.send_new_email_request
|
32
|
+
@user.save
|
33
|
+
|
34
|
+
visit new_email_path(:token => @user.new_email_token)
|
35
|
+
|
36
|
+
@user = User.find @user.id
|
37
|
+
@user.email.should eq(@user.new_email)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "shows form if token is invalid" do
|
41
|
+
@user.set_new_email = true
|
42
|
+
@user.new_email = "new@email.de"
|
43
|
+
@user.new_email_confirmation = "new@email.de"
|
44
|
+
@user.send_new_email_request
|
45
|
+
@user.save
|
46
|
+
|
47
|
+
visit new_email_path(:token => "wrong token here")
|
48
|
+
click_button "new_email_token_button"
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
it "set new email with password token form" do
|
53
|
+
@user.set_new_email = true
|
54
|
+
@user.new_email = "new@email.de"
|
55
|
+
@user.new_email_confirmation = "new@email.de"
|
56
|
+
@user.send_new_email_request
|
57
|
+
@user.save
|
58
|
+
|
59
|
+
visit new_email_path
|
60
|
+
fill_in "token", :with => @user.new_email_token
|
61
|
+
click_button "new_email_token_button"
|
62
|
+
|
63
|
+
@user = User.find @user.id
|
64
|
+
@user.email.should eq(@user.new_email)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "PasswordResets" do
|
4
|
+
it "emails user when requesting password reset" do
|
5
|
+
user = Factory(:user)
|
6
|
+
visit log_in_path
|
7
|
+
click_link "password_forgotten_link"
|
8
|
+
fill_in "email", :with => user.email
|
9
|
+
click_button "send_new_password_button"
|
10
|
+
current_path.should eq root_path
|
11
|
+
page.should have_content( I18n.t( "fe.confirmation.order_new_password.flash.success" ))
|
12
|
+
last_email.to.should include(user.email)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not email invalid user when requesting password reset" do
|
16
|
+
visit log_in_path
|
17
|
+
click_link "password_forgotten_link"
|
18
|
+
fill_in "email", :with => "diese.mail@gibt.es.nicht.de"
|
19
|
+
click_button "send_new_password_button"
|
20
|
+
current_path.should eq root_path
|
21
|
+
last_email.should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "password recovery with password token form" do
|
25
|
+
user = Factory(:user, :password_token => "ein_kleiner_token")
|
26
|
+
visit recover_password_auth_path
|
27
|
+
fill_in "token", :with => user.password_token
|
28
|
+
click_button "password_token_button"
|
29
|
+
current_path.should eq recover_password_path
|
30
|
+
end
|
31
|
+
|
32
|
+
it "password recovery without valid token leads to token_form" do
|
33
|
+
params = { :token => 'den_token_gibt_es_nicht' }
|
34
|
+
visit recover_password_path
|
35
|
+
current_path.should eq recover_password_auth_path
|
36
|
+
end
|
37
|
+
|
38
|
+
it "password recovery with valid token leads password recover form and user sets new pw" do
|
39
|
+
user = Factory(:user, :password_token => "12345", :confirmed => Time.now)
|
40
|
+
visit recover_password_path(:token => "12345")
|
41
|
+
current_path.should eq recover_password_path(:token => "12345")
|
42
|
+
fill_in "recover_password", :with => "geheim"
|
43
|
+
fill_in "recover_password_confirmation", :with => "geheim"
|
44
|
+
click_button "recover_password_button"
|
45
|
+
current_path.should eq log_in_path
|
46
|
+
|
47
|
+
## and logs in with new password
|
48
|
+
fill_in "email", :with => user.email
|
49
|
+
fill_in "password", :with => "geheim"
|
50
|
+
click_button "log_in_button"
|
51
|
+
current_path.should eq root_path
|
52
|
+
page.should have_content( I18n.t( "fe.session.create.flash.success" ))
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
data/lib/generators/hero/authentication/templates/tests/spec/requests/user_confirmation_spec.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "UserConfirmation" do
|
4
|
+
it "emails user to confirm his sign up" do
|
5
|
+
visit sign_up_form_path
|
6
|
+
fill_in "user_email", :with => "test@test.de"
|
7
|
+
fill_in "user_password", :with => "geheim"
|
8
|
+
fill_in "user_password_confirmation", :with => "geheim"
|
9
|
+
click_button "sign_up_button"
|
10
|
+
current_path.should eq root_path
|
11
|
+
page.should have_content( I18n.t( "fe.user.create.flash.success" ))
|
12
|
+
last_email.to.should include("test@test.de")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "user uses confirmation token form and is confirmed" do
|
16
|
+
user = Factory(:user, :signup_token => "halloklaus")
|
17
|
+
visit confirm_path(:action => :registration)
|
18
|
+
fill_in "token", :with => user.signup_token
|
19
|
+
click_button "token_button"
|
20
|
+
current_path.should eq log_in_path
|
21
|
+
page.should have_content( I18n.t( "fe.confirmation.registration.flash.success" ))
|
22
|
+
end
|
23
|
+
|
24
|
+
it "user not confirmed with false confirmation token" do
|
25
|
+
user = Factory(:user, :signup_token => "halloklaus")
|
26
|
+
visit confirm_path(:action => :registration)
|
27
|
+
fill_in "token", :with => "ein_anderer_token"
|
28
|
+
click_button "token_button"
|
29
|
+
current_path.should eq confirm_path(:action => :registration)
|
30
|
+
page.should have_content( I18n.t( "fe.confirmation.registration.flash.error" ))
|
31
|
+
end
|
32
|
+
|
33
|
+
it "user asks for new confirmation token" do
|
34
|
+
user = Factory(:user, :signup_token => "halloklaus2")
|
35
|
+
visit confirm_path(:action => :registration)
|
36
|
+
click_link "resend_signup_token"
|
37
|
+
current_path.should eq confirm_path(:action => "resend_confirmation")
|
38
|
+
fill_in "email", :with => user.email
|
39
|
+
fill_in "password", :with => user.password
|
40
|
+
click_button "resend_signup_token_button"
|
41
|
+
user = User.find(user.id)
|
42
|
+
last_email.to.should include(user.email)
|
43
|
+
page.should have_content( I18n.t( "fe.confirmation.resend_signup_token.flash.success" ))
|
44
|
+
user.signup_token.should_not eq "halloklaus2"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "confirmed user cannot request new confirmation token" do
|
48
|
+
user = Factory(:user, :signup_token => "halloklaus", :confirmed => Time.now)
|
49
|
+
visit confirm_path(:action => :registration)
|
50
|
+
click_link "resend_signup_token"
|
51
|
+
current_path.should eq confirm_path(:action => "resend_confirmation")
|
52
|
+
fill_in "email", :with => user.email
|
53
|
+
fill_in "password", :with => user.password
|
54
|
+
click_button "resend_signup_token_button"
|
55
|
+
last_email.should eq nil
|
56
|
+
current_path.should eq log_in_path
|
57
|
+
page.should have_content( I18n.t( "fe.confirmation.resend_signup_token.flash.error" ))
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "UserSignIn" do
|
4
|
+
it "Signed up user cannot login if not confirmed" do
|
5
|
+
user = Factory(:user, :confirmed => nil)
|
6
|
+
visit log_in_path
|
7
|
+
fill_in "email", :with => user.email
|
8
|
+
fill_in "password", :with => user.password
|
9
|
+
click_button "log_in_button"
|
10
|
+
page.should have_content( I18n.t( "fe.session.create.flash.error.not_confirmed" ))
|
11
|
+
current_path.should eq confirm_path(:action => :registration)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "UserSignUp" do
|
4
|
+
|
5
|
+
it "User can sign up" do
|
6
|
+
visit sign_up_form_path
|
7
|
+
fill_in "user_email", :with => "hallo@test.de"
|
8
|
+
fill_in "user_password", :with => "geheim"
|
9
|
+
fill_in "user_password_confirmation", :with => "geheim"
|
10
|
+
click_button "sign_up_button"
|
11
|
+
page.should have_content( I18n.t( "fe.user.create.flash.success" ))
|
12
|
+
current_path.should eq root_path
|
13
|
+
end
|
14
|
+
|
15
|
+
[
|
16
|
+
{:email => "test@test.de", :password => "", :password_confirmation => ""},
|
17
|
+
{:email => "test@test.de", :password => "geheim", :password_confirmation => ""},
|
18
|
+
{:email => "test@test.de", :password => "geheim", :password_confirmation => "gehei_"},
|
19
|
+
{:email => "test@test.de", :password => "", :password_confirmation => "geheim"},
|
20
|
+
{:email => "test@test", :password => "geheim", :password_confirmation => "geheim"},
|
21
|
+
{:email => "testtest.de", :password => "geheim", :password_confirmation => "geheim"}
|
22
|
+
].each do |u|
|
23
|
+
it "User cannot sign up with wrong parameters" do
|
24
|
+
visit sign_up_form_path
|
25
|
+
fill_in "user_email", :with => u[:email]
|
26
|
+
fill_in "user_password", :with => u[:password]
|
27
|
+
fill_in "user_password_confirmation", :with => u[:password_confirmation]
|
28
|
+
click_button "sign_up_button"
|
29
|
+
page.should have_content( I18n.t( "fe.user.create.flash.error" ))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
it "User can sign up with used email-address unless confirmed" do
|
35
|
+
user = Factory(:user)
|
36
|
+
visit sign_up_form_path
|
37
|
+
fill_in "user_email", :with => user.email
|
38
|
+
fill_in "user_password", :with => "geheim"
|
39
|
+
fill_in "user_password_confirmation", :with => "geheim"
|
40
|
+
click_button "sign_up_button"
|
41
|
+
page.should have_content( I18n.t( "fe.user.create.flash.success" ))
|
42
|
+
end
|
43
|
+
|
44
|
+
it "User cannot sign up with used email-address if confirmed" do
|
45
|
+
user = Factory(:user)
|
46
|
+
user.confirm_signup!
|
47
|
+
visit sign_up_form_path
|
48
|
+
fill_in "user_email", :with => user.email
|
49
|
+
fill_in "user_password", :with => "geheim"
|
50
|
+
fill_in "user_password_confirmation", :with => "geheim"
|
51
|
+
click_button "sign_up_button"
|
52
|
+
page.should have_content( I18n.t( "fe.user.create.flash.error" ))
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/generators/hero/authentication/templates/tests/spec/routing/confirmation_mailer_spec.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConfirmationMailer do
|
4
|
+
|
5
|
+
describe "#password_reset" do
|
6
|
+
let(:user) { Factory(:user, :password_token => "irgendwas") }
|
7
|
+
let(:mail) { ConfirmationMailer.send_password_reset(user) }
|
8
|
+
|
9
|
+
it "send user password reset url" do
|
10
|
+
mail.subject.should eq( I18n.t( 'confirmation_mailer.send_password_reset.subject' ))
|
11
|
+
mail.to.should eq([user.email])
|
12
|
+
mail.body.encoded.should match(recover_password_url(user.password_token))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#registration" do
|
17
|
+
let(:user) { Factory(:user, :signup_token => "irgendwas") }
|
18
|
+
let(:mail) { ConfirmationMailer.registration(user) }
|
19
|
+
|
20
|
+
it "send user confirmation url" do
|
21
|
+
mail.subject.should eq( I18n.t( 'confirmation_mailer.registration.subject' ))
|
22
|
+
mail.to.should eq([user.email])
|
23
|
+
mail.body.encoded.should match(confirm_url(user.signup_token))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#new_user_email" do
|
28
|
+
let(:user) { Factory(:user, :set_new_email => true, :new_email => "new@email.de", :new_email_confirmation => "new@email.de" , :new_email_token => "irgendwas") }
|
29
|
+
let(:mail) { ConfirmationMailer.new_email_request(user) }
|
30
|
+
|
31
|
+
it "send user new email confirmation url" do
|
32
|
+
mail.subject.should eq( I18n.t( 'confirmation_mailer.new_email_request.subject' ))
|
33
|
+
mail.to.should eq([user.new_email])
|
34
|
+
mail.body.encoded.should match( new_email_url(user.new_email_token ))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#resend_signup_token" do
|
39
|
+
let(:user) { Factory(:user, :signup_token => "irgendwas") }
|
40
|
+
let(:mail) { ConfirmationMailer.resend_signup_token(user) }
|
41
|
+
|
42
|
+
it "send user new confirmation url" do
|
43
|
+
mail.subject.should eq( I18n.t( 'confirmation_mailer.resend_signup_token.subject' ))
|
44
|
+
mail.to.should eq([user.email])
|
45
|
+
mail.body.encoded.should match(confirm_url( :registration, user.signup_token ))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require File.expand_path("../../config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'capybara/rspec'
|
6
|
+
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
8
|
+
# in spec/support/ and its subdirectories.
|
9
|
+
|
10
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
11
|
+
|
12
|
+
ConfirmationMailer.default_url_options = { :host => 'localhost:3000' }
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.mock_with :rspec
|
16
|
+
config.use_transactional_fixtures = false
|
17
|
+
config.include(MailerMacros)
|
18
|
+
config.before(:each) { reset_email }
|
19
|
+
|
20
|
+
config.before(:suite) do
|
21
|
+
DatabaseCleaner.strategy = :transaction
|
22
|
+
DatabaseCleaner.clean_with(:truncation)
|
23
|
+
end
|
24
|
+
|
25
|
+
config.before(:each) do
|
26
|
+
DatabaseCleaner.start
|
27
|
+
end
|
28
|
+
|
29
|
+
config.after(:each) do
|
30
|
+
DatabaseCleaner.clean
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|