Patch #37994 ยป 37994.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
# Displays a link to user's account page if active
|
||
|
def link_to_user(user, options={})
|
||
|
user.is_a?(User) ? link_to_principal(user, options) : h(user.to_s)
|
||
|
end
|
||
|
# Displays a link to user's account page or group page
|
||
|
def link_to_principal(principal, options={})
|
||
|
only_path = options[:only_path].nil? ? true : options[:only_path]
|
||
| ... | ... | |
|
css_classes += " #{options[:class]}" if css_classes && options[:class].present?
|
||
|
url ? link_to(name, url, :class => css_classes) : name
|
||
|
end
|
||
|
# Displays a link to edit group page if current user is admin
|
||
|
# Otherwise display only the group name
|
||
|
def link_to_group(group, options={})
|
||
|
if group.is_a?(Group)
|
||
|
name = h(group.name)
|
||
|
if User.current.admin?
|
||
|
only_path = options[:only_path].nil? ? true : options[:only_path]
|
||
|
link_to name, edit_group_path(group, :only_path => only_path)
|
||
|
else
|
||
|
name
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
alias link_to_user link_to_principal
|
||
|
alias link_to_group link_to_principal
|
||
|
# Displays a link to +issue+ with its subject.
|
||
|
# Examples:
|
||
| test/functional/groups_controller_test.rb | ||
|---|---|---|
|
assert_response :success
|
||
|
assert_include 'John Smith', response.body
|
||
|
end
|
||
|
def test_show_should_display_edit_link_for_admin
|
||
|
@request.session[:user_id] = 1
|
||
|
get :show, :params => {:id => 10}
|
||
|
assert_response :success
|
||
|
assert_select '.contextual > .icon-edit'
|
||
|
end
|
||
|
end
|
||
| test/functional/users_controller_test.rb | ||
|---|---|---|
|
assert_select 'div#groups', 1 do
|
||
|
assert_select 'h3', :text => 'Groups'
|
||
|
assert_select 'li', 2
|
||
|
assert_select 'a[href=?]', '/groups/10/edit', :text => 'A Team'
|
||
|
assert_select 'a[href=?]', '/groups/11/edit', :text => 'B Team'
|
||
|
assert_select 'a[href=?]', '/groups/10', :text => 'A Team'
|
||
|
assert_select 'a[href=?]', '/groups/11', :text => 'B Team'
|
||
|
end
|
||
|
end
|
||
| test/helpers/application_helper_test.rb | ||
|---|---|---|
|
assert_include "<>'&", link_to_principal("<>'&")
|
||
|
end
|
||
|
def test_link_to_group_should_return_only_group_name_for_non_admin_users
|
||
|
User.current = nil
|
||
|
group = Group.find(10)
|
||
|
assert_equal "A Team", link_to_group(group)
|
||
|
end
|
||
|
def test_link_to_group_should_link_to_group_edit_page_for_admin_users
|
||
|
User.current = User.find(1)
|
||
|
group = Group.find(10)
|
||
|
result = link_to("A Team", "/groups/10/edit")
|
||
|
assert_equal result, link_to_group(group)
|
||
|
end
|
||
|
def test_link_to_user_should_not_link_to_anonymous
|
||
|
user = User.anonymous
|
||
|
assert user.anonymous?
|
||