aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/public_body_controller.rb4
-rw-r--r--app/models/public_body.rb2
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb3
-rw-r--r--spec/controllers/public_body_controller_spec.rb7
-rw-r--r--spec/fixtures/public_bodies.yml18
-rw-r--r--spec/fixtures/public_body_translations.yml12
-rw-r--r--spec/models/public_body_spec.rb25
7 files changed, 60 insertions, 11 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 02f0ceb19..1f7032eed 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -113,8 +113,8 @@ class PublicBodyController < ApplicationController
elsif @tag == 'other'
category_list = PublicBodyCategories::get().tags().map{|c| "'"+c+"'"}.join(",")
where_condition += base_tag_condition + " AND has_tag_string_tags.name in (#{category_list})) = 0"
- elsif @tag.size == 1
- @tag.upcase!
+ elsif @tag.scan(/./mu).size == 1
+ @tag = Unicode.upcase @tag
# The first letter queries have to be done on
# translations, so just indicate to add that later:
first_letter = true
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/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 8a72db724..fe5087d7c 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -55,7 +55,8 @@ describe AdminPublicBodyController, "when administering public bodies" do
end
it "mass assigns tags" do
- n = PublicBody.count
+ condition = "public_body_translations.locale = ?"
+ n = PublicBody.joins(:translations).where([condition, "en"]).count
post :mass_tag_add, { :new_tag => "department", :table_name => "substring" }
request.flash[:notice].should == "Added tag to table of bodies."
response.should redirect_to(:action=>'list')
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 2d1b1466f..025ebfdba 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -250,6 +250,13 @@ describe PublicBodyController, "when listing bodies" do
response.code.should == '406'
end
+ it "should list authorities starting with a multibyte first letter" do
+ get :list, {:tag => "å", :show_locale => 'cs'}
+ response.should render_template('list')
+ assigns[:public_bodies].should == [ public_bodies(:accented_public_body) ]
+ assigns[:tag].should == "Å"
+ end
+
end
describe PublicBodyController, "when showing JSON version for API" do
diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml
index 1fa016d3a..71fe0a379 100644
--- a/spec/fixtures/public_bodies.yml
+++ b/spec/fixtures/public_bodies.yml
@@ -128,3 +128,21 @@ other_public_body:
info_requests_successful_count: 0
info_requests_not_held_count: 0
info_requests_overdue_count: 0
+accented_public_body:
+ id: 8
+ version: 1
+ name: 'Åčçèñtéd Authority'
+ first_letter: Å
+ request_email: accented@localhost
+ short_name: 'Åčçèñtéd Authority'
+ url_name: accented_authority
+ notes: This is to test unicode handling in body names
+ updated_at: 2008-10-25 10:51:01.161639
+ last_edit_comment: Another edit
+ last_edit_editor: louise
+ created_at: 2008-10-25 10:51:01.161639
+ api_key: 7
+ info_requests_count: 0
+ info_requests_successful_count: 0
+ info_requests_not_held_count: 0
+ info_requests_overdue_count: 0
diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml
index de1bf2f18..2030804ac 100644
--- a/spec/fixtures/public_body_translations.yml
+++ b/spec/fixtures/public_body_translations.yml
@@ -115,3 +115,15 @@ humpadink_he_IL_public_body_translation:
publication_scheme: ""
disclosure_log: ""
+accented_public_body_translation:
+ id: 10
+ public_body_id: 8
+ locale: cs
+ name: "Åčçèñtéd Authority"
+ first_letter: 'Å'
+ request_email: accented@localhost
+ short_name: "Åčçèñtéd Authority"
+ url_name: accented_authority
+ notes: This is to test unicode handling in body names
+ publication_scheme: ""
+ disclosure_log: ""
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 582f1430e..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"
@@ -300,7 +311,7 @@ describe PublicBody, " when loading CSV files" do
errors.should == []
notes.size.should == 2
notes[0].should == "line 1: creating new authority 'aBody' (locale: en):\n\t{\"name\":\"aBody\"}"
- notes[1].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[1].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
end
it "should do a dry run successfully" do
@@ -316,7 +327,7 @@ describe PublicBody, " when loading CSV files" do
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
"line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
]
- notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
@@ -334,7 +345,7 @@ describe PublicBody, " when loading CSV files" do
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
"line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
]
- notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count + 4
end
@@ -352,7 +363,7 @@ describe PublicBody, " when loading CSV files" do
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
"line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
]
- notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count + 4
end
@@ -368,7 +379,7 @@ describe PublicBody, " when loading CSV files" do
"line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"\}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"\}",
]
- notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
@@ -425,7 +436,7 @@ describe PublicBody, " when loading CSV files" do
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}",
]
- notes[6].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[6].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count + 3
@@ -451,7 +462,7 @@ describe PublicBody, " when loading CSV files" do
"line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"}",
]
- notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end