schematic 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -88,6 +88,21 @@ module Schematic
88
88
  end
89
89
  end
90
90
 
91
+ def generate_sequence_value_restrictions(builder, value)
92
+ enumeration_method = "xsd_#{value}_enumeration_restrictions".to_sym
93
+ builder.xs :complexType do |complex_type|
94
+ complex_type.xs :simpleContent do |simple_content|
95
+ simple_content.xs :restriction, "base" => "String" do |restriction|
96
+ if @klass.respond_to? enumeration_method
97
+ @klass.send(enumeration_method).each do |enumeration|
98
+ restriction.xs :enumeration, "value" => enumeration
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+
91
106
  def generate_additional_methods(builder, additional_methods)
92
107
  additional_methods.each do |method_name, values|
93
108
  method_xsd_name = method_name.to_s.dasherize
@@ -98,7 +113,9 @@ module Schematic
98
113
  complex_type.xs :sequence do |nested_sequence|
99
114
  if values.present?
100
115
  values.each do |value|
101
- nested_sequence.xs :element, "name" => value.to_s.dasherize, "minOccurs" => "0", "maxOccurs" => "unbounded"
116
+ nested_sequence.xs :element, "name" => value.to_s.dasherize, "minOccurs" => "0", "maxOccurs" => "unbounded" do |sequence_element|
117
+ generate_sequence_value_restrictions(sequence_element, value)
118
+ end
102
119
  end
103
120
  else
104
121
  nested_sequence.xs :any, "processContents" => "skip", "minOccurs" => "0", "maxOccurs" => "unbounded"
@@ -1,3 +1,3 @@
1
1
  module Schematic
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -114,8 +114,24 @@ describe Schematic::Serializers::Xsd do
114
114
  table {}
115
115
 
116
116
  model do
117
+ def foo=(value)
118
+ @foo = value
119
+ end
120
+
121
+ def foo
122
+ @foo
123
+ end
124
+
125
+ def self.xsd_foo_enumeration_restrictions
126
+ ["1", "2", "3"]
127
+ end
128
+
117
129
  def self.xsd_methods
118
- {:foo => [:bar]}
130
+ {:foo => [:foo]}
131
+ end
132
+
133
+ def to_xml(options = {})
134
+ super({:methods => [:foo]}.merge(options))
119
135
  end
120
136
  end
121
137
  end
@@ -134,7 +150,17 @@ describe Schematic::Serializers::Xsd do
134
150
  <xs:element name="foo" minOccurs="0" maxOccurs="1">
135
151
  <xs:complexType>
136
152
  <xs:sequence>
137
- <xs:element name="bar" minOccurs="0" maxOccurs="unbounded"/>
153
+ <xs:element name="foo" minOccurs="0" maxOccurs="unbounded">
154
+ <xs:complexType>
155
+ <xs:simpleContent>
156
+ <xs:restriction base="String">
157
+ <xs:enumeration value="1"/>
158
+ <xs:enumeration value="2"/>
159
+ <xs:enumeration value="3"/>
160
+ </xs:restriction>
161
+ </xs:simpleContent>
162
+ </xs:complexType>
163
+ </xs:element>
138
164
  </xs:sequence>
139
165
  <xs:attribute name="type" type="xs:string" fixed="array" use="optional"/>
140
166
  </xs:complexType>
@@ -143,6 +169,20 @@ describe Schematic::Serializers::Xsd do
143
169
  end
144
170
  sanitize_xml(SomeModel.to_xsd).should eq(xsd)
145
171
  end
172
+
173
+ it "should validate against its own XSD" do
174
+ invalid_instance = SomeModel.new(:foo => ["a", "b"])
175
+ xml = [invalid_instance].to_xml
176
+ lambda {
177
+ validate_xml_against_xsd(xml, SomeModel.to_xsd)
178
+ }.should raise_error
179
+
180
+ instance = SomeModel.new(:foo => ["1", "2"])
181
+ xml = [instance].to_xml
182
+ lambda {
183
+ validate_xml_against_xsd(xml, SomeModel.to_xsd)
184
+ }.should_not raise_error
185
+ end
146
186
  end
147
187
 
148
188
  context "given nested methods" do
@@ -58,7 +58,7 @@ describe Schematic::Serializers::Xsd do
58
58
  :some_datetime => DateTime.new,
59
59
  :some_boolean => true,
60
60
  :some_float => 1.5,
61
- :method_is_also_columns => [{:some => "somevalues"}],
61
+ :method_is_also_columns => ["somevalues"],
62
62
  :additional_method_array => {"somevalue" => "somekey"},
63
63
  :some_integer => 2)
64
64
  xml = [instance].to_xml
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: schematic
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.3
5
+ version: 0.3.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Case Commons, LLC
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-08 00:00:00 -04:00
13
+ date: 2011-06-15 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency