Commit 263e47b2f088221837c3e1b938ad1aefceef1173

Authored by AntonioTerceiro
1 parent 99ee2895

ActionItem9: updating tests



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@99 3f533792-8f58-4932-b0fe-aaf55b0a4547
test/fixtures/profiles.yml
1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 -one: 2 +johndoe:
3 id: 1 3 id: 1
4 name: 'John Doe' 4 name: 'John Doe'
5 identifier: johndoe 5 identifier: johndoe
6 virtual_community_id: 1 6 virtual_community_id: 1
  7 + owner_id: 1
7 template: 'default' 8 template: 'default'
8 icons_theme: 'default' 9 icons_theme: 'default'
9 theme: 'default' 10 theme: 'default'
10 -two: 11 +joerandomhacker:
11 id: 2 12 id: 2
12 name: 'Joe Random Hacker' 13 name: 'Joe Random Hacker'
13 identifier: joerandomhacker 14 identifier: joerandomhacker
14 virtual_community_id: 1 15 virtual_community_id: 1
  16 + owner_id: 2
15 template: 'simple' 17 template: 'simple'
16 icons_theme: 'simple' 18 icons_theme: 'simple'
17 theme: 'simple' 19 theme: 'simple'
test/fixtures/users.yml
1 -quentin: 1 +johndoe:
2 id: 1 2 id: 1
3 - login: quentin  
4 - email: quentin@example.com 3 + login: johndoe
  4 + email: johndoe@example.com
5 salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd 5 salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
6 crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test 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 created_at: <%= 5.days.ago.to_s :db %> 8 created_at: <%= 5.days.ago.to_s :db %>
9 # activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups 9 # activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
10 -aaron: 10 +joerandomhacker:
11 id: 2 11 id: 2
12 - login: aaron  
13 - email: aaron@example.com 12 + login: joerandomhacker
  13 + email: joerandomhacker@example.com
14 salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd 14 salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
15 crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test 15 crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
16 # activation_code: aaronscode # only if you're activating new signups 16 # activation_code: aaronscode # only if you're activating new signups
17 - created_at: <%= 1.days.ago.to_s :db %>  
18 \ No newline at end of file 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 &lt; Test::Unit::TestCase @@ -18,13 +18,13 @@ class AccountControllerTest &lt; Test::Unit::TestCase
18 end 18 end
19 19
20 def test_should_login_and_redirect 20 def test_should_login_and_redirect
21 - post :login, :login => 'quentin', :password => 'test' 21 + post :login, :login => 'johndoe', :password => 'test'
22 assert session[:user] 22 assert session[:user]
23 assert_response :redirect 23 assert_response :redirect
24 end 24 end
25 25
26 def test_should_fail_login_and_not_redirect 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 assert_nil session[:user] 28 assert_nil session[:user]
29 assert_response :success 29 assert_response :success
30 end 30 end
@@ -69,45 +69,45 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -69,45 +69,45 @@ class AccountControllerTest &lt; Test::Unit::TestCase
69 end 69 end
70 70
71 def test_should_logout 71 def test_should_logout
72 - login_as :quentin 72 + login_as :johndoe
73 get :logout 73 get :logout
74 assert_nil session[:user] 74 assert_nil session[:user]
75 assert_response :redirect 75 assert_response :redirect
76 end 76 end
77 77
78 def test_should_remember_me 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 assert_not_nil @response.cookies["auth_token"] 80 assert_not_nil @response.cookies["auth_token"]
81 end 81 end
82 82
83 def test_should_not_remember_me 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 assert_nil @response.cookies["auth_token"] 85 assert_nil @response.cookies["auth_token"]
86 end 86 end
87 87
88 def test_should_delete_token_on_logout 88 def test_should_delete_token_on_logout
89 - login_as :quentin 89 + login_as :johndoe
90 get :logout 90 get :logout
91 assert_equal @response.cookies["auth_token"], [] 91 assert_equal @response.cookies["auth_token"], []
92 end 92 end
93 93
94 def test_should_login_with_cookie 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 get :index 97 get :index
98 assert @controller.send(:logged_in?) 98 assert @controller.send(:logged_in?)
99 end 99 end
100 100
101 def test_should_fail_expired_cookie_login 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 get :index 105 get :index
106 assert !@controller.send(:logged_in?) 106 assert !@controller.send(:logged_in?)
107 end 107 end
108 108
109 def test_should_fail_cookie_login 109 def test_should_fail_cookie_login
110 - users(:quentin).remember_me 110 + users(:johndoe).remember_me
111 @request.cookies["auth_token"] = auth_token('invalid_auth_token') 111 @request.cookies["auth_token"] = auth_token('invalid_auth_token')
112 get :index 112 get :index
113 assert !@controller.send(:logged_in?) 113 assert !@controller.send(:logged_in?)
@@ -119,7 +119,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -119,7 +119,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
119 end 119 end
120 120
121 def test_should_display_logged_in_user_options 121 def test_should_display_logged_in_user_options
122 - login_as 'quentin' 122 + login_as 'johndoe'
123 get :index 123 get :index
124 assert_template 'index' 124 assert_template 'index'
125 end 125 end
test/integration/enable_disable_features_test.rb
@@ -5,7 +5,7 @@ class EnableDisableFeaturesTest &lt; ActionController::IntegrationTest @@ -5,7 +5,7 @@ class EnableDisableFeaturesTest &lt; ActionController::IntegrationTest
5 5
6 def test_enable_features 6 def test_enable_features
7 uses_host 'anhetegua.net' 7 uses_host 'anhetegua.net'
8 - login 'quentin', 'test' 8 + login 'johndoe', 'test'
9 get '/admin/features' 9 get '/admin/features'
10 assert_response :success 10 assert_response :success
11 assert_tag :tag => 'input', :attributes => { :name => 'features[feature1]' } 11 assert_tag :tag => 'input', :attributes => { :name => 'features[feature1]' }
test/unit/profile_test.rb
1 require File.dirname(__FILE__) + '/../test_helper' 1 require File.dirname(__FILE__) + '/../test_helper'
2 2
3 class ProfileTest < Test::Unit::TestCase 3 class ProfileTest < Test::Unit::TestCase
4 - fixtures :profiles, :virtual_communities 4 + fixtures :profiles, :virtual_communities, :users
5 5
6 def test_identifier_validation 6 def test_identifier_validation
7 p = Profile.new 7 p = Profile.new
@@ -39,4 +39,9 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -39,4 +39,9 @@ class ProfileTest &lt; Test::Unit::TestCase
39 assert_kind_of VirtualCommunity, p.virtual_community 39 assert_kind_of VirtualCommunity, p.virtual_community
40 end 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 end 47 end
test/unit/user_test.rb
@@ -42,30 +42,41 @@ class UserTest &lt; Test::Unit::TestCase @@ -42,30 +42,41 @@ class UserTest &lt; Test::Unit::TestCase
42 end 42 end
43 43
44 def test_should_reset_password 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 end 47 end
48 48
49 def test_should_not_rehash_password 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 end 52 end
53 53
54 def test_should_authenticate_user 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 end 56 end
57 57
58 def test_should_set_remember_token 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 end 62 end
63 63
64 def test_should_unset_remember_token 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 end 80 end
70 81
71 protected 82 protected