aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/public_body.rb6
-rw-r--r--spec/fixtures/public_body_translations.yml14
2 files changed, 13 insertions, 7 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index fb30da234..575e365ac 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -45,6 +45,7 @@ class PublicBody < ActiveRecord::Base
has_many :censor_rules, :order => 'created_at desc'
has_tag_string
+ before_save :set_api_key, :set_default_publication_scheme
translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme
@@ -89,13 +90,13 @@ class PublicBody < ActiveRecord::Base
end
end
- def after_initialize
+ def set_default_publication_scheme
# Make sure publication_scheme gets the correct default value.
# (This would work automatically, were publication_scheme not a translated attribute)
self.publication_scheme = "" if self.publication_scheme.nil?
end
- def before_save
+ def set_api_key
self.api_key = SecureRandom.base64(33) if self.api_key.nil?
end
@@ -549,6 +550,7 @@ class PublicBody < ActiveRecord::Base
def notes_as_html
self.notes
end
+
def notes_without_html
# assume notes are reasonably behaved HTML, so just use simple regexp on this
self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, "")
diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml
index cbb55bb0c..d705358c5 100644
--- a/spec/fixtures/public_body_translations.yml
+++ b/spec/fixtures/public_body_translations.yml
@@ -1,4 +1,4 @@
-geraldine_es_public_body_translation:
+geraldine_es_public_body_translation:
name: El A Geraldine Quango
first_letter: E
request_email: geraldine-requests@localhost
@@ -8,8 +8,9 @@ geraldine_es_public_body_translation:
url_name: etgq
locale: es
notes: ""
+ publication_scheme: ""
-geraldine_en_public_body_translation:
+geraldine_en_public_body_translation:
name: Geraldine Quango
first_letter: G
request_email: geraldine-requests@localhost
@@ -19,8 +20,9 @@ geraldine_en_public_body_translation:
url_name: tgq
locale: en
notes: ""
+ publication_scheme: ""
-humpadink_es_public_body_translation:
+humpadink_es_public_body_translation:
name: "El Department for Humpadinking"
first_letter: E
request_email: humpadink-requests@localhost
@@ -30,8 +32,9 @@ humpadink_es_public_body_translation:
url_name: edfh
locale: es
notes: Baguette
+ publication_scheme: ""
-humpadink_en_public_body_translation:
+humpadink_en_public_body_translation:
name: "Department for Humpadinking"
first_letter: D
request_email: humpadink-requests@localhost
@@ -41,8 +44,9 @@ humpadink_en_public_body_translation:
url_name: dfh
locale: en
notes: An albatross told me!!!
+ publication_scheme: ""
-forlorn_en_public_body_translation:
+forlorn_en_public_body_translation:
name: "Department of Loneliness"
first_letter: D
request_email: forlorn-requests@localhost