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-09-17 08:09:37 -04:00
|
|
|
include Spec::Support::Helpers::Features::SnippetSpecHelpers
|
|
|
|
|
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) }
|
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-18 03:52:28 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2020-09-17 08:09:37 -04:00
|
|
|
page.visit(edit_project_snippet_path(project, snippet))
|
2017-09-18 03:52:28 -04:00
|
|
|
|
2020-03-20 08:10:03 -04:00
|
|
|
wait_for_all_requests
|
|
|
|
end
|
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
it 'displays the snippet blob path and content' do
|
|
|
|
blob = snippet.blobs.first
|
2020-09-17 08:09:37 -04:00
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
aggregate_failures do
|
|
|
|
expect(snippet_get_first_blob_path).to eq blob.path
|
|
|
|
expect(snippet_get_first_blob_value).to have_content(blob.data.strip)
|
2020-09-17 08:09:37 -04:00
|
|
|
end
|
2017-09-18 03:52:28 -04:00
|
|
|
end
|
2020-03-09 08:07:45 -04:00
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
it 'updates a snippet' do
|
|
|
|
fill_in('snippet-title', with: 'Snippet new title')
|
|
|
|
click_button('Save')
|
2020-03-09 08:07:45 -04:00
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
expect(page).to have_content('Snippet new title')
|
2020-09-17 08:09:37 -04:00
|
|
|
end
|
2020-03-09 08:07:45 -04:00
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
context 'when the git operation fails' do
|
2020-09-17 08:09:37 -04:00
|
|
|
before do
|
2020-10-06 17:09:22 -04:00
|
|
|
allow_next_instance_of(Snippets::UpdateService) do |instance|
|
|
|
|
allow(instance).to receive(:create_commit).and_raise(StandardError, 'Error Message')
|
|
|
|
end
|
2020-09-17 08:09:37 -04:00
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
snippet_fill_in_form(title: 'Snippet new title', file_name: 'new_file_name')
|
|
|
|
|
|
|
|
click_button('Save')
|
2020-03-09 08:07:45 -04:00
|
|
|
end
|
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
it 'renders edit page and displays the error' do
|
|
|
|
expect(page.find('.flash-container')).to have_content('Error updating the snippet - Error Message')
|
|
|
|
expect(page).to have_content('Edit Snippet')
|
2020-03-09 08:07:45 -04:00
|
|
|
end
|
|
|
|
end
|
2017-09-18 03:52:28 -04:00
|
|
|
end
|