Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 21:09:13 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 21:09:13 +0300
commit71c85847eb6645f6cca91febd70668d544a4125d (patch)
tree734b225303f3ef27d07a8b1feec5cb94d77c1be1 /app/models/analytics
parenta2f3b3e5cf571da549b34c5500b5dd5723c045de (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/analytics')
-rw-r--r--app/models/analytics/devops_adoption/segment.rb2
-rw-r--r--app/models/analytics/devops_adoption/segment_selection.rb8
2 files changed, 5 insertions, 5 deletions
diff --git a/app/models/analytics/devops_adoption/segment.rb b/app/models/analytics/devops_adoption/segment.rb
index 71d4a312627..baab5b94126 100644
--- a/app/models/analytics/devops_adoption/segment.rb
+++ b/app/models/analytics/devops_adoption/segment.rb
@@ -7,7 +7,7 @@ class Analytics::DevopsAdoption::Segment < ApplicationRecord
has_many :groups, through: :segment_selections
validates :name, presence: true, uniqueness: true, length: { maximum: 255 }
- validate :validate_segment_count
+ validate :validate_segment_count, on: :create
accepts_nested_attributes_for :segment_selections, allow_destroy: true
diff --git a/app/models/analytics/devops_adoption/segment_selection.rb b/app/models/analytics/devops_adoption/segment_selection.rb
index 6b70c13a773..8f95ce088a2 100644
--- a/app/models/analytics/devops_adoption/segment_selection.rb
+++ b/app/models/analytics/devops_adoption/segment_selection.rb
@@ -14,7 +14,7 @@ class Analytics::DevopsAdoption::SegmentSelection < ApplicationRecord
validates :group_id, uniqueness: { scope: :segment_id, if: :group }
validate :exclusive_project_or_group
- validate :validate_selection_count
+ validate :validate_selection_count, on: :create
private
@@ -27,9 +27,9 @@ class Analytics::DevopsAdoption::SegmentSelection < ApplicationRecord
def validate_selection_count
return unless segment
- selection_count_for_segment = self.class.where(segment: segment).count
-
- if selection_count_for_segment >= ALLOWED_SELECTIONS_PER_SEGMENT
+ # handle single model creation and bulk creation from accepts_nested_attributes_for
+ selections = segment.segment_selections + [self]
+ if selections.reject(&:marked_for_destruction?).uniq.size > ALLOWED_SELECTIONS_PER_SEGMENT
errors.add(:segment, s_('DevopsAdoptionSegmentSelection|The maximum number of selections has been reached'))
end
end