aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/public_body.rb9
-rw-r--r--spec/models/public_body_spec.rb11
2 files changed, 15 insertions, 5 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index f6d182878..ee38a7269 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -341,12 +341,11 @@ class PublicBody < ActiveRecord::Base
tags.each do |tag|
if PublicBodyCategory.get().by_tag().include?(tag.name)
desc = PublicBodyCategory.get().singular_by_tag()[tag.name]
- if first
- # terrible that Ruby/Rails doesn't have an equivalent of ucfirst
- # (capitalize shockingly converts later characters to lowercase)
- desc = desc[0,1].capitalize + desc[1,desc.size]
- first = false
+
+ if index.zero?
+ desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
end
+
if html
# TODO: this should call proper route helpers, but is in model sigh
desc = '<a href="/body/list/' + tag.name + '">' + desc + '</a>'
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index db38e3a15..3415dc28b 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -37,6 +37,17 @@ describe PublicBody do
expect(public_body.type_of_authority).to eq('A public authority')
end
+ it 'handles Unicode' do
+ category = FactoryGirl.create(:public_body_category, :category_tag => 'spec',
+ :description => 'ünicode category')
+ heading = FactoryGirl.create(:public_body_heading)
+ heading.add_category(category)
+ public_body = FactoryGirl.create(:public_body, :tag_string => 'spec')
+
+
+ expect(public_body.type_of_authority).to eq('Ünicode category')
+ end
+
context 'when associated with one category' do
it 'returns the capitalised category description' do