schematic 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,9 +27,9 @@ module Schematic
27
27
  output
28
28
  end
29
29
 
30
- def generate_xsd(builder, klass, include_collection, options)
30
+ def generate_xsd(builder, klass, include_collection, options, exclude)
31
31
  xsd_generator.options = options
32
- xsd_generator.generate(builder, klass, include_collection)
32
+ xsd_generator.generate(builder, klass, include_collection, exclude)
33
33
  end
34
34
 
35
35
  def ignore(*fields)
@@ -54,10 +54,6 @@ module Schematic
54
54
  def required(*fields)
55
55
  fields.each { |field| required_elements << field }
56
56
  end
57
-
58
- def method_missing(method, *args, &block)
59
- @klass.send method, *args, &block
60
- end
61
57
  end
62
58
  end
63
59
  end
@@ -4,14 +4,14 @@ module Schematic
4
4
  attr_reader :output, :names
5
5
  attr_accessor :options
6
6
 
7
- def initialize(klass, options = {})
7
+ def initialize(klass)
8
8
  @klass = klass
9
9
  @names = Names.new(klass)
10
- self.options = options
11
10
  end
12
11
 
13
12
  def options=(hash = {})
14
- @options = {:generated_types => []}.merge(hash)
13
+ @options = hash
14
+ @options[:generated_types] ||= []
15
15
  @options[:generated_types] << @klass
16
16
  @options
17
17
  end
@@ -34,15 +34,18 @@ module Schematic
34
34
  end
35
35
  end
36
36
 
37
- def generate(builder, klass, include_collection=true)
37
+ def generate(builder, klass, include_collection=true, exclude_from_parent = [])
38
+ @exclude = exclude_from_parent
39
+
38
40
  nested_attributes.each do |nested_attribute|
39
41
  next if nested_attribute.klass == klass
40
42
  next if nested_attribute.klass == klass.superclass
41
43
  @options ||= {}
42
44
  @options[:generated_types] ||= []
43
- @options[:exclude] = klass.schematic_sandbox.ignored_elements[nested_attribute.name]
45
+ exclude = klass.schematic_sandbox.ignored_elements[nested_attribute.name].dup
44
46
  next if @options[:generated_types].include?(nested_attribute.klass)
45
- nested_attribute.klass.schematic_sandbox.generate_xsd(builder, klass, nested_attribute.macro == :has_many, @options)
47
+
48
+ nested_attribute.klass.schematic_sandbox.generate_xsd(builder, klass, nested_attribute.macro == :has_many, @options, exclude)
46
49
  @options[:generated_types] << nested_attribute.klass
47
50
  end
48
51
 
@@ -63,7 +66,7 @@ module Schematic
63
66
  builder.xs :complexType, "name" => @names.type do |complex_type|
64
67
  additional_methods = @klass.schematic_sandbox.added_elements.merge(@options[:methods] || {})
65
68
  ignored_methods = @klass.schematic_sandbox.ignored_elements.dup
66
- exclude = @options[:exclude]
69
+ exclude = @exclude
67
70
 
68
71
  case exclude
69
72
  when Hash
@@ -169,7 +172,7 @@ module Schematic
169
172
  def nested_attributes
170
173
  return [] unless @klass.respond_to?(:reflect_on_all_associations)
171
174
  @klass.reflect_on_all_associations.select do |association|
172
- @klass.instance_methods.include?("#{association.name}_attributes=".to_sym) &&
175
+ @klass.instance_methods.include?(:"#{association.name}_attributes=") &&
173
176
  association.options[:polymorphic] != true &&
174
177
  !@klass.schematic_sandbox.ignored_elements[association.name.to_sym].nil?
175
178
  end
@@ -1,3 +1,3 @@
1
1
  module Schematic
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
@@ -77,19 +77,4 @@ describe Schematic::Generator::Sandbox do
77
77
  subject.required_elements.should include(:bar)
78
78
  end
79
79
  end
80
-
81
- describe "methods on original object get called when not difined in sandbox module" do
82
- before do
83
- klass.stub(:foo)
84
- end
85
-
86
- it "should delegate missing methods to klass" do
87
- klass.should_receive(:foo)
88
-
89
- subject.run do
90
- self.foo
91
- end
92
- end
93
- end
94
80
  end
