diff --git a/back/app/models/group.rb b/back/app/models/group.rb index 80caa60f45f3..a490870c30c1 100644 --- a/back/app/models/group.rb +++ b/back/app/models/group.rb @@ -85,7 +85,10 @@ def self.membership_types private def generate_slug - self.slug ||= SlugService.new.generate_slug self, title_multiloc.values.first + self.slug ||= SlugService.new.generate_slug( + self, + title_multiloc.find { |_key, value| value.present? }&.last + ) end def set_membership_type diff --git a/back/spec/models/group_spec.rb b/back/spec/models/group_spec.rb index 26a90b00d472..4623e215329b 100644 --- a/back/spec/models/group_spec.rb +++ b/back/spec/models/group_spec.rb @@ -69,4 +69,13 @@ group.update_memberships_count! end end + + describe 'generate_slug' do + it 'generates a slug based on the first non-empty locale' do + group = described_class.new + group.title_multiloc = { en: '', 'nl-BE': 'title', 'fr-BE': 'titlefrançais' } + group.send(:generate_slug) + expect(group.slug).to eq('title') + end + end end