summaryrefslogtreecommitdiffstats
path: root/test/functional/auto_completes_controller_test.rb
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2021-02-25 04:07:37 +0000
committerGo MAEDA <maeda@farend.jp>2021-02-25 04:07:37 +0000
commit2f3222e0bdaacae4a2d17224d61a18cb060e9031 (patch)
tree7a2cd47e7fad3318cb71674db1e9d81dd975e7b7 /test/functional/auto_completes_controller_test.rb
parent3fd832f14ceb728896bcc31293197a790298be01 (diff)
downloadredmine-2f3222e0bdaacae4a2d17224d61a18cb060e9031.tar.gz
redmine-2f3222e0bdaacae4a2d17224d61a18cb060e9031.zip
Auto complete wiki page links (#33820).
Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@20755 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/auto_completes_controller_test.rb')
-rw-r--r--test/functional/auto_completes_controller_test.rb75
1 files changed, 74 insertions, 1 deletions
diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb
index bc1f2eba1..f51ff5bf5 100644
--- a/test/functional/auto_completes_controller_test.rb
+++ b/test/functional/auto_completes_controller_test.rb
@@ -28,7 +28,8 @@ class AutoCompletesControllerTest < Redmine::ControllerTest
:member_roles,
:members,
:enabled_modules,
- :journals, :journal_details
+ :journals, :journal_details,
+ :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
def test_issues_should_not_be_case_sensitive
get(
@@ -196,4 +197,76 @@ class AutoCompletesControllerTest < Redmine::ControllerTest
assert_equal 10, json.count
assert_equal Issue.last.id, json.first['id'].to_i
end
+
+ def test_wiki_pages_should_not_be_case_sensitive
+ get(
+ :wiki_pages,
+ params: {
+ project_id: 'ecookbook',
+ q: 'pAgE'
+ }
+ )
+ assert_response :success
+ assert_include 'Page_with_an_inline_image', response.body
+ end
+
+ def test_wiki_pages_should_return_json
+ get(
+ :wiki_pages,
+ params: {
+ project_id: 'ecookbook',
+ q: 'Page_with_an_inline_image'
+ }
+ )
+ assert_response :success
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Array, json
+ issue = json.first
+ assert_kind_of Hash, issue
+ assert_equal 4, issue['id']
+ assert_equal 'Page_with_an_inline_image', issue['value']
+ assert_equal 'Page_with_an_inline_image', issue['label']
+ end
+
+ def test_wiki_pages_without_view_wiki_pages_permission_should_not_return_pages
+ Role.anonymous.remove_permission! :view_wiki_pages
+ get :wiki_pages, params: { project_id: 'ecookbook', q: 'Page_with_an_inline_image' }
+
+ assert_response :success
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_equal 0, json.count
+ end
+
+ def test_wiki_pages_without_project_id_params_should_not_return_pages
+ get :wiki_pages, params: { project_id: '' }
+ assert_response :success
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_equal 0, json.count
+ end
+
+ def test_wiki_pages_should_return_json_content_type_response
+ get(
+ :wiki_pages,
+ params: {
+ project_id: 'ecookbook',
+ q: 'Page_with_an_inline_image'
+ }
+ )
+ assert_response :success
+ assert_include 'application/json', response.headers['Content-Type']
+ end
+
+ def test_wiki_pages_without_q_params_should_return_last_10_pages
+ # There are 8 pages generated by fixtures
+ # and we need three more to test the 10 limit
+ wiki = Wiki.find_by(project: Project.first)
+ 3.times do |n|
+ WikiPage.create(wiki: wiki, title: "test#{n}")
+ end
+ get :wiki_pages, params: { project_id: 'ecookbook' }
+ assert_response :success
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_equal 10, json.count
+ assert_equal wiki.pages[-2].id, json.first['id'].to_i
+ end
end