Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-18 18:10:37 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-18 18:10:37 +0300
commitb556d0fab74a7ef460d868e508ea5ca72d0e5eed (patch)
treed0e0dce2c15d056b37e0fdd9495d754cffe2f7ef /spec
parenta300f4d5c7fdd5d557288ee526986e0adb683b35 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/mailers/emails/profile_spec.rb4
-rw-r--r--spec/requests/api/users_spec.rb22
-rw-r--r--spec/scripts/lib/glfm/update_example_snapshots_spec.rb10
-rw-r--r--spec/scripts/lib/glfm/update_specification_spec.rb106
-rw-r--r--spec/services/boards/lists/list_service_spec.rb34
-rw-r--r--spec/support/shared_examples/models/boards/listable_shared_examples.rb8
6 files changed, 157 insertions, 27 deletions
diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb
index 073d8aee842..767eddb7f98 100644
--- a/spec/mailers/emails/profile_spec.rb
+++ b/spec/mailers/emails/profile_spec.rb
@@ -404,7 +404,7 @@ RSpec.describe Emails::Profile do
end
it 'includes a link to the change password documentation' do
- is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/#changing-your-password'
+ is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/user_passwords.html#change-your-password'
end
it 'mentions two factor authentication when two factor is not enabled' do
@@ -454,7 +454,7 @@ RSpec.describe Emails::Profile do
end
it 'includes a link to the change password documentation' do
- is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/#changing-your-password'
+ is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/user_passwords.html#change-your-password'
end
end
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 7acbd12cae9..1b0a27e78e3 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -165,6 +165,7 @@ RSpec.describe API::Users do
expect(json_response.first).not_to have_key('note')
expect(json_response.first).not_to have_key('namespace_id')
+ expect(json_response.first).not_to have_key('created_by')
end
end
@@ -175,6 +176,7 @@ RSpec.describe API::Users do
expect(json_response.first).not_to have_key('note')
expect(json_response.first).not_to have_key('namespace_id')
+ expect(json_response.first).not_to have_key('created_by')
end
end
@@ -186,6 +188,26 @@ RSpec.describe API::Users do
expect(json_response.first).to have_key('note')
expect(json_response.first['note']).to eq '2018-11-05 | 2FA removed | user requested | www.gitlab.com'
end
+
+ context 'with `created_by` details' do
+ it 'has created_by as nil with a self-registered account' do
+ get api("/users", admin), params: { username: user.username }
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(json_response.first).to have_key('created_by')
+ expect(json_response.first['created_by']).to eq(nil)
+ end
+
+ it 'is created_by a user and has those details' do
+ created = create(:user, created_by_id: user.id)
+
+ get api("/users", admin), params: { username: created.username }
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(json_response.first['created_by'].symbolize_keys)
+ .to eq(API::Entities::UserBasic.new(user).as_json)
+ end
+ end
end
context 'N+1 queries' do
diff --git a/spec/scripts/lib/glfm/update_example_snapshots_spec.rb b/spec/scripts/lib/glfm/update_example_snapshots_spec.rb
index 04f6c455e03..c97226c1a2d 100644
--- a/spec/scripts/lib/glfm/update_example_snapshots_spec.rb
+++ b/spec/scripts/lib/glfm/update_example_snapshots_spec.rb
@@ -2,8 +2,8 @@
require 'fast_spec_helper'
require_relative '../../../../scripts/lib/glfm/update_example_snapshots'
-# IMPORTANT NOTE: See https://docs.gitlab.com/ee/development/gitlab_flavored_markdown/specification_guide/
-# for details on the implementation and usage of the `update_example_snapshots` script being tested.
+# IMPORTANT NOTE: See https://docs.gitlab.com/ee/development/gitlab_flavored_markdown/specification_guide/#update-example-snapshotsrb-script
+# for details on the implementation and usage of the `update_example_snapshots.rb` script being tested.
# This developers guide contains diagrams and documentation of the script,
# including explanations and examples of all files it reads and writes.
#
@@ -16,11 +16,11 @@ require_relative '../../../../scripts/lib/glfm/update_example_snapshots'
# which runs a jest test environment. This results in each full run of the script
# taking between 30-60 seconds. The majority of this is spent loading the Rails environment.
#
-# However, only the `writing html.yml and prosemirror_json.yml` context is used
-# to test these slow sub-processes, and it only contains a single example.
+# However, only the `with full processing of static and WYSIWYG HTML` context is used
+# to test these slow sub-processes, and it only contains two examples.
#
# All other tests currently in the file pass the `skip_static_and_wysiwyg: true`
-# flag to `#process`, which skips the slow sub-processes. All of these tests
+# flag to `#process`, which skips the slow sub-processes. All of these other tests
# should run in sub-second time when the Spring pre-loader is used. This allows
# logic which is not directly related to the slow sub-processes to be TDD'd with a
# very rapid feedback cycle.
diff --git a/spec/scripts/lib/glfm/update_specification_spec.rb b/spec/scripts/lib/glfm/update_specification_spec.rb
index d13cc3f19eb..852b2b580e6 100644
--- a/spec/scripts/lib/glfm/update_specification_spec.rb
+++ b/spec/scripts/lib/glfm/update_specification_spec.rb
@@ -4,12 +4,35 @@ require 'fast_spec_helper'
require_relative '../../../../scripts/lib/glfm/update_specification'
require_relative '../../../support/helpers/next_instance_of'
+# IMPORTANT NOTE: See https://docs.gitlab.com/ee/development/gitlab_flavored_markdown/specification_guide/#update-specificationrb-script
+# for details on the implementation and usage of the `update_specification.rb` script being tested.
+# This developers guide contains diagrams and documentation of the script,
+# including explanations and examples of all files it reads and writes.
+#
+# Note that this test is not structured in a traditional way, with multiple examples
+# to cover all different scenarios. Instead, the content of the stubbed test fixture
+# files are crafted to cover multiple scenarios with in a single example run.
+#
+# This is because the invocation of the full script is slow, because it executes
+# a subshell for processing, which runs a full Rails environment.
+# This results in each full run of the script taking between 30-60 seconds.
+# The majority of this is spent loading the Rails environment.
+#
+# However, only the `with generation of spec.html` context is used
+# to test this slow sub-process, and it only contains one example.
+#
+# All other tests currently in the file pass the `skip_spec_html_generation: true`
+# flag to `#process`, which skips the slow sub-process. All of these other tests
+# should run in sub-second time when the Spring pre-loader is used. This allows
+# logic which is not directly related to the slow sub-processes to be TDD'd with a
+# very rapid feedback cycle.
RSpec.describe Glfm::UpdateSpecification, '#process' do
include NextInstanceOf
subject { described_class.new }
let(:ghfm_spec_txt_uri) { described_class::GHFM_SPEC_TXT_URI }
+ let(:ghfm_spec_txt_uri_parsed) { instance_double(URI::HTTPS, :ghfm_spec_txt_uri_parsed) }
let(:ghfm_spec_txt_uri_io) { StringIO.new(ghfm_spec_txt_contents) }
let(:ghfm_spec_md_path) { described_class::GHFM_SPEC_MD_PATH }
let(:ghfm_spec_txt_local_io) { StringIO.new(ghfm_spec_txt_contents) }
@@ -22,6 +45,9 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
let(:glfm_internal_extension_examples_md_io) { StringIO.new(glfm_internal_extension_examples_md_contents) }
let(:glfm_spec_txt_path) { described_class::GLFM_SPEC_TXT_PATH }
let(:glfm_spec_txt_io) { StringIO.new }
+ let(:glfm_spec_html_path) { described_class::GLFM_SPEC_HTML_PATH }
+ let(:glfm_spec_html_io) { StringIO.new }
+ let(:markdown_tempfile_io) { StringIO.new }
let(:ghfm_spec_txt_contents) do
<<~MARKDOWN
@@ -93,9 +119,10 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
# We mock out the URI and local file IO objects with real StringIO, instead of just mock
# objects. This gives better and more realistic coverage, while still avoiding
# actual network and filesystem I/O during the spec run.
- allow_next_instance_of(URI::HTTP) do |instance|
- allow(instance).to receive(:open).and_return(ghfm_spec_txt_uri_io)
- end
+
+ # input files
+ allow(URI).to receive(:parse).with(ghfm_spec_txt_uri).and_return(ghfm_spec_txt_uri_parsed)
+ allow(ghfm_spec_txt_uri_parsed).to receive(:open).and_return(ghfm_spec_txt_uri_io)
allow(File).to receive(:open).with(ghfm_spec_md_path) { ghfm_spec_txt_local_io }
allow(File).to receive(:open).with(glfm_intro_md_path) { glfm_intro_md_io }
allow(File).to receive(:open).with(glfm_official_specification_examples_md_path) do
@@ -104,7 +131,21 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
allow(File).to receive(:open).with(glfm_internal_extension_examples_md_path) do
glfm_internal_extension_examples_md_io
end
+
+ # output files
allow(File).to receive(:open).with(glfm_spec_txt_path, 'w') { glfm_spec_txt_io }
+ allow(File).to receive(:open).with(glfm_spec_html_path, 'w') { glfm_spec_html_io }
+
+ # Allow normal opening of Tempfile files created during script execution.
+ tempfile_basenames = [
+ described_class::MARKDOWN_TEMPFILE_BASENAME[0],
+ described_class::STATIC_HTML_TEMPFILE_BASENAME[0]
+ ].join('|')
+ # NOTE: This approach with a single regex seems to be the only way this can work. If you
+ # attempt to have multiple `allow...and_call_original` with `any_args`, the mocked
+ # parameter matching will fail to match the second one.
+ tempfiles_regex = /(#{tempfile_basenames})/
+ allow(File).to receive(:open).with(tempfiles_regex, any_args).and_call_original
# Prevent console output when running tests
allow(subject).to receive(:output)
@@ -115,7 +156,7 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
it 'does not download' do
expect(URI).not_to receive(:parse).with(ghfm_spec_txt_uri)
- subject.process
+ subject.process(skip_spec_html_generation: true)
expect(reread_io(ghfm_spec_txt_local_io)).to eq(ghfm_spec_txt_contents)
end
@@ -131,7 +172,7 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
context 'with success' do
it 'downloads and saves' do
- subject.process
+ subject.process(skip_spec_html_generation: true)
expect(reread_io(ghfm_spec_txt_local_io)).to eq(ghfm_spec_txt_contents)
end
@@ -149,7 +190,9 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
end
it 'raises an error' do
- expect { subject.process }.to raise_error /version mismatch.*expected.*29.*got.*30/i
+ expect do
+ subject.process(skip_spec_html_generation: true)
+ end.to raise_error /version mismatch.*expected.*29.*got.*30/i
end
end
@@ -157,7 +200,7 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
let(:ghfm_spec_txt_contents) { '' }
it 'raises an error if lines cannot be read' do
- expect { subject.process }.to raise_error /unable to read lines/i
+ expect { subject.process(skip_spec_html_generation: true) }.to raise_error /unable to read lines/i
end
end
@@ -167,7 +210,7 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
end
it 'raises an error if file is blank' do
- expect { subject.process }.to raise_error /unable to read string/i
+ expect { subject.process(skip_spec_html_generation: true) }.to raise_error /unable to read string/i
end
end
end
@@ -178,7 +221,7 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
let(:glfm_contents) { reread_io(glfm_spec_txt_io) }
before do
- subject.process
+ subject.process(skip_spec_html_generation: true)
end
it 'replaces the header text with the GitLab version' do
@@ -214,6 +257,51 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do
end
end
+ describe 'writing GLFM spec.html' do
+ let(:glfm_contents) { reread_io(glfm_spec_html_io) }
+
+ before do
+ subject.process
+ end
+
+ it 'renders HTML from spec.txt', :unlimited_max_formatted_output_length do
+ expected = <<~HTML
+ <div class="gl-relative markdown-code-block js-markdown-code">
+ <pre data-sourcepos="1:1-4:3" class="code highlight js-syntax-highlight language-yaml" lang="yaml" data-lang-params="frontmatter" v-pre="true"><code><span id="LC1" class="line" lang="yaml"><span class="na">title</span><span class="pi">:</span> <span class="s">GitLab Flavored Markdown (GLFM) Spec</span></span>
+ <span id="LC2" class="line" lang="yaml"><span class="na">version</span><span class="pi">:</span> <span class="s">alpha</span></span></code></pre>
+ <copy-code></copy-code>
+ </div>
+ <h1 data-sourcepos="6:1-6:14" dir="auto">
+ <a id="user-content-introduction" class="anchor" href="#introduction" aria-hidden="true"></a>Introduction</h1>
+ <h2 data-sourcepos="8:1-8:36" dir="auto">
+ <a id="user-content-what-is-gitlab-flavored-markdown" class="anchor" href="#what-is-gitlab-flavored-markdown" aria-hidden="true"></a>What is GitLab Flavored Markdown?</h2>
+ <p data-sourcepos="10:1-10:42" dir="auto">Intro text about GitLab Flavored Markdown.</p>
+ <h1 data-sourcepos="12:1-12:23" dir="auto">
+ <a id="user-content-section-with-examples" class="anchor" href="#section-with-examples" aria-hidden="true"></a>Section with Examples</h1>
+ <h2 data-sourcepos="14:1-14:9" dir="auto">
+ <a id="user-content-strong" class="anchor" href="#strong" aria-hidden="true"></a>Strong</h2>
+ <div class="gl-relative markdown-code-block js-markdown-code">
+ <pre data-sourcepos="16:1-20:32" class="code highlight js-syntax-highlight language-plaintext" lang="plaintext" data-canonical-lang="example" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">__bold__</span>
+ <span id="LC2" class="line" lang="plaintext">.</span>
+ <span id="LC3" class="line" lang="plaintext">&lt;p&gt;&lt;strong&gt;bold&lt;/strong&gt;&lt;/p&gt;</span></code></pre>
+ <copy-code></copy-code>
+ </div>
+ <p data-sourcepos="22:1-22:36" dir="auto">End of last GitHub examples section.</p>
+ <h1 data-sourcepos="24:1-24:46" dir="auto">
+ <a id="user-content-official-specification-section-with-examples" class="anchor" href="#official-specification-section-with-examples" aria-hidden="true"></a>Official Specification Section with Examples</h1>
+ <p data-sourcepos="26:1-26:14" dir="auto">Some examples.</p>
+ <h1 data-sourcepos="28:1-28:42" dir="auto">
+ <a id="user-content-internal-extension-section-with-examples" class="anchor" href="#internal-extension-section-with-examples" aria-hidden="true"></a>Internal Extension Section with Examples</h1>
+ <p data-sourcepos="30:1-30:14" dir="auto">Some examples.</p>
+
+ <h1 data-sourcepos="34:1-34:10" dir="auto">
+ <a id="user-content-appendix" class="anchor" href="#appendix" aria-hidden="true"></a>Appendix</h1>
+ <p data-sourcepos="36:1-36:14" dir="auto">Appendix text.</p>
+ HTML
+ expect(glfm_contents).to be == expected
+ end
+ end
+
def reread_io(io)
# Reset the io StringIO to the beginning position of the buffer
io.seek(0)
diff --git a/spec/services/boards/lists/list_service_spec.rb b/spec/services/boards/lists/list_service_spec.rb
index 0c8a8dc7329..2d41de42581 100644
--- a/spec/services/boards/lists/list_service_spec.rb
+++ b/spec/services/boards/lists/list_service_spec.rb
@@ -3,13 +3,40 @@
require 'spec_helper'
RSpec.describe Boards::Lists::ListService do
- let(:user) { create(:user) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:group) { create(:group) }
+
+ RSpec.shared_examples 'FOSS lists only' do
+ context 'when board contains a non FOSS list' do
+ # This scenario may happen when there used to be an EE license and user downgraded
+ let!(:backlog_list) { create_backlog_list(board) }
+ let_it_be(:milestone) { create(:milestone, group: group) }
+ let_it_be(:assignee_list) do
+ list = build(:list, board: board, user_id: user.id, list_type: List.list_types[:assignee], position: 0)
+ list.save!(validate: false)
+ list
+ end
+
+ let_it_be(:milestone_list) do
+ list = build(:list, board: board, milestone_id: milestone.id, list_type: List.list_types[:milestone], position: 1) # rubocop:disable Layout/LineLength
+ list.save!(validate: false)
+ list
+ end
+
+ it "returns only FOSS board's lists" do
+ # just making sure these non FOSS lists actually exist on the board
+ expect(board.lists.with_types([List.list_types[:assignee], List.list_types[:milestone]]).count).to eq 2
+ # check that the FOSS lists are not returned from the service
+ expect(service.execute(board)).to match_array [backlog_list, list, board.lists.closed.first]
+ end
+ end
+ end
describe '#execute' do
let(:service) { described_class.new(parent, user) }
context 'when board parent is a project' do
- let_it_be(:project) { create(:project) }
+ let_it_be(:project) { create(:project, group: group) }
let_it_be_with_reload(:board) { create(:board, project: project) }
let_it_be(:label) { create(:label, project: project) }
let_it_be(:list) { create(:list, board: board, label: label) }
@@ -18,10 +45,10 @@ RSpec.describe Boards::Lists::ListService do
let(:parent) { project }
it_behaves_like 'lists list service'
+ it_behaves_like 'FOSS lists only'
end
context 'when board parent is a group' do
- let_it_be(:group) { create(:group) }
let_it_be_with_reload(:board) { create(:board, group: group) }
let_it_be(:label) { create(:group_label, group: group) }
let_it_be(:list) { create(:list, board: board, label: label) }
@@ -30,6 +57,7 @@ RSpec.describe Boards::Lists::ListService do
let(:parent) { group }
it_behaves_like 'lists list service'
+ it_behaves_like 'FOSS lists only'
end
def create_backlog_list(board)
diff --git a/spec/support/shared_examples/models/boards/listable_shared_examples.rb b/spec/support/shared_examples/models/boards/listable_shared_examples.rb
index 250a4c1b1bd..ac8655a907f 100644
--- a/spec/support/shared_examples/models/boards/listable_shared_examples.rb
+++ b/spec/support/shared_examples/models/boards/listable_shared_examples.rb
@@ -27,14 +27,6 @@ RSpec.shared_examples 'boards listable model' do |list_factory|
.to eq([list1, list3, list4, list2])
end
end
-
- describe '.without_types' do
- it 'excludes lists of given types' do
- lists = described_class.without_types([:label, :closed])
-
- expect(lists).to match_array([list1])
- end
- end
end
describe '#destroyable?' do