Commit b2e08160e08a0bba5881f0e23b4fd7702717fc0f

Authored by Joenio Costa
2 parents 692651c0 d35bce8d

Merge branch 'master' of gitlab.com:noosfero/noosfero

app/helpers/boxes_helper.rb
@@ -227,7 +227,7 @@ module BoxesHelper @@ -227,7 +227,7 @@ module BoxesHelper
227 227
228 # DEPRECATED. Do not use this. 228 # DEPRECATED. Do not use this.
229 def import_blocks_stylesheets(options = {}) 229 def import_blocks_stylesheets(options = {})
230 - @blocks_css_files ||= current_blocks.map{|b|'blocks/' + block.class.name.to_css_class}.uniq 230 + @blocks_css_files ||= current_blocks.map{|block|'blocks/' + block.class.name.to_css_class}.uniq
231 stylesheet_import(@blocks_css_files, options) 231 stylesheet_import(@blocks_css_files, options)
232 end 232 end
233 def block_css_classes(block) 233 def block_css_classes(block)
test/functional/mailconf_controller_test.rb
@@ -2,16 +2,17 @@ require File.dirname(__FILE__) + '/../test_helper' @@ -2,16 +2,17 @@ require File.dirname(__FILE__) + '/../test_helper'
2 2
3 class MailconfControllerTest < ActionController::TestCase 3 class MailconfControllerTest < ActionController::TestCase
4 4
5 - all_fixtures  
6 -  
7 def setup 5 def setup
8 @controller = MailconfController.new 6 @controller = MailconfController.new
9 @request = ActionController::TestRequest.new 7 @request = ActionController::TestRequest.new
10 @response = ActionController::TestResponse.new 8 @response = ActionController::TestResponse.new
  9 + User.destroy_all
  10 + @user = create_user('ze')
11 11
12 MailConf.stubs(:enabled?).returns(true) 12 MailConf.stubs(:enabled?).returns(true)
13 MailConf.stubs(:webmail_url).returns('http://web.mail.net/') 13 MailConf.stubs(:webmail_url).returns('http://web.mail.net/')
14 end 14 end
  15 + attr_accessor :user
15 16
16 should 'check if mail is enabled' do 17 should 'check if mail is enabled' do
17 MailConf.expects(:enabled?).returns(false) 18 MailConf.expects(:enabled?).returns(false)
@@ -29,7 +30,8 @@ class MailconfControllerTest &lt; ActionController::TestCase @@ -29,7 +30,8 @@ class MailconfControllerTest &lt; ActionController::TestCase
29 end 30 end
30 31
31 should 'not be edited by others' do 32 should 'not be edited by others' do
32 - login_as('johndoe') 33 + another = create_user('johndoe')
  34 + login_as(another.login)
33 get :index, :profile => 'ze' 35 get :index, :profile => 'ze'
34 assert_response 403 36 assert_response 403
35 end 37 end
@@ -43,7 +45,7 @@ class MailconfControllerTest &lt; ActionController::TestCase @@ -43,7 +45,7 @@ class MailconfControllerTest &lt; ActionController::TestCase
43 should 'expose user to templates' do 45 should 'expose user to templates' do
44 login_as('ze') 46 login_as('ze')
45 get :index, :profile => 'ze' 47 get :index, :profile => 'ze'
46 - assert_equal users(:ze), assigns(:user) 48 + assert_equal user, assigns(:user)
47 end 49 end
48 50
49 should 'present enable/disable for e-mail use' do 51 should 'present enable/disable for e-mail use' do
@@ -58,7 +60,7 @@ class MailconfControllerTest &lt; ActionController::TestCase @@ -58,7 +60,7 @@ class MailconfControllerTest &lt; ActionController::TestCase
58 60
59 should 'display correctly the state false of e-mail enable/disable' do 61 should 'display correctly the state false of e-mail enable/disable' do
60 login_as('ze') 62 login_as('ze')
61 - users(:ze).update_attributes!(:enable_email => false) 63 + user.update_attributes!(:enable_email => false)
62 get :index, :profile => 'ze' 64 get :index, :profile => 'ze'
63 assert_tag :tag => 'a', :content => 'Enable e-Mail' 65 assert_tag :tag => 'a', :content => 'Enable e-Mail'
64 assert_no_tag :tag => 'a', :content => 'Disable e-Mail', :attributes => { :href => '/myprofile/ze/mailconf/disable' } 66 assert_no_tag :tag => 'a', :content => 'Disable e-Mail', :attributes => { :href => '/myprofile/ze/mailconf/disable' }
@@ -91,7 +93,7 @@ class MailconfControllerTest &lt; ActionController::TestCase @@ -91,7 +93,7 @@ class MailconfControllerTest &lt; ActionController::TestCase
91 93
92 should 'save mail enable/disable as false' do 94 should 'save mail enable/disable as false' do
93 login_as('ze') 95 login_as('ze')
94 - assert users(:ze).enable_email! 96 + assert user.enable_email!
95 post :disable, :profile => 'ze' 97 post :disable, :profile => 'ze'
96 assert !Profile['ze'].user.enable_email 98 assert !Profile['ze'].user.enable_email
97 end 99 end
@@ -122,8 +124,8 @@ class MailconfControllerTest &lt; ActionController::TestCase @@ -122,8 +124,8 @@ class MailconfControllerTest &lt; ActionController::TestCase
122 124
123 should 'not display input for enable/disable e-mail when has pending_enable_email' do 125 should 'not display input for enable/disable e-mail when has pending_enable_email' do
124 login_as('ze') 126 login_as('ze')
125 - users(:ze).update_attribute(:environment_id, Environment.default.id)  
126 - EmailActivation.create!(:requestor => users(:ze).person, :target => Environment.default) 127 + user.update_attribute(:environment_id, Environment.default.id)
  128 + EmailActivation.create!(:requestor => user.person, :target => Environment.default)
