Sha256: c9fb5f66314be1cd4c441edbd8f91516b034292f27d4f38ecd844f0f127142ae

Contents?: true

Size: 1.66 KB

Versions: 22

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe Hash do
  
  describe "to_xml" do
    
    it "should convert the nested resources into 'link' tags if the :convert_links option is present" do
      xml = Nokogiri.parse({"name" => "Almodovar", "tasks" => [{"name" => "Wadus"}]}.to_xml(:root => "project", :convert_links => true))
      
      # <project>
      #   <name>Almodovar</name>
      #   <link rel="tasks">
      #     <tasks type="array">
      #       <task>
      #         <name>Wadus</name>
      #       </task>
      #     </tasks>
      #   </link>
      # </project>
      xml.at_xpath("/project/name").text.should == "Almodovar"
      xml.at_xpath("/project/tasks").should be_nil
      xml.at_xpath("/project/link[@rel='tasks']/tasks[@type='array']/task/name").text.should == "Wadus"
    end
    
    it "should not convert the nested resources into 'link' tags if the :convert_links option is not present" do
      xml = Nokogiri.parse({"name" => "Almodovar", "tasks" => [{"name" => "Wadus"}]}.to_xml(:root => "project", :convert_links => false))

      # <project>
      #   <name>Almodovar</name>
      #   <tasks type="array">
      #     <task>
      #       <name>Wadus</name>
      #     </task>
      #   </tasks>
      # </project>      
      xml.at_xpath("/project/name").text.should == "Almodovar"
      xml.at_xpath("//link").should be_nil
      xml.at_xpath("/project/tasks[@type='array']/task/name").text.should == "Wadus"
    end
    
    
  end
  
end

describe Array do
  
  describe "to_xml" do
    
    it "should convert an array into xml" do
      [].to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<nil-classes type=\"array\"/>\n"
    end
    
  end
  
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
abiquo-etk-0.6.4 vendor/abiquo-0.1.2/spec/unit/to_xml_spec.rb
abiquo-etk-0.6.3 vendor/abiquo-0.1.2/spec/unit/to_xml_spec.rb
abiquo-etk-0.6.2 vendor/abiquo-0.1.2/spec/unit/to_xml_spec.rb
abiquo-etk-0.6.1 vendor/abiquo-0.1.2/spec/unit/to_xml_spec.rb
abiquo-etk-0.5.8 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.5.3 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.42 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.33 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.32 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.29 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.25 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.24 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.23 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.22 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.20 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.19 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.18 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.17 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.16 vendor/api_ruby_client/spec/unit/to_xml_spec.rb
abiquo-etk-0.4.15 vendor/api_ruby_client/spec/unit/to_xml_spec.rb