diff options
-rw-r--r-- | app/models/public_body.rb | 3 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 575e365ac..e5ef26047 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -47,6 +47,7 @@ class PublicBody < ActiveRecord::Base 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 # Convenience methods for creating/editing translations via forms @@ -553,7 +554,7 @@ class PublicBody < ActiveRecord::Base def notes_without_html # assume notes are reasonably behaved HTML, so just use simple regexp on this - self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, "") + @notes_without_html ||= (self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, "")) end def json_for_api diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 9e22a9c43..011824190 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -407,6 +407,7 @@ describe PublicBody, " when loading CSV files" do end describe PublicBody do + describe "calculated home page" do it "should return the home page verbatim if it's present" do public_body = PublicBody.new @@ -438,4 +439,17 @@ describe PublicBody do public_body.calculated_home_page.should == "https://example.com" end end + + describe 'when asked for notes without html' do + + before do + @public_body = PublicBody.new(:notes => 'some <a href="/notes">notes</a>') + end + + it 'should remove simple tags from notes' do + @public_body.notes_without_html.should == 'some notes' + end + + end + end |