127 get :index, :profile => 'ze' 129 get :index, :profile => 'ze'
128 assert_no_tag :tag => 'input', :attributes => {:name => 'user[enable_email]', :type => 'checkbox'} 130 assert_no_tag :tag => 'input', :attributes => {:name => 'user[enable_email]', :type => 'checkbox'}
129 end 131 end
test/functional/profile_controller_test.rb
@@ -1383,17 +1383,21 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1383,17 +1383,21 @@ class ProfileControllerTest &lt; ActionController::TestCase
1383 assert_equal "Comment successfully added.", assigns(:message) 1383 assert_equal "Comment successfully added.", assigns(:message)
1384 end 1384 end
1385 1385
1386 - should 'display comment in wall if user was removed' do 1386 + should 'display comment in wall if user was removed after click in view all comments' do
1387 UserStampSweeper.any_instance.stubs(:current_user).returns(profile) 1387 UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
1388 article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') 1388 article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
1389 to_be_removed = create_user('removed_user').person 1389 to_be_removed = create_user('removed_user').person
1390 comment = Comment.create!(:author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') 1390 comment = Comment.create!(:author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article')
1391 to_be_removed.destroy 1391 to_be_removed.destroy
1392 1392
  1393 + activity = ActionTracker::Record.last
  1394 +
1393 login_as(profile.identifier) 1395 login_as(profile.identifier)
1394 - get :index, :profile => profile.identifier 1396 + get :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall'
1395 1397
1396 - assert_tag :tag => 'span', :content => '(removed user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-removed'} 1398 + assert_select_rjs :insert_html do
  1399 + assert_select 'span', :content => '(removed user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-removed'}
  1400 + end
1397 end 1401 end
1398 1402
1399 should 'not display spam comments in wall' do 1403 should 'not display spam comments in wall' do
@@ -1407,7 +1411,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1407,7 +1411,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1407 assert !/This article makes me hungry/.match(@response.body), 'Spam comment was shown!' 1411 assert !/This article makes me hungry/.match(@response.body), 'Spam comment was shown!'
1408 end 1412 end
1409 1413
1410 - should 'display comment in wall from non logged users' do 1414 + should 'display comment in wall from non logged users after click in view all comments' do
1411 UserStampSweeper.any_instance.stubs(:current_user).returns(profile) 1415 UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
1412 article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') 1416 article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
1413 comment = Comment.create!(:name => 'outside user', :email => 'outside@localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') 1417 comment = Comment.create!(:name => 'outside user', :email => 'outside@localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article')
@@ -1415,7 +1419,14 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1415,7 +1419,14 @@ class ProfileControllerTest &lt; ActionController::TestCase
1415 login_as(profile.identifier) 1419 login_as(profile.identifier)
1416 get :index, :profile => profile.identifier 1420 get :index, :profile => profile.identifier
1417 1421
1418 - assert_tag :tag => 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'} 1422 + activity = ActionTracker::Record.last
  1423 +
  1424 + login_as(profile.identifier)
  1425 + get :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall'
  1426 +
  1427 + assert_select_rjs :insert_html do
  1428 + assert_select 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'}
  1429 + end
