Commit 40bcc023 authored by Alex Kalderimis's avatar Alex Kalderimis

Use nil-safe method to detect empty collections

Adds specs for new changes

Changelog: fixed
parent fb5bb717
...@@ -32,6 +32,7 @@ class Projects::HooksController < Projects::ApplicationController ...@@ -32,6 +32,7 @@ class Projects::HooksController < Projects::ApplicationController
end end
def edit def edit
redirect_to(action: :index) unless hook
end end
def update def update
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
= _('Recent Deliveries') = _('Recent Deliveries')
%p= _('When an event in GitLab triggers a webhook, you can use the request details to figure out if something went wrong.') %p= _('When an event in GitLab triggers a webhook, you can use the request details to figure out if something went wrong.')
.col-lg-9 .col-lg-9
- if hook_logs.any? - if hook_logs.present?
%table.table %table.table
%thead %thead
%tr %tr
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
Recent Deliveries Recent Deliveries
%p When an event in GitLab triggers a webhook, you can use the request details to figure out if something went wrong. %p When an event in GitLab triggers a webhook, you can use the request details to figure out if something went wrong.
.col-lg-9 .col-lg-9
- if hook_logs.any? - if hook_logs.present?
%table.table %table.table
%thead %thead
%tr %tr
......
---
title: Ensure we never error in web hook logs
merge_request: 60408
author:
type: fixed
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Projects::HooksController do RSpec.describe Projects::HooksController do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:user) { create(:user) }
let(:user) { project.owner }
before do before do
project.add_maintainer(user)
sign_in(user) sign_in(user)
end end
...@@ -20,6 +20,56 @@ RSpec.describe Projects::HooksController do ...@@ -20,6 +20,56 @@ RSpec.describe Projects::HooksController do
end end
end end
describe '#edit' do
let_it_be(:hook) { create(:project_hook, project: project) }
let(:params) do
{ namespace_id: project.namespace, project_id: project, id: hook.id }
end
render_views
it 'does not error if the hook cannot be found' do
get :edit, params: params.merge(id: non_existing_record_id)
expect(response).to have_gitlab_http_status(:not_found)
end
it 'assigns hook_logs' do
get :edit, params: params
expect(assigns[:hook]).to be_present
expect(assigns[:hook_logs]).to be_empty
it_renders_correctly
end
it 'handles when logs are present' do
create_list(:web_hook_log, 3, web_hook: hook)
get :edit, params: params
expect(assigns[:hook]).to be_present
expect(assigns[:hook_logs].count).to eq 3
it_renders_correctly
end
it 'can paginate logs' do
create_list(:web_hook_log, 21, web_hook: hook)
get :edit, params: params.merge(page: 2)
expect(assigns[:hook]).to be_present
expect(assigns[:hook_logs].count).to eq 1
it_renders_correctly
end
def it_renders_correctly
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
expect(response).to render_template('projects/hook_logs/_index')
end
end
describe '#create' do describe '#create' do
it 'sets all parameters' do it 'sets all parameters' do
hook_params = { hook_params = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment