add more specs

This commit is contained in:
Alex Turchyn authored and Pete Matsyburka committed 2024-10-20 15:26:14 +03:00
1 parent 6f90147a11
commit 178ee47093
5 files changed
+77 -40

No files matched your search

+2 -2
View File
@@ -65,11 +65,11 @@ module Params
raise_error(message || "#{key} must follow the #{regexp.source} format")
end
def unique(params, key, message: nil)
def unique_value(params, key, message: nil)
return unless params.is_a?(Array)
return if params.none?
return if params.all? { |p| p[key].blank? }
return if params.pluck(key).uniq.size == params.pluck(key).size
return if params.pluck(key).compact_blank.uniq.size == params.pluck(key).compact_blank.size
raise_error(message || "#{key} must be unique")
end
+1 -1
View File
@@ -60,7 +60,7 @@ module Params
if params[:submitters].present?
in_path(params, :submitters) do |submitters_params|
type(submitters_params, 0, Hash)
unique(submitters_params, :role)
unique_value(submitters_params, :role)
end
end