schematic 0.5.0 → 0.5.1
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/lib/schematic/generator/column.rb +4 -1
- data/lib/schematic/generator/types.rb +1 -0
- data/lib/schematic/generator/xsd.rb +3 -1
- data/lib/schematic/version.rb +1 -1
- data/spec/schematic/serializers/xsd_xsd_methods_spec.rb +15 -9
- data/spec/schematic_serializers_xsd_spec.rb +34 -24
- data/spec/spec_helper.rb +7 -0
- data/spec/support/extensions/active_model/validations/inclusion.rb +3 -4
- metadata +19 -19
@@ -19,7 +19,10 @@ module Schematic
|
|
19
19
|
def generate(builder)
|
20
20
|
return if skip_generation?
|
21
21
|
|
22
|
-
builder.xs :element,
|
22
|
+
builder.xs :element,
|
23
|
+
"name" => @column.name.dasherize,
|
24
|
+
"minOccurs" => minimum_occurrences_for_column,
|
25
|
+
"maxOccurs" => "1" do |field|
|
23
26
|
field.xs :complexType do |complex_type|
|
24
27
|
complex_type.xs :simpleContent do |simple_content|
|
25
28
|
simple_content.xs :restriction, "base" => map_type(@column) do |restriction|
|
@@ -19,6 +19,7 @@ module Schematic
|
|
19
19
|
complex_type.xs :simpleContent do |simple_content|
|
20
20
|
simple_content.xs :extension, "base" => xsd_type do |extension|
|
21
21
|
extension.xs :attribute, "name" => "type", "type" => "xs:string", "use" => "optional"
|
22
|
+
extension.xs :attribute, "name" => "nil", "type" => "xs:boolean", "use" => "optional"
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -38,7 +38,9 @@ module Schematic
|
|
38
38
|
nested_attributes.each do |nested_attribute|
|
39
39
|
next if nested_attribute.klass == klass
|
40
40
|
next if nested_attribute.klass == klass.superclass
|
41
|
-
|
41
|
+
@options ||= {}
|
42
|
+
@options[:generated_types] ||= []
|
43
|
+
next if @options[:generated_types].include?(nested_attribute.klass)
|
42
44
|
nested_attribute.klass.schematic_sandbox.generate_xsd(builder, klass, @options)
|
43
45
|
@options[:generated_types] << nested_attribute.klass
|
44
46
|
end
|
data/lib/schematic/version.rb
CHANGED
@@ -41,7 +41,9 @@ describe Schematic::Serializers::Xsd do
|
|
41
41
|
|
42
42
|
context "given a method with validations" do
|
43
43
|
with_model :some_model do
|
44
|
-
table
|
44
|
+
table :id => false do |t|
|
45
|
+
t.string :foo
|
46
|
+
end
|
45
47
|
|
46
48
|
model do
|
47
49
|
validates :foo_bar, :inclusion => { :in => [1,2,3] }
|
@@ -68,10 +70,10 @@ describe Schematic::Serializers::Xsd do
|
|
68
70
|
it "should generate validation restrictions for the method if there are any" do
|
69
71
|
xsd = generate_xsd_for_model(SomeModel) do
|
70
72
|
<<-XML
|
71
|
-
<xs:element name="
|
73
|
+
<xs:element name="foo" minOccurs="0" maxOccurs="1">
|
72
74
|
<xs:complexType>
|
73
75
|
<xs:simpleContent>
|
74
|
-
<xs:restriction base="
|
76
|
+
<xs:restriction base="String">
|
75
77
|
</xs:restriction>
|
76
78
|
</xs:simpleContent>
|
77
79
|
</xs:complexType>
|
@@ -111,7 +113,9 @@ describe Schematic::Serializers::Xsd do
|
|
111
113
|
|
112
114
|
context "given a singular enumeration restriction" do
|
113
115
|
with_model :some_model do
|
114
|
-
table
|
116
|
+
table :id => false do |t|
|
117
|
+
t.string :foo
|
118
|
+
end
|
115
119
|
|
116
120
|
model do
|
117
121
|
|
@@ -134,10 +138,10 @@ describe Schematic::Serializers::Xsd do
|
|
134
138
|
it "should include the additional methods" do
|
135
139
|
xsd = generate_xsd_for_model(SomeModel) do
|
136
140
|
<<-XML
|
137
|
-
<xs:element name="
|
141
|
+
<xs:element name="foo" minOccurs="0" maxOccurs="1">
|
138
142
|
<xs:complexType>
|
139
143
|
<xs:simpleContent>
|
140
|
-
<xs:restriction base="
|
144
|
+
<xs:restriction base="String">
|
141
145
|
</xs:restriction>
|
142
146
|
</xs:simpleContent>
|
143
147
|
</xs:complexType>
|
@@ -176,7 +180,9 @@ describe Schematic::Serializers::Xsd do
|
|
176
180
|
|
177
181
|
context "given a an array of methods" do
|
178
182
|
with_model :some_model do
|
179
|
-
table
|
183
|
+
table :id => false do |t|
|
184
|
+
t.string :bar
|
185
|
+
end
|
180
186
|
|
181
187
|
model do
|
182
188
|
def foo=(value)
|
@@ -204,10 +210,10 @@ describe Schematic::Serializers::Xsd do
|
|
204
210
|
it "should include the additional methods" do
|
205
211
|
xsd = generate_xsd_for_model(SomeModel) do
|
206
212
|
<<-XML
|
207
|
-
<xs:element name="
|
213
|
+
<xs:element name="bar" minOccurs="0" maxOccurs="1">
|
208
214
|
<xs:complexType>
|
209
215
|
<xs:simpleContent>
|
210
|
-
<xs:restriction base="
|
216
|
+
<xs:restriction base="String">
|
211
217
|
</xs:restriction>
|
212
218
|
</xs:simpleContent>
|
213
219
|
</xs:complexType>
|
@@ -56,7 +56,7 @@ describe Schematic::Serializers::Xsd do
|
|
56
56
|
subject { SomeModel.to_xsd }
|
57
57
|
|
58
58
|
with_model :some_model do
|
59
|
-
table do |t|
|
59
|
+
table :id => false do |t|
|
60
60
|
t.string "some_string"
|
61
61
|
t.text "some_text"
|
62
62
|
t.float "some_float"
|
@@ -134,39 +134,42 @@ describe Schematic::Serializers::Xsd do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
context "when the model has a nested attribute on a subclass with a reference to the superclass" do
|
137
|
-
with_model :parent do
|
138
|
-
table {}
|
139
|
-
model do
|
140
|
-
has_many :children, :class_name => "Namespace::Child"
|
141
|
-
accepts_nested_attributes_for :children
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
137
|
with_model :child do
|
146
138
|
table do |t|
|
147
139
|
t.integer :parent_id
|
148
140
|
end
|
149
|
-
|
150
|
-
model do
|
151
|
-
belongs_to :parent
|
152
|
-
end
|
141
|
+
model {}
|
153
142
|
end
|
143
|
+
with_model :parent do
|
144
|
+
table {}
|
145
|
+
model {}
|
146
|
+
end
|
147
|
+
|
154
148
|
|
155
149
|
before do
|
156
|
-
|
157
|
-
|
150
|
+
::Child.class_eval do
|
151
|
+
belongs_to :parent
|
152
|
+
end
|
153
|
+
module Namespace
|
154
|
+
if defined?(SubChild)
|
155
|
+
remove_const(:SubChild)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
class Namespace::SubChild < ::Child
|
158
159
|
accepts_nested_attributes_for :parent
|
159
160
|
end
|
161
|
+
::Parent.class_eval do
|
162
|
+
has_many :children, :class_name => "Namespace::SubChild"
|
163
|
+
accepts_nested_attributes_for :children
|
164
|
+
end
|
160
165
|
end
|
161
166
|
|
162
|
-
subject { Namespace::
|
167
|
+
subject { Namespace::SubChild.to_xsd }
|
163
168
|
|
164
|
-
it "should generate a valid XSD" do
|
169
|
+
it "should generate a valid xsd and validate against its own XSD" do
|
165
170
|
validate_xsd(subject)
|
166
|
-
|
167
|
-
|
168
|
-
it "should validate against its own XSD" do
|
169
|
-
child_instance = Namespace::Child.new(:parent_id => 123)
|
171
|
+
child_instance = Namespace::SubChild.new(:parent_id => 123)
|
172
|
+
child_instance.save!
|
170
173
|
xml = [child_instance].to_xml
|
171
174
|
lambda {
|
172
175
|
validate_xml_against_xsd(xml, subject)
|
@@ -175,7 +178,7 @@ describe Schematic::Serializers::Xsd do
|
|
175
178
|
end
|
176
179
|
|
177
180
|
context "when the model has a nested attribute on a subclass with a different class name than the association" do
|
178
|
-
with_model :
|
181
|
+
with_model :parent2 do
|
179
182
|
table {}
|
180
183
|
model do
|
181
184
|
has_many :children, :class_name => "SpecialChild"
|
@@ -189,11 +192,11 @@ describe Schematic::Serializers::Xsd do
|
|
189
192
|
end
|
190
193
|
|
191
194
|
model do
|
192
|
-
belongs_to :
|
195
|
+
belongs_to :parent2
|
193
196
|
end
|
194
197
|
end
|
195
198
|
|
196
|
-
subject {
|
199
|
+
subject { Parent2.to_xsd }
|
197
200
|
|
198
201
|
it "should generate a valid XSD" do
|
199
202
|
subject.should include "children-attributes"
|
@@ -281,6 +284,7 @@ describe Schematic::Serializers::Xsd do
|
|
281
284
|
<xs:simpleContent>
|
282
285
|
<xs:extension base="xs:integer">
|
283
286
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
287
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
284
288
|
</xs:extension>
|
285
289
|
</xs:simpleContent>
|
286
290
|
</xs:complexType>
|
@@ -288,6 +292,7 @@ describe Schematic::Serializers::Xsd do
|
|
288
292
|
<xs:simpleContent>
|
289
293
|
<xs:extension base="xs:float">
|
290
294
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
295
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
291
296
|
</xs:extension>
|
292
297
|
</xs:simpleContent>
|
293
298
|
</xs:complexType>
|
@@ -295,6 +300,7 @@ describe Schematic::Serializers::Xsd do
|
|
295
300
|
<xs:simpleContent>
|
296
301
|
<xs:extension base="xs:string">
|
297
302
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
303
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
298
304
|
</xs:extension>
|
299
305
|
</xs:simpleContent>
|
300
306
|
</xs:complexType>
|
@@ -302,6 +308,7 @@ describe Schematic::Serializers::Xsd do
|
|
302
308
|
<xs:simpleContent>
|
303
309
|
<xs:extension base="xs:string">
|
304
310
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
311
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
305
312
|
</xs:extension>
|
306
313
|
</xs:simpleContent>
|
307
314
|
</xs:complexType>
|
@@ -309,6 +316,7 @@ describe Schematic::Serializers::Xsd do
|
|
309
316
|
<xs:simpleContent>
|
310
317
|
<xs:extension base="xs:dateTime">
|
311
318
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
319
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
312
320
|
</xs:extension>
|
313
321
|
</xs:simpleContent>
|
314
322
|
</xs:complexType>
|
@@ -316,6 +324,7 @@ describe Schematic::Serializers::Xsd do
|
|
316
324
|
<xs:simpleContent>
|
317
325
|
<xs:extension base="xs:date">
|
318
326
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
327
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
319
328
|
</xs:extension>
|
320
329
|
</xs:simpleContent>
|
321
330
|
</xs:complexType>
|
@@ -323,6 +332,7 @@ describe Schematic::Serializers::Xsd do
|
|
323
332
|
<xs:simpleContent>
|
324
333
|
<xs:extension base="xs:boolean">
|
325
334
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
335
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
326
336
|
</xs:extension>
|
327
337
|
</xs:simpleContent>
|
328
338
|
</xs:complexType>
|
data/spec/spec_helper.rb
CHANGED
@@ -48,6 +48,7 @@ def generate_xsd_for_model(model, header_element = nil)
|
|
48
48
|
<xs:simpleContent>
|
49
49
|
<xs:extension base="xs:integer">
|
50
50
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
51
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
51
52
|
</xs:extension>
|
52
53
|
</xs:simpleContent>
|
53
54
|
</xs:complexType>
|
@@ -55,6 +56,7 @@ def generate_xsd_for_model(model, header_element = nil)
|
|
55
56
|
<xs:simpleContent>
|
56
57
|
<xs:extension base="xs:float">
|
57
58
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
59
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
58
60
|
</xs:extension>
|
59
61
|
</xs:simpleContent>
|
60
62
|
</xs:complexType>
|
@@ -62,6 +64,7 @@ def generate_xsd_for_model(model, header_element = nil)
|
|
62
64
|
<xs:simpleContent>
|
63
65
|
<xs:extension base="xs:string">
|
64
66
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
67
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
65
68
|
</xs:extension>
|
66
69
|
</xs:simpleContent>
|
67
70
|
</xs:complexType>
|
@@ -69,6 +72,7 @@ def generate_xsd_for_model(model, header_element = nil)
|
|
69
72
|
<xs:simpleContent>
|
70
73
|
<xs:extension base="xs:string">
|
71
74
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
75
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
72
76
|
</xs:extension>
|
73
77
|
</xs:simpleContent>
|
74
78
|
</xs:complexType>
|
@@ -76,6 +80,7 @@ def generate_xsd_for_model(model, header_element = nil)
|
|
76
80
|
<xs:simpleContent>
|
77
81
|
<xs:extension base="xs:dateTime">
|
78
82
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
83
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
79
84
|
</xs:extension>
|
80
85
|
</xs:simpleContent>
|
81
86
|
</xs:complexType>
|
@@ -83,6 +88,7 @@ def generate_xsd_for_model(model, header_element = nil)
|
|
83
88
|
<xs:simpleContent>
|
84
89
|
<xs:extension base="xs:date">
|
85
90
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
91
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
86
92
|
</xs:extension>
|
87
93
|
</xs:simpleContent>
|
88
94
|
</xs:complexType>
|
@@ -90,6 +96,7 @@ def generate_xsd_for_model(model, header_element = nil)
|
|
90
96
|
<xs:simpleContent>
|
91
97
|
<xs:extension base="xs:boolean">
|
92
98
|
<xs:attribute name="type" type="xs:string" use="optional"/>
|
99
|
+
<xs:attribute name="nil" type="xs:boolean" use="optional"/>
|
93
100
|
</xs:extension>
|
94
101
|
</xs:simpleContent>
|
95
102
|
</xs:complexType>
|
@@ -6,12 +6,11 @@ module ActiveModel
|
|
6
6
|
# == Active Model Inclusion Validator
|
7
7
|
module Validations
|
8
8
|
class InclusionValidator < EachValidator
|
9
|
-
ERROR_MESSAGE = "An object with the method #include? or a proc or lambda is required, " <<
|
10
|
-
"and must be supplied as the :in option of the configuration hash"
|
11
|
-
|
12
9
|
def check_validity!
|
13
10
|
unless [:include?, :call].any?{ |method| options[:in].respond_to?(method) }
|
14
|
-
|
11
|
+
error_message = "An object with the method #include? or a proc or lambda is required, " <<
|
12
|
+
"and must be supplied as the :in option of the configuration hash"
|
13
|
+
raise ArgumentError, error_message
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schematic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164310000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164310000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: builder
|
27
|
-
requirement: &
|
27
|
+
requirement: &2164309120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2164309120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &2164308120 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.1'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2164308120
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: with_model
|
49
|
-
requirement: &
|
49
|
+
requirement: &2164307420 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2164307420
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: nokogiri
|
60
|
-
requirement: &
|
60
|
+
requirement: &2164304880 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2164304880
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
|
-
requirement: &
|
71
|
+
requirement: &2164303960 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2164303960
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: autotest
|
82
|
-
requirement: &
|
82
|
+
requirement: &2164288000 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2164288000
|
91
91
|
description: Automatic XSD generation from ActiveRecord models
|
92
92
|
email:
|
93
93
|
- casecommons-dev@googlegroups.com
|
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
segments:
|
155
155
|
- 0
|
156
|
-
hash:
|
156
|
+
hash: -1652545114662954696
|
157
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
158
|
none: false
|
159
159
|
requirements:
|
@@ -162,10 +162,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
segments:
|
164
164
|
- 0
|
165
|
-
hash:
|
165
|
+
hash: -1652545114662954696
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project: schematic
|
168
|
-
rubygems_version: 1.8.
|
168
|
+
rubygems_version: 1.8.10
|
169
169
|
signing_key:
|
170
170
|
specification_version: 3
|
171
171
|
summary: Automatic XSD generation from ActiveRecord models
|