diff options
author | Krasimir Angelov <kangelov@gitlab.com> | 2019-08-20 13:29:16 +0300 |
---|---|---|
committer | Krasimir Angelov <kangelov@gitlab.com> | 2019-08-22 15:36:55 +0300 |
commit | d86b77bf20474702631d5fd89177c54a9f928760 (patch) | |
tree | 3a1fcdc0eda151cb1e9b9a391e6a68df43060c02 /spec/models/deployment_spec.rb | |
parent | 51c19691e4c4ceb60ef28fd08c6b13549a423a39 (diff) |
Extract logic who created deployment into Deployment#deployed_by
Prefer the deployable user over the deployment user.
Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/66037.
Diffstat (limited to 'spec/models/deployment_spec.rb')
-rw-r--r-- | spec/models/deployment_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index d4e631f109b..51ed8e9421b 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -322,4 +322,30 @@ describe Deployment do end end end + + describe '#deployed_by' do + it 'returns the deployment user if there is no deployable' do + deployment_user = create(:user) + deployment = create(:deployment, deployable: nil, user: deployment_user) + + expect(deployment.deployed_by).to eq(deployment_user) + end + + it 'returns the deployment user if the deployable have no user' do + deployment_user = create(:user) + build = create(:ci_build, user: nil) + deployment = create(:deployment, deployable: build, user: deployment_user) + + expect(deployment.deployed_by).to eq(deployment_user) + end + + it 'returns the deployable user if there is one' do + build_user = create(:user) + deployment_user = create(:user) + build = create(:ci_build, user: build_user) + deployment = create(:deployment, deployable: build, user: deployment_user) + + expect(deployment.deployed_by).to eq(build_user) + end + end end |