summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-22 18:11:55 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-22 18:11:55 +0000
commit346ea4d53c1adf8b2e2d6eafbadc528eef5fd83a (patch)
treee8fedb430eb1888e4ba6af5f5fa79bc729a3e406 /spec/support/shared_examples
parentf20364cefca2eebc958ce34fba46feeae9fdf59a (diff)
downloadgitlab-ce-346ea4d53c1adf8b2e2d6eafbadc528eef5fd83a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_examples')
-rw-r--r--spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb33
-rw-r--r--spec/support/shared_examples/models/wiki_shared_examples.rb34
2 files changed, 57 insertions, 10 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 5d77ed5fdfc..768b54dc73e 100644
--- a/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
@@ -15,20 +15,33 @@ RSpec.shared_examples 'wiki controller actions' do
sign_in(user)
end
- shared_examples 'recovers from git timeout' do
+ shared_examples 'recovers from git errors' do
let(:method_name) { :page }
- context 'when we encounter git command errors' do
+ context 'when we encounter CommandTimedOut error' do
it 'renders the appropriate template', :aggregate_failures do
- expect(controller).to receive(method_name) do
- raise ::Gitlab::Git::CommandTimedOut, 'Deadline Exceeded'
- end
+ expect(controller)
+ .to receive(method_name)
+ .and_raise(::Gitlab::Git::CommandTimedOut, 'Deadline Exceeded')
request
expect(response).to render_template('shared/wikis/git_error')
end
end
+
+ context 'when we encounter a NoRepository error' do
+ it 'renders the appropriate template', :aggregate_failures do
+ expect(controller)
+ .to receive(method_name)
+ .and_raise(Gitlab::Git::Repository::NoRepository)
+
+ request
+
+ expect(response).to render_template('shared/wikis/empty')
+ expect(assigns(:error)).to eq('Could not access the Wiki Repository at this time.')
+ end
+ end
end
describe 'GET #new' do
@@ -65,7 +78,7 @@ RSpec.shared_examples 'wiki controller actions' do
get :pages, params: routing_params.merge(id: wiki_title)
end
- it_behaves_like 'recovers from git timeout' do
+ it_behaves_like 'recovers from git errors' do
subject(:request) { get :pages, params: routing_params.merge(id: wiki_title) }
let(:method_name) { :wiki_pages }
@@ -122,7 +135,7 @@ RSpec.shared_examples 'wiki controller actions' do
end
end
- it_behaves_like 'recovers from git timeout' do
+ it_behaves_like 'recovers from git errors' do
subject(:request) { get :history, params: routing_params.merge(id: wiki_title) }
let(:allow_read_wiki) { true }
@@ -170,7 +183,7 @@ RSpec.shared_examples 'wiki controller actions' do
end
end
- it_behaves_like 'recovers from git timeout' do
+ it_behaves_like 'recovers from git errors' do
subject(:request) { get :diff, params: routing_params.merge(id: wiki_title, version_id: wiki.repository.commit.id) }
end
end
@@ -185,7 +198,7 @@ RSpec.shared_examples 'wiki controller actions' do
context 'when page exists' do
let(:id) { wiki_title }
- it_behaves_like 'recovers from git timeout'
+ it_behaves_like 'recovers from git errors'
it 'renders the page' do
request
@@ -366,7 +379,7 @@ RSpec.shared_examples 'wiki controller actions' do
subject(:request) { get(:edit, params: routing_params.merge(id: id_param)) }
it_behaves_like 'edit action'
- it_behaves_like 'recovers from git timeout'
+ it_behaves_like 'recovers from git errors'
context 'when page content encoding is valid' do
render_views
diff --git a/spec/support/shared_examples/models/wiki_shared_examples.rb b/spec/support/shared_examples/models/wiki_shared_examples.rb
index b0a63a1332e..017e51ecd24 100644
--- a/spec/support/shared_examples/models/wiki_shared_examples.rb
+++ b/spec/support/shared_examples/models/wiki_shared_examples.rb
@@ -94,6 +94,40 @@ RSpec.shared_examples 'wiki model' do
end
end
+ describe '#has_home_page?' do
+ context 'when home page exists' do
+ before do
+ wiki.repository.create_file(
+ user,
+ 'home.md',
+ 'home file',
+ branch_name: wiki.default_branch,
+ message: "created home page",
+ author_email: user.email,
+ author_name: user.name
+ )
+ end
+
+ it 'returns true' do
+ expect(wiki.has_home_page?).to eq(true)
+ end
+
+ it 'returns false when #find_page raise an error' do
+ allow(wiki)
+ .to receive(:find_page)
+ .and_raise(StandardError)
+
+ expect(wiki.has_home_page?).to eq(false)
+ end
+ end
+
+ context 'when home page does not exist' do
+ it 'returns false' do
+ expect(wiki.has_home_page?).to eq(false)
+ end
+ end
+ end
+
describe '#to_global_id' do
it 'returns a global ID' do
expect(wiki.to_global_id.to_s).to eq("gid://gitlab/#{wiki.class.name}/#{wiki.id}")