diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-06-04 12:15:32 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-06-06 11:09:09 +0100 |
commit | 249a1ef17747deadc773b6474df990d803294c44 (patch) | |
tree | 7d02b69ca91fa5f6e88d5f925a13538b32ee39b9 | |
parent | fe3e034cd20cb37d48ef4f3ab2d7c37189000b72 (diff) |
Move PublicBody domain logic from controller
Moves the magic 'site_administration' tag logic to the PublicBody
model. Easier to make the string passed to `PublicBody#has_tag?` configurable
if we want to allow this to be set per install.
-rw-r--r-- | app/controllers/public_body_controller.rb | 4 | ||||
-rw-r--r-- | app/models/public_body.rb | 3 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 14 |
3 files changed, 19 insertions, 2 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 9e34396bc..bd019a613 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -212,8 +212,8 @@ class PublicBodyController < ApplicationController # Create the CSV csv = PublicBodyCSV.new PublicBody.visible.find_each(:include => [:translations, :tags]) do |public_body| - next if public_body.has_tag?('site_administration') - csv << public_body + next if public_body.site_administration? + csv << public_body end # Export all the public bodies to that temporary path, make it readable, diff --git a/app/models/public_body.rb b/app/models/public_body.rb index d0e5bbb9e..20644a4da 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -399,6 +399,9 @@ class PublicBody < ActiveRecord::Base end end + def site_administration? + has_tag?('site_administration') + end class ImportCSVDryRun < StandardError end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 38e31783d..c0842e1c5 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -594,6 +594,20 @@ describe PublicBody do end + describe :site_administration? do + + it 'is true when the body has the site_administration tag' do + p = FactoryGirl.build(:public_body, :tag_string => 'site_administration') + p.site_administration?.should be_true + end + + it 'is false when the body does not have the site_administration tag' do + p = FactoryGirl.build(:public_body) + p.site_administration?.should be_false + end + + end + end describe PublicBody, " when override all public body request emails set" do |