diff options
author | lizconlan <liz@mysociety.org> | 2014-08-04 10:20:05 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-09-22 12:39:03 +0100 |
commit | 31c1f47a6bca88b2be9fb463721fb26698e79f82 (patch) | |
tree | 5aaf4cc10898d961bce126088c5574266f792f51 | |
parent | 373ee8b3ee6835b81fb7eb4ffec59db41b3925c1 (diff) |
Reinstate automatic loading of categories on get if no categories defined
-rw-r--r-- | app/models/public_body_category.rb | 2 | ||||
-rw-r--r-- | spec/controllers/admin_public_body_heading_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/public_body_category_spec.rb | 6 |
4 files changed, 14 insertions, 1 deletions
diff --git a/app/models/public_body_category.rb b/app/models/public_body_category.rb index 2e2c8d74e..cb15f67e6 100644 --- a/app/models/public_body_category.rb +++ b/app/models/public_body_category.rb @@ -22,6 +22,8 @@ class PublicBodyCategory < ActiveRecord::Base validates_presence_of :description, :message => N_('Description can\'t be blank') def self.get + load_categories if PublicBodyCategory.count < 1 + locale = I18n.locale.to_s || default_locale.to_s || "" categories = CategoryCollection.new I18n.with_locale(locale) do diff --git a/spec/controllers/admin_public_body_heading_controller_spec.rb b/spec/controllers/admin_public_body_heading_controller_spec.rb index 3d0850322..811bd9e74 100644 --- a/spec/controllers/admin_public_body_heading_controller_spec.rb +++ b/spec/controllers/admin_public_body_heading_controller_spec.rb @@ -58,7 +58,7 @@ describe AdminPublicBodyHeadingController do context 'when editing a public body heading' do before do PublicBodyCategory.load_categories - @heading= PublicBodyHeading.find_by_name("Silly ministries") + @heading = PublicBodyHeading.find_by_name("Silly ministries") end render_views diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index f64975580..6ff1a7215 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -7,6 +7,7 @@ describe PublicBodyController, "when showing a body" do render_views before(:each) do + PublicBodyCategory.stub!(:load_categories) load_raw_emails_data get_fixtures_xapian_index end @@ -75,6 +76,10 @@ end describe PublicBodyController, "when listing bodies" do render_views + before(:each) do + PublicBodyCategory.stub!(:load_categories) + end + it "should be successful" do get :list response.should be_success diff --git a/spec/models/public_body_category_spec.rb b/spec/models/public_body_category_spec.rb index 9ec99e395..8c0adbcc6 100644 --- a/spec/models/public_body_category_spec.rb +++ b/spec/models/public_body_category_spec.rb @@ -35,6 +35,12 @@ describe PublicBodyCategory do it 'should return a list of headings' do PublicBodyCategory::get().headings().should == ['Local and regional', 'Miscellaneous'] end + + it 'should call load_categories if categories are not already loaded' do + PublicBodyCategory.stub!(:count).and_return(0) + PublicBodyCategory.should_receive(:load_categories) + PublicBodyCategory::get() + end end describe 'when asked for tags by headings' do |