diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 06:06:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 06:06:32 +0300 |
commit | 284ae7dd7536df63fc6dd971f65ca420e26d2f05 (patch) | |
tree | 356c0c422685367487d15a8634e978d1f5e8f4ca /spec | |
parent | 2c0b1b6259d83e37c2a2b456a1f9afdb8817a3d5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/finders/deployments_finder_spec.rb | 61 | ||||
-rw-r--r-- | spec/requests/api/deployments_spec.rb | 43 |
2 files changed, 81 insertions, 23 deletions
diff --git a/spec/finders/deployments_finder_spec.rb b/spec/finders/deployments_finder_spec.rb new file mode 100644 index 00000000000..f21bb068c24 --- /dev/null +++ b/spec/finders/deployments_finder_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe DeploymentsFinder do + subject { described_class.new(project, params).execute } + + let(:project) { create(:project, :public, :repository) } + let(:params) { {} } + + describe "#execute" do + it 'returns all deployments by default' do + deployments = create_list(:deployment, 2, :success, project: project) + is_expected.to match_array(deployments) + end + + describe 'filtering' do + context 'when updated_at filters are specified' do + let(:params) { { updated_before: 1.day.ago, updated_after: 3.days.ago } } + let!(:deployment_1) { create(:deployment, :success, project: project, updated_at: 2.days.ago) } + let!(:deployment_2) { create(:deployment, :success, project: project, updated_at: 4.days.ago) } + let!(:deployment_3) { create(:deployment, :success, project: project, updated_at: 1.hour.ago) } + + it 'returns deployments with matched updated_at' do + is_expected.to match_array([deployment_1]) + end + end + end + + describe 'ordering' do + using RSpec::Parameterized::TableSyntax + + let(:params) { { order_by: order_by, sort: sort } } + + let!(:deployment_1) { create(:deployment, :success, project: project, iid: 11, ref: 'master', created_at: Time.now, updated_at: Time.now) } + let!(:deployment_2) { create(:deployment, :success, project: project, iid: 12, ref: 'feature', created_at: 1.day.ago, updated_at: 2.hours.ago) } + let!(:deployment_3) { create(:deployment, :success, project: project, iid: 8, ref: 'patch', created_at: 2.days.ago, updated_at: 1.hour.ago) } + + where(:order_by, :sort, :ordered_deployments) do + 'created_at' | 'asc' | [:deployment_3, :deployment_2, :deployment_1] + 'created_at' | 'desc' | [:deployment_1, :deployment_2, :deployment_3] + 'id' | 'asc' | [:deployment_1, :deployment_2, :deployment_3] + 'id' | 'desc' | [:deployment_3, :deployment_2, :deployment_1] + 'iid' | 'asc' | [:deployment_3, :deployment_1, :deployment_2] + 'iid' | 'desc' | [:deployment_2, :deployment_1, :deployment_3] + 'ref' | 'asc' | [:deployment_2, :deployment_1, :deployment_3] + 'ref' | 'desc' | [:deployment_3, :deployment_1, :deployment_2] + 'updated_at' | 'asc' | [:deployment_2, :deployment_3, :deployment_1] + 'updated_at' | 'desc' | [:deployment_1, :deployment_3, :deployment_2] + 'invalid' | 'asc' | [:deployment_1, :deployment_2, :deployment_3] + 'iid' | 'err' | [:deployment_3, :deployment_1, :deployment_2] + end + + with_them do + it 'returns the deployments ordered' do + expect(subject).to eq(ordered_deployments.map { |name| public_send(name) }) + end + end + end + end +end diff --git a/spec/requests/api/deployments_spec.rb b/spec/requests/api/deployments_spec.rb index 26849c0991d..91e047774bf 100644 --- a/spec/requests/api/deployments_spec.rb +++ b/spec/requests/api/deployments_spec.rb @@ -31,39 +31,36 @@ describe API::Deployments do end describe 'ordering' do - using RSpec::Parameterized::TableSyntax - - let(:order_by) { nil } - let(:sort) { nil } + let(:order_by) { 'iid' } + let(:sort) { 'desc' } subject { get api("/projects/#{project.id}/deployments?order_by=#{order_by}&sort=#{sort}", user) } + before do + subject + end + def expect_deployments(ordered_deployments) - json_response.each_with_index do |deployment_json, index| - expect(deployment_json['id']).to eq(public_send(ordered_deployments[index]).id) - end + expect(json_response.map { |d| d['id'] }).to eq(ordered_deployments.map(&:id)) end - before do - subject + it 'returns ordered deployments' do + expect(json_response.map { |i| i['id'] }).to eq([deployment_2.id, deployment_1.id, deployment_3.id]) end - where(:order_by, :sort, :ordered_deployments) do - 'created_at' | 'asc' | [:deployment_3, :deployment_2, :deployment_1] - 'created_at' | 'desc' | [:deployment_1, :deployment_2, :deployment_3] - 'id' | 'asc' | [:deployment_1, :deployment_2, :deployment_3] - 'id' | 'desc' | [:deployment_3, :deployment_2, :deployment_1] - 'iid' | 'asc' | [:deployment_3, :deployment_1, :deployment_2] - 'iid' | 'desc' | [:deployment_2, :deployment_1, :deployment_3] - 'ref' | 'asc' | [:deployment_2, :deployment_1, :deployment_3] - 'ref' | 'desc' | [:deployment_3, :deployment_1, :deployment_2] - 'updated_at' | 'asc' | [:deployment_2, :deployment_3, :deployment_1] - 'updated_at' | 'desc' | [:deployment_1, :deployment_3, :deployment_2] + context 'with invalid order_by' do + let(:order_by) { 'wrong_sorting_value' } + + it 'returns error' do + expect(response).to have_gitlab_http_status(400) + end end - with_them do - it 'returns the deployments ordered' do - expect_deployments(ordered_deployments) + context 'with invalid sorting' do + let(:sort) { 'wrong_sorting_direction' } + + it 'returns error' do + expect(response).to have_gitlab_http_status(400) end end end |