Gemfile:
gem 'sanitize-rails', :require => 'sanitize/rails'
config/initializers/sanitizer.rb:
Sanitize::Rails.configure(
:elements => [ ... ],
:attribiutes => { ... },
...
)
There's an example in the example/
directory.
app/models/foo.rb:
sanitizes :field
sanitizes :some_other_field, :on => :create
sanitizes :yet_another_field, :on => :save
ActionView sanitize
helper is overriden to use
the Sanitize gem - transparently.
Only Test::Unit for now - please write matchers and send a pull request :-)
test/test_helper:
Sanitize::Rails::TestHelpers.setup(self,
:invalid => 'some <a>string',
:valid => 'some <a>string</a>'
)
your test:
assert_sanitizes(Model, :field, :some_other_field)
Tested with Rails 3.0 ~ 4.0 under Ruby 1.9 and 2.0.
MIT
Have fun!