diff options
Diffstat (limited to 'spec/models/terraform')
-rw-r--r-- | spec/models/terraform/state_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/terraform/state_version_spec.rb | 18 |
2 files changed, 30 insertions, 0 deletions
diff --git a/spec/models/terraform/state_spec.rb b/spec/models/terraform/state_spec.rb index ed311314086..1319e2adb03 100644 --- a/spec/models/terraform/state_spec.rb +++ b/spec/models/terraform/state_spec.rb @@ -8,8 +8,11 @@ RSpec.describe Terraform::State do it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:locked_by_user).class_name('User') } + it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:project_id) } + it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) } + describe 'scopes' do describe '.ordered_by_name' do let_it_be(:project) { create(:project) } @@ -25,6 +28,15 @@ RSpec.describe Terraform::State do it { expect(subject.map(&:name)).to eq(names.sort) } end + + describe '.with_name' do + let_it_be(:matching_name) { create(:terraform_state, name: 'matching-name') } + let_it_be(:other_name) { create(:terraform_state, name: 'other-name') } + + subject { described_class.with_name(matching_name.name) } + + it { is_expected.to contain_exactly(matching_name) } + end end describe '#destroy' do diff --git a/spec/models/terraform/state_version_spec.rb b/spec/models/terraform/state_version_spec.rb index 97ac77d5e7b..ac2e8d167b3 100644 --- a/spec/models/terraform/state_version_spec.rb +++ b/spec/models/terraform/state_version_spec.rb @@ -24,6 +24,24 @@ RSpec.describe Terraform::StateVersion do it { expect(subject.map(&:version)).to eq(versions.sort.reverse) } end + + describe '.with_files_stored_locally' do + subject { described_class.with_files_stored_locally } + + it 'includes states with local storage' do + create_list(:terraform_state_version, 5) + + expect(subject).to have_attributes(count: 5) + end + + it 'excludes states without local storage' do + stub_terraform_state_object_storage + + create_list(:terraform_state_version, 5) + + expect(subject).to have_attributes(count: 0) + end + end end context 'file storage' do |