diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-01-31 03:26:40 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-02-07 01:12:24 +0300 |
commit | c8b63a28afa811881b617546fe94a19378585a04 (patch) | |
tree | 2b1bd2e9d52e059de0589a014f518f23e9b71ca3 /spec/models/environment_spec.rb | |
parent | 3aa1264dc6c0de3625bb1a2d6a0ee90140a2f519 (diff) |
Improve performance of finding last deployed environment
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r-- | spec/models/environment_spec.rb | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index e40a9bf4fbe..7b68d0756d0 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -22,22 +22,17 @@ 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 + 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(: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 + let!(:deployment1) { create(:deployment, environment: environment1) } - it 'returns the environment that the commit was last deployed to' do - expect(Environment.latest_for_commit([environment1, environment2, environment3], commit)).to be(environment2) + it 'returns the environments in order of having been last deployed' do + # byebug + expect(project.environments.order_by_last_deployed_at.to_a).to eq([environment3, environment2, environment1]) end end |