-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
app/views/redmine_drawio/hooks/_api_not_enabled_warning.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<% flash[:warning] = l(:drawio_warning_api_needs_to_be_enabled) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (C) 2022 Liane Hampe <[email protected]>, xmera. | ||
|
||
require File.expand_path('test_helper', File.dirname(__dir__)) | ||
require File.expand_path('authenticate_user', File.dirname(__dir__)) | ||
require File.expand_path('load_fixtures', File.dirname(__dir__)) | ||
require File.expand_path('with_drawio_settings', File.dirname(__dir__)) | ||
|
||
class ViewHooksTest < ActionDispatch::IntegrationTest | ||
include Redmine::I18n | ||
include RedmineDrawio::AuthenticateUser | ||
include RedmineDrawio::LoadFixtures | ||
include RedmineDrawio::WithDrawioSettings | ||
|
||
fixtures :users, :email_addresses, :roles | ||
|
||
def setup | ||
@hook = RedmineDrawio::ViewLayoutsBaseHtmlHeadHook.instance | ||
end | ||
|
||
def teardown | ||
Setting.rest_api_enabled = nil | ||
end | ||
|
||
test 'render warning_api_needs_to_be_enabled when api is disabled' do | ||
render_view_hooks(user: 'admin', password: 'admin') | ||
assert_select '#flash_warning', text: l(:drawio_warning_api_needs_to_be_enabled) | ||
end | ||
|
||
test 'do not render warning_api_needs_to_be_enabled when api is enabled' do | ||
render_view_hooks(user: 'admin', password: 'admin', rest_api_enabled: '1') | ||
assert_select '#flash_warning', 0 | ||
end | ||
|
||
test 'do not render warning_api_needs_to_be_enabled for non admin user' do | ||
render_view_hooks(user: 'jsmith', password: 'jsmith', rest_api_enabled: '1') | ||
assert_select '#flash_warning', 0 | ||
end | ||
|
||
test 'do not render hash code when api is disabled' do | ||
render_view_hooks(user: 'admin', password: 'admin') | ||
assert @hook.send(:hash_code).blank? | ||
end | ||
|
||
test 'render hash code when api is enabled' do | ||
render_view_hooks(user: 'admin', password: 'admin', rest_api_enabled: '1') | ||
assert @hook.send(:hash_code).present? | ||
end | ||
|
||
private | ||
|
||
def render_view_hooks(user:, password:, rest_api_enabled: '0') | ||
Setting.rest_api_enabled = rest_api_enabled | ||
log_user(user, password) | ||
get '/' | ||
assert_response :success | ||
end | ||
end |