2019-10-16 09:07:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-07 00:06:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe EnvironmentsFinder do
|
2020-04-08 00:09:30 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:user) { project.creator }
|
|
|
|
let(:environment) { create(:environment, :available, project: project) }
|
2017-02-07 00:06:46 +00:00
|
|
|
|
2020-04-08 00:09:30 +00:00
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
2017-02-07 00:06:46 +00:00
|
|
|
|
2020-04-08 00:09:30 +00:00
|
|
|
describe '#find' 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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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(
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
result = described_class.new(project, user, search: 'test', states: :available).find
|
|
|
|
|
|
|
|
expect(result).to contain_exactly(environment3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-07 00:06:46 +00:00
|
|
|
end
|