diff options
author | Robert Speicher <robert@gitlab.com> | 2017-02-07 19:14:19 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-02-07 19:14:19 +0000 |
commit | 58eae0961ea6e2147a288cda8a56a51303bbf13b (patch) | |
tree | 0bbd873650dfc889af8df7e197397959d774d411 /spec/models/environment_spec.rb | |
parent | d3aaa1a2a0313b7132479d4211e406fde5bc9324 (diff) | |
parent | 0fdf54ddf5894ec1057b7351140fdce4f0df0ed1 (diff) | |
download | gitlab-ce-58eae0961ea6e2147a288cda8a56a51303bbf13b.tar.gz |
Merge branch 'route-map' into 'master'
Add 'View on [env]' link to blobs and individual files in diffs
See merge request !8867
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r-- | spec/models/environment_spec.rb | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 8b57d8600fe..960f29f3805 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -7,8 +7,6 @@ describe Environment, models: true do it { is_expected.to belong_to(:project) } it { is_expected.to have_many(:deployments) } - it { is_expected.to delegate_method(:last_deployment).to(:deployments).as(:last) } - it { is_expected.to delegate_method(:stop_action).to(:last_deployment) } it { is_expected.to delegate_method(:manual_actions).to(:last_deployment) } @@ -22,6 +20,20 @@ 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 '.order_by_last_deployed_at' do + let(:project) { create(:project) } + 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!(:deployment3) { create(:deployment, environment: environment1) } + + it 'returns the environments in order of having been last deployed' do + expect(project.environments.order_by_last_deployed_at.to_a).to eq([environment3, environment2, environment1]) + end + end + describe '#nullify_external_url' do it 'replaces a blank url with nil' do env = build(:environment, external_url: "") @@ -323,4 +335,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 |