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