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 "&lt;b&gt;She Sells And Sand Sandwiches</b>" }
  it { SongCell.(song).copyright.must_equal "&lt;a&gt;Copy&lt;/a&gt;" }
  it { SongCell.(song).lyrics.must_equal "&lt;i&gt;Words&lt;/i&gt;" }
  # 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

Version Path
cells-4.1.7 test/property_test.rb
cells-4.1.6 test/property_test.rb
cells-4.1.5 test/property_test.rb
cells-4.1.4 test/property_test.rb
cells-4.1.3 test/property_test.rb
cells-4.1.2 test/property_test.rb
cells-4.1.1 test/property_test.rb
cells-4.1.0 test/property_test.rb
cells-4.1.0.rc1 test/property_test.rb
cells-4.0.5 test/property_test.rb
cells-4.0.4 test/property_test.rb