Sha256: bcf71544b802f7395f0fd77bd1f0c2b5ae9c87ecd711315f92e2f41f0008a1a3

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 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

    def title(*)
      "#{super}</b>" # super + "</b>" still escapes, but this is Rails.
    end

    def raw_title
      title(escape: false)
    end
  end

  let (:song) { Struct.new(:title, :artist).new("<b>She Sells And Sand Sandwiches", Object) }

  # ::property escapes, everywhere.
  it { SongCell.(song).title.must_equal "&lt;b&gt;She Sells And Sand Sandwiches</b>" }
  # 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

4 entries across 4 versions & 1 rubygems

Version Path
cells-4.0.3 test/property_test.rb
cells-4.0.2 test/property_test.rb
cells-4.0.1 test/property_test.rb
cells-4.0.0 test/property_test.rb