schematic 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module Schematic
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def type
|
10
|
-
@klass.name.
|
10
|
+
@klass.name.gsub(/::/,'')
|
11
11
|
end
|
12
12
|
|
13
13
|
def element
|
@@ -22,6 +22,10 @@ module Schematic
|
|
22
22
|
type.pluralize
|
23
23
|
end
|
24
24
|
|
25
|
+
def nested_attribute_name
|
26
|
+
"#{element_collection}-attributes"
|
27
|
+
end
|
28
|
+
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -12,7 +12,7 @@ module Schematic
|
|
12
12
|
|
13
13
|
def options=(hash = {})
|
14
14
|
@options = {:generated_types => []}.merge(hash)
|
15
|
-
@options[:generated_types] << @klass
|
15
|
+
@options[:generated_types] << @klass
|
16
16
|
@options
|
17
17
|
end
|
18
18
|
|
@@ -38,9 +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
|
-
next if @options && @options[:generated_types] && @options[:generated_types].include?(klass)
|
41
|
+
next if @options && @options[:generated_types] && @options[:generated_types].include?(nested_attribute.klass)
|
42
42
|
nested_attribute.klass.generate_xsd(builder, klass, @options)
|
43
|
-
@options[:generated_types] << klass
|
43
|
+
@options[:generated_types] << nested_attribute.klass
|
44
44
|
end
|
45
45
|
|
46
46
|
generate_complex_type_for_collection(builder)
|
@@ -64,7 +64,7 @@ module Schematic
|
|
64
64
|
generate_column_elements(all, additional_methods, ignored_methods)
|
65
65
|
|
66
66
|
nested_attributes.each do |nested_attribute|
|
67
|
-
all.xs :element, "name" =>
|
67
|
+
all.xs :element, "name" => nested_attribute.klass.xsd_generator.names.nested_attribute_name, "type" => nested_attribute.klass.xsd_generator.names.collection_type, "minOccurs" => "0", "maxOccurs" => "1"
|
68
68
|
end
|
69
69
|
|
70
70
|
generate_additional_methods(all, additional_methods)
|
data/lib/schematic/version.rb
CHANGED
@@ -98,7 +98,7 @@ describe Schematic::Serializers::Xsd do
|
|
98
98
|
with_model :parent do
|
99
99
|
table {}
|
100
100
|
model do
|
101
|
-
has_many :children
|
101
|
+
has_many :children, :class_name => "Namespace::Child"
|
102
102
|
accepts_nested_attributes_for :children
|
103
103
|
end
|
104
104
|
end
|
@@ -125,29 +125,37 @@ describe Schematic::Serializers::Xsd do
|
|
125
125
|
it "should generate a valid XSD" do
|
126
126
|
validate_xsd(subject)
|
127
127
|
end
|
128
|
+
|
129
|
+
it "should validate against its own XSD" do
|
130
|
+
child_instance = Namespace::Child.new(:parent_id => 123)
|
131
|
+
xml = [child_instance].to_xml
|
132
|
+
lambda {
|
133
|
+
validate_xml_against_xsd(xml, subject)
|
134
|
+
}.should_not raise_error
|
135
|
+
end
|
128
136
|
end
|
129
137
|
|
130
138
|
context "when the model has a circular nested attribute reference" do
|
131
|
-
with_model :
|
139
|
+
with_model :plate do
|
132
140
|
table {}
|
133
141
|
model do
|
134
|
-
has_many :
|
135
|
-
accepts_nested_attributes_for :
|
142
|
+
has_many :cheeses
|
143
|
+
accepts_nested_attributes_for :cheeses
|
136
144
|
end
|
137
145
|
end
|
138
146
|
|
139
|
-
with_model :
|
147
|
+
with_model :cheese do
|
140
148
|
table do |t|
|
141
|
-
t.integer :
|
149
|
+
t.integer :plate_id
|
142
150
|
end
|
143
151
|
|
144
152
|
model do
|
145
|
-
belongs_to :
|
146
|
-
accepts_nested_attributes_for :
|
153
|
+
belongs_to :plate
|
154
|
+
accepts_nested_attributes_for :plate
|
147
155
|
end
|
148
156
|
end
|
149
157
|
|
150
|
-
subject {
|
158
|
+
subject { Cheese.to_xsd }
|
151
159
|
|
152
160
|
it "should generate a valid XSD" do
|
153
161
|
validate_xsd(subject)
|