schematic 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -67,11 +67,20 @@ module Schematic
67
67
  generate_column_elements(all, additional_methods, ignored_methods, required_methods)
68
68
 
69
69
  nested_attributes.each do |nested_attribute|
70
- all.xs :element,
71
- "name" => nested_attribute_name(nested_attribute.name),
72
- "type" => nested_attribute.klass.schematic_sandbox.xsd_generator.names.collection_type,
73
- "minOccurs" => "0",
74
- "maxOccurs" => "1"
70
+ case nested_attribute.macro
71
+ when :has_many
72
+ all.xs :element,
73
+ "name" => nested_attribute_name(nested_attribute.name),
74
+ "type" => nested_attribute.klass.schematic_sandbox.xsd_generator.names.collection_type,
75
+ "minOccurs" => "0",
76
+ "maxOccurs" => "1"
77
+ when :has_one
78
+ all.xs :element,
79
+ "name" => nested_attribute_name(nested_attribute.name, {:pluralized => false}),
80
+ "type" => nested_attribute.klass.schematic_sandbox.xsd_generator.names.type,
81
+ "minOccurs" => "0",
82
+ "maxOccurs" => "1"
83
+ end
75
84
  end
76
85
 
77
86
  generate_additional_methods(all, additional_methods)
@@ -155,8 +164,12 @@ module Schematic
155
164
  { "xmlns:#{ns}" => Namespaces::PROVIDERS[provider][key] }
156
165
  end
157
166
 
158
- def nested_attribute_name(name)
159
- "#{name.to_s.gsub("_", "-").pluralize}-attributes"
167
+ def nested_attribute_name(name, options={})
168
+ pluralized = options.delete(:pluralized)
169
+ pluralized = true if pluralized.nil?
170
+ name = name.to_s.gsub("_", "-")
171
+ name = name.pluralize if pluralized
172
+ "#{name}-attributes"
160
173
  end
161
174
 
162
175
  end
@@ -1,3 +1,3 @@
1
1
  module Schematic
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -177,7 +177,7 @@ describe Schematic::Serializers::Xsd do
177
177
  end
178
178
  end
179
179
 
180
- context "when the model has a nested attribute on a subclass with a different class name than the association" do
180
+ context "when the model has a nested attribute on a subclass with a different class name than the has_many association" do
181
181
  with_model :parent2 do
182
182
  table {}
183
183
  model do
@@ -205,6 +205,34 @@ describe Schematic::Serializers::Xsd do
205
205
  end
206
206
  end
207
207
 
208
+ context "when the model has a nested attribute for a has_one association" do
209
+ with_model :car do
210
+ table {}
211
+ model do
212
+ has_one :engine
213
+ accepts_nested_attributes_for :engine
214
+ end
215
+ end
216
+
217
+ with_model :engine do
218
+ table do |t|
219
+ t.integer :car_id
220
+ end
221
+
222
+ model do
223
+ belongs_to :car
224
+ end
225
+ end
226
+
227
+ subject { Car.to_xsd }
228
+
229
+ it "should generate a valid XSD" do
230
+ subject.should include "engine-attributes"
231
+ subject.should_not include "engines-attributes"
232
+ validate_xsd(subject)
233
+ end
234
+ end
235
+
208
236
  context "when the model has a circular nested attribute reference" do
209
237
  with_model :plate do
210
238
  table {}
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.1
4
+ version: 0.5.2
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-09-15 00:00:00.000000000Z
12
+ date: 2011-09-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2164310000 !ruby/object:Gem::Requirement
16
+ requirement: &2165083140 !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: *2164310000
24
+ version_requirements: *2165083140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: builder
27
- requirement: &2164309120 !ruby/object:Gem::Requirement
27
+ requirement: &2165081880 !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: *2164309120
35
+ version_requirements: *2165081880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &2164308120 !ruby/object:Gem::Requirement
38
+ requirement: &2165080860 !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: *2164308120
46
+ version_requirements: *2165080860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: with_model
49
- requirement: &2164307420 !ruby/object:Gem::Requirement
49
+ requirement: &2165079840 !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: *2164307420
57
+ version_requirements: *2165079840
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: nokogiri
60
- requirement: &2164304880 !ruby/object:Gem::Requirement
60
+ requirement: &2165078840 !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: *2164304880
68
+ version_requirements: *2165078840
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &2164303960 !ruby/object:Gem::Requirement
71
+ requirement: &2165077900 !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: *2164303960
79
+ version_requirements: *2165077900
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: autotest
82
- requirement: &2164288000 !ruby/object:Gem::Requirement
82
+ requirement: &2165076920 !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: *2164288000
90
+ version_requirements: *2165076920
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: -1652545114662954696
156
+ hash: 4493981086317892751
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  none: false
159
159
  requirements:
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: -1652545114662954696
165
+ hash: 4493981086317892751
166
166
  requirements: []
167
167
  rubyforge_project: schematic
168
168
  rubygems_version: 1.8.10