diff options
-rw-r--r-- | app/models/public_body_category.rb | 5 | ||||
-rw-r--r-- | config/initializers/alaveteli.rb | 2 | ||||
-rw-r--r-- | lib/category_and_heading_migrator.rb | 91 | ||||
-rw-r--r-- | lib/public_body_categories.rb | 11 | ||||
-rw-r--r-- | spec/models/public_body_category_spec.rb | 29 | ||||
-rw-r--r-- | spec/models/public_body_heading_spec.rb | 20 |
6 files changed, 0 insertions, 158 deletions
diff --git a/app/models/public_body_category.rb b/app/models/public_body_category.rb index c313e5734..198e8b737 100644 --- a/app/models/public_body_category.rb +++ b/app/models/public_body_category.rb @@ -49,11 +49,6 @@ class PublicBodyCategory < ActiveRecord::Base PublicBodyCategory.find_by_sql(sql) end - # Called from the old-style public_body_categories_[locale].rb data files - def self.add(locale, data_list) - CategoryAndHeadingMigrator.add_categories_and_headings_from_list(locale, data_list) - end - # Convenience methods for creating/editing translations via forms def find_translation_by_locale(locale) translations.find_by_locale(locale) diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb index d2096fd52..840639228 100644 --- a/config/initializers/alaveteli.rb +++ b/config/initializers/alaveteli.rb @@ -53,8 +53,6 @@ require 'theme' require 'xapian_queries' require 'date_quarter' require 'public_body_csv' -require 'category_and_heading_migrator' -require 'public_body_categories' require 'routing_filters' require 'alaveteli_text_masker' diff --git a/lib/category_and_heading_migrator.rb b/lib/category_and_heading_migrator.rb deleted file mode 100644 index 402ea7204..000000000 --- a/lib/category_and_heading_migrator.rb +++ /dev/null @@ -1,91 +0,0 @@ -module CategoryAndHeadingMigrator - - # This module migrates data from public_body_categories_[locale].rb files - # into PublicBodyHeading and PublicBodyCategory models - - # Load all the data from public_body_categories_[locale].rb files. - def self.migrate_categories_and_headings - if PublicBodyCategory.count > 0 - puts "PublicBodyCategories exist already, not migrating." - else - @first_locale = true - I18n.available_locales.each do |locale| - begin - load "public_body_categories_#{locale}.rb" - rescue MissingSourceFile - end - @first_locale = false - end - end - end - - # Load the categories and headings for a locale - def self.add_categories_and_headings_from_list(locale, data_list) - # set the counter for headings loaded from this locale - @@locale_heading_display_order = 0 - current_heading = nil - data_list.each do |list_item| - if list_item.is_a?(Array) - # item is list of category data - add_category(list_item, current_heading, locale) - else - # item is heading name - current_heading = add_heading(list_item, locale, @first_locale) - end - end - end - - def self.add_category(category_data, heading, locale) - tag, title, description = category_data - category = PublicBodyCategory.find_by_category_tag(tag) - if category - add_category_in_locale(category, title, description, locale) - else - category = PublicBodyCategory.create(:category_tag => tag, - :title => title, - :description => description) - - # add the translation if this is not the default locale - # (occurs when a category is not defined in default locale) - unless category.translations.map { |t| t.locale }.include?(locale) - add_category_in_locale(category, title, description, locale) - end - end - heading.add_category(category) - end - - def self.add_category_in_locale(category, title, description, locale) - I18n.with_locale(locale) do - category.title = title - category.description = description - category.save - end - end - - def self.add_heading(name, locale, first_locale) - heading = nil - I18n.with_locale(locale) do - heading = PublicBodyHeading.find_by_name(name) - end - # For multi-locale installs, we assume that all public_body_[locale].rb files - # use the same headings in the same order, so we add translations to the heading - # that was in the same position in the list loaded from other public_body_[locale].rb - # files. - if heading.nil? && !@first_locale - heading = PublicBodyHeading.where(:display_order => @@locale_heading_display_order).first - end - - if heading - I18n.with_locale(locale) do - heading.name = name - heading.save - end - else - I18n.with_locale(locale) do - heading = PublicBodyHeading.create(:name => name) - end - end - @@locale_heading_display_order += 1 - heading - end -end diff --git a/lib/public_body_categories.rb b/lib/public_body_categories.rb deleted file mode 100644 index 3528e85b1..000000000 --- a/lib/public_body_categories.rb +++ /dev/null @@ -1,11 +0,0 @@ -# Allow the PublicBodyCategory model to be addressed using the same syntax -# as the old PublicBodyCategories class without needing to rename everything, -# make sure we're not going to break any themes -class PublicBodyCategories - - def self.method_missing(method, *args, &block) - warn 'Use of PublicBodyCategories is deprecated and will be removed in release 0.21. Please use PublicBodyCategory instead.' - PublicBodyCategory.send(method, *args, &block) - end - -end diff --git a/spec/models/public_body_category_spec.rb b/spec/models/public_body_category_spec.rb index 96fe5686b..c16c9b8a1 100644 --- a/spec/models/public_body_category_spec.rb +++ b/spec/models/public_body_category_spec.rb @@ -9,35 +9,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyCategory do - describe 'when loading the data' do - it 'should use the display_order field to preserve the original data order' do - PublicBodyCategory.add(:en, [ - "Local and regional", - [ "local_council", "Local councils", "a local council" ], - "Miscellaneous", - [ "other", "Miscellaneous", "miscellaneous" ], - [ "aardvark", "Aardvark", "daft test"],]) - - headings = PublicBodyHeading.all - cat_group1 = headings[0].public_body_categories - cat_group1.count.should eq 1 - cat_group1[0].title.should eq "Local councils" - - cat_group2 = headings[1].public_body_categories - cat_group2.count.should eq 2 - cat_group2[0].title.should eq "Miscellaneous" - cat_group2[0].public_body_category_links.where( - :public_body_heading_id => headings[1].id). - first. - category_display_order.should eq 0 - - cat_group2[1].title.should eq "Aardvark" - cat_group2[1].public_body_category_links.where( - :public_body_heading_id => headings[1].id). - first. - category_display_order.should eq 1 - end - end context 'when validating' do diff --git a/spec/models/public_body_heading_spec.rb b/spec/models/public_body_heading_spec.rb index 9372e0a07..620f7da9c 100644 --- a/spec/models/public_body_heading_spec.rb +++ b/spec/models/public_body_heading_spec.rb @@ -10,26 +10,6 @@ require 'spec_helper' describe PublicBodyHeading do - context 'when loading the data' do - - before do - PublicBodyCategory.add(:en, [ - "Local and regional", - [ "local_council", "Local councils", "a local council" ], - "Miscellaneous", - [ "other", "Miscellaneous", "miscellaneous" ],]) - end - - it 'should use the display_order field to preserve the original data order' do - headings = PublicBodyHeading.all - headings[0].name.should eq 'Local and regional' - headings[0].display_order.should eq 0 - headings[1].name.should eq 'Miscellaneous' - headings[1].display_order.should eq 1 - end - - end - context 'when validating' do it 'should require a name' do |