diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-03-27 11:22:43 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-03-28 12:06:47 +0200 |
commit | 601f50c6421f135b52f737a3b59baa32e6a8f1fd (patch) | |
tree | a904ead845fadeffb41a91d48452a04cf520f33c /spec/controllers | |
parent | 19a4403443ff6217e6a024667f8ef1eea2f38f4a (diff) | |
download | gitlab-ce-601f50c6421f135b52f737a3b59baa32e6a8f1fd.tar.gz |
Add endpoint that returns a list of deployments that happened within last 8.hours
add index created_at
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/projects/deployments_controller_spec.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb new file mode 100644 index 00000000000..97a9fb8ae61 --- /dev/null +++ b/spec/controllers/projects/deployments_controller_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe Projects::DeploymentsController do + include ApiHelpers + + let(:user) { create(:user) } + let(:project) { create(:empty_project) } + let(:environment) { create(:environment, name: 'production', project: project) } + let(:deployment) { create(:deployment, project: project, environment: environment) } + + before do + project.team << [user, :master] + + sign_in(user) + end + + describe 'GET #index' do + it 'returns list of deployments withing last 8 hours' do + create(:deployment, environment: environment, created_at: 9.hours.ago) + create(:deployment, environment: environment, created_at: 7.hours.ago) + create(:deployment, environment: environment) + + get :index, environment_params + + expect(response).to be_ok + + expect(json_response['deployments'].count).to eq(2) + end + + it 'returns a list with deployments information' do + deployment = create(:deployment, environment: environment) + + get :index, environment_params + expect(response).to be_ok + + deployments = json_response['deployments'] + deployment_info = deployments.first.with_indifferent_access + created_at = deployment_info.delete(:created_at).to_time.utc + + expect(deployments.count).to eq(1) + expect(deployment_info).to include(:id, :iid, :sha, :ref, :tag) + expect(deployment).to have_attributes(deployment_info) + expect(deployment.created_at).to be_within(1.second).of(created_at) + end + end + + def environment_params(opts={}) + opts.reverse_merge(namespace_id: project.namespace, project_id: project, environment_id: environment.id) + end +end |