summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_helper.rb9
-rw-r--r--test/unit/helpers/application_helper_test.rb20
2 files changed, 23 insertions, 6 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 66a6f2646..3c2cece7b 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -114,6 +114,15 @@ class ActiveSupport::TestCase
saved_settings.each {|k, v| Setting[k] = v} if saved_settings
end
+ # Yields the block with user as the current user
+ def with_current_user(user, &block)
+ saved_user = User.current
+ User.current = user
+ yield
+ ensure
+ User.current = saved_user
+ end
+
def change_user_password(login, new_password)
user = User.first(:conditions => {:login => login})
user.password, user.password_confirmation = new_password, new_password
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index 9855efa27..4bf191f01 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -1010,15 +1010,23 @@ RAW
def test_link_to_user
user = User.find(2)
- t = link_to_user(user)
- assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t
+ assert_equal '<a href="/users/2" class="user active">John Smith</a>', link_to_user(user)
end
def test_link_to_user_should_not_link_to_locked_user
- user = User.find(5)
- assert user.locked?
- t = link_to_user(user)
- assert_equal user.name, t
+ with_current_user nil do
+ user = User.find(5)
+ assert user.locked?
+ assert_equal 'Dave2 Lopper2', link_to_user(user)
+ end
+ end
+
+ def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin
+ with_current_user User.find(1) do
+ user = User.find(5)
+ assert user.locked?
+ assert_equal '<a href="/users/5" class="user locked">Dave2 Lopper2</a>', link_to_user(user)
+ end
end
def test_link_to_user_should_not_link_to_anonymous