debian-mirror-gitlab/spec/controllers/dashboard_controller_spec.rb

147 lines
3.7 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe DashboardController do
2018-11-29 20:51:05 +05:30
context 'signed in' do
let(:user) { create(:user) }
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
2018-11-29 20:51:05 +05:30
before do
project.add_maintainer(user)
sign_in(user)
end
2017-08-17 22:00:37 +05:30
2018-11-29 20:51:05 +05:30
describe 'GET issues' do
2022-05-07 20:08:51 +05:30
context 'when issues_full_text_search is disabled' do
before do
stub_feature_flags(issues_full_text_search: false)
end
it_behaves_like 'issuables list meta-data', :issue, :issues
end
context 'when issues_full_text_search is enabled' do
before do
stub_feature_flags(issues_full_text_search: true)
end
it_behaves_like 'issuables list meta-data', :issue, :issues
end
2018-11-29 20:51:05 +05:30
it_behaves_like 'issuables requiring filter', :issues
end
2017-08-17 22:00:37 +05:30
2018-11-29 20:51:05 +05:30
describe 'GET merge requests' do
it_behaves_like 'issuables list meta-data', :merge_request, :merge_requests
it_behaves_like 'issuables requiring filter', :merge_requests
end
2017-08-17 22:00:37 +05:30
end
2018-11-29 20:51:05 +05:30
2020-02-01 01:16:34 +05:30
describe "GET activity as JSON" do
2020-07-28 23:09:34 +05:30
include DesignManagementTestHelpers
2020-02-01 01:16:34 +05:30
render_views
let(:user) { create(:user) }
let(:project) { create(:project, :public, issues_access_level: ProjectFeature::PRIVATE) }
2020-07-28 23:09:34 +05:30
let(:other_project) { create(:project, :public) }
2020-02-01 01:16:34 +05:30
before do
2020-07-28 23:09:34 +05:30
enable_design_management
2020-02-01 01:16:34 +05:30
create(:event, :created, project: project, target: create(:issue))
2020-04-22 19:07:51 +05:30
create(:wiki_page_event, :created, project: project)
create(:wiki_page_event, :updated, project: project)
2020-07-28 23:09:34 +05:30
create(:design_event, project: project)
create(:design_event, author: user, project: other_project)
2020-02-01 01:16:34 +05:30
sign_in(user)
request.cookies[:event_filter] = 'all'
end
context 'when user has permission to see the event' do
before do
project.add_developer(user)
2020-07-28 23:09:34 +05:30
other_project.add_developer(user)
2020-02-01 01:16:34 +05:30
end
it 'returns count' do
get :activity, params: { format: :json }
2020-07-28 23:09:34 +05:30
expect(json_response['count']).to eq(6)
2020-02-01 01:16:34 +05:30
end
end
context 'when user has no permission to see the event' do
it 'filters out invisible event' do
get :activity, params: { format: :json }
expect(json_response['html']).to include(_('No activities found'))
end
it 'filters out invisible event when calculating the count' do
get :activity, params: { format: :json }
expect(json_response['count']).to eq(0)
end
end
end
2019-07-07 11:18:12 +05:30
describe "#check_filters_presence!" do
let(:user) { create(:user) }
before do
sign_in(user)
get :merge_requests, params: params
end
context "no filters" do
let(:params) { {} }
2022-05-07 20:08:51 +05:30
shared_examples_for 'no filters are set' do
it 'sets @no_filters_set to true' do
expect(assigns[:no_filters_set]).to eq(true)
end
end
it_behaves_like 'no filters are set'
context 'when key is present but value is not' do
let(:params) { { author_username: nil } }
it_behaves_like 'no filters are set'
end
context 'when in param is set but no search' do
let(:params) { { in: 'title' } }
it_behaves_like 'no filters are set'
end
end
shared_examples_for 'filters are set' do
2019-07-07 11:18:12 +05:30
it 'sets @no_filters_set to false' do
2022-05-07 20:08:51 +05:30
expect(assigns[:no_filters_set]).to eq(false)
2019-07-07 11:18:12 +05:30
end
end
context "scalar filters" do
let(:params) { { author_id: user.id } }
2022-05-07 20:08:51 +05:30
it_behaves_like 'filters are set'
2019-07-07 11:18:12 +05:30
end
context "array filters" do
let(:params) { { label_name: ['bug'] } }
2022-05-07 20:08:51 +05:30
it_behaves_like 'filters are set'
end
context 'search' do
let(:params) { { search: 'test' } }
it_behaves_like 'filters are set'
2019-07-07 11:18:12 +05:30
end
end
2017-08-17 22:00:37 +05:30
end