1419 end 1430 end
1420 1431
1421 should 'add locale on mailing' do 1432 should 'add locale on mailing' do
test/functional/users_controller_test.rb
@@ -11,10 +11,16 @@ class UsersControllerTest &lt; ActionController::TestCase @@ -11,10 +11,16 @@ class UsersControllerTest &lt; ActionController::TestCase
11 @request = ActionController::TestRequest.new 11 @request = ActionController::TestRequest.new
12 @response = ActionController::TestResponse.new 12 @response = ActionController::TestResponse.new
13 13
14 - admin_user = create_user_with_permission('adminuser', 'manage_environment_users', Environment.default) 14 + Environment.destroy_all
  15 + @environment = fast_create(Environment, :is_default => true)
  16 +
  17 +
  18 + admin_user = create_user_with_permission('adminuser', 'manage_environment_users', environment)
15 login_as('adminuser') 19 login_as('adminuser')
16 end 20 end
17 21
  22 + attr_accessor :environment
  23 +
18 should 'not access without right permission' do 24 should 'not access without right permission' do
19 create_user('guest') 25 create_user('guest')
20 login_as 'guest' 26 login_as 'guest'
@@ -63,6 +69,7 @@ class UsersControllerTest &lt; ActionController::TestCase @@ -63,6 +69,7 @@ class UsersControllerTest &lt; ActionController::TestCase
63 69
64 should 'set admin role' do 70 should 'set admin role' do
65 person = create_user.person 71 person = create_user.person
  72 + Role.create!(:name => 'Admin', :key => 'environment_administrator', :environment_id => environment.id, :permissions => ['view_environment_admin_panel'])
66 assert_equal false, person.is_admin? 73 assert_equal false, person.is_admin?
67 post :set_admin_role, :id => person.id, :q => '' 74 post :set_admin_role, :id => person.id, :q => ''
68 person.reload 75 person.reload
@@ -70,8 +77,9 @@ class UsersControllerTest &lt; ActionController::TestCase @@ -70,8 +77,9 @@ class UsersControllerTest &lt; ActionController::TestCase
70 end 77 end
71 78
72 should 'reset admin role' do 79 should 'reset admin role' do
73 - environment = Environment.default  
74 person = create_user.person 80 person = create_user.person
  81 + Role.create!(:name => 'Admin', :key => 'environment_administrator', :environment_id => environment.id, :permissions => ['view_environment_admin_panel'])
  82 +
