diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-25 15:10:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-25 15:10:19 +0300 |
commit | e5d3d8c323872cb5dee33c5388b3157294c30343 (patch) | |
tree | 8d954820c1f876c9df58fc7ac06a181782822db4 /spec/support | |
parent | 45760607bc053b7379f81edd5ea91dd2a6471522 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
4 files changed, 70 insertions, 2 deletions
diff --git a/spec/support/database/gitlab_schemas.yml b/spec/support/database/gitlab_schemas.yml index c4fee55e071..d46f2803c93 100644 --- a/spec/support/database/gitlab_schemas.yml +++ b/spec/support/database/gitlab_schemas.yml @@ -286,6 +286,7 @@ licenses: :gitlab_main lists: :gitlab_main list_user_preferences: :gitlab_main loose_foreign_keys_deleted_records: :gitlab_main +member_tasks: :gitlab_main members: :gitlab_main merge_request_assignees: :gitlab_main merge_request_blocks: :gitlab_main diff --git a/spec/support/shared_examples/models/member_shared_examples.rb b/spec/support/shared_examples/models/member_shared_examples.rb index 56c202cb228..a2909c66e22 100644 --- a/spec/support/shared_examples/models/member_shared_examples.rb +++ b/spec/support/shared_examples/models/member_shared_examples.rb @@ -299,6 +299,22 @@ RSpec.shared_examples_for "member creation" do end end end + + context 'when `tasks_to_be_done` and `tasks_project_id` are passed' do + before do + stub_experiments(invite_members_for_task: true) + end + + it 'creates a member_task with the correct attributes', :aggregate_failures do + task_project = source.is_a?(Group) ? create(:project, group: source) : source + described_class.new(source, user, :developer, tasks_to_be_done: %w(ci code), tasks_project_id: task_project.id).execute + + member = source.members.last + + expect(member.tasks_to_be_done).to match_array([:ci, :code]) + expect(member.member_task.project).to eq(task_project) + end + end end end @@ -379,5 +395,20 @@ RSpec.shared_examples_for "bulk member creation" do expect(members).to all(be_persisted) end end + + context 'when `tasks_to_be_done` and `tasks_project_id` are passed' do + before do + stub_experiments(invite_members_for_task: true) + end + + it 'creates a member_task with the correct attributes', :aggregate_failures do + task_project = source.is_a?(Group) ? create(:project, group: source) : source + members = described_class.add_users(source, [user1], :developer, tasks_to_be_done: %w(ci code), tasks_project_id: task_project.id) + member = members.last + + expect(member.tasks_to_be_done).to match_array([:ci, :code]) + expect(member.member_task.project).to eq(task_project) + end + end end end diff --git a/spec/support/shared_examples/namespaces/traversal_examples.rb b/spec/support/shared_examples/namespaces/traversal_examples.rb index d126b242fb0..0e60476f10a 100644 --- a/spec/support/shared_examples/namespaces/traversal_examples.rb +++ b/spec/support/shared_examples/namespaces/traversal_examples.rb @@ -22,6 +22,8 @@ RSpec.shared_examples 'namespace traversal' do let_it_be(:deep_nested_group) { create(:group, parent: nested_group) } let_it_be(:very_deep_nested_group) { create(:group, parent: deep_nested_group) } let_it_be(:groups) { [group, nested_group, deep_nested_group, very_deep_nested_group] } + let_it_be(:project) { create(:project, group: nested_group) } + let_it_be(:project_namespace) { create(:project_namespace, project: project) } describe '#root_ancestor' do it 'returns the correct root ancestor' do @@ -65,6 +67,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.ancestors).to contain_exactly(group, nested_group) expect(nested_group.ancestors).to contain_exactly(group) expect(group.ancestors).to eq([]) + expect(project_namespace.ancestors).to be_empty end context 'with asc hierarchy_order' do @@ -73,6 +76,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.ancestors(hierarchy_order: :asc)).to eq [nested_group, group] expect(nested_group.ancestors(hierarchy_order: :asc)).to eq [group] expect(group.ancestors(hierarchy_order: :asc)).to eq([]) + expect(project_namespace.ancestors(hierarchy_order: :asc)).to be_empty end end @@ -82,6 +86,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.ancestors(hierarchy_order: :desc)).to eq [group, nested_group] expect(nested_group.ancestors(hierarchy_order: :desc)).to eq [group] expect(group.ancestors(hierarchy_order: :desc)).to eq([]) + expect(project_namespace.ancestors(hierarchy_order: :desc)).to be_empty end end @@ -98,6 +103,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.ancestor_ids).to contain_exactly(group.id, nested_group.id) expect(nested_group.ancestor_ids).to contain_exactly(group.id) expect(group.ancestor_ids).to be_empty + expect(project_namespace.ancestor_ids).to be_empty end context 'with asc hierarchy_order' do @@ -106,6 +112,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.ancestor_ids(hierarchy_order: :asc)).to eq [nested_group.id, group.id] expect(nested_group.ancestor_ids(hierarchy_order: :asc)).to eq [group.id] expect(group.ancestor_ids(hierarchy_order: :asc)).to eq([]) + expect(project_namespace.ancestor_ids(hierarchy_order: :asc)).to eq([]) end end @@ -115,6 +122,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.ancestor_ids(hierarchy_order: :desc)).to eq [group.id, nested_group.id] expect(nested_group.ancestor_ids(hierarchy_order: :desc)).to eq [group.id] expect(group.ancestor_ids(hierarchy_order: :desc)).to eq([]) + expect(project_namespace.ancestor_ids(hierarchy_order: :desc)).to eq([]) end end @@ -131,6 +139,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.self_and_ancestors).to contain_exactly(group, nested_group, deep_nested_group) expect(nested_group.self_and_ancestors).to contain_exactly(group, nested_group) expect(group.self_and_ancestors).to contain_exactly(group) + expect(project_namespace.self_and_ancestors).to contain_exactly(project_namespace) end context 'with asc hierarchy_order' do @@ -139,6 +148,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.self_and_ancestors(hierarchy_order: :asc)).to eq [deep_nested_group, nested_group, group] expect(nested_group.self_and_ancestors(hierarchy_order: :asc)).to eq [nested_group, group] expect(group.self_and_ancestors(hierarchy_order: :asc)).to eq([group]) + expect(project_namespace.self_and_ancestors(hierarchy_order: :asc)).to eq([project_namespace]) end end @@ -148,6 +158,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.self_and_ancestors(hierarchy_order: :desc)).to eq [group, nested_group, deep_nested_group] expect(nested_group.self_and_ancestors(hierarchy_order: :desc)).to eq [group, nested_group] expect(group.self_and_ancestors(hierarchy_order: :desc)).to eq([group]) + expect(project_namespace.self_and_ancestors(hierarchy_order: :desc)).to eq([project_namespace]) end end @@ -164,6 +175,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.self_and_ancestor_ids).to contain_exactly(group.id, nested_group.id, deep_nested_group.id) expect(nested_group.self_and_ancestor_ids).to contain_exactly(group.id, nested_group.id) expect(group.self_and_ancestor_ids).to contain_exactly(group.id) + expect(project_namespace.self_and_ancestor_ids).to contain_exactly(project_namespace.id) end context 'with asc hierarchy_order' do @@ -172,6 +184,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.self_and_ancestor_ids(hierarchy_order: :asc)).to eq [deep_nested_group.id, nested_group.id, group.id] expect(nested_group.self_and_ancestor_ids(hierarchy_order: :asc)).to eq [nested_group.id, group.id] expect(group.self_and_ancestor_ids(hierarchy_order: :asc)).to eq([group.id]) + expect(project_namespace.self_and_ancestor_ids(hierarchy_order: :asc)).to eq([project_namespace.id]) end end @@ -181,6 +194,7 @@ RSpec.shared_examples 'namespace traversal' do expect(deep_nested_group.self_and_ancestor_ids(hierarchy_order: :desc)).to eq [group.id, nested_group.id, deep_nested_group.id] expect(nested_group.self_and_ancestor_ids(hierarchy_order: :desc)).to eq [group.id, nested_group.id] expect(group.self_and_ancestor_ids(hierarchy_order: :desc)).to eq([group.id]) + expect(project_namespace.self_and_ancestor_ids(hierarchy_order: :desc)).to eq([project_namespace.id]) end end @@ -205,6 +219,10 @@ RSpec.shared_examples 'namespace traversal' do describe '#recursive_descendants' do it_behaves_like 'recursive version', :descendants end + + it 'does not include project namespaces' do + expect(group.descendants.to_a).not_to include(project_namespace) + end end describe '#self_and_descendants' do @@ -223,6 +241,10 @@ RSpec.shared_examples 'namespace traversal' do it_behaves_like 'recursive version', :self_and_descendants end + + it 'does not include project namespaces' do + expect(group.self_and_descendants.to_a).not_to include(project_namespace) + end end describe '#self_and_descendant_ids' do diff --git a/spec/support/shared_examples/namespaces/traversal_scope_examples.rb b/spec/support/shared_examples/namespaces/traversal_scope_examples.rb index a315598b989..ba28ce1b45d 100644 --- a/spec/support/shared_examples/namespaces/traversal_scope_examples.rb +++ b/spec/support/shared_examples/namespaces/traversal_scope_examples.rb @@ -26,9 +26,23 @@ RSpec.shared_examples 'namespace traversal scopes' do end describe '.without_sti_condition' do - subject { described_class.without_sti_condition } + subject { described_class.where(type: 'Group').without_sti_condition } - it { expect(subject.where_values_hash).not_to have_key(:type) } + context 'when include_sti_condition is enabled' do + before do + stub_feature_flags(include_sti_condition: true) + end + + it { expect(subject.where_values_hash).to have_key('type') } + end + + context 'when include_sti_condition is disabled' do + before do + stub_feature_flags(include_sti_condition: false) + end + + it { expect(subject.where_values_hash).not_to have_key('type') } + end end describe '.order_by_depth' do |