Sha256: 9e0e34d48d0e977773d864ff5f2b82f9862c07e93e5e192163cfa1e2e2f02bbb

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

require 'spec_helper'

describe "Attribute Default Value" do

  context "when given a default value" do

    class Meal
      include XmlMapper
      tag 'meal'
      attribute :type, String, :default => 'omnivore'
    end

    let(:subject) { Meal }
    let(:default_meal_type) { 'omnivore' }

    context "when no value has been specified" do
      it "returns the default value" do
        meal = subject.parse('<meal />')
        expect(meal.type).to eq default_meal_type
      end
    end

    context "when saving to xml" do

      let(:expected_xml) { %{<?xml version="1.0"?>\n<meal/>\n} }

      it "the default value is not included" do
        meal = subject.new
        expect(meal.to_xml).to eq expected_xml
      end
    end

    context "when a new, non-nil value has been set" do
      it "returns the new value" do
        meal = subject.parse('<meal />')
        meal.type = 'vegan'

        expect(meal.type).to_not eq default_meal_type
      end

      let(:expected_xml) { %{<?xml version="1.0"?>\n<meal type="kosher"/>\n} }

      it "saves the new value to the xml" do
        meal = subject.new
        meal.type = 'kosher'
        expect(meal.to_xml).to eq expected_xml
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
xmlmapper-0.8.1 spec/attribute_default_value_spec.rb
xmlmapper-0.8.0 spec/attribute_default_value_spec.rb
xmlmapper-0.7.3 spec/attribute_default_value_spec.rb
xmlmapper-0.7.2 spec/attribute_default_value_spec.rb
xmlmapper-0.7.1 spec/attribute_default_value_spec.rb
xmlmapper-0.7.0 spec/attribute_default_value_spec.rb
xmlmapper-0.6.5 spec/attribute_default_value_spec.rb
xmlmapper-0.6.4 spec/attribute_default_value_spec.rb
xmlmapper-0.6.3 spec/attribute_default_value_spec.rb
xmlmapper-0.6.2 spec/attribute_default_value_spec.rb
xmlmapper-0.6.1 spec/attribute_default_value_spec.rb
xmlmapper-0.6.0 spec/attribute_default_value_spec.rb