Commit 265fbfea authored by Alexander Turinske's avatar Alexander Turinske

Abstract out details of policy_helper

- move details into a private method to make
  #policy_details more readable
- abstract out reusable test data
parent 1f7e1907
......@@ -4,15 +4,7 @@ module PolicyHelper
def policy_details(project, policy = nil, environment = nil)
return unless project
details = {
network_policies_endpoint: project_security_network_policies_path(project),
configure_agent_help_path: help_page_url('user/clusters/agent/repository.html'),
create_agent_help_path: help_page_url('user/clusters/agent/index.md', anchor: 'create-an-agent-record-in-gitlab'),
environments_endpoint: project_environments_path(project),
project_path: project.full_path,
threat_monitoring_path: project_threat_monitoring_path(project)
}
details = details(project)
return details unless policy && environment
edit_details = {
......@@ -21,4 +13,17 @@ module PolicyHelper
}
details.merge(edit_details)
end
private
def details(project)
{
network_policies_endpoint: project_security_network_policies_path(project),
configure_agent_help_path: help_page_url('user/clusters/agent/repository.html'),
create_agent_help_path: help_page_url('user/clusters/agent/index.md', anchor: 'create-an-agent-record-in-gitlab'),
environments_endpoint: project_environments_path(project),
project_path: project.full_path,
threat_monitoring_path: project_threat_monitoring_path(project)
}
end
end
---
title: Abstract out details of policy_helper
merge_request: 52714
author:
type: other
......@@ -4,6 +4,8 @@ require 'spec_helper'
RSpec.describe PolicyHelper do
let(:project) { create(:project, :repository, :public) }
let(:environment) { create(:environment, project: project) }
let(:policy) do
Gitlab::Kubernetes::CiliumNetworkPolicy.new(
name: 'policy',
......@@ -13,21 +15,23 @@ RSpec.describe PolicyHelper do
)
end
let(:environment) { create(:environment, project: project) }
describe '#policy_details' do
context 'when a new policy is being created' do
subject { helper.policy_details(project) }
it 'returns expected policy data' do
expect(subject).to match(
let(:base_data) do
{
network_policies_endpoint: kind_of(String),
configure_agent_help_path: kind_of(String),
create_agent_help_path: kind_of(String),
environments_endpoint: kind_of(String),
project_path: project.full_path,
threat_monitoring_path: kind_of(String)
)
}
end
describe '#policy_details' do
context 'when a new policy is being created' do
subject { helper.policy_details(project) }
it 'returns expected policy data' do
expect(subject).to match(base_data)
end
end
......@@ -36,15 +40,19 @@ RSpec.describe PolicyHelper do
it 'returns expected policy data' do
expect(subject).to match(
network_policies_endpoint: kind_of(String),
configure_agent_help_path: kind_of(String),
create_agent_help_path: kind_of(String),
environments_endpoint: kind_of(String),
project_path: project.full_path,
threat_monitoring_path: kind_of(String),
base_data.merge(
policy: policy.to_json,
environment_id: environment.id
)
)
end
end
context 'when no environment is passed in' do
subject { helper.policy_details(project, policy) }
it 'returns expected policy data' do
expect(subject).to match(base_data)
end
end
end
......
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