Skip to content

Commit 810353a

Browse files
Add view_wiki_show_action_dropdown hook via Deface and comprehensive hook tests for wiki, issues and contacts controllers
1 parent c5f8a8c commit 810353a

File tree

9 files changed

+284
-2
lines changed

9 files changed

+284
-2
lines changed

app/overrides/wiki_show.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ module WikiShow
77
insert_before: 'p.wiki-update-info',
88
original: '39c0ff8f0b6a468264526af5046c3c6db7e94997',
99
partial: 'hooks/view_wiki_show_bottom'
10+
11+
Deface::Override.new virtual_path: 'wiki/show',
12+
name: 'wiki-show-action-dropdown',
13+
insert_after: 'erb[loud]:contains("label_history")',
14+
original: '83d97f2d91c682d3329bc2df00856cc6f6cc4b09',
15+
partial: 'hooks/view_wiki_show_action_dropdown'
1016
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
= call_hook :view_wiki_show_action_dropdown, page: @page, project: @project

test/fixtures/contacts.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
adam:
2+
id: 1
3+
first_name: Adam
4+
last_name: Ondra
5+
middle_name: Superstar
6+
company: Ocun
7+
email: adam@mail.com
8+
website: https://www.adamondra.com/
9+
primary_city: Brno
10+
primary_country_code: CZ
11+
primary_postcode: 602 00
12+
other_city: Arco
13+
other_country_code: IT
14+
author_id: 1
15+
assigned_to_id: 3
16+
created_on: <%= 2.days.ago.to_fs(:db) %>
17+
18+
kurt:
19+
id: 2
20+
first_name: Kurt
21+
last_name: Albert
22+
middle_name: Superstar
23+
job_title: CEO
24+
company: Ocun
25+
birthday: 1954-01-28
26+
email: kurt@mail.de,kurt@mail.com
27+
description: Kurt was the infentor of redpoint
28+
primary_city: Ebermannstadt
29+
primary_country_code: DE
30+
primary_street1: Gasseldorf
31+
primary_state: Bayern
32+
primary_postcode: 91320
33+
other_city: Oberschellenbach
34+
other_country_code: DE
35+
other_street1: Unbekannt 2
36+
other_state: Bayern
37+
other_postcode: 90321
38+
created_on: <%= 3.days.ago.to_fs(:db) %>
39+
author_id: 1
40+
41+
ocun:
42+
id: 3
43+
first_name: Ocun
44+
job_title: web project
45+
is_company: true
46+
company_contact_id: 1
47+
email: info@global.ocun.com
48+
invoice_email: billing@ocun.com
49+
description: Realy cool project
50+
website: https://www.ocun.com
51+
author_id: 3
52+
53+
john:
54+
id: 4
55+
first_name: John
56+
last_name: Smith
57+
job_title: CEO
58+
is_company: false
59+
email: jsmith@somenet.foo
60+
description: "Contact with user realation\nUser id = 2"
61+
author_id: 2
62+
63+
blackdiamond:
64+
id: 5
65+
first_name: 'Black Diamond'
66+
job_title: web project
67+
is_company: true
68+
visibility: <%= Contact::VISIBILITY_PRIVATE %>
69+
email: company@8a.nu
70+
description: "Here at Black Diamond it's all about climbing and skiing. We share the same experiences that you do on rock, ice and snow and these experiences push us to make the best gear possible for our worldwide family of climbers and skiers."
71+
website: "https://www.blackdiamondequipment.com"
72+
phone: "1-800-775-5552"
73+
author_id: 2
74+
75+
spammer:
76+
id: 6
77+
first_name: Spammer
78+
email: spam@junk.com
79+
created_on: <%= 2.days.ago.to_fs(:db) %>
80+
spam: true
81+
author_id: 1
82+
83+
without_mail:
84+
id: 7
85+
first_name: Seppi
86+
created_on: <%= 2.days.ago.to_fs(:db) %>
87+
email: ''
88+
author_id: 1
89+
90+
noone:
91+
id: 8
92+
first_name: Project2 Only
93+
created_on: <%= 2.days.ago.to_fs(:db) %>
94+
author_id: 1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
contact_project_one:
2+
project_id: 1
3+
contact_id: 1
4+
5+
contact_project_two:
6+
project_id: 1
7+
contact_id: 2
8+
9+
contact_project_three:
10+
project_id: 1
11+
contact_id: 3
12+
13+
contact_project_004:
14+
project_id: 2
15+
contact_id: 1
16+
17+
contact_project_005:
18+
project_id: 1
19+
contact_id: 4
20+
21+
contact_project_006:
22+
project_id: 1
23+
contact_id: 5
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# frozen_string_literal: true
2+
3+
require File.expand_path '../../test_helper', __FILE__
4+
5+
class ViewContactsFormDetailsBottomRenderOn < Redmine::Hook::ViewListener
6+
render_on :view_contacts_form_details_bottom, inline: '<div class="test-contacts-form">Hook content</div>'
7+
end
8+
9+
class ContactsControllerTest < Additionals::ControllerTest
10+
def setup
11+
skip 'Skip test, because redmine_servicedesk is not installed' unless AdditionalsPlugin.active_servicedesk?
12+
prepare_tests
13+
14+
# Enable contacts module for project 1
15+
project = Project.find 1
16+
project.enable_module! :contacts
17+
18+
# Add contacts permissions to Manager role
19+
manager_role = Role.find 1
20+
manager_role.add_permission! :view_contacts
21+
manager_role.add_permission! :add_contacts
22+
manager_role.add_permission! :edit_contacts
23+
end
24+
25+
def test_new_with_hook_view_contacts_form_details_bottom
26+
Redmine::Hook.add_listener ViewContactsFormDetailsBottomRenderOn
27+
@request.session[:user_id] = 2
28+
29+
get :new,
30+
params: { project_id: 1 }
31+
32+
assert_response :success
33+
assert_select 'div.test-contacts-form', text: 'Hook content'
34+
end
35+
36+
def test_edit_with_hook_view_contacts_form_details_bottom
37+
Redmine::Hook.add_listener ViewContactsFormDetailsBottomRenderOn
38+
@request.session[:user_id] = 2
39+
40+
contact = contacts :adam
41+
skip 'No contacts available for edit test' if contact.nil?
42+
43+
get :edit,
44+
params: { id: contact.id }
45+
46+
assert_response :success
47+
assert_select 'div.test-contacts-form', text: 'Hook content'
48+
end
49+
end

