Skip to content

Commit

Permalink
Merge pull request #6274 from CitizenLabDotCo/CL-4182-allow-slug-in-a…
Browse files Browse the repository at this point in the history
…ny-langauge

CL-4182: Use first language with text for slug
  • Loading branch information
EdwinKato authored Nov 2, 2023
2 parents febc2db + 66a12d3 commit d3491f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion back/app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions back/spec/models/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d3491f4

Please sign in to comment.