Sha256: 3b44876f29d593edd5b09171eccc0760b9bc9b5dfb0b9c2f008e01d3d8138b2a
Contents?: true
Size: 1.31 KB
Versions: 11
Compression:
Stored size: 1.31 KB
Contents
require "test_helper" class PropertyTest < MiniTest::Spec class SongCell < Cell::ViewModel property :title def title super + "</b>" end end let (:song) { Struct.new(:title).new("<b>She Sells And Sand Sandwiches") } # ::property creates automatic accessor. it { SongCell.(song).title.must_equal "<b>She Sells And Sand Sandwiches</b>" } end class EscapedPropertyTest < MiniTest::Spec class SongCell < Cell::ViewModel include Escaped property :title property :artist property :copyright, :lyrics def title(*) "#{super}</b>" # super + "</b>" still escapes, but this is Rails. end def raw_title title(escape: false) end end let (:song) do Struct .new(:title, :artist, :copyright, :lyrics) .new("<b>She Sells And Sand Sandwiches", Object, "<a>Copy</a>", "<i>Words</i>") end # ::property escapes, everywhere. it { SongCell.(song).title.must_equal "<b>She Sells And Sand Sandwiches</b>" } it { SongCell.(song).copyright.must_equal "<a>Copy</a>" } it { SongCell.(song).lyrics.must_equal "<i>Words</i>" } # no escaping for non-strings. it { SongCell.(song).artist.must_equal Object } # no escaping when escape: false it { SongCell.(song).raw_title.must_equal "<b>She Sells And Sand Sandwiches</b>" } end
Version data entries
11 entries across 11 versions & 1 rubygems