diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-08 09:13:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-08 09:13:33 +0300 |
commit | 9fe6f84c1fd4bb8cb6b8ec466ee59c76aff0dad5 (patch) | |
tree | 22b2a39d3b57b44616483868a82f1b0af4392c90 | |
parent | 2e2957367a311963930ea30bc2087a3018772fba (diff) |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | .gitlab/CODEOWNERS | 10 | ||||
-rw-r--r-- | .gitlab/ci/rails.gitlab-ci.yml | 16 | ||||
-rw-r--r-- | app/models/users/credit_card_validation.rb | 4 | ||||
-rw-r--r-- | app/models/wiki.rb | 96 | ||||
-rw-r--r-- | app/views/shared/issuable/_sidebar_assignees.html.haml | 2 | ||||
-rw-r--r-- | config/feature_flags/development/update_legacy_slack_installations.yml | 8 | ||||
-rw-r--r-- | config/feature_flags/development/wiki_find_page_with_normal_repository_rpcs.yml | 8 | ||||
-rw-r--r-- | lib/gitlab/git/wiki.rb | 24 | ||||
-rw-r--r-- | lib/gitlab/git/wiki_page.rb | 34 | ||||
-rw-r--r-- | qa/Gemfile.lock | 2 | ||||
-rw-r--r-- | qa/qa/page/merge_request/show.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/git/wiki_spec.rb | 63 | ||||
-rw-r--r-- | spec/models/users/credit_card_validation_spec.rb | 24 | ||||
-rw-r--r-- | spec/services/git/wiki_push_service_spec.rb | 32 | ||||
-rw-r--r-- | spec/support/shared_examples/models/wiki_shared_examples.rb | 162 |
15 files changed, 354 insertions, 133 deletions
diff --git a/.gitlab/CODEOWNERS b/.gitlab/CODEOWNERS index 2ba4d6835c5..64feb4c7d55 100644 --- a/.gitlab/CODEOWNERS +++ b/.gitlab/CODEOWNERS @@ -11,9 +11,11 @@ docs/CODEOWNERS @clefelhocz1 @timzallmann @cdu1 @whaber @dsatcher @sgoldstein @j ## Allows release tooling to update the Gitaly Version GITALY_SERVER_VERSION @project_278964_bot6 @gitlab-org/maintainers/rails-backend @gitlab-org/delivery -## Excludes documentation markdown file changes from required approval +## Excludes documentation markdown files and deprecation/removal announcements from required approval /doc/*.md /doc/**/*.md +/data/deprecations/ +/data/removals/ ^[Backend] *.rb @gitlab-org/maintainers/rails-backend @@ -290,10 +292,10 @@ ee/lib/ee/gitlab/checks/** @proglottis @toon @zj-gitlab lib/gitlab/checks/** @proglottis @toon @zj-gitlab ^[Documentation Directories] -.markdownlint.yml @marcel.amirault @eread @aqualls @dianalogan -/doc/.markdownlint @marcel.amirault @eread @aqualls @dianalogan +.markdownlint.yml @marcel.amirault @eread @aqualls @dianalogan @kpaizee +/doc/.markdownlint @marcel.amirault @eread @aqualls @dianalogan @kpaizee /doc/ @gl-docsteam -/doc/.vale/ @marcel.amirault @eread @aqualls @dianalogan +/doc/.vale/ @marcel.amirault @eread @aqualls @dianalogan @kpaizee ^[Documentation Pages] /doc/administration/application_settings_cache.md @sselhorn diff --git a/.gitlab/ci/rails.gitlab-ci.yml b/.gitlab/ci/rails.gitlab-ci.yml index 9b8eb5571a7..5235db776a8 100644 --- a/.gitlab/ci/rails.gitlab-ci.yml +++ b/.gitlab/ci/rails.gitlab-ci.yml @@ -131,28 +131,28 @@ ############################ # rspec job parallel configs .rspec-migration-parallel: - parallel: 9 + parallel: 12 .rspec-ee-migration-parallel: - parallel: 3 + parallel: 4 .rspec-unit-parallel: - parallel: 22 + parallel: 28 .rspec-ee-unit-parallel: - parallel: 16 + parallel: 18 .rspec-integration-parallel: - parallel: 10 + parallel: 12 .rspec-ee-integration-parallel: - parallel: 4 + parallel: 6 .rspec-system-parallel: - parallel: 24 + parallel: 28 .rspec-ee-system-parallel: - parallel: 6 + parallel: 10 # rspec job parallel configs ############################ diff --git a/app/models/users/credit_card_validation.rb b/app/models/users/credit_card_validation.rb index 6f1cadb4344..272f31aa9ce 100644 --- a/app/models/users/credit_card_validation.rb +++ b/app/models/users/credit_card_validation.rb @@ -23,7 +23,9 @@ module Users end def similar_holder_names_count - self.class.where('lower(holder_name) = :value', value: holder_name.downcase).count + return 0 unless holder_name + + self.class.where('lower(holder_name) = lower(:value)', value: holder_name).count end end end diff --git a/app/models/wiki.rb b/app/models/wiki.rb index d28a73b644f..fac79a8194a 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -103,6 +103,17 @@ class Wiki def find_by_id(container_id) container_class.find_by_id(container_id)&.wiki end + + def sluggified_full_path(title, extension) + sluggified_title(title) + '.' + extension + end + + def sluggified_title(title) + title = Gitlab::EncodingHelper.encode_utf8_no_detect(title) + title = File.expand_path(title, '/') + title = Pathname.new(title).relative_path_from('/').to_s + title.tr(' ', '-') + end end def initialize(container, user = nil) @@ -206,10 +217,11 @@ class Wiki # # Returns an initialized WikiPage instance or nil def find_page(title, version = nil, load_content: true) - page_title, page_dir = page_title_and_dir(title) - - if page = wiki.page(title: page_title, version: version, dir: page_dir, load_content: load_content) - WikiPage.new(self, page) + if find_page_with_repository_rpcs? + create_wiki_repository unless repository_exists? + find_page_with_repository_rpcs(title, version, load_content: load_content) + else + find_page_with_legacy_wiki_service(title, version, load_content: load_content) end end @@ -419,19 +431,83 @@ class Wiki end def sluggified_full_path(title, extension) - sluggified_title(title) + '.' + extension + self.class.sluggified_full_path(title, extension) end def sluggified_title(title) - utf8_encoded_title = Gitlab::EncodingHelper.encode_utf8_no_detect(title) + self.class.sluggified_title(title) + end - sanitized_title(utf8_encoded_title).tr(' ', '-') + def canonicalize_filename(filename) + Gitlab::Git::Wiki::GollumSlug.canonicalize_filename(filename) end - def sanitized_title(title) - clean_absolute_path = File.expand_path(title, '/') + def find_page_with_legacy_wiki_service(title, version, load_content: false) + page_title, page_dir = page_title_and_dir(title) + + if page = wiki.page(title: page_title, version: version, dir: page_dir, load_content: load_content) + WikiPage.new(self, page) + end + end + + def find_matched_file(title, version) + escaped_path = RE2::Regexp.escape(sluggified_title(title)) + # We could not use ALLOWED_EXTENSIONS_REGEX constant or similar regexp with + # Regexp.union. The result combination complicated modifiers: + # /(?i-mx:md|mkdn?|mdown|markdown)|(?i-mx:rdoc).../ + # Regexp used by Gitaly is Go's Regexp package. It does not support those + # features. So, we have to compose another more-friendly regexp to pass to + # Gitaly side. + extension_regexp = Wiki::MARKUPS.map { |_, format| format[:extension_regex].source }.join("|") + path_regexp = Gitlab::EncodingHelper.encode_utf8_no_detect("(?i)^#{escaped_path}\\.(#{extension_regexp})$") + + matched_files = repository.search_files_by_regexp(path_regexp, version) + return if matched_files.blank? + + Gitlab::EncodingHelper.encode_utf8_no_detect(matched_files.first) + end + + def find_page_format(path) + ext = File.extname(path).downcase[1..] + MARKUPS.find { |_, markup| markup[:extension_regex].match?(ext) }&.first + end + + def check_page_historical(path, commit) + repository.last_commit_for_path('HEAD', path).id != commit.id + end + + def find_page_with_repository_rpcs(title, version, load_content: true) + version = version.presence || 'HEAD' + path = find_matched_file(title, version) + return if path.blank? + + blob_options = load_content ? {} : { limit: 0 } + blob = repository.blob_at(version, path, **blob_options) + commit = repository.commit(blob.commit_id) + format = find_page_format(path) + + page = Gitlab::Git::WikiPage.new( + url_path: sluggified_title(path.sub(/\.[^.]+\z/, "")), + title: canonicalize_filename(path), + format: format, + path: sluggified_title(path), + raw_data: blob.data, + name: canonicalize_filename(path), + historical: version == 'HEAD' ? false : check_page_historical(path, commit), + version: Gitlab::Git::WikiPageVersion.new(commit, format) + ) + WikiPage.new(self, page) + end + + def find_page_with_repository_rpcs? + group = + if container.is_a?(::Group) + container + else + container.group + end - Pathname.new(clean_absolute_path).relative_path_from('/').to_s + Feature.enabled?(:wiki_find_page_with_normal_repository_rpcs, group, type: :development) end end diff --git a/app/views/shared/issuable/_sidebar_assignees.html.haml b/app/views/shared/issuable/_sidebar_assignees.html.haml index 2fd4c598580..e9b04579808 100644 --- a/app/views/shared/issuable/_sidebar_assignees.html.haml +++ b/app/views/shared/issuable/_sidebar_assignees.html.haml @@ -6,7 +6,7 @@ max_assignees: dropdown_options[:data][:"max-select"], directly_invite_members: can_admin_project_member?(@project) } } .title.hide-collapsed - = _('Assignee') + = s_('Label|Assignee') = gl_loading_icon(inline: true) .js-sidebar-assignee-data.selectbox.hide-collapsed diff --git a/config/feature_flags/development/update_legacy_slack_installations.yml b/config/feature_flags/development/update_legacy_slack_installations.yml new file mode 100644 index 00000000000..0ec42b1859f --- /dev/null +++ b/config/feature_flags/development/update_legacy_slack_installations.yml @@ -0,0 +1,8 @@ +--- +name: update_legacy_slack_installations +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/96208 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/371810 +milestone: '15.4' +type: development +group: group::integrations +default_enabled: false diff --git a/config/feature_flags/development/wiki_find_page_with_normal_repository_rpcs.yml b/config/feature_flags/development/wiki_find_page_with_normal_repository_rpcs.yml new file mode 100644 index 00000000000..bad0578d50a --- /dev/null +++ b/config/feature_flags/development/wiki_find_page_with_normal_repository_rpcs.yml @@ -0,0 +1,8 @@ +--- +name: wiki_find_page_with_normal_repository_rpcs +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/95897 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/371487 +milestone: '15.4' +type: development +group: group::gitaly +default_enabled: false diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index 4bab94968d7..2228fcb886e 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -70,18 +70,6 @@ module Gitlab @repository.exists? end - def write_page(name, format, content, commit_details) - wrapped_gitaly_errors do - gitaly_write_page(name, format, content, commit_details) - end - end - - def update_page(page_path, title, format, content, commit_details) - wrapped_gitaly_errors do - gitaly_update_page(page_path, title, format, content, commit_details) - end - end - def list_pages(limit: 0, sort: nil, direction_desc: false, load_content: false) wrapped_gitaly_errors do gitaly_list_pages( @@ -113,21 +101,13 @@ module Gitlab @gitaly_wiki_client ||= Gitlab::GitalyClient::WikiService.new(@repository) end - def gitaly_write_page(name, format, content, commit_details) - gitaly_wiki_client.write_page(name, format, content, commit_details) - end - - def gitaly_update_page(page_path, title, format, content, commit_details) - gitaly_wiki_client.update_page(page_path, title, format, content, commit_details) - end - def gitaly_find_page(title:, version: nil, dir: nil, load_content: true) return unless title.present? wiki_page, version = gitaly_wiki_client.find_page(title: title, version: version, dir: dir, load_content: load_content) return unless wiki_page - Gitlab::Git::WikiPage.new(wiki_page, version) + Gitlab::Git::WikiPage.from_gitaly_wiki_page(wiki_page, version) rescue GRPC::InvalidArgument nil end @@ -143,7 +123,7 @@ module Gitlab end gitaly_pages.map do |wiki_page, version| - Gitlab::Git::WikiPage.new(wiki_page, version) + Gitlab::Git::WikiPage.from_gitaly_wiki_page(wiki_page, version) end end end diff --git a/lib/gitlab/git/wiki_page.rb b/lib/gitlab/git/wiki_page.rb index a1f3d64ccde..57b7e7d53dd 100644 --- a/lib/gitlab/git/wiki_page.rb +++ b/lib/gitlab/git/wiki_page.rb @@ -5,17 +5,31 @@ module Gitlab class WikiPage attr_reader :url_path, :title, :format, :path, :version, :raw_data, :name, :historical, :formatted_data - # This class abstracts away Gitlab::GitalyClient::WikiPage - def initialize(gitaly_page, version) - @url_path = gitaly_page.url_path - @title = gitaly_page.title - @format = gitaly_page.format - @path = gitaly_page.path - @raw_data = gitaly_page.raw_data - @name = gitaly_page.name - @historical = gitaly_page.historical? + class << self + # Abstracts away Gitlab::GitalyClient::WikiPage + def from_gitaly_wiki_page(gitaly_page, version) + new( + url_path: gitaly_page.url_path, + title: gitaly_page.title, + format: gitaly_page.format, + path: gitaly_page.path, + raw_data: gitaly_page.raw_data, + name: gitaly_page.name, + historical: gitaly_page.historical?, + version: version + ) + end + end - @version = version + def initialize(hash) + @url_path = hash[:url_path] + @title = hash[:title] + @format = hash[:format] + @path = hash[:path] + @raw_data = hash[:raw_data] + @name = hash[:name] + @historical = hash[:historical] + @version = hash[:version] end def historical? diff --git a/qa/Gemfile.lock b/qa/Gemfile.lock index 741619a2532..dd14b675769 100644 --- a/qa/Gemfile.lock +++ b/qa/Gemfile.lock @@ -118,7 +118,7 @@ GEM gitlab (4.18.0) httparty (~> 0.18) terminal-table (>= 1.5.1) - gitlab-qa (8.4.1) + gitlab-qa (8.4.2) activesupport (~> 6.1) gitlab (~> 4.18.0) http (~> 5.0) diff --git a/qa/qa/page/merge_request/show.rb b/qa/qa/page/merge_request/show.rb index 9fc0cf0ccf8..2587241ed18 100644 --- a/qa/qa/page/merge_request/show.rb +++ b/qa/qa/page/merge_request/show.rb @@ -363,7 +363,7 @@ module QA # Revisit after merge page re-architect is done https://gitlab.com/gitlab-org/gitlab/-/issues/300042 # To remove page refresh logic if possible wait_until_ready_to_merge - wait_until { !find_element(:merge_button).has_text?("when pipeline succeeds") } + wait_until { !find_element(:merge_button).text.include?('when pipeline succeeds') } click_element(:merge_button) end diff --git a/spec/lib/gitlab/git/wiki_spec.rb b/spec/lib/gitlab/git/wiki_spec.rb index dddcf8c40fc..05c7ac149e4 100644 --- a/spec/lib/gitlab/git/wiki_spec.rb +++ b/spec/lib/gitlab/git/wiki_spec.rb @@ -8,9 +8,15 @@ RSpec.describe Gitlab::Git::Wiki do let(:project) { create(:project) } let(:user) { project.first_owner } let(:project_wiki) { ProjectWiki.new(project, user) } + let(:repository) { project_wiki.repository } + let(:default_branch) { described_class.default_ref(project) } subject(:wiki) { project_wiki.wiki } + before do + repository.create_if_not_exists(project_wiki.default_branch) + end + describe '#pages' do before do create_page('page1', 'content') @@ -44,7 +50,7 @@ RSpec.describe Gitlab::Git::Wiki do after do destroy_page('page1') - destroy_page('page1', 'foo') + destroy_page('foo/page1') end it 'returns the right page' do @@ -71,20 +77,20 @@ RSpec.describe Gitlab::Git::Wiki do end describe '#preview_slug' do - where(:title, :format, :expected_slug) do - 'The Best Thing' | :markdown | 'The-Best-Thing' - 'The Best Thing' | :md | 'The-Best-Thing' - 'The Best Thing' | :txt | 'The-Best-Thing' - 'A Subject/Title Here' | :txt | 'A-Subject/Title-Here' - 'A subject' | :txt | 'A-subject' - 'A 1/B 2/C 3' | :txt | 'A-1/B-2/C-3' - 'subject/title' | :txt | 'subject/title' - 'subject/title.md' | :txt | 'subject/title.md' - 'foo<bar>+baz' | :txt | 'foo-bar--baz' - 'foo%2Fbar' | :txt | 'foo%2Fbar' - '' | :markdown | '.md' - '' | :md | '.md' - '' | :txt | '.txt' + where(:title, :file_extension, :format, :expected_slug) do + 'The Best Thing' | :md | :markdown | 'The-Best-Thing' + 'The Best Thing' | :md | :md | 'The-Best-Thing' + 'The Best Thing' | :txt | :txt | 'The-Best-Thing' + 'A Subject/Title Here' | :txt | :txt | 'A-Subject/Title-Here' + 'A subject' | :txt | :txt | 'A-subject' + 'A 1/B 2/C 3' | :txt | :txt | 'A-1/B-2/C-3' + 'subject/title' | :txt | :txt | 'subject/title' + 'subject/title.md' | :txt | :txt | 'subject/title.md' + 'foo<bar>+baz' | :txt | :txt | 'foo-bar--baz' + 'foo%2Fbar' | :txt | :txt | 'foo%2Fbar' + '' | :md | :markdown | '.md' + '' | :md | :md | '.md' + '' | :txt | :txt | '.txt' end with_them do @@ -97,7 +103,7 @@ RSpec.describe Gitlab::Git::Wiki do it 'matches the slug generated by gitaly' do skip('Gitaly cannot generate a slug for an empty title') unless title.present? - create_page(title, 'content', format: format) + create_page(title, 'content', file_extension) gitaly_slug = wiki.list_pages.first.url_path @@ -106,16 +112,23 @@ RSpec.describe Gitlab::Git::Wiki do end end - def create_page(name, content, format: :markdown) - wiki.write_page(name, format, content, commit_details(name)) - end - - def commit_details(name) - Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}") + def create_page(name, content, extension = :md) + repository.create_file( + user, ::Wiki.sluggified_full_path(name, extension.to_s), content, + branch_name: default_branch, + message: "created page #{name}", + author_email: user.email, + author_name: user.name + ) end - def destroy_page(title, dir = '') - page = wiki.page(title: title, dir: dir) - project_wiki.delete_page(page, "test commit") + def destroy_page(name, extension = :md) + repository.delete_file( + user, ::Wiki.sluggified_full_path(name, extension.to_s), + branch_name: described_class.default_ref(project), + message: "delete page #{name}", + author_email: user.email, + author_name: user.name + ) end end diff --git a/spec/models/users/credit_card_validation_spec.rb b/spec/models/users/credit_card_validation_spec.rb index c003e004d29..58b529ff18a 100644 --- a/spec/models/users/credit_card_validation_spec.rb +++ b/spec/models/users/credit_card_validation_spec.rb @@ -29,14 +29,26 @@ RSpec.describe Users::CreditCardValidation do end end - describe '.similar_holder_names_count' do - subject!(:credit_card_validation) { create(:credit_card_validation, holder_name: 'ALICE M SMITH') } + describe '#similar_holder_names_count' do + subject!(:credit_card_validation) { create(:credit_card_validation, holder_name: holder_name) } - let!(:match) { create(:credit_card_validation, holder_name: 'Alice M Smith') } - let!(:non_match) { create(:credit_card_validation, holder_name: 'Bob B Brown') } + context 'when holder_name is present' do + let(:holder_name) { 'ALICE M SMITH' } - it 'returns the count of cards with similar case insensitive holder names' do - expect(subject.similar_holder_names_count).to eq(2) + let!(:match) { create(:credit_card_validation, holder_name: 'Alice M Smith') } + let!(:non_match) { create(:credit_card_validation, holder_name: 'Bob B Brown') } + + it 'returns the count of cards with similar case insensitive holder names' do + expect(subject.similar_holder_names_count).to eq(2) + end + end + + context 'when holder_name is nil' do + let(:holder_name) { nil } + + it 'returns 0' do + expect(subject.similar_holder_names_count).to eq(0) + end end end end diff --git a/spec/services/git/wiki_push_service_spec.rb b/spec/services/git/wiki_push_service_spec.rb index 7e5d7066e89..878a5c4ccf0 100644 --- a/spec/services/git/wiki_push_service_spec.rb +++ b/spec/services/git/wiki_push_service_spec.rb @@ -9,9 +9,13 @@ RSpec.describe Git::WikiPushService, services: true do let_it_be(:key_id) { create(:key, user: current_user).shell_id } let(:wiki) { create(:project_wiki, user: current_user) } - let(:git_wiki) { wiki.wiki } + let(:default_branch) { wiki.default_branch } let(:repository) { wiki.repository } + before do + repository.create_if_not_exists(default_branch) + end + describe '#execute' do it 'executes model-specific callbacks' do expect(wiki).to receive(:after_post_receive) @@ -351,7 +355,12 @@ RSpec.describe Git::WikiPushService, services: true do # that have not gone through our services. def write_new_page - generate(:wiki_page_title).tap { |t| git_wiki.write_page(t, 'markdown', 'Hello', commit_details) } + generate(:wiki_page_title).tap do |t| + repository.create_file( + current_user, ::Wiki.sluggified_full_path(t, 'md'), 'Hello', + **commit_details + ) + end end # We write something to the wiki-repo that is not a page - as, for example, an @@ -368,15 +377,26 @@ RSpec.describe Git::WikiPushService, services: true do def update_page(title, new_title = nil) new_title = title unless new_title.present? - page = git_wiki.page(title: title) - git_wiki.update_page(page.path, new_title, 'markdown', 'Hey', commit_details) + + old_path = ::Wiki.sluggified_full_path(title, 'md') + new_path = ::Wiki.sluggified_full_path(new_title, 'md') + + repository.update_file( + current_user, new_path, 'Hey', + **commit_details.merge(previous_path: old_path) + ) end def delete_page(page) - wiki.delete_page(page, 'commit message') + repository.delete_file(current_user, page.path, **commit_details) end def commit_details - create(:git_wiki_commit_details, author: current_user) + { + branch_name: default_branch, + message: "commit message", + author_email: current_user.email, + author_name: current_user.name + } end end diff --git a/spec/support/shared_examples/models/wiki_shared_examples.rb b/spec/support/shared_examples/models/wiki_shared_examples.rb index 604c57768fe..5f6a10bd754 100644 --- a/spec/support/shared_examples/models/wiki_shared_examples.rb +++ b/spec/support/shared_examples/models/wiki_shared_examples.rb @@ -286,67 +286,134 @@ RSpec.shared_examples 'wiki model' do end describe '#find_page' do - before do - subject.create_page('index page', 'This is an awesome Gollum Wiki') - end + shared_examples 'wiki model #find_page' do + before do + subject.create_page('index page', 'This is an awesome Gollum Wiki') + end - it 'returns the latest version of the page if it exists' do - page = subject.find_page('index page') + it 'returns the latest version of the page if it exists' do + page = subject.find_page('index page') - expect(page.title).to eq('index page') - end + expect(page.title).to eq('index page') + end - it 'returns nil if the page or version does not exist' do - expect(subject.find_page('non-existent')).to be_nil - expect(subject.find_page('index page', 'non-existent')).to be_nil - end + it 'returns nil if the page or version does not exist' do + expect(subject.find_page('non-existent')).to be_nil + expect(subject.find_page('index page', 'non-existent')).to be_nil + end - it 'can find a page by slug' do - page = subject.find_page('index-page') + it 'can find a page by slug' do + page = subject.find_page('index-page') - expect(page.title).to eq('index page') - end + expect(page.title).to eq('index page') + end - it 'returns a WikiPage instance' do - page = subject.find_page('index page') + it 'returns a WikiPage instance' do + page = subject.find_page('index page') - expect(page).to be_a WikiPage - end + expect(page).to be_a WikiPage + end - context 'pages with multibyte-character title' do - before do - subject.create_page('autre pagé', "C'est un génial Gollum Wiki") + context 'pages with multibyte-character title' do + before do + subject.create_page('autre pagé', "C'est un génial Gollum Wiki") + end + + it 'can find a page by slug' do + page = subject.find_page('autre pagé') + + expect(page.title).to eq('autre pagé') + end end - it 'can find a page by slug' do - page = subject.find_page('autre pagé') + context 'pages with invalidly-encoded content' do + before do + subject.create_page('encoding is fun', "f\xFCr".b) + end + + it 'can find the page' do + page = subject.find_page('encoding is fun') + + expect(page.content).to eq('fr') + end + end + + context 'pages with different file extensions' do + where(:extension, :path, :title) do + [ + [:md, "wiki-markdown.md", "wiki markdown"], + [:markdown, "wiki-markdown-2.md", "wiki markdown 2"], + [:rdoc, "wiki-rdoc.rdoc", "wiki rdoc"], + [:asciidoc, "wiki-asciidoc.asciidoc", "wiki asciidoc"], + [:adoc, "wiki-asciidoc-2.adoc", "wiki asciidoc 2"], + [:org, "wiki-org.org", "wiki org"], + [:textile, "wiki-textile.textile", "wiki textile"], + [:creole, "wiki-creole.creole", "wiki creole"], + [:rest, "wiki-rest.rest", "wiki rest"], + [:rst, "wiki-rest-2.rst", "wiki rest 2"], + [:mediawiki, "wiki-mediawiki.mediawiki", "wiki mediawiki"], + [:wiki, "wiki-mediawiki-2.wiki", "wiki mediawiki 2"], + [:pod, "wiki-pod.pod", "wiki pod"], + [:text, "wiki-text.txt", "wiki text"] + ] + end - expect(page.title).to eq('autre pagé') + with_them do + before do + wiki.repository.create_file( + user, path, "content of wiki file", + branch_name: wiki.default_branch, + message: "created page #{path}", + author_email: user.email, + author_name: user.name + ) + end + + it "can find page with #{params[:extension]} extension" do + page = subject.find_page(title) + + expect(page.content).to eq("content of wiki file") + end + end end end - context 'pages with invalidly-encoded content' do + context 'find page with legacy wiki service' do before do - subject.create_page('encoding is fun', "f\xFCr".b) + stub_feature_flags(wiki_find_page_with_normal_repository_rpcs: false) end - it 'can find the page' do - page = subject.find_page('encoding is fun') + it_behaves_like 'wiki model #find_page' + end - expect(page.content).to eq('fr') - end + context 'find page with normal repository RPCs' do + it_behaves_like 'wiki model #find_page' end end describe '#find_sidebar' do - before do - subject.create_page(described_class::SIDEBAR, 'This is an awesome Sidebar') + shared_examples 'wiki model #find_sidebar' do + before do + subject.create_page(described_class::SIDEBAR, 'This is an awesome Sidebar') + end + + it 'finds the page defined as _sidebar' do + page = subject.find_sidebar + + expect(page.content).to eq('This is an awesome Sidebar') + end end - it 'finds the page defined as _sidebar' do - page = subject.find_sidebar + context 'find sidebar with legacy wiki service' do + before do + stub_feature_flags(wiki_find_page_with_normal_repository_rpcs: false) + end - expect(page.content).to eq('This is an awesome Sidebar') + it_behaves_like 'wiki model #find_sidebar' + end + + context 'find sidebar with normal repository RPCs' do + it_behaves_like 'wiki model #find_sidebar' end end @@ -450,9 +517,7 @@ RSpec.shared_examples 'wiki model' do expect(subject.error_message).to match(/Duplicate page:/) end - end - it_behaves_like 'create_page tests' do it 'returns false if a page exists already in the repository', :aggregate_failures do subject.create_page('test page', 'content') @@ -540,6 +605,16 @@ RSpec.shared_examples 'wiki model' do end end end + + it_behaves_like 'create_page tests' + + context 'create page with legacy find_page wiki service' do + it_behaves_like 'create_page tests' do + before do + stub_feature_flags(wiki_find_page_with_normal_repository_rpcs: false) + end + end + end end describe '#update_page' do @@ -636,6 +711,17 @@ RSpec.shared_examples 'wiki model' do include_context 'extended examples' end + context 'update page with legacy find_page wiki service' do + it_behaves_like 'update_page tests' do + before do + stub_feature_flags(wiki_find_page_with_normal_repository_rpcs: false) + end + + include_context 'common examples' + include_context 'extended examples' + end + end + context 'when format is invalid' do let!(:page) { create(:wiki_page, wiki: subject, title: 'test page') } |