95
-
@@ -304,6 +304,142 @@ describe Schematic::Serializers::Xsd do
304
304
  end
305
305
  end
306
306
 
307
+ context "when the model has a nested attribute and ignores one of the methods of the nested attribute" do
308
+ with_model :parent do
309
+ table do |t|
310
+ t.string :first_name
311
+ t.string :last_name
312
+ end
313
+
314
+ model do
315
+ has_one :child
316
+ accepts_nested_attributes_for :child
317
+ schematic do
318
+ ignore :child => [:last_name]
319
+ end
320
+ end
321
+ end
322
+
323
+ with_model :child do
324
+ table do |t|
325
+ t.integer :parent_id
326
+ t.string :first_name
327
+ t.string :last_name
328
+ end
329
+
330
+ model do
331
+ belongs_to :parent
332
+ end
333
+ end
334
+
335
+ describe "the parent XSD" do
336
+ subject { Parent.to_xsd }
337
+
338
+ it "should be valid" do
339
+ subject.should include "child-attributes"
340
+ subject.should include "first-name"
341
+ subject.should include "last-name"
342
+ validate_xsd(subject)
343
+ end
344
+ end
345
+
346
+ describe "the child XSD" do
347
+ subject { Child.to_xsd }
348
+
349
+ it "should be valid" do
350
+ subject.should include "first-name"
351
+ subject.should include "last-name"
352
+ validate_xsd(subject)
353
+ end
354
+ end
355
+ end
356
+
357
+ context "when the model has a nested attribute and ignores a required method of the nested attribute" do
358
+ with_model :person do
359
+ model do
360
+ has_one :house
361
+ accepts_nested_attributes_for :house
362
+ schematic do
363
+ ignore :house => [:address]
364
+ end
365
+ end
366
+ end
367
+
368
+ with_model :house do
369
+ table do |t|
370
+ t.string :address
371
+ t.integer :price
372
+ t.belongs_to :person
373
+ end
374
+ model do
375
+ belongs_to :person
376
+ validates :address, presence: true
377
+ end
378
+ end
379
+
380
+ describe "the parent XSD" do
381
+ subject { Person.to_xsd }
382
+ it "should be valid" do
383
+ subject.should include %{"house-attributes"}
384
+ subject.should include %{"price"}
385
+ subject.should_not include %{"address"}
386
+ validate_xsd(subject)
387
+ end
388
+ end
389
+
390
+ describe "the child XSD" do
391
+ subject { House.to_xsd }
392
+ it "should be valid" do
393
+ subject.should include %{"price"}
394
+ subject.should include %{"address"}
395
+ validate_xsd(subject)
396
+ end
397
+ end
398
+ end
399
+
400
+ context "when the model has a polymorphic nested attribute and ignores a required method of the nested attribute" do
401
+ with_model :person do
402
+ model do
403
+ has_one :house, as: :homeowner
404
+ accepts_nested_attributes_for :house
405
+ schematic do
406
+ ignore :house => [:address]
407
+ end
408
+ end
409
+ end
410
+
411
+ with_model :house do
412
+ table do |t|
413
+ t.string :address
414
+ t.integer :price
415
+ t.belongs_to :homeowner, polymorphic: true
416
+ end
417
+ model do
418
+ belongs_to :homeowner, polymorphic: true
419
+ validates :address, presence: true
420
+ end
421
+ end
422
+
423
+ describe "the parent XSD" do
424
+ subject { Person.to_xsd }
425
+ it "should be valid" do
426
+ subject.should include %{"house-attributes"}
427
+ subject.should include %{"price"}
428
+ subject.should_not include %{"address"}
429
+ validate_xsd(subject)
430
+ end
431
+ end
432
+
433
+ describe "the child XSD" do
434
+ subject { House.to_xsd }
435
+ it "should be valid" do
436
+ subject.should include %{"price"}
437
+ subject.should include %{"address"}
438
+ validate_xsd(subject)
439
+ end
440
+ end
441
+ end
442
+
307
443
  context "when the model has a circular nested attribute reference" do
308
444
  with_model :plate do
309
445
  model do
