BigW Consortium Gitlab

snippets_spec.rb 1.63 KB
Newer Older
1 2 3 4
require 'spec_helper'

describe 'Snippets tab on a user profile', feature: true, js: true do
  context 'when the user has snippets' do
5
    let(:user) { create(:user) }
6 7 8 9 10 11 12 13

    context 'pagination' do
      let!(:snippets) { create_list(:snippet, 2, :public, author: user) }

      before do
        allow(Snippet).to receive(:default_per_page).and_return(1)
        visit user_path(user)
        page.within('.user-profile-nav') { click_link 'Snippets' }
14
        wait_for_requests
15 16 17
      end

      it_behaves_like 'paginated snippets', remote: true
18 19
    end

20 21 22 23 24 25 26
    context 'list content' do
      let!(:public_snippet) { create(:snippet, :public, author: user) }
      let!(:internal_snippet) { create(:snippet, :internal, author: user) }
      let!(:private_snippet) { create(:snippet, :private, author: user) }
      let!(:other_snippet) { create(:snippet, :public) }

      it 'contains only internal and public snippets of a user when a user is logged in' do
27
        sign_in(create(:user))
28 29
        visit user_path(user)
        page.within('.user-profile-nav') { click_link 'Snippets' }
30
        wait_for_requests
31 32 33 34 35 36 37 38 39 40

        expect(page).to have_selector('.snippet-row', count: 2)

        expect(page).to have_content(public_snippet.title)
        expect(page).to have_content(internal_snippet.title)
      end

      it 'contains only public snippets of a user when a user is not logged in' do
        visit user_path(user)
        page.within('.user-profile-nav') { click_link 'Snippets' }
41
        wait_for_requests
42 43 44 45 46

        expect(page).to have_selector('.snippet-row', count: 1)
        expect(page).to have_content(public_snippet.title)
      end
    end
47 48
  end
end