test/functional/issues_controller_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
require File.expand_path '../../test_helper', __FILE__
44

5+
class ViewIssueActionDropdownRenderOn < Redmine::Hook::ViewListener
6+
render_on :view_issue_action_dropdown, inline: '<span class="test-issue-action-dropdown">Hook content</span>'
7+
end
8+
9+
class ViewIssueActionMenuRenderOn < Redmine::Hook::ViewListener
10+
render_on :view_issue_action_menu, inline: '<span class="test-issue-action-menu">Hook content</span>'
11+
end
12+
513
class IssuesControllerTest < Additionals::ControllerTest
614
def setup
715
manager_role = roles :roles_001
@@ -192,4 +200,26 @@ def test_show_attachments_as_hidden
192200
assert_select 'fieldset.hide-attachments', count: 1
193201
end
194202
end
203+
204+
def test_show_with_hook_view_issue_action_dropdown
205+
Redmine::Hook.add_listener ViewIssueActionDropdownRenderOn
206+
@request.session[:user_id] = 2
207+
208+
get :show,
209+
params: { id: 1 }
210+
211+
assert_response :success
212+
assert_select 'span.test-issue-action-dropdown', text: 'Hook content'
213+
end
214+
215+
def test_show_with_hook_view_issue_action_menu
216+
Redmine::Hook.add_listener ViewIssueActionMenuRenderOn
217+
@request.session[:user_id] = 2
218+
219+
get :show,
220+
params: { id: 1 }
221+
222+
assert_response :success
223+
assert_select 'span.test-issue-action-menu', text: 'Hook content'
224+
end
195225
end

test/functional/wiki_controller_test.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
require File.expand_path '../../test_helper', __FILE__
44

5+
class ViewWikiShowActionDropdownRenderOn < Redmine::Hook::ViewListener
6+
render_on :view_wiki_show_action_dropdown, inline: '<span class="test-action-dropdown">Hook content</span>'
7+
end
8+
9+
class ViewWikiShowBottomRenderOn < Redmine::Hook::ViewListener
10+
render_on :view_wiki_show_bottom, inline: '<div class="test-wiki-bottom">Hook content</div>'
11+
end
12+
13+
class ViewWikiFormBottomRenderOn < Redmine::Hook::ViewListener
14+
render_on :view_wiki_form_bottom, inline: '<div class="test-wiki-form-bottom">Hook content</div>'
15+
end
16+
17+
class ViewWikiIndexBottomRenderOn < Redmine::Hook::ViewListener
18+
render_on :view_wiki_index_bottom, inline: '<div class="test-wiki-index-bottom">Hook content</div>'
19+
end
20+
21+
class ViewWikiDateIndexBottomRenderOn < Redmine::Hook::ViewListener
22+
render_on :view_wiki_date_index_bottom, inline: '<div class="test-wiki-date-index-bottom">Hook content</div>'
23+
end
24+
525
class WikiControllerTest < Additionals::ControllerTest
626
WIKI_MACRO_USER_ID = 2
727

