2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-18 03:52:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe 'Projects > Snippets > User updates a snippet', :js do
|
2020-03-09 08:07:45 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: user.namespace) }
|
2020-03-20 08:10:03 -04:00
|
|
|
let_it_be(:snippet, reload: true) { create(:project_snippet, :repository, project: project, author: user) }
|
|
|
|
|
2017-09-18 03:52:28 -04:00
|
|
|
before do
|
2019-12-17 13:07:48 -05:00
|
|
|
stub_feature_flags(snippets_vue: false)
|
2020-04-21 11:21:10 -04:00
|
|
|
stub_feature_flags(snippets_edit_vue: false)
|
2020-03-20 08:10:03 -04:00
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-18 03:52:28 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
visit(project_snippet_path(project, snippet))
|
|
|
|
|
|
|
|
page.within('.detail-page-header') do
|
|
|
|
first(:link, 'Edit').click
|
|
|
|
end
|
2020-03-20 08:10:03 -04:00
|
|
|
wait_for_all_requests
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays the snippet blob path and content' do
|
|
|
|
blob = snippet.blobs.first
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(page.find_field('project_snippet_file_name').value).to eq blob.path
|
|
|
|
expect(page.find('.file-content')).to have_content(blob.data.strip)
|
|
|
|
expect(page.find('.snippet-file-content', visible: false).value).to eq blob.data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-09 08:07:45 -04:00
|
|
|
it 'updates a snippet' do
|
2017-09-18 03:52:28 -04:00
|
|
|
fill_in('project_snippet_title', with: 'Snippet new title')
|
|
|
|
click_button('Save')
|
|
|
|
|
|
|
|
expect(page).to have_content('Snippet new title')
|
|
|
|
end
|
2020-03-09 08:07:45 -04:00
|
|
|
|
|
|
|
context 'when the git operation fails' do
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(Snippets::UpdateService) do |instance|
|
2020-05-13 17:08:55 -04:00
|
|
|
allow(instance).to receive(:create_commit).and_raise(StandardError, 'Error Message')
|
2020-03-09 08:07:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
fill_in('project_snippet_title', with: 'Snippet new title')
|
2020-04-21 11:21:10 -04:00
|
|
|
fill_in('project_snippet_file_name', with: 'new_file_name')
|
2020-03-09 08:07:45 -04:00
|
|
|
|
|
|
|
click_button('Save')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders edit page and displays the error' do
|
2020-05-13 17:08:55 -04:00
|
|
|
expect(page.find('.flash-container span').text).to eq('Error updating the snippet - Error Message')
|
2020-03-09 08:07:45 -04:00
|
|
|
expect(page).to have_content('Edit Snippet')
|
|
|
|
end
|
|
|
|
end
|
2017-09-18 03:52:28 -04:00
|
|
|
end
|