schematic 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore
CHANGED
@@ -91,7 +91,9 @@ module Schematic
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
else
|
94
|
-
|
94
|
+
column_klass = Struct.new(:name, :type)
|
95
|
+
column = column_klass.new(method_name.to_s, :string)
|
96
|
+
Column.new(@klass, column, {}, @klass.xsd_ignore_methods).generate(builder)
|
95
97
|
end
|
96
98
|
end
|
97
99
|
end
|
data/lib/schematic/version.rb
CHANGED
@@ -24,12 +24,89 @@ describe Schematic::Serializers::Xsd do
|
|
24
24
|
</xs:simpleContent>
|
25
25
|
</xs:complexType>
|
26
26
|
</xs:element>
|
27
|
-
<xs:element name="foo-bar" minOccurs="0" maxOccurs="1"
|
27
|
+
<xs:element name="foo-bar" minOccurs="0" maxOccurs="1">
|
28
|
+
<xs:complexType>
|
29
|
+
<xs:simpleContent>
|
30
|
+
<xs:restriction base="String">
|
31
|
+
</xs:restriction>
|
32
|
+
</xs:simpleContent>
|
33
|
+
</xs:complexType>
|
34
|
+
</xs:element>
|
35
|
+
XML
|
36
|
+
end
|
37
|
+
|
38
|
+
sanitize_xml(SomeModel.to_xsd).should eq(xsd)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "given a method with validations" do
|
43
|
+
with_model :some_model do
|
44
|
+
table {}
|
45
|
+
|
46
|
+
model do
|
47
|
+
validates :foo_bar, :inclusion => { :in => [1,2,3] }
|
48
|
+
|
49
|
+
def foo_bar=(value)
|
50
|
+
@foo_bar = value
|
51
|
+
end
|
52
|
+
|
53
|
+
def foo_bar
|
54
|
+
@foo_bar
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_xml(options = {})
|
58
|
+
super({:methods => [:foo_bar]}.merge(options))
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.xsd_methods
|
62
|
+
{:foo_bar => nil}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
it "should generate validation restrictions for the method if there are any" do
|
69
|
+
xsd = generate_xsd_for_model(SomeModel) do
|
70
|
+
<<-XML
|
71
|
+
<xs:element name="id" minOccurs="0" maxOccurs="1">
|
72
|
+
<xs:complexType>
|
73
|
+
<xs:simpleContent>
|
74
|
+
<xs:restriction base="Integer">
|
75
|
+
</xs:restriction>
|
76
|
+
</xs:simpleContent>
|
77
|
+
</xs:complexType>
|
78
|
+
</xs:element>
|
79
|
+
<xs:element name="foo-bar" minOccurs="0" maxOccurs="1">
|
80
|
+
<xs:complexType>
|
81
|
+
<xs:simpleContent>
|
82
|
+
<xs:restriction base="String">
|
83
|
+
<xs:enumeration value="1"/>
|
84
|
+
<xs:enumeration value="2"/>
|
85
|
+
<xs:enumeration value="3"/>
|
86
|
+
</xs:restriction>
|
87
|
+
</xs:simpleContent>
|
88
|
+
</xs:complexType>
|
89
|
+
</xs:element>
|
28
90
|
XML
|
29
91
|
end
|
30
92
|
|
31
93
|
sanitize_xml(SomeModel.to_xsd).should eq(xsd)
|
32
94
|
end
|
95
|
+
|
96
|
+
it "should validate against the xsd" do
|
97
|
+
xsd = SomeModel.to_xsd
|
98
|
+
|
99
|
+
invalid_instance = SomeModel.new(:foo_bar => "d")
|
100
|
+
xml = [invalid_instance].to_xml
|
101
|
+
lambda {
|
102
|
+
validate_xml_against_xsd(xml, xsd)
|
103
|
+
}.should raise_error
|
104
|
+
valid_instance = SomeModel.new(:foo_bar => 1)
|
105
|
+
xml = [valid_instance].to_xml
|
106
|
+
lambda {
|
107
|
+
validate_xml_against_xsd(xml, xsd)
|
108
|
+
}.should_not raise_error
|
109
|
+
end
|
33
110
|
end
|
34
111
|
|
35
112
|
context "given a an array of methods" do
|
@@ -96,7 +173,14 @@ describe Schematic::Serializers::Xsd do
|
|
96
173
|
<xs:element name="bar" minOccurs="0" maxOccurs="1">
|
97
174
|
<xs:complexType>
|
98
175
|
<xs:all>
|
99
|
-
<xs:element name="baz" minOccurs="0" maxOccurs="1"
|
176
|
+
<xs:element name="baz" minOccurs="0" maxOccurs="1">
|
177
|
+
<xs:complexType>
|
178
|
+
<xs:simpleContent>
|
179
|
+
<xs:restriction base="String">
|
180
|
+
</xs:restriction>
|
181
|
+
</xs:simpleContent>
|
182
|
+
</xs:complexType>
|
183
|
+
</xs:element>
|
100
184
|
</xs:all>
|
101
185
|
<xs:attribute name="type" type="xs:string" fixed="array" use="optional"/>
|
102
186
|
</xs:complexType>
|
@@ -266,7 +266,14 @@ describe Schematic::Serializers::Xsd do
|
|
266
266
|
</xs:simpleContent>
|
267
267
|
</xs:complexType>
|
268
268
|
</xs:element>
|
269
|
-
<xs:element name="foo-bar" minOccurs="0" maxOccurs="1"
|
269
|
+
<xs:element name="foo-bar" minOccurs="0" maxOccurs="1">
|
270
|
+
<xs:complexType>
|
271
|
+
<xs:simpleContent>
|
272
|
+
<xs:restriction base="String">
|
273
|
+
</xs:restriction>
|
274
|
+
</xs:simpleContent>
|
275
|
+
</xs:complexType>
|
276
|
+
</xs:element>
|
270
277
|
XML
|
271
278
|
end
|
272
279
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: schematic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.7
|
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-05-
|
13
|
+
date: 2011-05-16 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|