1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Snippet', :js, feature_category: :source_code_management do
let_it_be(:owner) { create(:user) }
let_it_be(:snippet) { create(:personal_snippet, :public, :repository, author: owner) }
let(:anchor) { nil }
let(:file_path) { 'files/ruby/popen.rb' }
before do
# rubocop: disable RSpec/AnyInstanceOf -- TODO: The usage of let_it_be forces us
allow_any_instance_of(Snippet).to receive(:blobs)
.and_return([snippet.repository.blob_at('master', file_path)])
# rubocop: enable RSpec/AnyInstanceOf
end
def visit_page
visit snippet_path(snippet, anchor: anchor)
end
context 'when signed in' do
before do
sign_in(user)
visit_page
end
context 'as the snippet owner' do
let(:user) { owner }
it_behaves_like 'show and render proper snippet blob'
it_behaves_like 'does show New Snippet button'
it_behaves_like 'a "Your work" page with sidebar and breadcrumbs', :dashboard_snippets_path, :snippets
end
context 'as external user' do
let_it_be(:user) { create(:user, :external) }
it_behaves_like 'show and render proper snippet blob'
it_behaves_like 'does not show New Snippet button'
it_behaves_like 'a "Your work" page with sidebar and breadcrumbs', :dashboard_snippets_path, :snippets
end
context 'as another user' do
let_it_be(:user) { create(:user) }
it_behaves_like 'show and render proper snippet blob'
it_behaves_like 'does show New Snippet button'
it_behaves_like 'a "Your work" page with sidebar and breadcrumbs', :dashboard_snippets_path, :snippets
end
end
context 'when unauthenticated' do
before do
visit_page
end
it_behaves_like 'show and render proper snippet blob'
it_behaves_like 'does not show New Snippet button'
it 'shows the "Explore" sidebar' do
expect(page).to have_css('#super-sidebar-context-header', text: 'Explore')
end
end
end
|