metadata CHANGED
@@ -1,100 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: schematic
3
- version: !ruby/object:Gem::Version
4
- version: 0.5.5
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.5.6
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Case Commons, LLC
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-10 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2011-10-11 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: activerecord
16
- requirement: &2152311800 !ruby/object:Gem::Requirement
17
+ requirement: &id001 !ruby/object:Gem::Requirement
17
18
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
21
22
  version: 3.0.0
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *2152311800
25
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
26
27
  name: builder
27
- requirement: &2152311020 !ruby/object:Gem::Requirement
28
+ requirement: &id002 !ruby/object:Gem::Requirement
28
29
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *2152311020
36
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
37
38
  name: rspec-rails
38
- requirement: &2152310340 !ruby/object:Gem::Requirement
39
+ requirement: &id003 !ruby/object:Gem::Requirement
39
40
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '2.1'
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "2.1"
44
45
  type: :development
45
46
  prerelease: false
46
- version_requirements: *2152310340
47
- - !ruby/object:Gem::Dependency
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
48
49
  name: with_model
49
- requirement: &2152309480 !ruby/object:Gem::Requirement
50
+ requirement: &id004 !ruby/object:Gem::Requirement
50
51
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
55
56
  type: :development
56
57
  prerelease: false
57
- version_requirements: *2152309480
58
- - !ruby/object:Gem::Dependency
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
59
60
  name: nokogiri
60
- requirement: &2152308540 !ruby/object:Gem::Requirement
61
+ requirement: &id005 !ruby/object:Gem::Requirement
61
62
  none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
66
67
  type: :development
67
68
  prerelease: false
68
- version_requirements: *2152308540
69
- - !ruby/object:Gem::Dependency
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
70
71
  name: sqlite3
71
- requirement: &2152307820 !ruby/object:Gem::Requirement
72
+ requirement: &id006 !ruby/object:Gem::Requirement
72
73
  none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
77
78
  type: :development
78
79
  prerelease: false
79
- version_requirements: *2152307820
80
- - !ruby/object:Gem::Dependency
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
81
82
  name: autotest
82
- requirement: &2152307120 !ruby/object:Gem::Requirement
83
+ requirement: &id007 !ruby/object:Gem::Requirement
83
84
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
88
89
  type: :development
89
90
  prerelease: false
90
- version_requirements: *2152307120
91
+ version_requirements: *id007
91
92
  description: Automatic XSD generation from ActiveRecord models
92
- email:
93
+ email:
93
94
  - casecommons-dev@googlegroups.com
94
95
  executables: []
96
+
95
97
  extensions: []
98
+
96
99
  extra_rdoc_files: []
97
- files:
100
+
101
+ files:
98
102
  - .gitignore
99
103
  - .rspec
100
104
  - .rvmrc
@@ -141,35 +145,38 @@ files:
141
145
  - spec/xsd/xml.xsd
142
146
  homepage: https://github.com/Casecommons/schematic
143
147
  licenses: []
148
+
144
149
  post_install_message:
145
150
  rdoc_options: []
146
- require_paths:
151
+
152
+ require_paths:
147
153
  - lib
148
- required_ruby_version: !ruby/object:Gem::Requirement
154
+ required_ruby_version: !ruby/object:Gem::Requirement
149
155
  none: false
150
- requirements:
151
- - - ! '>='
152
- - !ruby/object:Gem::Version
153
- version: '0'
154
- segments:
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ hash: 3959164304158595365
160
+ segments:
155
161
  - 0
156
- hash: -2905881266573223577
157
- required_rubygems_version: !ruby/object:Gem::Requirement
162
+ version: "0"
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
164
  none: false
159
- requirements:
160
- - - ! '>='
161
- - !ruby/object:Gem::Version
162
- version: '0'
163
- segments:
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ hash: 3959164304158595365
169
+ segments:
164
170
  - 0
165
- hash: -2905881266573223577
171
+ version: "0"
166
172
  requirements: []
173
+
167
174
  rubyforge_project: schematic
168
175
  rubygems_version: 1.8.10
169
176
  signing_key:
170
177
  specification_version: 3
171
178
  summary: Automatic XSD generation from ActiveRecord models
172
- test_files:
179
+ test_files:
173
180
  - spec/schematic/generator/restrictions/custom_spec.rb
174
181
  - spec/schematic/generator/restrictions/enumeration_spec.rb
175
182
  - spec/schematic/generator/restrictions/length_spec.rb