diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/snippets_helper_spec.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/helpers/snippets_helper_spec.rb b/spec/helpers/snippets_helper_spec.rb index 6fdf4f5cfb4..b5b431b5818 100644 --- a/spec/helpers/snippets_helper_spec.rb +++ b/spec/helpers/snippets_helper_spec.rb @@ -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="#{url}.js"></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 |