diff options
Diffstat (limited to 'spec/presenters/snippet_blob_presenter_spec.rb')
-rw-r--r-- | spec/presenters/snippet_blob_presenter_spec.rb | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/spec/presenters/snippet_blob_presenter_spec.rb b/spec/presenters/snippet_blob_presenter_spec.rb index 7464c0ac15b..915f43fe572 100644 --- a/spec/presenters/snippet_blob_presenter_spec.rb +++ b/spec/presenters/snippet_blob_presenter_spec.rb @@ -13,13 +13,14 @@ RSpec.describe SnippetBlobPresenter do subject { described_class.new(snippet.blob).rich_data } context 'with PersonalSnippet' do - let(:raw_url) { "http://127.0.0.1:3000/snippets/#{snippet.id}/raw" } - let(:snippet) { build(:personal_snippet) } + let(:snippet) { create(:personal_snippet, :repository) } - it 'returns nil when the snippet blob is binary' do - allow(snippet.blob).to receive(:binary?).and_return(true) + context 'when blob is binary' do + it 'returns the HTML associated with the binary' do + allow(snippet).to receive(:blob).and_return(snippet.repository.blob_at('master', 'files/images/logo-black.png')) - expect(subject).to be_nil + expect(subject).to include('file-content image_file') + end end context 'with markdown format' do @@ -40,7 +41,7 @@ RSpec.describe SnippetBlobPresenter do let(:snippet) { create(:personal_snippet, file_name: 'test.ipynb') } it 'returns rich notebook content' do - expect(subject.strip).to eq %Q(<div class="file-content" data-endpoint="/snippets/#{snippet.id}/raw" id="js-notebook-viewer"></div>) + expect(subject.strip).to eq %Q(<div class="file-content" data-endpoint="/-/snippets/#{snippet.id}/raw" id="js-notebook-viewer"></div>) end end @@ -48,7 +49,7 @@ RSpec.describe SnippetBlobPresenter do let(:snippet) { create(:personal_snippet, file_name: 'openapi.yml') } it 'returns rich openapi content' do - expect(subject).to eq %Q(<div class="file-content" data-endpoint="/snippets/#{snippet.id}/raw" id="js-openapi-viewer"></div>\n) + expect(subject).to eq %Q(<div class="file-content" data-endpoint="/-/snippets/#{snippet.id}/raw" id="js-openapi-viewer"></div>\n) end end @@ -108,7 +109,7 @@ RSpec.describe SnippetBlobPresenter do end end - describe '#raw_path' do + describe 'route helpers' do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user) } @@ -118,28 +119,62 @@ RSpec.describe SnippetBlobPresenter do project.add_developer(user) end - subject { described_class.new(snippet.blobs.first, current_user: user).raw_path } + describe '#raw_path' do + subject { described_class.new(snippet.blobs.first, current_user: user).raw_path } + + it_behaves_like 'snippet blob raw path' + + context 'with snippet_multiple_files feature disabled' do + before do + stub_feature_flags(snippet_multiple_files: false) + end + + context 'with ProjectSnippet' do + let(:snippet) { project_snippet } + + it 'returns the raw path' do + expect(subject).to eq "/#{snippet.project.full_path}/-/snippets/#{snippet.id}/raw" + end + end + + context 'with PersonalSnippet' do + let(:snippet) { personal_snippet } - it_behaves_like 'snippet blob raw path' + it 'returns the raw path' do + expect(subject).to eq "/-/snippets/#{snippet.id}/raw" + end + end + end + end + + describe '#raw_url' do + subject { described_class.new(snippet.blobs.first, current_user: user).raw_url } - context 'with snippet_multiple_files feature disabled' do before do - stub_feature_flags(snippet_multiple_files: false) + stub_default_url_options(host: 'test.host') end - context 'with ProjectSnippet' do - let(:snippet) { project_snippet } + it_behaves_like 'snippet blob raw url' - it 'returns the raw path' do - expect(subject).to eq "/#{snippet.project.full_path}/snippets/#{snippet.id}/raw" + context 'with snippet_multiple_files feature disabled' do + before do + stub_feature_flags(snippet_multiple_files: false) + end + + context 'with ProjectSnippet' do + let(:snippet) { project_snippet } + + it 'returns the raw project snippet url' do + expect(subject).to eq("http://test.host/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}/raw") + end end - end - context 'with PersonalSnippet' do - let(:snippet) { personal_snippet } + context 'with PersonalSnippet' do + let(:snippet) { personal_snippet } - it 'returns the raw path' do - expect(subject).to eq "/snippets/#{snippet.id}/raw" + it 'returns the raw personal snippet url' do + expect(subject).to eq("http://test.host/-/snippets/#{personal_snippet.id}/raw") + end end end end |