Add description sanitization to Budget::Phase with model specs

This commit is contained in:
Bertocq
2018-01-15 20:37:39 +01:00
parent 21b62106e5
commit d505cda949
2 changed files with 15 additions and 0 deletions

View File

@@ -14,6 +14,9 @@ class Budget
validates :description, length: { maximum: DESCRIPTION_MAX_LENGTH }
validate :dates_range_valid?
before_validation :sanitize_description
scope :enabled, -> { where(enabled: true) }
scope :drafting, -> { find_by_kind('drafting') }
scope :accepting, -> { find_by_kind('accepting')}
@@ -39,5 +42,9 @@ class Budget
end
end
def sanitize_description
self.description = WYSIWYGSanitizer.new.sanitize(description)
end
end
end

View File

@@ -77,4 +77,12 @@ describe Budget::Phase do
end
end
end
describe "#sanitize_description" do
it "removes html entities from the description" do
expect{
first_phase.update_attributes(description: "<a>a</p> <javascript>javascript</javascript>")
}.to change{ first_phase.description }.to('a javascript')
end
end
end