diff options
-rw-r--r-- | app/models/public_body.rb | 2 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 828e8c94a..485a794b0 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -71,7 +71,7 @@ class PublicBody < ActiveRecord::Base def PublicBody.set_first_letter(instance) unless instance.name.nil? or instance.name.empty? # we use a regex to ensure it works with utf-8/multi-byte - first_letter = instance.name.scan(/^./mu)[0].upcase + first_letter = Unicode.upcase instance.name.scan(/^./mu)[0] if first_letter != instance.first_letter instance.first_letter = first_letter end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index b0cb15f27..0324e3f5a 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -190,6 +190,17 @@ describe PublicBody, " when saving" do @public_body.first_letter.should == 'T' end + it "should update first letter, even if it's a multibyte character" do + pb = PublicBody.new(:name => 'åccents, lower-case', + :short_name => 'ALC', + :request_email => 'foo@localhost', + :last_edit_editor => 'test', + :last_edit_comment => '') + pb.first_letter.should be_nil + pb.save! + pb.first_letter.should == 'Å' + end + it "should save the name when renaming an existing public body" do public_body = public_bodies(:geraldine_public_body) public_body.name = "Mark's Public Body" |