3 class UserRolesHelperTest < ActionView::TestCase
4 fixtures :users, :user_roles
6 def test_role_icon_normal
7 @user = users(:normal_user)
9 icon = role_icon(users(:normal_user), "moderator")
10 assert_dom_equal "", icon
12 icon = role_icon(users(:moderator_user), "moderator")
13 assert_dom_equal '<img border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />', icon
16 def test_role_icon_administrator
17 @user = users(:administrator_user)
19 icon = role_icon(users(:normal_user), "moderator")
20 assert_dom_equal '<a confirm="Are you sure you want to grant the role `moderator' to the user `test'?" rel="nofollow" data-method="post" href="/user/test/role/moderator/grant"><img border="0" alt="Grant moderator access" title="Grant moderator access" src="/images/roles/blank_moderator.png" width="20" height="20" /></a>', icon
22 icon = role_icon(users(:moderator_user), "moderator")
23 assert_dom_equal '<a confirm="Are you sure you want to revoke the role `moderator' from the user `moderator'?" rel="nofollow" data-method="post" href="/user/moderator/role/moderator/revoke"><img border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" /></a>', icon
26 def test_role_icons_normal
27 @user = users(:normal_user)
29 icons = role_icons(users(:normal_user))
30 assert_dom_equal " ", icons
32 icons = role_icons(users(:moderator_user))
33 assert_dom_equal ' <img border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />', icons
35 icons = role_icons(users(:super_user))
36 assert_dom_equal ' <img border="0" alt="This user is an administrator" title="This user is an administrator" src="/images/roles/administrator.png" width="20" height="20" /> <img border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />', icons
39 def test_role_icons_administrator
40 @user = users(:administrator_user)
42 icons = role_icons(users(:normal_user))
43 assert_dom_equal ' <a confirm="Are you sure you want to grant the role `administrator' to the user `test'?" rel="nofollow" data-method="post" href="/user/test/role/administrator/grant"><img border="0" alt="Grant administrator access" title="Grant administrator access" src="/images/roles/blank_administrator.png" width="20" height="20" /></a> <a confirm="Are you sure you want to grant the role `moderator' to the user `test'?" rel="nofollow" data-method="post" href="/user/test/role/moderator/grant"><img border="0" alt="Grant moderator access" title="Grant moderator access" src="/images/roles/blank_moderator.png" width="20" height="20" /></a>', icons
45 icons = role_icons(users(:moderator_user))
46 assert_dom_equal ' <a confirm="Are you sure you want to grant the role `administrator' to the user `moderator'?" rel="nofollow" data-method="post" href="/user/moderator/role/administrator/grant"><img border="0" alt="Grant administrator access" title="Grant administrator access" src="/images/roles/blank_administrator.png" width="20" height="20" /></a> <a confirm="Are you sure you want to revoke the role `moderator' from the user `moderator'?" rel="nofollow" data-method="post" href="/user/moderator/role/moderator/revoke"><img border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" /></a>', icons
48 icons = role_icons(users(:super_user))
49 assert_dom_equal ' <a confirm="Are you sure you want to revoke the role `administrator' from the user `super'?" rel="nofollow" data-method="post" href="/user/super/role/administrator/revoke"><img border="0" alt="Revoke administrator access" title="Revoke administrator access" src="/images/roles/administrator.png" width="20" height="20" /></a> <a confirm="Are you sure you want to revoke the role `moderator' from the user `super'?" rel="nofollow" data-method="post" href="/user/super/role/moderator/revoke"><img border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" /></a>', icons