Sha256: 388e0db56e566e7c6e0ebbf9b9a8d413565bf5962766b27fa4656a50a9d8704a

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

require 'test_helper'
require 'representable/json'  # FIXME.
require 'representable/xml/collection'
require 'representable/xml/hash'

require 'representable/xml'

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), nil)
      end

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

      it "inserts with #write" do
        parent = Nokogiri::XML::Node.new("song", @doc)
        @property.write(parent, "The Gargoyle")
        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), nil)
    end

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
representable-2.3.0 test/xml_bindings_test.rb
representable-2.2.3 test/xml_bindings_test.rb
representable-2.2.2 test/xml_bindings_test.rb
representable-2.2.1 test/xml_bindings_test.rb
representable-2.2.0 test/xml_bindings_test.rb