Sha256: be3da58d7164a85fa66c40fecd2d1414463731879b6d843c21f7dca9a447565d

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

require "spec_helper"

describe Schematic::Generator::Restrictions::Enumeration do
  describe ".to_xsd" do
    context "with a model with inclusion validations" do
      subject { sanitize_xml(EnumerationModel.to_xsd) }
      with_model :enumeration_model do
        table :id => false do |t|
          t.string "title"
        end

        model do
          validates :title, :inclusion => { :in => ["a", "b", "c"] }
        end
      end

      it "should validate against it's own XSD" do
        invalid_instance = EnumerationModel.new(:title => "d")
        xml = [invalid_instance].to_xml
        lambda {
          validate_xml_against_xsd(xml, subject)
        }.should raise_error
        valid_instance = EnumerationModel.new(:title => "a")
        xml = [valid_instance].to_xml
        lambda {
          validate_xml_against_xsd(xml, subject)
        }.should_not raise_error
      end

      it "should mark that the field with the allowed values" do
        xsd = generate_xsd_for_model(EnumerationModel) do
          <<-XML
              <xs:element name="title" minOccurs="0" maxOccurs="1">
                <xs:complexType>
                  <xs:simpleContent>
                    <xs:restriction base="String">
                      <xs:enumeration value="a"/>
                      <xs:enumeration value="b"/>
                      <xs:enumeration value="c"/>
                    </xs:restriction>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
          XML
        end

        subject.should == xsd
      end
    end
  end
end


Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
schematic-0.3.4 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.3.3 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.3.2 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.3.1 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.3.0 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.2.3 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.2.1 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.1.9 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.1.8 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.1.7 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.1.6 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.1.5 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.1.4 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.1.3 spec/schematic/generator/restrictions/enumeration_spec.rb
schematic-0.1.2 spec/schematic/generator/restrictions/enumeration_spec.rb