aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenare Degan <henare.degan@gmail.com>2012-12-10 00:09:55 +1100
committerHenare Degan <henare.degan@gmail.com>2012-12-11 11:09:38 +1100
commit1f8bc6560b5240a7aa84ac8d6bdc47eea5d2d781 (patch)
tree3d7ba35ab3080c9a19171158793202e561bea5f7
parent9b60a7e72244b4b2ac917ba39b9e4081ef8d3e03 (diff)
The with_locale has been removed in Globalize3
I think Globalize is supposed to pick up the locale from I18n anyway so I don't know if these are needed. I think I still haven't done the right thing but it's time to move on.
-rw-r--r--app/controllers/admin_public_body_controller.rb10
-rw-r--r--app/controllers/general_controller.rb2
-rw-r--r--app/controllers/public_body_controller.rb6
-rw-r--r--app/controllers/request_controller.rb6
-rw-r--r--app/models/public_body.rb49
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb10
-rw-r--r--spec/controllers/public_body_controller_spec.rb8
-rw-r--r--spec/models/public_body_spec.rb6
8 files changed, 47 insertions, 50 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index dfd8989da..c41d05c8d 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -14,7 +14,7 @@ class AdminPublicBodyController < AdminController
def _lookup_query_internal
@locale = self.locale_from_params()
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
@query = params[:query]
if @query == ""
@query = nil
@@ -75,7 +75,7 @@ class AdminPublicBodyController < AdminController
def show
@locale = self.locale_from_params()
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
@public_body = PublicBody.find(params[:id])
render
end
@@ -87,7 +87,7 @@ class AdminPublicBodyController < AdminController
end
def create
- PublicBody.with_locales(I18n.default_locale) do
+ I18n.with_locale(I18n.default_locale) do
params[:public_body][:last_edit_editor] = admin_current_user()
@public_body = PublicBody.new(params[:public_body])
if @public_body.save
@@ -106,7 +106,7 @@ class AdminPublicBodyController < AdminController
end
def update
- PublicBody.with_locales(I18n.default_locale) do
+ I18n.with_locale(I18n.default_locale) do
params[:public_body][:last_edit_editor] = admin_current_user()
@public_body = PublicBody.find(params[:id])
if @public_body.update_attributes(params[:public_body])
@@ -120,7 +120,7 @@ class AdminPublicBodyController < AdminController
def destroy
@locale = self.locale_from_params()
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
public_body = PublicBody.find(params[:id])
if public_body.info_requests.size > 0
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 8cf4ba6b7..faf34aa04 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -25,7 +25,7 @@ class GeneralController < ApplicationController
@locale = self.locale_from_params()
locale_condition = 'public_body_translations.locale = ?'
conditions = [locale_condition, @locale]
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
if body_short_names.empty?
# This is too slow
@popular_bodies = PublicBody.visible.find(:all,
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 542a2a433..5265706bf 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -16,7 +16,7 @@ class PublicBodyController < ApplicationController
return
end
@locale = self.locale_from_params()
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
@public_body = PublicBody.find_by_url_name_with_historic(params[:url_name])
raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil?
if @public_body.url_name.nil?
@@ -71,7 +71,7 @@ class PublicBodyController < ApplicationController
@public_body = PublicBody.find_by_url_name_with_historic(params[:url_name])
raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil?
- PublicBody.with_locales(self.locale_from_params()) do
+ I18n.with_locale(self.locale_from_params()) do
if params[:submitted_view_email]
if verify_recaptcha
flash.discard(:error)
@@ -129,7 +129,7 @@ class PublicBodyController < ApplicationController
@description = _("in the category ‘{{category_name}}’", :category_name=>category_name)
end
end
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
@public_bodies = PublicBody.paginate(
:order => "public_body_translations.name", :page => params[:page], :per_page => 100,
:conditions => conditions,
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index aca806027..c4e37f4c3 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -52,7 +52,7 @@ class RequestController < ApplicationController
medium_cache
end
@locale = self.locale_from_params()
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
# Look up by old style numeric identifiers
if params[:url_title].match(/^[0-9]+$/)
@@ -799,7 +799,7 @@ class RequestController < ApplicationController
# FOI officers can upload a response
def upload_response
@locale = self.locale_from_params()
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
@info_request = InfoRequest.find_by_url_title!(params[:url_title])
@reason_params = {
@@ -856,7 +856,7 @@ class RequestController < ApplicationController
def download_entire_request
@locale = self.locale_from_params()
- PublicBody.with_locales(@locale) do
+ I18n.with_locale(@locale) do
info_request = InfoRequest.find_by_url_title!(params[:url_title])
if authenticated?(
:web => _("To download the zip file"),
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index bdcdc3732..2792b8f59 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -104,28 +104,25 @@ class PublicBody < ActiveRecord::Base
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)
- locale = self.locale || I18n.locale
- PublicBody.with_locales(locale) do
- found = PublicBody.find(:all,
- :conditions => ["public_body_translations.url_name=?", name],
- :joins => :translations,
- :readonly => false)
- # If many bodies are found (usually because the url_name is the same across
- # locales) return any of them
- return found.first if found.size >= 1
-
- # If none found, then search the history of short names
- old = PublicBody::Version.find_all_by_url_name(name)
- # Find unique public bodies in it
- old = old.map { |x| x.public_body_id }
- old = old.uniq
- # Maybe return the first one, so we show something relevant,
- # rather than throwing an error?
- raise "Two bodies with the same historical URL name: #{name}" if old.size > 1
- return unless old.size == 1
- # does acts_as_versioned provide a method that returns the current version?
- return PublicBody.find(old.first)
- end
+ found = PublicBody.find(:all,
+ :conditions => ["public_body_translations.url_name=?", name],
+ :joins => :translations,
+ :readonly => false)
+ # If many bodies are found (usually because the url_name is the same across
+ # locales) return any of them
+ return found.first if found.size >= 1
+
+ # If none found, then search the history of short names
+ old = PublicBody::Version.find_all_by_url_name(name)
+ # Find unique public bodies in it
+ old = old.map { |x| x.public_body_id }
+ old = old.uniq
+ # Maybe return the first one, so we show something relevant,
+ # rather than throwing an error?
+ raise "Two bodies with the same historical URL name: #{name}" if old.size > 1
+ return unless old.size == 1
+ # does acts_as_versioned provide a method that returns the current version?
+ return PublicBody.find(old.first)
end
# Set the first letter, which is used for faster queries
@@ -336,7 +333,7 @@ class PublicBody < ActiveRecord::Base
# The "internal admin" is a special body for internal use.
def PublicBody.internal_admin_body
- PublicBody.with_locales(I18n.default_locale) do
+ I18n.with_locale(I18n.default_locale) do
pb = PublicBody.find_by_url_name("internal_admin_authority")
if pb.nil?
pb = PublicBody.new(
@@ -374,7 +371,7 @@ class PublicBody < ActiveRecord::Base
# of updating them
bodies_by_name = {}
set_of_existing = Set.new()
- PublicBody.with_locales(I18n.default_locale) do
+ I18n.with_locale(I18n.default_locale) do
bodies = (tag.nil? || tag.empty?) ? PublicBody.find(:all) : PublicBody.find_by_tag(tag)
for existing_body in bodies
# Hide InternalAdminBody from import notes
@@ -417,7 +414,7 @@ class PublicBody < ActiveRecord::Base
if public_body = bodies_by_name[name] # Existing public body
available_locales.each do |locale|
- PublicBody.with_locales(locale) do
+ I18n.with_locale(locale) do
changed = ActiveSupport::OrderedHash.new
field_list.each do |field_name|
localized_field_name = (locale.to_s == I18n.default_locale.to_s) ? field_name : "#{field_name}.#{locale}"
@@ -452,7 +449,7 @@ class PublicBody < ActiveRecord::Base
else # New public body
public_body = PublicBody.new(:name=>"", :short_name=>"", :request_email=>"")
available_locales.each do |locale|
- PublicBody.with_locales(locale) do
+ I18n.with_locale(locale) do
changed = ActiveSupport::OrderedHash.new
field_list.each do |field_name|
localized_field_name = (locale.to_s == I18n.default_locale.to_s) ? field_name : "#{field_name}.#{locale}"
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 289be07df..255eacbd0 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -288,7 +288,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
end
it "saves edits to a public body" do
- PublicBody.with_locales(:es) do
+ I18n.with_locale(:es) do
pb = PublicBody.find(id=3)
pb.name.should == "El Department for Humpadinking"
post :update, {
@@ -308,10 +308,10 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
end
pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
- PublicBody.with_locales(:es) do
+ I18n.with_locale(:es) do
pb.name.should == "Renamed"
end
- PublicBody.with_locales(:en) do
+ I18n.with_locale(:en) do
pb.name.should == "Department for Humpadinking"
end
end
@@ -357,12 +357,12 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do
body = PublicBody.find_by_name("New Quango")
body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"]
- PublicBody.with_locales(:en) do
+ I18n.with_locale(:en) do
body.name.should == "New Quango"
body.url_name.should == "new_quango"
body.first_letter.should == "N"
end
- PublicBody.with_locales(:es) do
+ I18n.with_locale(:es) do
body.name.should == "Mi Nuevo Quango"
body.url_name.should == "mi_nuevo_quango"
body.first_letter.should == "M"
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index e97db5a12..9c7f7dc7f 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -44,14 +44,14 @@ describe PublicBodyController, "when showing a body" do
end
it "should assign the body using different locale from that used for url_name" do
- PublicBody.with_locales(:es) do
+ I18n.with_locale(:es) do
get :show, {:url_name => "dfh", :view => 'all'}
assigns[:public_body].notes.should == "Baguette"
end
end
it "should assign the body using same locale as that used in url_name" do
- PublicBody.with_locales(:es) do
+ I18n.with_locale(:es) do
get :show, {:url_name => "edfh", :view => 'all'}
assigns[:public_body].notes.should == "Baguette"
end
@@ -87,7 +87,7 @@ describe PublicBodyController, "when listing bodies" do
end
it "should list all bodies from default locale, even when there are no translations for selected locale" do
- PublicBody.with_locales(:en) do
+ I18n.with_locale(:en) do
@english_only = PublicBody.new(:name => 'English only',
:short_name => 'EO',
:request_email => 'english@flourish.org',
@@ -95,7 +95,7 @@ describe PublicBodyController, "when listing bodies" do
:last_edit_comment => '')
@english_only.save
end
- PublicBody.with_locales(:es) do
+ I18n.with_locale(:es) do
get :list
assigns[:public_bodies].include?(@english_only).should == true
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 127391e79..f247f561c 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -210,7 +210,7 @@ describe PublicBody, "when searching" do
end
it "should cope with same url_name across multiple locales" do
- PublicBody.with_locales(:es) do
+ I18n.with_locale(:es) do
# use the unique spanish name to retrieve and edit
body = PublicBody.find_by_url_name_with_historic('etgq')
body.short_name = 'tgq' # Same as english version
@@ -231,7 +231,7 @@ end
describe PublicBody, " when dealing public body locales" do
it "shouldn't fail if it internal_admin_body was created in a locale other than the default" do
# first time, do it with the non-default locale
- PublicBody.with_locales(:es) do
+ I18n.with_locale(:es) do
PublicBody.internal_admin_body
end
@@ -378,7 +378,7 @@ describe PublicBody, " when loading CSV files" do
PublicBody.count.should == original_count + 3
- # XXX Not sure why trying to do a PublicBody.with_locales fails here. Seems related to
+ # XXX Not sure why trying to do a PublicBody.with_locale fails here. Seems related to
# the way categories are loaded every time from the PublicBody class. For now we just
# test some translation was done.
body = PublicBody.find_by_name('North West Fake Authority')