adva_user 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README +114 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/adva_user.gemspec +17 -0
- data/app/controllers/admin/base_account_controller.rb +13 -0
- data/app/controllers/admin/users_controller.rb +95 -0
- data/app/controllers/password_controller.rb +36 -0
- data/app/controllers/session_controller.rb +30 -0
- data/app/helpers/users_helper.rb +27 -0
- data/app/models/account.rb +7 -0
- data/app/models/membership.rb +16 -0
- data/app/models/password_mailer.rb +43 -0
- data/app/models/user.rb +106 -0
- data/app/views/admin/users/_form.html.erb +29 -0
- data/app/views/admin/users/_sidebar.html.erb +8 -0
- data/app/views/admin/users/edit.html.erb +7 -0
- data/app/views/admin/users/index.html.erb +13 -0
- data/app/views/admin/users/new.html.erb +5 -0
- data/app/views/admin/users/show.html.erb +27 -0
- data/app/views/layouts/login.html.erb +24 -0
- data/app/views/password/edit.html.erb +14 -0
- data/app/views/password/new.html.erb +13 -0
- data/app/views/password_mailer/reset_password_email.html.erb +3 -0
- data/app/views/password_mailer/updated_password_email.html.erb +1 -0
- data/app/views/session/new.html.erb +17 -0
- data/config/initializers/menus.rb +25 -0
- data/config/routes.rb +14 -0
- data/db/migrate/20080402000001_create_users_table.rb +33 -0
- data/db/migrate/20080402000005_create_memberships_table.rb +13 -0
- data/db/migrate/20090625124502_create_accounts.rb +13 -0
- data/db/migrate/20090625133231_add_account_to_user.rb +10 -0
- data/lib/action_controller/authenticate_anonymous.rb +70 -0
- data/lib/action_controller/authenticate_user.rb +201 -0
- data/lib/active_record/belongs_to_author.rb +37 -0
- data/lib/adva_user.rb +28 -0
- data/lib/adva_user/version.rb +3 -0
- data/lib/login/helper_integration.rb +11 -0
- data/lib/login/mail_config.rb +39 -0
- data/test/contexts.rb +42 -0
- data/test/fixtures.rb +18 -0
- data/test/functional/admin/users_controller_test.rb +176 -0
- data/test/functional/password_controller_test.rb +96 -0
- data/test/functional/session_controller_test.rb +1 -0
- data/test/functional/user_controller_test.rb +95 -0
- data/test/integration/anonymous_login_test.rb +39 -0
- data/test/integration/edit_user_test.rb +44 -0
- data/test/integration/memberships_test.rb +52 -0
- data/test/integration/user_deletion_test.rb +27 -0
- data/test/integration/user_login_test.rb +53 -0
- data/test/integration/user_login_with_remember_me_test.rb +20 -0
- data/test/integration/user_registration_test.rb +64 -0
- data/test/test_helper.rb +1 -0
- data/test/unit/cells/user_cell_test.rb +13 -0
- data/test/unit/helpers/users_helper_test.rb +52 -0
- data/test/unit/models/account_test.rb +21 -0
- data/test/unit/models/anonymous_test.rb +54 -0
- data/test/unit/models/password_mailer_test.rb +26 -0
- data/test/unit/models/user_mailer_test.rb +16 -0
- data/test/unit/models/user_test.rb +173 -0
- data/vendor/gems/authentication/.gitignore +17 -0
- data/vendor/gems/authentication/Gemfile +4 -0
- data/vendor/gems/authentication/LICENSE +22 -0
- data/vendor/gems/authentication/MIT-LICENSE +38 -0
- data/vendor/gems/authentication/README +39 -0
- data/vendor/gems/authentication/README.md +29 -0
- data/vendor/gems/authentication/RUNNING_UNIT_TESTS +13 -0
- data/vendor/gems/authentication/Rakefile +61 -0
- data/vendor/gems/authentication/authentication.gemspec +17 -0
- data/vendor/gems/authentication/lib/authentication.rb +270 -0
- data/vendor/gems/authentication/lib/authentication/active_record_extensions.rb +11 -0
- data/vendor/gems/authentication/lib/authentication/bogus.rb +13 -0
- data/vendor/gems/authentication/lib/authentication/hash_helper.rb +26 -0
- data/vendor/gems/authentication/lib/authentication/ldap.rb +49 -0
- data/vendor/gems/authentication/lib/authentication/remember_me.rb +52 -0
- data/vendor/gems/authentication/lib/authentication/salted_hash.rb +53 -0
- data/vendor/gems/authentication/lib/authentication/single_token.rb +53 -0
- data/vendor/gems/authentication/lib/authentication/version.rb +3 -0
- data/vendor/gems/authentication/lib/radius/dictionary +207 -0
- data/vendor/gems/authentication/test_backup/abstract_unit.rb +30 -0
- data/vendor/gems/authentication/test_backup/active_record_extension_test.rb +17 -0
- data/vendor/gems/authentication/test_backup/authentication_test.rb +231 -0
- data/vendor/gems/authentication/test_backup/database.yml +12 -0
- data/vendor/gems/authentication/test_backup/fixtures/user.rb +3 -0
- data/vendor/gems/authentication/test_backup/fixtures/users.yml +3 -0
- data/vendor/gems/authentication/test_backup/options_test.rb +100 -0
- data/vendor/gems/authentication/test_backup/remember_me_test.rb +41 -0
- data/vendor/gems/authentication/test_backup/salted_hash_test.rb +38 -0
- data/vendor/gems/authentication/test_backup/schema.rb +10 -0
- data/vendor/gems/authentication/test_backup/single_token_test.rb +44 -0
- data/vendor/gems/authentication/test_backup/test_helper.rb +8 -0
- metadata +157 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
|
2
|
+
|
|
3
|
+
module IntegrationTests
|
|
4
|
+
class MembershipsTest < ActionController::IntegrationTest
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
@site = use_site! 'site with pages'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "when superuser creates a new user on the backend,
|
|
11
|
+
the new user should have a membership to the page it was created on (fix for bug #288)" do
|
|
12
|
+
login_as_superuser
|
|
13
|
+
visit_new_user_form
|
|
14
|
+
post_the_new_user_form
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "when superuser creates a new superuser on the backend the new superuser does not need to
|
|
18
|
+
be member of any site" do
|
|
19
|
+
login_as_superuser
|
|
20
|
+
visit_new_user_form
|
|
21
|
+
post_the_new_user_form_for_superuser
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def visit_new_user_form
|
|
25
|
+
visit "/admin/sites/#{@site.id}/users/new"
|
|
26
|
+
renders_template "admin/users/new"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def post_the_new_user_form
|
|
30
|
+
fill_in :user_first_name, :with => 'John'
|
|
31
|
+
fill_in :user_last_name, :with => 'Doe'
|
|
32
|
+
fill_in :user_email, :with => 'memberships@test.org'
|
|
33
|
+
fill_in :user_password, :with => 'pass'
|
|
34
|
+
click_button :save
|
|
35
|
+
|
|
36
|
+
user = User.find_by_email('memberships@test.org')
|
|
37
|
+
assert !user.memberships.blank?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def post_the_new_user_form_for_superuser
|
|
41
|
+
fill_in :user_first_name, :with => 'John'
|
|
42
|
+
fill_in :user_last_name, :with => 'Superuser'
|
|
43
|
+
fill_in :user_email, :with => 'superusers.memberships@test.org'
|
|
44
|
+
fill_in :user_password, :with => 'pass'
|
|
45
|
+
check :role_superuser
|
|
46
|
+
click_button :save
|
|
47
|
+
|
|
48
|
+
user = User.find_by_email('superusers.memberships@test.org')
|
|
49
|
+
assert user.memberships.empty?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
|
2
|
+
|
|
3
|
+
module IntegrationTests
|
|
4
|
+
class UserDeletionTest < ActionController::IntegrationTest
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
@site = use_site! 'site with pages'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "A user deletes his account" do
|
|
11
|
+
# user logs in to the site
|
|
12
|
+
user = login_as_user
|
|
13
|
+
|
|
14
|
+
# TODO
|
|
15
|
+
# there's no user profile page so far
|
|
16
|
+
# visit user_path
|
|
17
|
+
# click_link 'Edit'
|
|
18
|
+
# click_link 'Delete'
|
|
19
|
+
|
|
20
|
+
# user deletes the own profile
|
|
21
|
+
delete user_path
|
|
22
|
+
|
|
23
|
+
# user should not be there anymore
|
|
24
|
+
lambda { User.find(user.id) }.should raise_error(ActiveRecord::RecordNotFound)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
|
2
|
+
|
|
3
|
+
module IntegrationTests
|
|
4
|
+
class UserLoginTest < ActionController::IntegrationTest
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
@site = use_site! 'site with pages'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "A verified user logs in with valid credentials" do
|
|
11
|
+
visit '/login'
|
|
12
|
+
|
|
13
|
+
fill_in 'user_email', :with => 'a-user@example.com'
|
|
14
|
+
fill_in 'user_password', :with => 'a password'
|
|
15
|
+
click_button 'login'
|
|
16
|
+
|
|
17
|
+
controller.current_user.should_not be_nil
|
|
18
|
+
controller.current_user.email.should == 'a-user@example.com'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "A verified user logs in with invalid credentials" do
|
|
22
|
+
visit '/login'
|
|
23
|
+
fill_in 'user_email', :with => 'a-user@example.com'
|
|
24
|
+
fill_in 'user_password', :with => 'a wrong password'
|
|
25
|
+
click_button 'login'
|
|
26
|
+
|
|
27
|
+
controller.current_user.should be_nil
|
|
28
|
+
renders_template 'session/new'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
test "An unverified user logs in with valid credentials" do
|
|
32
|
+
visit '/login'
|
|
33
|
+
fill_in 'user_email', :with => 'an-unverified-user@example.com'
|
|
34
|
+
fill_in 'user_password', :with => 'a password'
|
|
35
|
+
click_button 'login'
|
|
36
|
+
|
|
37
|
+
# FIXME we don't provide any more specific feedback?
|
|
38
|
+
controller.current_user.should be_nil
|
|
39
|
+
renders_template 'session/new'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test "An unverified user logs in with invalid credentials" do
|
|
43
|
+
visit '/login'
|
|
44
|
+
fill_in 'user_email', :with => 'an-unverified-user@example.com'
|
|
45
|
+
fill_in 'user_password', :with => 'a wrong password'
|
|
46
|
+
click_button 'login'
|
|
47
|
+
|
|
48
|
+
# FIXME we don't provide any more specific feedback?
|
|
49
|
+
controller.current_user.should be_nil
|
|
50
|
+
renders_template 'session/new'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
|
2
|
+
|
|
3
|
+
module IntegrationTests
|
|
4
|
+
class UserLoginWithRememberMeTest < ActionController::IntegrationTest
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
@site = use_site! 'site with pages'
|
|
8
|
+
@user = User.find_by_email('a-superuser@example.com')
|
|
9
|
+
token = @user.assign_token!('remember me')
|
|
10
|
+
cookies[:remember_me] = Rack::Utils.escape("#{@user.id};#{token}")
|
|
11
|
+
cookies[:uid] = @user.id.to_s
|
|
12
|
+
cookies[:uname] = @user.name
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test "User with remember me cookie does not need to login again" do
|
|
16
|
+
visit '/admin'
|
|
17
|
+
assert_template 'admin/sites/show'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
|
2
|
+
|
|
3
|
+
module IntegrationTests
|
|
4
|
+
class UserRegistrationTest < ActionController::IntegrationTest
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
@site = use_site! 'site with pages'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "User clicks through section frontend section index pages" do
|
|
11
|
+
registers_to_site_membership
|
|
12
|
+
verify_the_email_adress
|
|
13
|
+
check_logged_in
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def registers_to_site_membership
|
|
17
|
+
visit "/user/new"
|
|
18
|
+
renders_template "user/new"
|
|
19
|
+
|
|
20
|
+
fill_in "user_first_name", :with => 'John'
|
|
21
|
+
fill_in "user_email", :with => 'john-doe@test.com'
|
|
22
|
+
fill_in "user_password", :with => 'password'
|
|
23
|
+
click_button "register"
|
|
24
|
+
|
|
25
|
+
renders_template "user/verification_sent"
|
|
26
|
+
|
|
27
|
+
# user record should exist but not be verified
|
|
28
|
+
john_doe.should_not be_nil
|
|
29
|
+
john_doe.verified?.should be_false
|
|
30
|
+
|
|
31
|
+
# should have sent an email notification
|
|
32
|
+
verification_email.to.should include(john_doe.email)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def verify_the_email_adress
|
|
36
|
+
# extract the verification url from the email
|
|
37
|
+
# http://www.example.com/user/verify?token=1%3Bbd69ea84ed49b61623da2c4d74de2936eb0b0229
|
|
38
|
+
verification_email.body =~ /^(http:.*)$/
|
|
39
|
+
visit $1
|
|
40
|
+
|
|
41
|
+
john_doe.reload.verified?.should be_true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def check_logged_in
|
|
45
|
+
controller.current_user.should == john_doe
|
|
46
|
+
|
|
47
|
+
session[:uid].should == john_doe.id
|
|
48
|
+
cookies['uid'].should == john_doe.id.to_s
|
|
49
|
+
cookies['uname'].should == CGI.escape(john_doe.name)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def john_doe
|
|
54
|
+
@john_doe ||= User.find_by_email('john-doe@test.com')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def verification_email
|
|
58
|
+
@verification_email ||= begin
|
|
59
|
+
ActionMailer::Base.deliveries.should_not be_empty
|
|
60
|
+
ActionMailer::Base.deliveries.last
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../adva_cms/test/test_helper')
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# FIXME Commented out test! Convert!
|
|
2
|
+
#
|
|
3
|
+
# require File.dirname(__FILE__) + '/../spec_helper'
|
|
4
|
+
#
|
|
5
|
+
# describe UserCell do
|
|
6
|
+
# it "renders" do
|
|
7
|
+
# site = mock('site', :id => 1)
|
|
8
|
+
# section = mock('section', :id => 1, :track_method_calls => nil) # TODO: use real object?
|
|
9
|
+
# controller = mock('controller', :perform_caching => false, :site => site, :section => section)
|
|
10
|
+
# cell = UserCell.new(controller, nil)
|
|
11
|
+
# cell.render_state(:recent).should =~ /recent users/i
|
|
12
|
+
# end
|
|
13
|
+
# end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
|
|
2
|
+
|
|
3
|
+
class UsersHelperTest < ActionView::TestCase
|
|
4
|
+
include UsersHelper
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
super
|
|
8
|
+
|
|
9
|
+
@user = User.first
|
|
10
|
+
@email = 'email@gravatar.com'
|
|
11
|
+
@md5 = 'eafcd5f6d59e86088dfcf706831b297e'
|
|
12
|
+
|
|
13
|
+
stub(self).request.returns(ActionController::TestRequest.new)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# who
|
|
17
|
+
test "#who returns 'You' if the given user is the current user" do
|
|
18
|
+
stub(self).current_user.returns(@user)
|
|
19
|
+
who(@user).should == 'You'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test "#who returns the given user's name if the given user is not the current user" do
|
|
23
|
+
stub(self).current_user.returns(nil)
|
|
24
|
+
who(@user).should == @user.name
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test "#gravatar_img returns an image tag with the class 'avatar' merged to the given options" do
|
|
28
|
+
gravatar_img(@user).should have_tag('img[src^=?][class=?]', 'http://www.gravatar.com', 'avatar')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
test "#gravatar_img adds the gravatar_url for the given user's email adress" do
|
|
32
|
+
mock(self).gravatar_url(@user.email).returns('gravatar_url')
|
|
33
|
+
gravatar_img(@user)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# gravatar_url
|
|
37
|
+
test "#gravatar_url returns a default image url if the given email adress is blank" do
|
|
38
|
+
gravatar_url.should == '/assets/adva_cms/avatar.gif'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test "#gravatar_url the resulting gravatar url includes the md5/hexdigested email adress as the gravatar_id" do
|
|
42
|
+
gravatar_url(@email).should =~ /gravatar_id=#{@md5}/
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test "#gravatar_url the resulting gravatar url includes a size parameter with the given size" do
|
|
46
|
+
gravatar_url(@email, 50).should =~ /size=50/
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test "#gravatar_url the resulting gravatar url includes a default parameter" do
|
|
50
|
+
gravatar_url(@email).should =~ %r(default=http://test.host/assets/adva_cms/avatar.gif)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
|
|
2
|
+
|
|
3
|
+
class AccountTest < ActiveSupport::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
super
|
|
6
|
+
@user1 = User.find_by_first_name('user1')
|
|
7
|
+
@user2 = User.find_by_first_name('user2')
|
|
8
|
+
@user3 = User.find_by_first_name('user3')
|
|
9
|
+
@user4 = User.find_by_first_name('user4')
|
|
10
|
+
|
|
11
|
+
@account = Account.find_by_name('an account')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test 'creation' do
|
|
15
|
+
@account.name.should == 'an account'
|
|
16
|
+
@account.users.should include(@user1)
|
|
17
|
+
@account.users.should include(@user2)
|
|
18
|
+
@account.users.should include(@user3)
|
|
19
|
+
@account.users.should exclude(@user4)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
|
|
2
|
+
|
|
3
|
+
class AnonymousTest < ActiveSupport::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
super
|
|
6
|
+
@anonymous = User.anonymous :name => 'John Doe'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
test 'acts as authenticated user (with single token authentication)' do
|
|
10
|
+
User.should act_as_authenticated_user
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# VALIDATIONS
|
|
14
|
+
|
|
15
|
+
test 'validates the presence of a name' do
|
|
16
|
+
@anonymous.should validate_presence_of(:first_name)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'validates the presence of an email' do
|
|
20
|
+
@anonymous.should validate_presence_of(:email)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test 'validates the length of the name (3-40 chars)' do
|
|
24
|
+
@anonymous.should validate_length_of(:first_name, :within => 3..40)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'email format validation succeeds with a valid email address' do
|
|
28
|
+
@anonymous.email = 'valid@email.org'
|
|
29
|
+
@anonymous.should be_valid
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test 'email format validation fails with an invalid email address' do
|
|
33
|
+
@anonymous.email = 'invalid-email.org'
|
|
34
|
+
@anonymous.should_not be_valid
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# INSTANCE METHODS
|
|
38
|
+
|
|
39
|
+
test '#has_role? returns true when the passed role is Role::Anonymous' do
|
|
40
|
+
@anonymous.should have_role(:anonymous)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test '#has_role? returns false when the passed role is not Role::Anonymous' do
|
|
44
|
+
@anonymous.should_not have_role(:user)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test '#anonymous? returns true' do
|
|
48
|
+
@anonymous.should be_anonymous
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
test '#registered? returns false' do
|
|
52
|
+
@anonymous.should_not be_registered
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
|
|
2
|
+
|
|
3
|
+
class PasswordMailerTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test "observes events" do
|
|
6
|
+
Event.observers.should include('PasswordMailer')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
test "implements #handle_user_password_reset_requested!" do
|
|
10
|
+
PasswordMailer.should respond_to(:handle_user_password_reset_requested!)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "implements #handle_user_password_updated!" do
|
|
14
|
+
PasswordMailer.should respond_to(:handle_user_password_updated!)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "receives #handle_user_password_reset_requested! when a :user_password_reset_requested event is triggered" do
|
|
18
|
+
mock(PasswordMailer).handle_user_password_reset_requested!.with(anything)
|
|
19
|
+
Event.trigger(:user_password_reset_requested, User.new, self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test "receives #handle_user_password_updated! when a :user_password_updated event is triggered" do
|
|
23
|
+
mock(PasswordMailer).handle_user_password_updated!.with(anything)
|
|
24
|
+
Event.trigger(:user_password_updated, User.new, self)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
|
|
2
|
+
|
|
3
|
+
class UserMailerTest < ActiveSupport::TestCase
|
|
4
|
+
test "observes events" do
|
|
5
|
+
Event.observers.should include('UserMailer')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "implements #handle_user_registered!" do
|
|
9
|
+
UserMailer.should respond_to(:handle_user_registered!)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test "receives #handle_user_registered! when a :user_registered event is triggered" do
|
|
13
|
+
mock(UserMailer).handle_user_registered!.with(anything)
|
|
14
|
+
Event.trigger(:user_registered, User.new, self)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
|
|
2
|
+
|
|
3
|
+
class UserTest < ActiveSupport::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
super
|
|
6
|
+
@user = User.find_by_first_name('a user')
|
|
7
|
+
@credentials = { :email => @user.email, :password => 'a password' }
|
|
8
|
+
@valid_user_params = { :email => 'test@example.org', :password => 'test', :first_name => 'name' }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'acts as authenticated user' do
|
|
12
|
+
User.should act_as_authenticated_user
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# ASSOCIATIONS
|
|
16
|
+
|
|
17
|
+
test "has many sites" do
|
|
18
|
+
@user.should have_many(:sites)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "has many memberships" do
|
|
22
|
+
@user.should have_many(:memberships)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test "has many roles" do
|
|
26
|
+
@user.should have_many(:roles)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# VALIDATIONS
|
|
30
|
+
|
|
31
|
+
test "validates the presence of a first name" do
|
|
32
|
+
@user.should validate_presence_of(:first_name)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
test "validates the presence of an email adress" do
|
|
36
|
+
@user.should validate_presence_of(:email)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
test "validates the uniqueness of the email" do
|
|
40
|
+
@user.should validate_uniqueness_of(:email)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test "validates the presence of a password if the password is required" do
|
|
44
|
+
@user.should validate_presence_of(:password, :if => :password_required?)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test "validates the length of the last name" do
|
|
48
|
+
@user.should validate_length_of(:last_name, :within => 0..40)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
test "creates a user with blank last name" do
|
|
52
|
+
@user.last_name = ''
|
|
53
|
+
@user.save.should be_true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
test "validates the length of the first name" do
|
|
57
|
+
@user.should validate_length_of(:first_name, :within => 1..40)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
test "validates the length of the password" do
|
|
61
|
+
@user.should validate_length_of(:password, :within => 4..40)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# CLASS METHODS
|
|
65
|
+
|
|
66
|
+
# User.authenticate
|
|
67
|
+
test 'User.authenticate returns the user if user#authenticate succeeds' do
|
|
68
|
+
User.authenticate(@credentials).should == @user
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
test 'User.authenticate returns false if user#authenticate fails' do
|
|
72
|
+
@credentials[:email] = 'does_not_exist@email.org'
|
|
73
|
+
User.authenticate(@credentials).should be_false
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
test 'User.authenticate returns false if no user with the given email exists' do
|
|
77
|
+
@credentials[:password] = 'wrong password'
|
|
78
|
+
User.authenticate(@credentials).should be_false
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# User.admins_and_superusers
|
|
82
|
+
test 'User.admins_and_superusers returns all site admins and superusers' do
|
|
83
|
+
admin = User.find_by_first_name('an admin')
|
|
84
|
+
superuser = User.find_by_first_name('a superuser')
|
|
85
|
+
|
|
86
|
+
result = User.admins_and_superusers
|
|
87
|
+
result.should include(admin)
|
|
88
|
+
result.should include(superuser)
|
|
89
|
+
# result.size.should == 2
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# User.create_superuser
|
|
93
|
+
test 'User.create_superuser defaults :first_name to the name part of the email' do
|
|
94
|
+
user = User.create_superuser(:email => 'first.name@example.com')
|
|
95
|
+
user.first_name == 'first.name'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
test 'User.create_superuser uses default values for email and password' do
|
|
99
|
+
user = User.create_superuser(:email => nil, :password => nil, :first_name => nil)
|
|
100
|
+
user.email.should == 'admin@example.org'
|
|
101
|
+
user.password.should == 'admin'
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
test 'User.create_superuser uses params values if given' do
|
|
105
|
+
user = User.create_superuser(@valid_user_params)
|
|
106
|
+
user.email.should == 'test@example.org'
|
|
107
|
+
user.password.should == 'test'
|
|
108
|
+
user.first_name == 'name'
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
test 'User.create_superuser verifies the user' do
|
|
112
|
+
user = User.create_superuser(@valid_user_params)
|
|
113
|
+
user.verified?.should be_true
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
test 'User.create_superuser saves the user' do
|
|
117
|
+
user = User.create_superuser(@valid_user_params)
|
|
118
|
+
user.new_record?.should be_false
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
test 'assigns the password hash' do
|
|
122
|
+
user = User.create_superuser(@valid_user_params)
|
|
123
|
+
user.password_hash.should_not be_blank
|
|
124
|
+
user.password_salt.should_not be_blank
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# INSTANCE METHODS
|
|
128
|
+
|
|
129
|
+
test '#verify! sets the verified_at timestamp and saves the user' do
|
|
130
|
+
@user.update_attributes(:verified_at => nil)
|
|
131
|
+
@user.verify!
|
|
132
|
+
@user.reload.verified_at.should_not be_nil
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# test '#restore! restores the user record' do
|
|
136
|
+
# @user.deleted_at = @time_now
|
|
137
|
+
# @user.should_receive(:update_attributes).with :deleted_at => nil
|
|
138
|
+
# @user.restore!
|
|
139
|
+
# end
|
|
140
|
+
|
|
141
|
+
test '#anonymous? returns true when anonymous is true' do
|
|
142
|
+
User.new(:anonymous => true).anonymous?.should be_true
|
|
143
|
+
User.new.anonymous?.should be_false
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# registered?
|
|
147
|
+
test '#registered? returns true when the record is not new' do
|
|
148
|
+
@user.registered?.should be_true
|
|
149
|
+
User.new.registered?.should be_false
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
test '#to_s returns the name' do # FIXME hu? where's that used?
|
|
153
|
+
@user.to_s.should == @user.name
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
test "#homepage returns the http://homepage is homepage is set to 'homepage'" do
|
|
157
|
+
@user.homepage ='homepage'
|
|
158
|
+
@user.homepage.should == 'http://homepage'
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
test "#homepage returns the http://homepage is homepage is set to 'http://homepage'" do
|
|
162
|
+
@user.homepage ='http://homepage'
|
|
163
|
+
@user.homepage.should == 'http://homepage'
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
test "#homepage returns nil if homepage is not set" do
|
|
167
|
+
@user.homepage.should be_nil
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
test "#email_with_name returns formatted string to use with email headers" do
|
|
171
|
+
@user.email_with_name.should == "a user <a-user@example.com>"
|
|
172
|
+
end
|
|
173
|
+
end
|