Commit 2f536c6f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets Committed by Dmytro Zaporozhets

Rename find to execute in EnvironmentsFinder

To follow the same naming other finders have
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Signed-off-by: default avatarDmytro Zaporozhets <dzaporozhets@gitlab.com>
parent 3334ec9a
......@@ -58,7 +58,7 @@ module Projects
def environment
strong_memoize(:environment) do
if cluster_params.key?(:environment_name)
EnvironmentsFinder.new(project, current_user, name: cluster_params[:environment_name]).find.first
EnvironmentsFinder.new(project, current_user, name: cluster_params[:environment_name]).execute.first
else
project.default_environment
end
......
......@@ -9,12 +9,7 @@ class EnvironmentsFinder
@project, @current_user, @params = project, current_user, params
end
# This method will eventually take the place of `#execute` as an
# efficient way to get relevant environment entries.
# Currently, `#execute` method has a serious technical debt and
# we will likely rework on it in the future.
# See more https://gitlab.com/gitlab-org/gitlab-foss/issues/63381
def find
def execute
environments = project.environments
environments = by_name(environments)
environments = by_search(environments)
......
......@@ -21,7 +21,7 @@ module Resolvers
def resolve(**args)
return unless project.present?
EnvironmentsFinder.new(project, context[:current_user], args).find
EnvironmentsFinder.new(project, context[:current_user], args).execute
rescue EnvironmentsFinder::InvalidStatesError => exception
raise Gitlab::Graphql::Errors::ArgumentError, exception.message
end
......
......@@ -84,7 +84,7 @@ module Prometheus
def environment
strong_memoize(:environment) do
EnvironmentsFinder.new(project, nil, name: 'production').find.first ||
EnvironmentsFinder.new(project, nil, name: 'production').execute.first ||
project.environments.first
end
end
......
......@@ -26,7 +26,7 @@ module API
get ':id/environments' do
authorize! :read_environment, user_project
environments = ::EnvironmentsFinder.new(user_project, current_user, params).find
environments = ::EnvironmentsFinder.new(user_project, current_user, params).execute
present paginate(environments), with: Entities::Environment, current_user: current_user
end
......
......@@ -132,7 +132,7 @@ module Gitlab
EnvironmentsFinder
.new(project, nil, { name: environment_name })
.find
.execute
.first
end
end
......
......@@ -11,37 +11,37 @@ RSpec.describe EnvironmentsFinder do
project.add_maintainer(user)
end
describe '#find' do
describe '#execute' do
context 'with states parameter' do
let(:stopped_environment) { create(:environment, :stopped, project: project) }
it 'returns environments with the requested state' do
result = described_class.new(project, user, states: 'available').find
result = described_class.new(project, user, states: 'available').execute
expect(result).to contain_exactly(environment)
end
it 'returns environments with any of the requested states' do
result = described_class.new(project, user, states: %w(available stopped)).find
result = described_class.new(project, user, states: %w(available stopped)).execute
expect(result).to contain_exactly(environment, stopped_environment)
end
it 'raises exception when requested state is invalid' do
expect { described_class.new(project, user, states: %w(invalid stopped)).find }.to(
expect { described_class.new(project, user, states: %w(invalid stopped)).execute }.to(
raise_error(described_class::InvalidStatesError, 'Requested states are invalid')
)
end
context 'works with symbols' do
it 'returns environments with the requested state' do
result = described_class.new(project, user, states: :available).find
result = described_class.new(project, user, states: :available).execute
expect(result).to contain_exactly(environment)
end
it 'returns environments with any of the requested states' do
result = described_class.new(project, user, states: [:available, :stopped]).find
result = described_class.new(project, user, states: [:available, :stopped]).execute
expect(result).to contain_exactly(environment, stopped_environment)
end
......@@ -53,7 +53,7 @@ RSpec.describe EnvironmentsFinder do
let(:environment3) { create(:environment, :available, name: 'test3', project: project) }
it 'searches environments by name and state' do
result = described_class.new(project, user, search: 'test', states: :available).find
result = described_class.new(project, user, search: 'test', states: :available).execute
expect(result).to contain_exactly(environment3)
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