Commit 7235f963 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Render snippet blob filename in dashboard

When Snippets are versioned we should display the correct
filename in the dashboard list
parent a0bea201
......@@ -160,4 +160,14 @@ module SnippetsHelper
title: 'Download',
rel: 'noopener noreferrer')
end
def snippet_file_name(snippet)
blob = if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty?
snippet.blobs.first
else
snippet.blob
end
blob.name
end
end
- link_project = local_assigns.fetch(:link_project, false)
- notes_count = @noteable_meta_data[snippet.id].user_notes_count
- file_name = snippet_file_name(snippet)
%li.snippet-row.py-3
= image_tag avatar_icon_for_user(snippet.author), class: "avatar s40 d-none d-sm-block", alt: ''
......@@ -7,10 +8,10 @@
.title
= link_to gitlab_snippet_path(snippet) do
= snippet.title
- if snippet.file_name.present?
- if file_name.present?
%span.snippet-filename.d-none.d-sm-inline-block.ml-2
= sprite_icon('doc-code', size: 16, css_class: 'file-icon align-text-bottom')
= snippet.file_name
= file_name
%ul.controls
%li
......
......@@ -3,8 +3,10 @@
require 'spec_helper'
describe 'Dashboard snippets' do
let_it_be(:user) { create(:user) }
context 'when the project has snippets' do
let(:project) { create(:project, :public) }
let(:project) { create(:project, :public, creator: user) }
let!(:snippets) { create_list(:project_snippet, 2, :public, author: project.owner, project: project) }
before do
......@@ -22,7 +24,7 @@ describe 'Dashboard snippets' do
end
context 'when there are no project snippets', :js do
let(:project) { create(:project, :public) }
let(:project) { create(:project, :public, creator: user) }
before do
sign_in(project.owner)
......@@ -47,9 +49,49 @@ describe 'Dashboard snippets' do
end
end
context 'rendering file names' do
let_it_be(:snippet) { create(:personal_snippet, :public, author: user, file_name: 'foo.txt') }
let_it_be(:versioned_snippet) { create(:personal_snippet, :repository, :public, author: user, file_name: 'bar.txt') }
before do
sign_in(user)
end
context 'when feature flag :version_snippets is disabled' do
before do
stub_feature_flags(version_snippets: false)
visit dashboard_snippets_path
end
it 'contains the snippet file names from the DB' do
aggregate_failures do
expect(page).to have_content 'foo.txt'
expect(page).to have_content('bar.txt')
expect(page).not_to have_content('.gitattributes')
end
end
end
context 'when feature flag :version_snippets is enabled' do
before do
stub_feature_flags(version_snippets: true)
visit dashboard_snippets_path
end
it 'contains both the versioned and non-versioned filenames' do
aggregate_failures do
expect(page).to have_content 'foo.txt'
expect(page).to have_content('.gitattributes')
expect(page).not_to have_content('bar.txt')
end
end
end
end
context 'filtering by visibility' do
let(:user) { create(:user) }
let!(:snippets) do
let_it_be(:snippets) do
[
create(:personal_snippet, :public, author: user),
create(:personal_snippet, :internal, author: user),
......@@ -99,7 +141,7 @@ describe 'Dashboard snippets' do
end
context 'as an external user' do
let(:user) { create(:user, :external) }
let_it_be(:user) { create(:user, :external) }
before do
sign_in(user)
......
......@@ -151,4 +151,35 @@ describe SnippetsHelper do
"<input type=\"text\" readonly=\"readonly\" class=\"js-snippet-url-area snippet-embed-input form-control\" data-url=\"#{url}\" value=\"<script src=&quot;#{url}.js&quot;></script>\" autocomplete=\"off\"></input>"
end
end
describe '#snippet_file_name' do
subject { helper.snippet_file_name(snippet) }
where(:snippet_type, :flag_enabled, :trait, :filename) do
[
[:personal_snippet, false, nil, 'foo.txt'],
[:personal_snippet, true, nil, 'foo.txt'],
[:personal_snippet, false, :repository, 'foo.txt'],
[:personal_snippet, true, :repository, '.gitattributes'],
[:project_snippet, false, nil, 'foo.txt'],
[:project_snippet, true, nil, 'foo.txt'],
[:project_snippet, false, :repository, 'foo.txt'],
[:project_snippet, true, :repository, '.gitattributes']
]
end
with_them do
let(:snippet) { create(snippet_type, trait, file_name: 'foo.txt') }
before do
allow(helper).to receive(:current_user).and_return(snippet.author)
stub_feature_flags(version_snippets: flag_enabled)
end
it 'returns the correct filename' do
expect(subject).to eq filename
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment