diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-01-29 22:01:31 -0600 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-02-06 16:12:24 -0600 |
commit | 3aa1264dc6c0de3625bb1a2d6a0ee90140a2f519 (patch) | |
tree | 73b450be24d8ea336adedca5dc2ed2edd02474c6 /spec/models/environment_spec.rb | |
parent | 8f85a11d9fcc1f4ccde7c46652f0be00edf46a78 (diff) | |
download | gitlab-ce-3aa1264dc6c0de3625bb1a2d6a0ee90140a2f519.tar.gz |
Add tests
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r-- | spec/models/environment_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index eba392044bf..e40a9bf4fbe 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -22,6 +22,25 @@ describe Environment, models: true do it { is_expected.to validate_length_of(:external_url).is_at_most(255) } it { is_expected.to validate_uniqueness_of(:external_url).scoped_to(:project_id) } + describe '.latest_for_commit' do + let!(:environment1) { create(:environment, project: project) } + let!(:environment2) { create(:environment, project: project) } + let!(:environment3) { create(:environment, project: project) } + let!(:deployment1) { create(:deployment, environment: environment1) } + let!(:deployment2) { create(:deployment, environment: environment2) } + let(:commit) { RepoHelpers.sample_commit } + + before do + allow(environment1).to receive(:first_deployment_for).with(commit).and_return(deployment1) + allow(environment2).to receive(:first_deployment_for).with(commit).and_return(deployment2) + allow(environment3).to receive(:first_deployment_for).with(commit).and_return(nil) + end + + it 'returns the environment that the commit was last deployed to' do + expect(Environment.latest_for_commit([environment1, environment2, environment3], commit)).to be(environment2) + end + end + describe '#nullify_external_url' do it 'replaces a blank url with nil' do env = build(:environment, external_url: "") @@ -301,4 +320,33 @@ describe Environment, models: true do end end end + + describe '#external_url_for' do + let(:source_path) { 'source/file.html' } + let(:sha) { RepoHelpers.sample_commit.id } + + before do + environment.external_url = 'http://example.com' + end + + context 'when the public path is not known' do + before do + allow(project).to receive(:public_path_for_source_path).with(source_path, sha).and_return(nil) + end + + it 'returns nil' do + expect(environment.external_url_for(source_path, sha)).to be_nil + end + end + + context 'when the public path is known' do + before do + allow(project).to receive(:public_path_for_source_path).with(source_path, sha).and_return('file.html') + end + + it 'returns the full external URL' do + expect(environment.external_url_for(source_path, sha)).to eq('http://example.com/file.html') + end + end + end end |