2016-09-02 07:29:05 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-10-03 04:35:01 -04:00
|
|
|
describe 'Snippets tab on a user profile', :js do
|
2016-09-02 07:29:05 -04:00
|
|
|
context 'when the user has snippets' do
|
2016-09-23 13:28:14 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-04-28 18:06:27 -04:00
|
|
|
|
|
|
|
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' }
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-28 18:06:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'paginated snippets', remote: true
|
2016-09-02 07:29:05 -04:00
|
|
|
end
|
|
|
|
|
2017-04-28 18:06:27 -04:00
|
|
|
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
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(create(:user))
|
2017-04-28 18:06:27 -04:00
|
|
|
visit user_path(user)
|
|
|
|
page.within('.user-profile-nav') { click_link 'Snippets' }
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-28 18:06:27 -04:00
|
|
|
|
|
|
|
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' }
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-28 18:06:27 -04:00
|
|
|
|
|
|
|
expect(page).to have_selector('.snippet-row', count: 1)
|
|
|
|
expect(page).to have_content(public_snippet.title)
|
|
|
|
end
|
|
|
|
end
|
2016-09-02 07:29:05 -04:00
|
|
|
end
|
|
|
|
end
|