75 environment.add_admin(person) 83 environment.add_admin(person)
76 assert person.is_admin? 84 assert person.is_admin?
77 85
test/integration/forgot_password_test.rb
@@ -19,7 +19,7 @@ class ForgotPasswordTest &lt; ActionController::IntegrationTest @@ -19,7 +19,7 @@ class ForgotPasswordTest &lt; ActionController::IntegrationTest
19 assert_response :success 19 assert_response :success
20 assert_tag :tag => 'form', :attributes => { :action => '/account/forgot_password', :method => 'post' } 20 assert_tag :tag => 'form', :attributes => { :action => '/account/forgot_password', :method => 'post' }
21 21
22 - post '/account/forgot_password', :change_password => { :field => 'login', :value => 'forgotten', :environment_id => Environment.default.id } 22 + post '/account/forgot_password', :field => 'login', :value => 'forgotten', :environment_id => Environment.default.id
23 23
24 assert_response :success 24 assert_response :success
25 assert_template 'password_recovery_sent' 25 assert_template 'password_recovery_sent'
@@ -52,7 +52,7 @@ class ForgotPasswordTest &lt; ActionController::IntegrationTest @@ -52,7 +52,7 @@ class ForgotPasswordTest &lt; ActionController::IntegrationTest
52 assert_response :success 52 assert_response :success
53 assert_tag :tag => 'form', :attributes => { :action => '/account/forgot_password', :method => 'post' } 53 assert_tag :tag => 'form', :attributes => { :action => '/account/forgot_password', :method => 'post' }
54 54
55 - post '/account/forgot_password', :change_password => { :field => 'email', :value => 'forgotten@localhost.localdomain', :environment_id => Environment.default.id } 55 + post '/account/forgot_password', :field => 'email', :value => 'forgotten@localhost.localdomain', :environment_id => Environment.default.id
56 56
57 assert_response :success 57 assert_response :success
58 assert_template 'password_recovery_sent' 58 assert_template 'password_recovery_sent'
test/unit/profile_test.rb
@@ -1300,7 +1300,6 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1300,7 +1300,6 @@ class ProfileTest &lt; ActiveSupport::TestCase
1300 1300
1301 should 'list folder articles' do 1301 should 'list folder articles' do
1302 profile = fast_create(Profile) 1302 profile = fast_create(Profile)
1303 - Article.destroy_all  
1304 p1 = Folder.create!(:name => 'parent1', :profile => profile) 1303 p1 = Folder.create!(:name => 'parent1', :profile => profile)
1305 p2 = Blog.create!(:name => 'parent2', :profile => profile) 1304 p2 = Blog.create!(:name => 'parent2', :profile => profile)
1306 1305
@@ -1761,7 +1760,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1761,7 +1760,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1761 env = fast_create(Environment) 1760 env = fast_create(Environment)
1762 roles = %w(foo bar profile_foo profile_bar).map{ |r| Role.create!(:name => r, :environment_id => env.id, :permissions => ["some"]) } 1761 roles = %w(foo bar profile_foo profile_bar).map{ |r| Role.create!(:name => r, :environment_id => env.id, :permissions => ["some"]) }
1763 Role.create! :name => 'test', :environment_id => env.id + 1 1762 Role.create! :name => 'test', :environment_id => env.id + 1
1764 - assert_equal roles, Profile::Roles.all_roles(env.id) 1763 + assert_equivalent roles, Profile::Roles.all_roles(env.id)
1765 end 1764 end
1766 1765
1767 should 'define method for role' do 1766 should 'define method for role' do
test/unit/user_test.rb
@@ -337,10 +337,8 @@ class UserTest &lt; ActiveSupport::TestCase @@ -337,10 +337,8 @@ class UserTest &lt; ActiveSupport::TestCase
337 Person.any_instance.stubs(:created_at).returns(DateTime.parse('16-08-2010')) 337 Person.any_instance.stubs(:created_at).returns(DateTime.parse('16-08-2010'))
338 expected_hash = { 338 expected_hash = {
339 'login' => 'x_and_y', 'is_admin' => true, 'since_month' => 8, 339 'login' => 'x_and_y', 'is_admin' => true, 'since_month' => 8,
340 - 'chat_enabled' => false, 'since_year' => 2010, 'avatar' =>  
341 - 'http://www.gravatar.com/avatar/a0517761d5125820c28d87860bc7c02e?only_path=false&d=&size=20',  
342 - 'email_domain' => nil, 'amount_of_friends' => 0,  
343 - 'friends_list' => {}, 'enterprises' => [], 340 + 'chat_enabled' => false, 'since_year' => 2010, 'email_domain' => nil,
  341 + 'amount_of_friends' => 0, 'friends_list' => {}, 'enterprises' => [],
344 } 342 }
345 343
346 assert_equal expected_hash['login'], person.user.data_hash['login'] 344 assert_equal expected_hash['login'], person.user.data_hash['login']
@@ -348,7 +346,13 @@ class UserTest &lt; ActiveSupport::TestCase @@ -348,7 +346,13 @@ class UserTest &lt; ActiveSupport::TestCase
348 assert_equal expected_hash['since_month'], person.user.data_hash['since_month'] 346 assert_equal expected_hash['since_month'], person.user.data_hash['since_month']
349 assert_equal expected_hash['chat_enabled'], person.user.data_hash['chat_enabled'] 347 assert_equal expected_hash['chat_enabled'], person.user.data_hash['chat_enabled']
350 assert_equal expected_hash['since_year'], person.user.data_hash['since_year'] 348 assert_equal expected_hash['since_year'], person.user.data_hash['since_year']
351 - assert_equal expected_hash['avatar'], person.user.data_hash['avatar'] 349 +
  350 + # Avatar stuff
  351 + assert_match 'http://www.gravatar.com/avatar/a0517761d5125820c28d87860bc7c02e', person.user.data_hash['avatar']
  352 + assert_match 'only_path=false', person.user.data_hash['avatar']
  353 + assert_match 'd=', person.user.data_hash['avatar']
  354 + assert_match 'size=20', person.user.data_hash['avatar']
  355 +
352 assert_equal expected_hash['email_domain'], person.user.data_hash['email_domain'] 356 assert_equal expected_hash['email_domain'], person.user.data_hash['email_domain']
353 assert_equal expected_hash['amount_of_friends'], person.user.data_hash['amount_of_friends'] 357 assert_equal expected_hash['amount_of_friends'], person.user.data_hash['amount_of_friends']
354 assert_equal expected_hash['friends_list'], person.user.data_hash['friends_list'] 358 assert_equal expected_hash['friends_list'], person.user.data_hash['friends_list']