@@ -10,6 +30,64 @@ def setup
1030
EnabledModule.create project_id: 1, name: 'wiki'
1131
end
1232

33+
def test_show_with_hook_view_wiki_show_action_dropdown
34+
Redmine::Hook.add_listener ViewWikiShowActionDropdownRenderOn
35+
@request.session[:user_id] = WIKI_MACRO_USER_ID
36+
page = WikiPage.generate! title: __method__.to_s
37+
38+
get :show,
39+
params: { project_id: 1, id: page.title }
40+
41+
assert_response :success
42+
assert_select 'span.test-action-dropdown', text: 'Hook content'
43+
end
44+
45+
def test_show_with_hook_view_wiki_show_bottom
46+
Redmine::Hook.add_listener ViewWikiShowBottomRenderOn
47+
@request.session[:user_id] = WIKI_MACRO_USER_ID
48+
page = WikiPage.generate! title: __method__.to_s
49+
50+
get :show,
51+
params: { project_id: 1, id: page.title }
52+
53+
assert_response :success
54+
assert_select 'div.test-wiki-bottom', text: 'Hook content'
55+
end
56+
57+
def test_edit_with_hook_view_wiki_form_bottom
58+
Redmine::Hook.add_listener ViewWikiFormBottomRenderOn
59+
@request.session[:user_id] = WIKI_MACRO_USER_ID
60+
page = WikiPage.generate! title: __method__.to_s
61+
62+
get :edit,
63+
params: { project_id: 1, id: page.title }
64+
65+
assert_response :success
66+
assert_select 'div.test-wiki-form-bottom', text: 'Hook content'
67+
end
68+
69+
def test_index_with_hook_view_wiki_index_bottom
70+
Redmine::Hook.add_listener ViewWikiIndexBottomRenderOn
71+
@request.session[:user_id] = WIKI_MACRO_USER_ID
72+
73+
get :index,
74+
params: { project_id: 1 }
75+
76+
assert_response :success
77+
assert_select 'div.test-wiki-index-bottom', text: 'Hook content'
78+
end
79+
80+
def test_date_index_with_hook_view_wiki_date_index_bottom
81+
Redmine::Hook.add_listener ViewWikiDateIndexBottomRenderOn
82+
@request.session[:user_id] = WIKI_MACRO_USER_ID
83+
84+
get :date_index,
85+
params: { project_id: 1 }
86+
87+
assert_response :success
88+
assert_select 'div.test-wiki-date-index-bottom', text: 'Hook content'
89+
end
90+
1391
def test_show_with_youtube_macro
1492
@request.session[:user_id] = WIKI_MACRO_USER_ID
1593
page = WikiPage.generate! content: '{{youtube(KMU0tzLwhbE)}}',

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module PluginFixturesLoader
5151
def plugin_fixtures_list
5252
custom = %i[dashboards dashboard_roles]
5353
custom += %i[hrm_user_types hrm_working_calendars] if AdditionalsPlugin.active_hrm?
54+
custom += %i[contacts contacts_projects] if AdditionalsPlugin.active_servicedesk?
5455
custom
5556
end
5657
end

test/unit/user_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_non_admin_should_can_not_be_admin
3030
end
3131

3232
def test_sudoer_should_can_be_admin
33-
skip 'Skip redmine_sudo test, because redmine_contacts is not installed' unless AdditionalsPlugin.active_sudo?
33+
skip 'Skip test, because redmine_sudo is not installed' unless AdditionalsPlugin.active_sudo?
3434

3535
user = users :users_001
3636
user.sudoer = true
@@ -53,7 +53,7 @@ def test_sudoer_should_can_be_admin
5353
end
5454

5555
def test_non_sudoer_without_admin_can_not_be_admin
56-
skip 'Skip redmine_sudo test, because redmine_contacts is not installed' unless AdditionalsPlugin.active_sudo?
56+
skip 'Skip test, because redmine_contacts is not installed' unless AdditionalsPlugin.active_sudo?
5757

5858
assert_not User.where(sudoer: false, admin: false).order(:id).first.can_be_admin?
5959
end

0 commit comments

Comments
 (0)