debian-mirror-gitlab/spec/finders/environments/environments_finder_spec.rb

63 lines
2.1 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2021-06-08 01:23:25 +05:30
RSpec.describe Environments::EnvironmentsFinder do
2020-04-22 19:07:51 +05:30
let(:project) { create(:project, :repository) }
let(:user) { project.creator }
let(:environment) { create(:environment, :available, project: project) }
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
before do
project.add_maintainer(user)
end
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
describe '#execute' do
context 'with states parameter' do
let(:stopped_environment) { create(:environment, :stopped, project: project) }
it 'returns environments with the requested state' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, states: 'available').execute
2020-04-22 19:07:51 +05:30
expect(result).to contain_exactly(environment)
end
it 'returns environments with any of the requested states' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, states: %w(available stopped)).execute
2020-04-22 19:07:51 +05:30
expect(result).to contain_exactly(environment, stopped_environment)
end
it 'raises exception when requested state is invalid' do
2021-04-29 21:17:54 +05:30
expect { described_class.new(project, user, states: %w(invalid stopped)).execute }.to(
2020-04-22 19:07:51 +05:30
raise_error(described_class::InvalidStatesError, 'Requested states are invalid')
)
end
context 'works with symbols' do
it 'returns environments with the requested state' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, states: :available).execute
2020-04-22 19:07:51 +05:30
expect(result).to contain_exactly(environment)
end
it 'returns environments with any of the requested states' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, states: [:available, :stopped]).execute
2020-04-22 19:07:51 +05:30
expect(result).to contain_exactly(environment, stopped_environment)
end
end
end
context 'with search and states' do
let(:environment2) { create(:environment, :stopped, name: 'test2', project: project) }
let(:environment3) { create(:environment, :available, name: 'test3', project: project) }
it 'searches environments by name and state' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, search: 'test', states: :available).execute
2020-04-22 19:07:51 +05:30
expect(result).to contain_exactly(environment3)
end
end
end
2017-08-17 22:00:37 +05:30
end