require "spec_helper" describe Schematic::Serializers::Xsd do before do class EmptyModel < ActiveRecord::Base def self.columns [] end end end describe ".extend" do context "when the model inherits ActiveRecord::Base" do subject { EmptyModel } it "should allow the model to be extended" do lambda { subject.class_eval do extend Schematic::Serializers::Xsd end }.should_not raise_error end end context "when the model does not inherit ActiveRecord::Base" do subject { Object } it "should raise an exception" do lambda { subject.class_eval do extend Schematic::Serializers::Xsd end }.should raise_error(Schematic::InvalidClass) end end end describe ".to_xsd" do context "for an empty model with no attributes or validations" do subject { EmptyModel.to_xsd } it "should return an xsd for an array of the model" do xsd = <<-XML XML subject.should == sanitize_xml(xsd) end end context "for a model with attributes" do subject { SomeModel.to_xsd } context "for a any attribute" do with_model :some_model do table :id => false do |t| t.float 'some_float' end end it "should define the correct xsd element" do xsd = generate_xsd_for_model(SomeModel) do <<-XML XML end subject.should == sanitize_xml(xsd) end end describe "additional methods" do with_model :some_model do table {} end it "should include the additional method" do xsd = generate_xsd_for_model(SomeModel) do <<-XML XML end SomeModel.to_xsd(:methods => {:foo_bar => nil}).should == sanitize_xml(xsd) end end describe "nested attributes" do end end context "with a model with validations" do context "presence of validation" do context "when allow blank is true" do end context "when allow blank is false" do end end describe "length validation" do end describe "inclusion validation" do end end end private def sanitize_xml(xml) xml.split("\n").map(&:strip).join("") end def generate_xsd_for_model(model) <<-XML #{yield} XML end end