Project

General

Profile

Defect #35308 » add_test.patch

Mizuki ISHIKAWA, 2021-05-27 02:39

View differences:

app/views/news/index.html.erb
1 1
<div class="contextual">
2 2
<%= link_to(l(:label_news_new),
3 3
            (@project ? project_news_index_path(@project) : news_index_path),
4
            :class => 'icon icon-add',
5
            :onclick => 'showAndScrollTo("add-news", "news_title"); return false;') if (@project.nil? || (@project && User.current.allowed_to?(:manage_news, @project))) %>
4
            :class => 'icon icon-add add-news-link',
5
            :onclick => 'showAndScrollTo("add-news", "news_title"); return false;') if User.current.allowed_to?(:manage_news, @project, global: true) %>
6 6
<%= watcher_link(@project.enabled_module('news'), User.current) if @project && User.current.logged? %>
7 7
</div>
8 8

  
test/functional/news_controller_test.rb
53 53
    assert_response 403
54 54
  end
55 55

  
56
  def test_index_without_global_manage_news_permission_should_not_display_add_news_link
57
    user = User.find(2)
58
    @request.session[:user_id] = user.id
59
    Role.all.each {|r| r.remove_permission! :manage_news}
60
    get :index
61
    assert_select '.add-news-link', count: 0
62

  
63
    user.members.first.roles.first.add_permission! :manage_news
64
    get :index
65
    assert_select '.add-news-link', count: 1
66
  end
67

  
56 68
  def test_show
57 69
    get(:show, :params => {:id => 1})
58 70
    assert_response :success
(2-2/2)