diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-14 18:10:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-14 18:10:05 +0300 |
commit | 654daa2ccbf58f9f36d94bfafcaea323e350ccd3 (patch) | |
tree | 7de886a951c6fe86db3b60fe36708b5656e8d85e /spec/models | |
parent | a42fc481401fd6c4900b79125c446c7e4c1c572e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/cache_markdown_field_spec.rb | 31 | ||||
-rw-r--r-- | spec/models/note_spec.rb | 31 | ||||
-rw-r--r-- | spec/models/personal_snippet_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 6 |
4 files changed, 68 insertions, 8 deletions
diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb index 5f8c65e429e..440943171c3 100644 --- a/spec/models/concerns/cache_markdown_field_spec.rb +++ b/spec/models/concerns/cache_markdown_field_spec.rb @@ -20,6 +20,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do @title, @description, @cached_markdown_version = args[:title], args[:description], args[:cached_markdown_version] @title_html, @description_html = args[:title_html], args[:description_html] @author, @project = args[:author], args[:project] + @parent_user = args[:parent_user] end attr_accessor :title, :description, :cached_markdown_version @@ -41,8 +42,8 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do let(:cache_version) { Gitlab::MarkdownCache::CACHE_COMMONMARK_VERSION << 16 } - def thing_subclass(klass, extra_attribute) - Class.new(klass) { attr_accessor(extra_attribute) } + def thing_subclass(klass, *extra_attributes) + Class.new(klass) { attr_accessor(*extra_attributes) } end shared_examples 'a class with cached markdown fields' do @@ -192,11 +193,33 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do end context 'with an author' do - let(:thing) { thing_subclass(klass, :author).new(title: markdown, title_html: html, author: :author_value) } + let(:user) { build(:user) } + let(:thing) { thing_subclass(klass, :author).new(title: markdown, title_html: html, author: user) } it 'sets the author in the context' do is_expected.to have_key(:author) - expect(context[:author]).to eq(:author_value) + expect(context[:author]).to eq(user) + end + end + + context 'with a parent_user' do + let(:user) { build(:user) } + let(:thing) { thing_subclass(klass, :author, :parent_user).new(title: markdown, title_html: html, parent_user: user, author: user) } + + it 'sets the user in the context' do + is_expected.to have_key(:user) + expect(context[:user]).to eq(user) + end + + context 'when the personal_snippet_reference_filters flag is disabled' do + before do + stub_feature_flags(personal_snippet_reference_filters: false) + end + + it 'does not set the user in the context' do + is_expected.not_to have_key(:user) + expect(context[:user]).to be_nil + end end end end diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 864f7221181..7edd7849bbe 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -1373,11 +1373,11 @@ RSpec.describe Note do describe 'banzai_render_context' do let(:project) { build(:project_empty_repo) } + subject(:context) { noteable.banzai_render_context(:title) } + context 'when noteable is a merge request' do let(:noteable) { build :merge_request, target_project: project, source_project: project } - subject(:context) { noteable.banzai_render_context(:title) } - it 'sets the label_url_method in the context' do expect(context[:label_url_method]).to eq(:project_merge_requests_url) end @@ -1386,11 +1386,34 @@ RSpec.describe Note do context 'when noteable is an issue' do let(:noteable) { build :issue, project: project } - subject(:context) { noteable.banzai_render_context(:title) } - it 'sets the label_url_method in the context' do expect(context[:label_url_method]).to eq(:project_issues_url) end end + + context 'when noteable is a personal snippet' do + let(:noteable) { build(:personal_snippet) } + + it 'sets the parent user in the context' do + expect(context[:user]).to eq(noteable.author) + end + end + end + + describe '#parent_user' do + it 'returns the author of a personal snippet' do + note = build(:note_on_personal_snippet) + expect(note.parent_user).to eq(note.noteable.author) + end + + it 'returns nil for project snippet' do + note = build(:note_on_project_snippet) + expect(note.parent_user).to be_nil + end + + it 'returns nil when noteable is not a snippet' do + note = build(:note_on_issue) + expect(note.parent_user).to be_nil + end end end diff --git a/spec/models/personal_snippet_spec.rb b/spec/models/personal_snippet_spec.rb index 2236c9dfed7..234f6e4b4b5 100644 --- a/spec/models/personal_snippet_spec.rb +++ b/spec/models/personal_snippet_spec.rb @@ -24,4 +24,12 @@ RSpec.describe PersonalSnippet do let(:expected_web_url_path) { "-/snippets/#{container.id}" } let(:expected_repo_url_path) { "snippets/#{container.id}" } end + + describe '#parent_user' do + it 'returns the snippet author' do + snippet = build(:personal_snippet) + + expect(snippet.parent_user).to eq(snippet.author) + end + end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index a465425e735..e6d51e0bfd7 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -680,6 +680,12 @@ RSpec.describe Project do end end end + + context 'when argument is a user' do + it 'returns full path to the project' do + expect(project.to_reference_base(owner)).to eq 'sample-namespace/sample-project' + end + end end describe '#to_human_reference' do |