diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-24 03:09:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-24 03:09:52 +0300 |
commit | 0abfd0b478192436e7328469320923a04885a3b7 (patch) | |
tree | 89d0c8221a93de4bddf86e83eae08b3c18bd6c1a /spec | |
parent | 4e7abe540dbd1d170bfb2b3594e645cbfb48cac3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/finders/milestones_finder_spec.rb | 92 | ||||
-rw-r--r-- | spec/requests/api/group_milestones_spec.rb | 78 | ||||
-rw-r--r-- | spec/requests/api/project_milestones_spec.rb | 87 | ||||
-rw-r--r-- | spec/tasks/gitlab/db_rake_spec.rb | 10 |
4 files changed, 197 insertions, 70 deletions
diff --git a/spec/finders/milestones_finder_spec.rb b/spec/finders/milestones_finder_spec.rb index 8dd83df3a28..c4c62e21ad9 100644 --- a/spec/finders/milestones_finder_spec.rb +++ b/spec/finders/milestones_finder_spec.rb @@ -62,9 +62,31 @@ RSpec.describe MilestonesFinder do end context 'with filters' do - let_it_be(:milestone_1) { create(:milestone, group: group, state: 'closed', title: 'one test', start_date: now - 1.day, due_date: now) } - let_it_be(:milestone_3) { create(:milestone, project: project_1, state: 'closed', start_date: now + 2.days, due_date: now + 3.days) } + let_it_be(:milestone_1) do + create( + :milestone, + group: group, + state: 'closed', + title: 'one test', + start_date: now - 1.day, + due_date: now, + updated_at: now - 3.days + ) + end + + let_it_be(:milestone_3) do + create( + :milestone, + project: project_1, + state: 'closed', + description: 'three test', + start_date: now + 2.days, + due_date: now + 3.days, + updated_at: now - 5.days + ) + end + let(:result) { described_class.new(params).execute } let(:params) do { project_ids: [project_1.id, project_2.id], @@ -76,62 +98,96 @@ RSpec.describe MilestonesFinder do it 'filters by id' do params[:ids] = [milestone_1.id, milestone_2.id] - result = described_class.new(params).execute - expect(result).to contain_exactly(milestone_1, milestone_2) end it 'filters by active state' do params[:state] = 'active' - result = described_class.new(params).execute expect(result).to contain_exactly(milestone_2, milestone_4) end it 'filters by closed state' do params[:state] = 'closed' - result = described_class.new(params).execute expect(result).to contain_exactly(milestone_1, milestone_3) end it 'filters by title' do - result = described_class.new(params.merge(title: 'one test')).execute + params[:title] = 'one test' - expect(result.to_a).to contain_exactly(milestone_1) + expect(result).to contain_exactly(milestone_1) end it 'filters by search_title' do - result = described_class.new(params.merge(search_title: 'one t')).execute + params[:search_title] = 'test' + + expect(result).to contain_exactly(milestone_1) + end + + it 'filters by search (title, description)' do + params[:search] = 'test' - expect(result.to_a).to contain_exactly(milestone_1) + expect(result).to contain_exactly(milestone_1, milestone_3) end context 'by timeframe' do it 'returns milestones with start_date and due_date between timeframe' do params.merge!(start_date: now - 1.day, end_date: now + 3.days) - milestones = described_class.new(params).execute - - expect(milestones).to match_array([milestone_1, milestone_2, milestone_3]) + expect(result).to contain_exactly(milestone_1, milestone_2, milestone_3) end it 'returns milestones which starts before the timeframe' do milestone = create(:milestone, project: project_2, start_date: now - 5.days) params.merge!(start_date: now - 3.days, end_date: now - 2.days) - milestones = described_class.new(params).execute - - expect(milestones).to match_array([milestone]) + expect(result).to contain_exactly(milestone) end it 'returns milestones which ends after the timeframe' do milestone = create(:milestone, project: project_2, due_date: now + 6.days) params.merge!(start_date: now + 6.days, end_date: now + 7.days) - milestones = described_class.new(params).execute + expect(result).to contain_exactly(milestone) + end + end + + context 'by updated_at' do + it 'returns milestones updated before a given date' do + params[:updated_before] = 4.days.ago.iso8601 + + expect(result).to contain_exactly(milestone_3) + end + + it 'returns milestones updated after a given date' do + params[:updated_after] = 4.days.ago.iso8601 + + expect(result).to contain_exactly(milestone_1, milestone_2, milestone_4) + end + + it 'returns milestones updated between the given dates' do + params.merge!(updated_after: 6.days.ago.iso8601, updated_before: 4.days.ago.iso8601) + + expect(result).to contain_exactly(milestone_3) + end + end + + context 'by iids' do + before do + params[:iids] = 1 + end - expect(milestones).to match_array([milestone]) + it 'returns milestone for the given iids' do + expect(result).to contain_exactly(milestone_2, milestone_3, milestone_4) + end + + context 'when include_parent_milestones is true' do + it 'ignores the iid filter' do + params[:include_parent_milestones] = true + + expect(result).to contain_exactly(milestone_1, milestone_2, milestone_3, milestone_4) + end end end end diff --git a/spec/requests/api/group_milestones_spec.rb b/spec/requests/api/group_milestones_spec.rb index 91f64d02d43..2f05b0fcf21 100644 --- a/spec/requests/api/group_milestones_spec.rb +++ b/spec/requests/api/group_milestones_spec.rb @@ -4,35 +4,41 @@ require 'spec_helper' RSpec.describe API::GroupMilestones, feature_category: :team_planning do let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group, :private) } + let_it_be_with_refind(:group) { create(:group, :private) } let_it_be(:project) { create(:project, namespace: group) } let_it_be(:group_member) { create(:group_member, group: group, user: user) } - let_it_be(:closed_milestone) { create(:closed_milestone, group: group, title: 'version1', description: 'closed milestone') } - let_it_be(:milestone) { create(:milestone, group: group, title: 'version2', description: 'open milestone') } + let_it_be(:closed_milestone) do + create(:closed_milestone, group: group, title: 'version1', description: 'closed milestone') + end + + let_it_be_with_reload(:milestone) do + create(:milestone, group: group, title: 'version2', description: 'open milestone', updated_at: 4.days.ago) + end let(:route) { "/groups/#{group.id}/milestones" } + shared_examples 'listing all milestones' do + it 'returns correct list of milestones' do + get api(route, user), params: params + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.size).to eq(milestones.size) + expect(json_response.map { |entry| entry["id"] }).to eq(milestones.map(&:id)) + end + end + it_behaves_like 'group and project milestones', "/groups/:id/milestones" describe 'GET /groups/:id/milestones' do - context 'when include_parent_milestones is true' do - let_it_be(:ancestor_group) { create(:group, :private) } - let_it_be(:ancestor_group_milestone) { create(:milestone, group: ancestor_group) } - let_it_be(:params) { { include_parent_milestones: true } } - - before_all do - group.update!(parent: ancestor_group) - end + let_it_be(:ancestor_group) { create(:group, :private) } + let_it_be(:ancestor_group_milestone) { create(:milestone, group: ancestor_group, updated_at: 2.days.ago) } - shared_examples 'listing all milestones' do - it 'returns correct list of milestones' do - get api(route, user), params: params + before_all do + group.update!(parent: ancestor_group) + end - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.size).to eq(milestones.size) - expect(json_response.map { |entry| entry["id"] }).to eq(milestones.map(&:id)) - end - end + context 'when include_parent_milestones is true' do + let(:params) { { include_parent_milestones: true } } context 'when user has access to ancestor groups' do let(:milestones) { [ancestor_group_milestone, milestone, closed_milestone] } @@ -45,10 +51,26 @@ RSpec.describe API::GroupMilestones, feature_category: :team_planning do it_behaves_like 'listing all milestones' context 'when iids param is present' do - let_it_be(:params) { { include_parent_milestones: true, iids: [milestone.iid] } } + let(:params) { { include_parent_milestones: true, iids: [milestone.iid] } } it_behaves_like 'listing all milestones' end + + context 'when updated_before param is present' do + let(:params) { { updated_before: 1.day.ago.iso8601, include_parent_milestones: true } } + + it_behaves_like 'listing all milestones' do + let(:milestones) { [ancestor_group_milestone, milestone] } + end + end + + context 'when updated_after param is present' do + let(:params) { { updated_after: 1.day.ago.iso8601, include_parent_milestones: true } } + + it_behaves_like 'listing all milestones' do + let(:milestones) { [closed_milestone] } + end + end end context 'when user has no access to ancestor groups' do @@ -63,6 +85,22 @@ RSpec.describe API::GroupMilestones, feature_category: :team_planning do end end end + + context 'when updated_before param is present' do + let(:params) { { updated_before: 1.day.ago.iso8601 } } + + it_behaves_like 'listing all milestones' do + let(:milestones) { [milestone] } + end + end + + context 'when updated_after param is present' do + let(:params) { { updated_after: 1.day.ago.iso8601 } } + + it_behaves_like 'listing all milestones' do + let(:milestones) { [closed_milestone] } + end + end end describe 'GET /groups/:id/milestones/:milestone_id/issues' do diff --git a/spec/requests/api/project_milestones_spec.rb b/spec/requests/api/project_milestones_spec.rb index 9d722e4a445..978ac28ef73 100644 --- a/spec/requests/api/project_milestones_spec.rb +++ b/spec/requests/api/project_milestones_spec.rb @@ -6,8 +6,12 @@ RSpec.describe API::ProjectMilestones, feature_category: :team_planning do let_it_be(:user) { create(:user) } let_it_be_with_reload(:project) { create(:project, namespace: user.namespace) } let_it_be(:closed_milestone) { create(:closed_milestone, project: project, title: 'version1', description: 'closed milestone') } - let_it_be(:milestone) { create(:milestone, project: project, title: 'version2', description: 'open milestone') } let_it_be(:route) { "/projects/#{project.id}/milestones" } + let_it_be(:milestone) do + create(:milestone, project: project, title: 'version2', description: 'open milestone', updated_at: 5.days.ago) + end + + let(:params) { {} } before_all do project.add_reporter(user) @@ -15,38 +19,43 @@ RSpec.describe API::ProjectMilestones, feature_category: :team_planning do it_behaves_like 'group and project milestones', "/projects/:id/milestones" + shared_examples 'listing all milestones' do + it 'returns correct list of milestones' do + get api(route, user), params: params + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.size).to eq(milestones.size) + expect(json_response.map { |entry| entry["id"] }).to match_array(milestones.map(&:id)) + end + end + describe 'GET /projects/:id/milestones' do - context 'when include_parent_milestones is true' do - let_it_be(:ancestor_group) { create(:group, :private) } - let_it_be(:group) { create(:group, :private, parent: ancestor_group) } - let_it_be(:ancestor_group_milestone) { create(:milestone, group: ancestor_group) } - let_it_be(:group_milestone) { create(:milestone, group: group) } + let_it_be(:ancestor_group) { create(:group, :private) } + let_it_be(:group) { create(:group, :private, parent: ancestor_group) } + let_it_be(:ancestor_group_milestone) { create(:milestone, group: ancestor_group, updated_at: 1.day.ago) } + let_it_be(:group_milestone) { create(:milestone, group: group, updated_at: 3.days.ago) } - let(:params) { { include_parent_milestones: true } } + context 'when project parent is a namespace' do + let(:milestones) { [milestone, closed_milestone] } - shared_examples 'listing all milestones' do - it 'returns correct list of milestones' do - get api(route, user), params: params + it_behaves_like 'listing all milestones' - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.size).to eq(milestones.size) - expect(json_response.map { |entry| entry["id"] }).to eq(milestones.map(&:id)) - end + context 'when include_parent_milestones is true' do + let(:params) { { include_parent_milestones: true } } + + it_behaves_like 'listing all milestones' end + end - context 'when project parent is a namespace' do - it_behaves_like 'listing all milestones' do - let(:milestones) { [milestone, closed_milestone] } - end + context 'when project parent is a group' do + before_all do + project.update!(namespace: group) end - context 'when project parent is a group' do + context 'when include_parent_milestones is true' do + let(:params) { { include_parent_milestones: true } } let(:milestones) { [group_milestone, ancestor_group_milestone, milestone, closed_milestone] } - before_all do - project.update!(namespace: group) - end - it_behaves_like 'listing all milestones' context 'when iids param is present' do @@ -64,6 +73,38 @@ RSpec.describe API::ProjectMilestones, feature_category: :team_planning do expect(response).to have_gitlab_http_status(:not_found) end end + + context 'when updated_before param is present' do + let(:params) { { updated_before: 12.hours.ago.iso8601, include_parent_milestones: true } } + + it_behaves_like 'listing all milestones' do + let(:milestones) { [group_milestone, ancestor_group_milestone, milestone] } + end + end + + context 'when updated_after param is present' do + let(:params) { { updated_after: 2.days.ago.iso8601, include_parent_milestones: true } } + + it_behaves_like 'listing all milestones' do + let(:milestones) { [ancestor_group_milestone, closed_milestone] } + end + end + end + + context 'when updated_before param is present' do + let(:params) { { updated_before: 12.hours.ago.iso8601 } } + + it_behaves_like 'listing all milestones' do + let(:milestones) { [milestone] } + end + end + + context 'when updated_after param is present' do + let(:params) { { updated_after: 2.days.ago.iso8601 } } + + it_behaves_like 'listing all milestones' do + let(:milestones) { [closed_milestone] } + end end end end diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb index a9977e07feb..e506144ea3e 100644 --- a/spec/tasks/gitlab/db_rake_spec.rb +++ b/spec/tasks/gitlab/db_rake_spec.rb @@ -16,7 +16,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor before do # Stub out db tasks allow(Rake::Task['db:migrate']).to receive(:invoke).and_return(true) - allow(Rake::Task['db:structure:load']).to receive(:invoke).and_return(true) + allow(Rake::Task['db:schema:load']).to receive(:invoke).and_return(true) allow(Rake::Task['db:seed_fu']).to receive(:invoke).and_return(true) end @@ -1049,14 +1049,6 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor skip_unless_ci_uses_database_tasks end - describe 'db:structure:dump against a single database' do - it 'invokes gitlab:db:clean_structure_sql' do - expect(Rake::Task['gitlab:db:clean_structure_sql']).to receive(:invoke).twice.and_return(true) - - expect { run_rake_task('db:structure:dump:main') }.not_to raise_error - end - end - describe 'db:schema:dump against a single database' do it 'invokes gitlab:db:clean_structure_sql' do expect(Rake::Task['gitlab:db:clean_structure_sql']).to receive(:invoke).once.and_return(true) |