Commit 4830c9c0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'pl-spec_flat_map' into 'master'

Prefer `flat_map` over `map` + `flatten` in specs

See merge request gitlab-org/gitlab-ee!14799
parents 02cc617b 8450a388
......@@ -72,8 +72,8 @@ describe Gitlab::Metrics::Dashboard::Processor do
private
def all_metrics
dashboard[:panel_groups].map do |group|
group[:panels].map { |panel| panel[:metrics] }
end.flatten
dashboard[:panel_groups].flat_map do |group|
group[:panels].flat_map { |panel| panel[:metrics] }
end
end
end
......@@ -9,7 +9,7 @@ describe Gitlab::Prometheus::MetricGroup do
subject do
described_class.for_project(project)
.map(&:metrics).flatten
.flat_map(&:metrics)
.map(&:id)
end
......
......@@ -62,7 +62,7 @@ describe Groups::ParticipantsService do
service.instance_variable_set(:@noteable, epic)
result = service.group_members
expected_users = (group.self_and_hierarchy.map(&:users).flatten + subproject.users)
expected_users = (group.self_and_hierarchy.flat_map(&:users) + subproject.users)
.map(&method(:user_to_autocompletable))
expect(expected_users.count).to eq(5)
......
......@@ -158,7 +158,7 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
get_show_json
json_response.dig('pipeline', 'details', 'stages').tap do |stages|
expect(stages.map(&:keys).flatten)
expect(stages.flat_map(&:keys))
.to eq %w[name title status path dropdown_path]
end
end
......
......@@ -7,8 +7,8 @@ describe Gitlab::DatabaseImporters::CommonMetrics::Importer do
context "does import common_metrics.yml" do
let(:groups) { subject.content['panel_groups'] }
let(:panels) { groups.map { |group| group['panels'] }.flatten }
let(:metrics) { panels.map { |group| group['metrics'] }.flatten }
let(:panels) { groups.flat_map { |group| group['panels'] } }
let(:metrics) { panels.flat_map { |group| group['metrics'] } }
let(:metric_ids) { metrics.map { |metric| metric['id'] } }
before do
......
......@@ -179,9 +179,9 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
end
it 'has priorities associated to labels' do
priorities = saved_project_json['issues'].first['label_links'].map { |link| link['label']['priorities'] }
priorities = saved_project_json['issues'].first['label_links'].flat_map { |link| link['label']['priorities'] }
expect(priorities.flatten).not_to be_empty
expect(priorities).not_to be_empty
end
it 'has issue resource label events' do
......
......@@ -101,9 +101,9 @@ describe Gitlab::Metrics::Dashboard::Processor do
private
def all_metrics
dashboard[:panel_groups].map do |group|
group[:panels].map { |panel| panel[:metrics] }
end.flatten
dashboard[:panel_groups].flat_map do |group|
group[:panels].flat_map { |panel| panel[:metrics] }
end
end
def get_metric_details(metric)
......
......@@ -17,7 +17,7 @@ describe Gitlab::Prometheus::MetricGroup do
end
it 'returns exactly three metric queries' do
expect(subject.map(&:metrics).flatten.map(&:id)).to contain_exactly(
expect(subject.flat_map(&:metrics).map(&:id)).to contain_exactly(
common_metric_group_a.id, common_metric_group_b_q1.id,
common_metric_group_b_q2.id)
end
......@@ -37,7 +37,7 @@ describe Gitlab::Prometheus::MetricGroup do
subject do
described_class.for_project(other_project)
.map(&:metrics).flatten
.flat_map(&:metrics)
.map(&:id)
end
......
......@@ -81,10 +81,9 @@ describe WikiPage do
grouped_entries = described_class.group_by_directory(wiki.list_pages)
actual_order =
grouped_entries.map do |page_or_dir|
grouped_entries.flat_map do |page_or_dir|
get_slugs(page_or_dir)
end
.flatten
expect(actual_order).to eq(expected_order)
end
end
......
......@@ -265,7 +265,7 @@ describe Issuable::BulkUpdateService do
end
it 'removes the label IDs from all issues passed' do
expect(issues.map(&:reload).map(&:label_ids).flatten).not_to include(merge_requests.id)
expect(issues.map(&:reload).flat_map(&:label_ids)).not_to include(merge_requests.id)
end
it 'does not update issues not passed in' do
......@@ -297,11 +297,11 @@ describe Issuable::BulkUpdateService do
let(:remove_labels) { [regression] }
it 'removes the label IDs from all issues passed' do
expect(issues.map(&:reload).map(&:label_ids).flatten).not_to include(regression.id)
expect(issues.map(&:reload).flat_map(&:label_ids)).not_to include(regression.id)
end
it 'ignores the label IDs parameter' do
expect(issues.map(&:reload).map(&:label_ids).flatten).not_to include(merge_requests.id)
expect(issues.map(&:reload).flat_map(&:label_ids)).not_to include(merge_requests.id)
end
it 'does not update issues not passed in' do
......@@ -320,11 +320,11 @@ describe Issuable::BulkUpdateService do
end
it 'removes the label IDs from all issues passed' do
expect(issues.map(&:reload).map(&:label_ids).flatten).not_to include(merge_requests.id)
expect(issues.map(&:reload).flat_map(&:label_ids)).not_to include(merge_requests.id)
end
it 'ignores the label IDs parameter' do
expect(issues.map(&:reload).map(&:label_ids).flatten).not_to include(regression.id)
expect(issues.map(&:reload).flat_map(&:label_ids)).not_to include(regression.id)
end
it 'does not update issues not passed in' do
......
......@@ -179,7 +179,7 @@ describe Issues::UpdateService, :mailer do
it 'sends email to user2 about assign of new issue and email to user3 about issue unassignment' do
deliveries = ActionMailer::Base.deliveries
email = deliveries.last
recipients = deliveries.last(2).map(&:to).flatten
recipients = deliveries.last(2).flat_map(&:to)
expect(recipients).to include(user2.email, user3.email)
expect(email.subject).to include(issue.title)
end
......
......@@ -99,7 +99,7 @@ describe MergeRequests::UpdateService, :mailer do
it 'sends email to user2 about assign of new merge request and email to user3 about merge request unassignment' do
deliveries = ActionMailer::Base.deliveries
email = deliveries.last
recipients = deliveries.last(2).map(&:to).flatten
recipients = deliveries.last(2).flat_map(&:to)
expect(recipients).to include(user2.email, user3.email)
expect(email.subject).to include(merge_request.title)
end
......
......@@ -33,7 +33,7 @@ module Spec
# Packs string components into an openssh-encoded pubkey.
def pack_pubkey_components(strings)
(strings.map { |s| [s.length].pack('N') }).zip(strings).flatten.join
(strings.flat_map { |s| [s.length].pack('N') }).zip(strings).join
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment