summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb111
1 files changed, 91 insertions, 20 deletions
diff --git a/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb b/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
index b5f2c0d07bf..4df3139d56e 100644
--- a/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
@@ -104,6 +104,35 @@ RSpec.shared_examples 'wiki controller actions' do
end
end
+ describe 'GET #diff' do
+ context 'when commit exists' do
+ it 'renders the diff' do
+ get :diff, params: routing_params.merge(id: wiki_title, version_id: wiki.repository.commit.id)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template('shared/wikis/diff')
+ expect(assigns(:diffs)).to be_a(Gitlab::Diff::FileCollection::Base)
+ expect(assigns(:diff_notes_disabled)).to be(true)
+ end
+ end
+
+ context 'when commit does not exist' do
+ it 'returns a 404 error' do
+ get :diff, params: routing_params.merge(id: wiki_title, version_id: 'invalid')
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'when page does not exist' do
+ it 'returns a 404 error' do
+ get :diff, params: routing_params.merge(id: 'invalid')
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+
describe 'GET #show' do
render_views
@@ -118,6 +147,7 @@ RSpec.shared_examples 'wiki controller actions' do
subject
expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template('shared/wikis/show')
expect(assigns(:page).title).to eq(wiki_title)
expect(assigns(:sidebar_wiki_entries)).to contain_exactly(an_instance_of(WikiPage))
expect(assigns(:sidebar_limited)).to be(false)
@@ -130,6 +160,7 @@ RSpec.shared_examples 'wiki controller actions' do
subject
expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template('shared/wikis/show')
expect(flash[:notice]).to eq(_('The content of this page is not encoded in UTF-8. Edits can only be made via the Git repository.'))
end
end
@@ -138,19 +169,37 @@ RSpec.shared_examples 'wiki controller actions' do
context 'when the page does not exist' do
let(:id) { 'does not exist' }
- before do
- subject
- end
+ context 'when the user can create pages' do
+ before do
+ subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template('shared/wikis/edit')
+ end
+
+ it 'builds a new wiki page with the id as the title' do
+ expect(assigns(:page).title).to eq(id)
+ end
+
+ context 'when a random_title param is present' do
+ let(:random_title) { true }
- it 'builds a new wiki page with the id as the title' do
- expect(assigns(:page).title).to eq(id)
+ it 'builds a new wiki page with no title' do
+ expect(assigns(:page).title).to be_empty
+ end
+ end
end
- context 'when a random_title param is present' do
- let(:random_title) { true }
+ context 'when the user cannot create pages' do
+ before do
+ sign_out(:user)
+ end
- it 'builds a new wiki page with no title' do
- expect(assigns(:page).title).to be_empty
+ it 'shows the empty state' do
+ subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template('shared/wikis/empty')
end
end
end
@@ -166,6 +215,7 @@ RSpec.shared_examples 'wiki controller actions' do
it 'delivers the file with the correct headers' do
subject
+ expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq('true')
expect(response.cache_control[:public]).to be(false)
@@ -179,12 +229,31 @@ RSpec.shared_examples 'wiki controller actions' do
it 'renders json in a correct format' do
post :preview_markdown, params: routing_params.merge(id: 'page/path', text: '*Markdown* text')
+ expect(response).to have_gitlab_http_status(:ok)
expect(json_response.keys).to match_array(%w(body references))
end
end
- describe 'GET #edit' do
- subject { get(:edit, params: routing_params.merge(id: wiki_title)) }
+ shared_examples 'edit action' do
+ context 'when the page does not exist' do
+ let(:id_param) { 'invalid' }
+
+ it 'redirects to show' do
+ subject
+
+ expect(response).to redirect_to_wiki(wiki, 'invalid')
+ end
+ end
+
+ context 'when id param is blank' do
+ let(:id_param) { ' ' }
+
+ it 'redirects to the home page' do
+ subject
+
+ expect(response).to redirect_to_wiki(wiki, 'home')
+ end
+ end
context 'when page content encoding is invalid' do
it 'redirects to show' do
@@ -208,6 +277,14 @@ RSpec.shared_examples 'wiki controller actions' do
expect(response).to redirect_to_wiki(wiki, page)
end
end
+ end
+
+ describe 'GET #edit' do
+ let(:id_param) { wiki_title }
+
+ subject { get(:edit, params: routing_params.merge(id: id_param)) }
+
+ it_behaves_like 'edit action'
context 'when page content encoding is valid' do
render_views
@@ -224,23 +301,17 @@ RSpec.shared_examples 'wiki controller actions' do
describe 'PATCH #update' do
let(:new_title) { 'New title' }
let(:new_content) { 'New content' }
+ let(:id_param) { wiki_title }
subject do
patch(:update,
params: routing_params.merge(
- id: wiki_title,
+ id: id_param,
wiki: { title: new_title, content: new_content }
))
end
- context 'when page content encoding is invalid' do
- it 'redirects to show' do
- allow(controller).to receive(:valid_encoding?).and_return(false)
-
- subject
- expect(response).to redirect_to_wiki(wiki, wiki.list_pages.first)
- end
- end
+ it_behaves_like 'edit action'
context 'when page content encoding is valid' do
render_views