@@ -305,6 +305,9 module ApplicationHelper | |||
|
305 | 305 | # Returns a string for users/groups option tags |
|
306 | 306 | def principals_options_for_select(collection, selected=nil) |
|
307 | 307 | s = '' |
|
308 | if collection.include?(User.current) | |
|
309 | s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id) | |
|
310 | end | |
|
308 | 311 | groups = '' |
|
309 | 312 | collection.sort.each do |element| |
|
310 | 313 | selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) |
@@ -854,18 +854,21 RAW | |||
|
854 | 854 | end |
|
855 | 855 | |
|
856 | 856 | def test_principals_options_for_select_with_users |
|
857 | User.current = nil | |
|
857 | 858 | users = [User.find(2), User.find(4)] |
|
858 | 859 | assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>), |
|
859 | 860 | principals_options_for_select(users) |
|
860 | 861 | end |
|
861 | 862 | |
|
862 | 863 | def test_principals_options_for_select_with_selected |
|
864 | User.current = nil | |
|
863 | 865 | users = [User.find(2), User.find(4)] |
|
864 | 866 | assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>), |
|
865 | 867 | principals_options_for_select(users, User.find(4)) |
|
866 | 868 | end |
|
867 | 869 | |
|
868 | 870 | def test_principals_options_for_select_with_users_and_groups |
|
871 | User.current = nil | |
|
869 | 872 | users = [User.find(2), Group.find(11), User.find(4), Group.find(10)] |
|
870 | 873 | assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) + |
|
871 | 874 | %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>), |
@@ -875,4 +878,10 RAW | |||
|
875 | 878 | def test_principals_options_for_select_with_empty_collection |
|
876 | 879 | assert_equal '', principals_options_for_select([]) |
|
877 | 880 | end |
|
881 | ||
|
882 | def test_principals_options_for_select_should_include_me_option_when_current_user_is_in_collection | |
|
883 | users = [User.find(2), User.find(4)] | |
|
884 | User.current = User.find(4) | |
|
885 | assert_include '<option value="4"><< me >></option>', principals_options_for_select(users) | |
|
886 | end | |
|
878 | 887 | end |
General Comments 0
You need to be logged in to leave comments.
Login now