debian-mirror-gitlab/spec/controllers/groups/releases_controller_spec.rb

76 lines
2.3 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::ReleasesController do
let(:group) { create(:group) }
let!(:project) { create(:project, :repository, :public, namespace: group) }
let!(:private_project) { create(:project, :repository, :private, namespace: group) }
2022-04-04 11:22:00 +05:30
let(:guest) { create(:user) }
2020-10-24 23:57:45 +05:30
let!(:release_1) { create(:release, project: project, tag: 'v1', released_at: Time.zone.parse('2020-02-15')) }
let!(:release_2) { create(:release, project: project, tag: 'v2', released_at: Time.zone.parse('2020-02-20')) }
let!(:private_release_1) { create(:release, project: private_project, tag: 'p1', released_at: Time.zone.parse('2020-03-01')) }
let!(:private_release_2) { create(:release, project: private_project, tag: 'p2', released_at: Time.zone.parse('2020-03-05')) }
before do
2022-04-04 11:22:00 +05:30
group.add_guest(guest)
2020-10-24 23:57:45 +05:30
end
describe 'GET #index' do
context 'as json' do
let(:format) { :json }
subject { get :index, params: { group_id: group }, format: format }
context 'json_response' do
before do
subject
end
it 'returns an application/json content_type' do
2021-02-22 17:27:13 +05:30
expect(response.media_type).to eq 'application/json'
2020-10-24 23:57:45 +05:30
end
it 'returns OK' do
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'the user is not authorized' do
before do
subject
end
it 'does not return any releases' do
2022-04-04 11:22:00 +05:30
expect(json_response.map {|r| r['tag'] } ).to be_empty
2020-10-24 23:57:45 +05:30
end
it 'returns OK' do
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'the user is authorized' do
it "returns all group's public and private project's releases as JSON, ordered by released_at" do
2022-04-04 11:22:00 +05:30
sign_in(guest)
2020-10-24 23:57:45 +05:30
subject
expect(json_response.map {|r| r['tag'] } ).to match_array(%w(p2 p1 v2 v1))
end
end
context 'N+1 queries' do
it 'avoids N+1 database queries' do
control_count = ActiveRecord::QueryRecorder.new { subject }.count
create_list(:release, 5, project: project)
create_list(:release, 5, project: private_project)
expect { subject }.not_to exceed_query_limit(control_count)
end
end
end
end
end