Commit 263e47b2f088221837c3e1b938ad1aefceef1173
1 parent
99ee2895
Exists in
master
and in
29 other branches
ActionItem9: updating tests
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@99 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
55 additions
and
37 deletions
Show diff stats
test/fixtures/profiles.yml
1 | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
2 | -one: | |
2 | +johndoe: | |
3 | 3 | id: 1 |
4 | 4 | name: 'John Doe' |
5 | 5 | identifier: johndoe |
6 | 6 | virtual_community_id: 1 |
7 | + owner_id: 1 | |
7 | 8 | template: 'default' |
8 | 9 | icons_theme: 'default' |
9 | 10 | theme: 'default' |
10 | -two: | |
11 | +joerandomhacker: | |
11 | 12 | id: 2 |
12 | 13 | name: 'Joe Random Hacker' |
13 | 14 | identifier: joerandomhacker |
14 | 15 | virtual_community_id: 1 |
16 | + owner_id: 2 | |
15 | 17 | template: 'simple' |
16 | 18 | icons_theme: 'simple' |
17 | 19 | theme: 'simple' | ... | ... |
test/fixtures/users.yml
1 | -quentin: | |
1 | +johndoe: | |
2 | 2 | id: 1 |
3 | - login: quentin | |
4 | - email: quentin@example.com | |
3 | + login: johndoe | |
4 | + email: johndoe@example.com | |
5 | 5 | salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd |
6 | 6 | crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test |
7 | - #crypted_password: "ce2/iFrNtQ8=\n" # quentin, use only if you're using 2-way encryption | |
7 | + #crypted_password: "ce2/iFrNtQ8=\n" # johndoe, use only if you're using 2-way encryption | |
8 | 8 | created_at: <%= 5.days.ago.to_s :db %> |
9 | 9 | # activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups |
10 | -aaron: | |
10 | +joerandomhacker: | |
11 | 11 | id: 2 |
12 | - login: aaron | |
13 | - email: aaron@example.com | |
12 | + login: joerandomhacker | |
13 | + email: joerandomhacker@example.com | |
14 | 14 | salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd |
15 | 15 | crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test |
16 | 16 | # activation_code: aaronscode # only if you're activating new signups |
17 | - created_at: <%= 1.days.ago.to_s :db %> | |
18 | 17 | \ No newline at end of file |
18 | + created_at: <%= 1.days.ago.to_s :db %> | ... | ... |
test/functional/account_controller_test.rb
... | ... | @@ -18,13 +18,13 @@ class AccountControllerTest < Test::Unit::TestCase |
18 | 18 | end |
19 | 19 | |
20 | 20 | def test_should_login_and_redirect |
21 | - post :login, :login => 'quentin', :password => 'test' | |
21 | + post :login, :login => 'johndoe', :password => 'test' | |
22 | 22 | assert session[:user] |
23 | 23 | assert_response :redirect |
24 | 24 | end |
25 | 25 | |
26 | 26 | def test_should_fail_login_and_not_redirect |
27 | - post :login, :login => 'quentin', :password => 'bad password' | |
27 | + post :login, :login => 'johndoe', :password => 'bad password' | |
28 | 28 | assert_nil session[:user] |
29 | 29 | assert_response :success |
30 | 30 | end |
... | ... | @@ -69,45 +69,45 @@ class AccountControllerTest < Test::Unit::TestCase |
69 | 69 | end |
70 | 70 | |
71 | 71 | def test_should_logout |
72 | - login_as :quentin | |
72 | + login_as :johndoe | |
73 | 73 | get :logout |
74 | 74 | assert_nil session[:user] |
75 | 75 | assert_response :redirect |
76 | 76 | end |
77 | 77 | |
78 | 78 | def test_should_remember_me |
79 | - post :login, :login => 'quentin', :password => 'test', :remember_me => "1" | |
79 | + post :login, :login => 'johndoe', :password => 'test', :remember_me => "1" | |
80 | 80 | assert_not_nil @response.cookies["auth_token"] |
81 | 81 | end |
82 | 82 | |
83 | 83 | def test_should_not_remember_me |
84 | - post :login, :login => 'quentin', :password => 'test', :remember_me => "0" | |
84 | + post :login, :login => 'johndoe', :password => 'test', :remember_me => "0" | |
85 | 85 | assert_nil @response.cookies["auth_token"] |
86 | 86 | end |
87 | 87 | |
88 | 88 | def test_should_delete_token_on_logout |
89 | - login_as :quentin | |
89 | + login_as :johndoe | |
90 | 90 | get :logout |
91 | 91 | assert_equal @response.cookies["auth_token"], [] |
92 | 92 | end |
93 | 93 | |
94 | 94 | def test_should_login_with_cookie |
95 | - users(:quentin).remember_me | |
96 | - @request.cookies["auth_token"] = cookie_for(:quentin) | |
95 | + users(:johndoe).remember_me | |
96 | + @request.cookies["auth_token"] = cookie_for(:johndoe) | |
97 | 97 | get :index |
98 | 98 | assert @controller.send(:logged_in?) |
99 | 99 | end |
100 | 100 | |
101 | 101 | def test_should_fail_expired_cookie_login |
102 | - users(:quentin).remember_me | |
103 | - users(:quentin).update_attribute :remember_token_expires_at, 5.minutes.ago | |
104 | - @request.cookies["auth_token"] = cookie_for(:quentin) | |
102 | + users(:johndoe).remember_me | |
103 | + users(:johndoe).update_attribute :remember_token_expires_at, 5.minutes.ago | |
104 | + @request.cookies["auth_token"] = cookie_for(:johndoe) | |
105 | 105 | get :index |
106 | 106 | assert !@controller.send(:logged_in?) |
107 | 107 | end |
108 | 108 | |
109 | 109 | def test_should_fail_cookie_login |
110 | - users(:quentin).remember_me | |
110 | + users(:johndoe).remember_me | |
111 | 111 | @request.cookies["auth_token"] = auth_token('invalid_auth_token') |
112 | 112 | get :index |
113 | 113 | assert !@controller.send(:logged_in?) |
... | ... | @@ -119,7 +119,7 @@ class AccountControllerTest < Test::Unit::TestCase |
119 | 119 | end |
120 | 120 | |
121 | 121 | def test_should_display_logged_in_user_options |
122 | - login_as 'quentin' | |
122 | + login_as 'johndoe' | |
123 | 123 | get :index |
124 | 124 | assert_template 'index' |
125 | 125 | end | ... | ... |
test/integration/enable_disable_features_test.rb
... | ... | @@ -5,7 +5,7 @@ class EnableDisableFeaturesTest < ActionController::IntegrationTest |
5 | 5 | |
6 | 6 | def test_enable_features |
7 | 7 | uses_host 'anhetegua.net' |
8 | - login 'quentin', 'test' | |
8 | + login 'johndoe', 'test' | |
9 | 9 | get '/admin/features' |
10 | 10 | assert_response :success |
11 | 11 | assert_tag :tag => 'input', :attributes => { :name => 'features[feature1]' } | ... | ... |
test/unit/profile_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class ProfileTest < Test::Unit::TestCase |
4 | - fixtures :profiles, :virtual_communities | |
4 | + fixtures :profiles, :virtual_communities, :users | |
5 | 5 | |
6 | 6 | def test_identifier_validation |
7 | 7 | p = Profile.new |
... | ... | @@ -39,4 +39,9 @@ class ProfileTest < Test::Unit::TestCase |
39 | 39 | assert_kind_of VirtualCommunity, p.virtual_community |
40 | 40 | end |
41 | 41 | |
42 | + def test_can_have_user_as_owner | |
43 | + p = profiles(:johndoe) | |
44 | + assert_kind_of User, p.owner | |
45 | + end | |
46 | + | |
42 | 47 | end | ... | ... |
test/unit/user_test.rb
... | ... | @@ -42,30 +42,41 @@ class UserTest < Test::Unit::TestCase |
42 | 42 | end |
43 | 43 | |
44 | 44 | def test_should_reset_password |
45 | - users(:quentin).update_attributes(:password => 'new password', :password_confirmation => 'new password') | |
46 | - assert_equal users(:quentin), User.authenticate('quentin', 'new password') | |
45 | + users(:johndoe).update_attributes(:password => 'new password', :password_confirmation => 'new password') | |
46 | + assert_equal users(:johndoe), User.authenticate('johndoe', 'new password') | |
47 | 47 | end |
48 | 48 | |
49 | 49 | def test_should_not_rehash_password |
50 | - users(:quentin).update_attributes(:login => 'quentin2') | |
51 | - assert_equal users(:quentin), User.authenticate('quentin2', 'test') | |
50 | + users(:johndoe).update_attributes(:login => 'johndoe2') | |
51 | + assert_equal users(:johndoe), User.authenticate('johndoe2', 'test') | |
52 | 52 | end |
53 | 53 | |
54 | 54 | def test_should_authenticate_user |
55 | - assert_equal users(:quentin), User.authenticate('quentin', 'test') | |
55 | + assert_equal users(:johndoe), User.authenticate('johndoe', 'test') | |
56 | 56 | end |
57 | 57 | |
58 | 58 | def test_should_set_remember_token |
59 | - users(:quentin).remember_me | |
60 | - assert_not_nil users(:quentin).remember_token | |
61 | - assert_not_nil users(:quentin).remember_token_expires_at | |
59 | + users(:johndoe).remember_me | |
60 | + assert_not_nil users(:johndoe).remember_token | |
61 | + assert_not_nil users(:johndoe).remember_token_expires_at | |
62 | 62 | end |
63 | 63 | |
64 | 64 | def test_should_unset_remember_token |
65 | - users(:quentin).remember_me | |
66 | - assert_not_nil users(:quentin).remember_token | |
67 | - users(:quentin).forget_me | |
68 | - assert_nil users(:quentin).remember_token | |
65 | + users(:johndoe).remember_me | |
66 | + assert_not_nil users(:johndoe).remember_token | |
67 | + users(:johndoe).forget_me | |
68 | + assert_nil users(:johndoe).remember_token | |
69 | + end | |
70 | + | |
71 | + def test_should_create_profile | |
72 | + users_count = User.count | |
73 | + profiles_count = Profile.count | |
74 | + | |
75 | + user = User.create!(:login => 'new_user', :email => 'new_user@example.com', :password => 'test', :password_confirmation => 'test') | |
76 | + | |
77 | + assert Profile.exists?(['user_id = ?', user.id]) | |
78 | + assert_equal users_count + 1, User.count | |
79 | + assert_equal profiles_count + 1, Profile.count | |
69 | 80 | end |
70 | 81 | |
71 | 82 | protected | ... | ... |