Sha256: 367381b06375e70d6e2619c93a25dc1f83868037be014eb191dba78744d3eae4

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'helper'
require 'peddler/parsers/model'
require 'nokogiri'

class PeddlerModelParserTest < MiniTest::Test
  def build(xml)
    document = Nokogiri(xml)
    Peddler::Parsers::Model.new(document)
  end

  def test_parses_money
    xml = <<-EOF
    <Price xmlns="example">
      <CurrencyCode>USD</CurrencyCode>
      <Amount>10.00</Amount>
    </Price>
    EOF
    model = build(xml)
    money = model.money_at_xpath('Price')
    assert_equal '$10.00', money.format
  end

  def test_parses_japanese_yen
    xml = <<-EOF
    <Price xmlns="example">
      <CurrencyCode>JPY</CurrencyCode>
      <Amount>1000.00</Amount>
    </Price>
    EOF
    model = build(xml)
    money = model.money_at_xpath('Price')
    assert_equal '¥1,000', money.format
  end

  def test_parses_truthy_value
    xml = <<-EOF
    <Bool xmlns="example">
      true
    </Bool>
    EOF
    model = build(xml)
    assert_equal true, model.boolean_at_xpath('Bool')

    xml = <<-EOF
    <Bool xmlns="example">
      Yes
    </Bool>
    EOF
    model = build(xml)
    assert_equal true, model.boolean_at_xpath('Bool')
  end

  def test_parses_falsy_value
    xml = <<-EOF
    <Bool xmlns="example>
      false
    </Bool>
    EOF
    model = build(xml)
    assert_equal false, model.boolean_at_xpath('Bool')

    xml = <<-EOF
    <Bool xmlns="example>
      No
    </Bool>
    EOF
    model = build(xml)
    assert_equal false, model.boolean_at_xpath('Bool')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
peddler-0.6.5 test/peddler/parsers/test_model.rb
peddler-0.6.4 test/peddler/parsers/test_model.rb