2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-12 12:48:53 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Projects::GraphsController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-10-12 12:48:53 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-10-12 12:48:53 -04:00
|
|
|
end
|
|
|
|
|
2017-03-02 12:57:01 -05:00
|
|
|
describe 'GET languages' do
|
|
|
|
it "redirects_to action charts" do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:commits, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' })
|
2017-03-02 12:57:01 -05:00
|
|
|
|
|
|
|
expect(response).to redirect_to action: :charts
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET commits' do
|
|
|
|
it "redirects_to action charts" do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:commits, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' })
|
2017-03-02 12:57:01 -05:00
|
|
|
|
|
|
|
expect(response).to redirect_to action: :charts
|
|
|
|
end
|
|
|
|
end
|
2019-02-25 02:57:34 -05:00
|
|
|
|
|
|
|
describe 'charts' do
|
2019-05-04 05:11:06 -04:00
|
|
|
context 'with an anonymous user' do
|
|
|
|
let(:project) { create(:project, :repository, :public) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_out(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders charts with 200 status code' do
|
|
|
|
get(:charts, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' })
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to render_template(:charts)
|
|
|
|
end
|
2020-05-15 02:08:40 -04:00
|
|
|
|
2020-06-05 11:08:23 -04:00
|
|
|
context 'when anonymous users can read build report results' do
|
|
|
|
it 'sets the daily coverage options' do
|
|
|
|
Timecop.freeze do
|
|
|
|
get(:charts, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' })
|
|
|
|
|
|
|
|
expect(assigns[:daily_coverage_options]).to eq(
|
|
|
|
base_params: {
|
2020-06-09 14:08:28 -04:00
|
|
|
start_date: Date.current - 90.days,
|
|
|
|
end_date: Date.current,
|
2020-06-05 11:08:23 -04:00
|
|
|
ref_path: project.repository.expand_ref('master'),
|
|
|
|
param_type: 'coverage'
|
|
|
|
},
|
|
|
|
download_path: namespace_project_ci_daily_build_group_report_results_path(
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
format: :csv
|
2020-06-09 14:08:28 -04:00
|
|
|
),
|
|
|
|
graph_api_path: namespace_project_ci_daily_build_group_report_results_path(
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
format: :json
|
2020-06-05 11:08:23 -04:00
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when anonymous users cannot read build report results' do
|
|
|
|
before do
|
|
|
|
project.update_column(:public_builds, false)
|
|
|
|
|
2020-05-15 02:08:40 -04:00
|
|
|
get(:charts, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' })
|
2020-06-05 11:08:23 -04:00
|
|
|
end
|
2020-05-15 02:08:40 -04:00
|
|
|
|
2020-06-05 11:08:23 -04:00
|
|
|
it 'does not set daily coverage options' do
|
|
|
|
expect(assigns[:daily_coverage_options]).to be_nil
|
2020-05-15 02:08:40 -04:00
|
|
|
end
|
|
|
|
end
|
2020-06-22 11:09:27 -04:00
|
|
|
|
|
|
|
it_behaves_like 'tracking unique visits', :charts do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:request_params) { { namespace_id: project.namespace.path, project_id: project.path, id: 'master' } }
|
|
|
|
let(:target_id) { 'p_analytics_repo' }
|
|
|
|
end
|
2019-05-04 05:11:06 -04:00
|
|
|
end
|
|
|
|
|
2019-02-25 02:57:34 -05:00
|
|
|
context 'when languages were previously detected' do
|
2019-03-20 13:23:23 -04:00
|
|
|
let(:project) { create(:project, :repository, detected_repository_languages: true) }
|
2019-02-25 02:57:34 -05:00
|
|
|
let!(:repository_language) { create(:repository_language, project: project) }
|
|
|
|
|
|
|
|
it 'sets the languages properly' do
|
|
|
|
get(:charts, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' })
|
|
|
|
|
|
|
|
expect(assigns[:languages]).to eq(
|
|
|
|
[value: repository_language.share,
|
|
|
|
label: repository_language.name,
|
|
|
|
color: repository_language.color,
|
|
|
|
highlight: repository_language.color])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-10-12 12:48:53 -04:00
|
|
|
end
|