Sha256: 879173330b72c8673f5a3cd50fdfec6fbfff1d6c0a246799463b9b8242969449

Contents?: true

Size: 1.59 KB

Versions: 8

Compression:

Stored size: 1.59 KB

Contents

require 'test_helper'
require 'representable/xml/hash'

class XMLBindingTest < MiniTest::Spec
  module SongRepresenter
    include Representable::XML
    property :name
    self.representation_wrap = :song
  end

  class SongWithRepresenter < ::Song
    include Representable
    include SongRepresenter
    self.representation_wrap = :song
  end

  before do
    @doc  = Nokogiri::XML::Document.new
    @song = SongWithRepresenter.new("Thinning the Herd")
  end




  describe "AttributeBinding" do
    describe "with plain text items" do
      before do
        @property = Representable::XML::Binding::Attribute.new(Representable::Definition.new(:name, :attribute => true))
      end

      it "extracts with #read" do
        assert_equal "The Gargoyle", @property.read(Nokogiri::XML("<song name=\"The Gargoyle\" />").root, "name")
      end

      it "inserts with #write" do
        parent = Nokogiri::XML::Node.new("song", @doc)
        @property.write(parent, "The Gargoyle", "name")
        assert_xml_equal("<song name=\"The Gargoyle\" />", parent.to_s)
      end
    end
  end

  describe "ContentBinding" do
    before do
      @property = Representable::XML::Binding::Content.new(Representable::Definition.new(:name, :content => true))
    end

    it "extracts with #read" do
      assert_equal "The Gargoyle", @property.read(Nokogiri::XML("<song>The Gargoyle</song>").root, "song")
    end

    it "inserts with #write" do
      parent = Nokogiri::XML::Node.new("song", @doc)
      @property.write(parent, "The Gargoyle", "song")
      assert_xml_equal("<song>The Gargoyle</song>", parent.to_s)
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/representable-3.2.0/test/xml_bindings_test.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/representable-3.2.0/test/xml_bindings_test.rb
representable-3.2.0 test/xml_bindings_test.rb
representable-3.1.1 test/xml_bindings_test.rb
representable-3.1.0 test/xml_bindings_test.rb
representable-3.0.4 test/xml_bindings_test.rb
representable-3.0.3 test/xml_bindings_test.rb
representable-3.0.2 test/xml_bindings_test.rb