schematic 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -8
- data/.travis.yml +17 -0
- data/Gemfile +6 -1
- data/LICENSE +1 -1
- data/README.md +106 -0
- data/Rakefile +3 -8
- data/lib/schematic.rb +3 -42
- data/lib/schematic/exceptions.rb +13 -0
- data/lib/schematic/generator/column.rb +17 -11
- data/lib/schematic/generator/namespaces.rb +3 -3
- data/lib/schematic/generator/restrictions/base.rb +5 -5
- data/lib/schematic/generator/restrictions/custom.rb +3 -2
- data/lib/schematic/generator/restrictions/enumeration.rb +5 -2
- data/lib/schematic/generator/restrictions/length.rb +4 -2
- data/lib/schematic/generator/restrictions/numericality.rb +3 -1
- data/lib/schematic/generator/restrictions/pattern.rb +4 -3
- data/lib/schematic/generator/sandbox.rb +4 -1
- data/lib/schematic/generator/types.rb +14 -13
- data/lib/schematic/generator/uniqueness.rb +7 -8
- data/lib/schematic/generator/xsd.rb +32 -26
- data/lib/schematic/serializers/xsd.rb +6 -6
- data/lib/schematic/version.rb +1 -1
- data/schematic.gemspec +23 -24
- data/spec/schematic/generator/restrictions/custom_spec.rb +15 -18
- data/spec/schematic/generator/restrictions/enumeration_spec.rb +31 -31
- data/spec/schematic/generator/restrictions/length_spec.rb +35 -30
- data/spec/schematic/generator/restrictions/mixin_spec.rb +11 -15
- data/spec/schematic/generator/restrictions/numericality_spec.rb +11 -11
- data/spec/schematic/generator/restrictions/pattern_spec.rb +20 -21
- data/spec/schematic/generator/sandbox_spec.rb +17 -17
- data/spec/schematic/generator/uniqueness_spec.rb +38 -37
- data/spec/schematic/serializers/xsd_extend_spec.rb +11 -11
- data/spec/schematic/serializers/xsd_validation_presence_spec.rb +16 -11
- data/spec/schematic/serializers/xsd_xsd_ignore_methods_spec.rb +3 -3
- data/spec/schematic/serializers/xsd_xsd_methods_spec.rb +27 -24
- data/spec/schematic/serializers/xsd_xsd_minimum_occurrences_for_spec.rb +13 -8
- data/spec/schematic_serializers_xsd_spec.rb +70 -67
- data/spec/spec_helper.rb +8 -113
- data/spec/support/database.rb +9 -0
- data/spec/support/helpers.rb +111 -0
- data/spec/support/with_model.rb +5 -0
- data/spec/{xsd → support/xsd}/XMLSchema.xsd +0 -0
- data/spec/{xsd → support/xsd}/xml.xsd +0 -0
- metadata +54 -69
- data/.rspec +0 -1
- data/.rvmrc +0 -1
- data/README.rdoc +0 -103
- data/spec/support/extensions/active_model/validations/inclusion.rb +0 -69
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'schematic/generator/xsd'
|
3
|
+
|
1
4
|
module Schematic
|
2
5
|
module Generator
|
3
6
|
class Sandbox
|
@@ -20,7 +23,7 @@ module Schematic
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def to_xsd(options = {})
|
23
|
-
output =
|
26
|
+
output = ''
|
24
27
|
builder = Builder::XmlMarkup.new(:target => output, :indent => 2)
|
25
28
|
xsd_generator.options = options
|
26
29
|
xsd_generator.header(builder)
|
@@ -2,24 +2,25 @@ module Schematic
|
|
2
2
|
module Generator
|
3
3
|
class Types
|
4
4
|
COMPLEX = {
|
5
|
-
:integer
|
6
|
-
:float
|
7
|
-
:string
|
8
|
-
:text
|
9
|
-
:datetime => { :complex_type =>
|
10
|
-
:date
|
11
|
-
:boolean
|
12
|
-
|
5
|
+
:integer => { :complex_type => 'Integer', :xsd_type => 'xs:integer' }.freeze,
|
6
|
+
:float => { :complex_type => 'Float', :xsd_type => 'xs:float' }.freeze,
|
7
|
+
:string => { :complex_type => 'String', :xsd_type => 'xs:string' }.freeze,
|
8
|
+
:text => { :complex_type => 'Text', :xsd_type => 'xs:string' }.freeze,
|
9
|
+
:datetime => { :complex_type => 'DateTime', :xsd_type => 'xs:dateTime' }.freeze,
|
10
|
+
:date => { :complex_type => 'Date', :xsd_type => 'xs:date' }.freeze,
|
11
|
+
:boolean => { :complex_type => 'Boolean', :xsd_type => 'xs:boolean' }.freeze,
|
12
|
+
:uuid => { :complex_type => 'String', :xsd_type => 'xs:string' }.freeze,
|
13
|
+
}.freeze
|
13
14
|
|
14
15
|
def self.xsd(builder)
|
15
|
-
Types::COMPLEX.each do |
|
16
|
+
Types::COMPLEX.values.uniq.each do |value|
|
16
17
|
complex_type_name = value[:complex_type]
|
17
18
|
xsd_type = value[:xsd_type]
|
18
|
-
builder.xs :complexType,
|
19
|
+
builder.xs :complexType, 'name' => complex_type_name do |complex_type|
|
19
20
|
complex_type.xs :simpleContent do |simple_content|
|
20
|
-
simple_content.xs :extension,
|
21
|
-
extension.xs :attribute,
|
22
|
-
extension.xs :attribute,
|
21
|
+
simple_content.xs :extension, 'base' => xsd_type do |extension|
|
22
|
+
extension.xs :attribute, 'name' => 'type', 'type' => 'xs:string', 'use' => 'optional'
|
23
|
+
extension.xs :attribute, 'name' => 'nil', 'type' => 'xs:boolean', 'use' => 'optional'
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -1,18 +1,20 @@
|
|
1
|
+
require 'active_record/validations/uniqueness'
|
2
|
+
require 'schematic/generator/column_validator'
|
3
|
+
|
1
4
|
module Schematic
|
2
5
|
module Generator
|
3
6
|
class Uniqueness < ColumnValidator
|
4
|
-
|
5
7
|
def generate(builder)
|
6
8
|
for_validator ActiveRecord::Validations::UniquenessValidator do |validator|
|
7
9
|
unique_name = validator.attributes.first.to_s.dasherize
|
8
10
|
additional_fields = (Array.wrap(validator.options[:scope]) || []).map(&:to_s).map(&:dasherize)
|
9
11
|
|
10
12
|
names = Schematic::Generator::Names.new(@klass)
|
11
|
-
builder.xs :unique,
|
12
|
-
unique.xs :selector,
|
13
|
-
unique.xs :field,
|
13
|
+
builder.xs :unique, 'name' => "#{unique_name}-must-be-unique" do |unique|
|
14
|
+
unique.xs :selector, 'xpath' => "./#{names.element}"
|
15
|
+
unique.xs :field, 'xpath' => unique_name
|
14
16
|
additional_fields.each do |additional_field|
|
15
|
-
unique.xs :field,
|
17
|
+
unique.xs :field, 'xpath' => additional_field
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -20,6 +22,3 @@ module Schematic
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
@@ -1,3 +1,9 @@
|
|
1
|
+
require 'schematic/generator/column'
|
2
|
+
require 'schematic/generator/names'
|
3
|
+
require 'schematic/generator/namespaces'
|
4
|
+
require 'schematic/generator/types'
|
5
|
+
require 'schematic/generator/uniqueness'
|
6
|
+
|
1
7
|
module Schematic
|
2
8
|
module Generator
|
3
9
|
class Xsd
|
@@ -21,7 +27,7 @@ module Schematic
|
|
21
27
|
end
|
22
28
|
|
23
29
|
def schema(builder)
|
24
|
-
builder.xs :schema, ns(
|
30
|
+
builder.xs :schema, ns('xs', :w3, :schema) do |schema|
|
25
31
|
Types.xsd(schema)
|
26
32
|
element_for_klass(schema)
|
27
33
|
generate(schema, @klass)
|
@@ -29,7 +35,7 @@ module Schematic
|
|
29
35
|
end
|
30
36
|
|
31
37
|
def element_for_klass(builder)
|
32
|
-
builder.xs :element,
|
38
|
+
builder.xs :element, 'name' => @names.element_collection, 'type' => @names.collection_type do |element|
|
33
39
|
generate_uniqueness_constraints(element)
|
34
40
|
end
|
35
41
|
end
|
@@ -65,16 +71,16 @@ module Schematic
|
|
65
71
|
end
|
66
72
|
|
67
73
|
def generate_complex_type_for_collection(builder)
|
68
|
-
builder.xs :complexType,
|
74
|
+
builder.xs :complexType, 'name' => @names.collection_type do |complex_type|
|
69
75
|
complex_type.xs :sequence do |sequence|
|
70
|
-
sequence.xs :element,
|
76
|
+
sequence.xs :element, 'name' => @names.element, 'type' => @names.type, 'minOccurs' => '0', 'maxOccurs' => 'unbounded'
|
71
77
|
end
|
72
|
-
complex_type.xs :attribute,
|
78
|
+
complex_type.xs :attribute, 'name' => 'type', 'type' => 'xs:string', 'fixed' => 'array'
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
76
82
|
def generate_complex_type_for_model(builder)
|
77
|
-
builder.xs :complexType,
|
83
|
+
builder.xs :complexType, 'name' => @names.type do |complex_type|
|
78
84
|
additional_methods = @klass.schematic_sandbox.added_elements.merge(@options[:methods] || {})
|
79
85
|
ignored_methods = @klass.schematic_sandbox.ignored_elements.dup
|
80
86
|
exclude = @exclude
|
@@ -98,22 +104,22 @@ module Schematic
|
|
98
104
|
case nested_attribute.macro
|
99
105
|
when :has_many
|
100
106
|
all.xs :element,
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
107
|
+
'name' => nested_attribute_name(nested_attribute.name),
|
108
|
+
'type' => nested_attribute.klass.schematic_sandbox.xsd_generator.names.collection_type,
|
109
|
+
'minOccurs' => '0',
|
110
|
+
'maxOccurs' => '1'
|
105
111
|
when :has_one
|
106
112
|
all.xs :element,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
113
|
+
'name' => nested_attribute_name(nested_attribute.name, {:pluralized => false}),
|
114
|
+
'type' => nested_attribute.klass.schematic_sandbox.xsd_generator.names.type,
|
115
|
+
'minOccurs' => '0',
|
116
|
+
'maxOccurs' => '1'
|
111
117
|
when :belongs_to
|
112
118
|
all.xs :element,
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
119
|
+
'name' => nested_attribute_name(nested_attribute.name, {:pluralized => false}),
|
120
|
+
'type' => nested_attribute.klass.schematic_sandbox.xsd_generator.names.type,
|
121
|
+
'minOccurs' => '0',
|
122
|
+
'maxOccurs' => '1'
|
117
123
|
end
|
118
124
|
end
|
119
125
|
|
@@ -140,10 +146,10 @@ module Schematic
|
|
140
146
|
enumeration_method = "xsd_#{value}_enumeration_restrictions".to_sym
|
141
147
|
builder.xs :complexType do |complex_type|
|
142
148
|
complex_type.xs :simpleContent do |simple_content|
|
143
|
-
simple_content.xs :restriction,
|
149
|
+
simple_content.xs :restriction, 'base' => 'String' do |restriction|
|
144
150
|
if @klass.respond_to? enumeration_method
|
145
151
|
@klass.send(enumeration_method).each do |enumeration|
|
146
|
-
restriction.xs :enumeration,
|
152
|
+
restriction.xs :enumeration, 'value' => enumeration
|
147
153
|
end
|
148
154
|
end
|
149
155
|
end
|
@@ -155,18 +161,18 @@ module Schematic
|
|
155
161
|
additional_methods.each do |method_name, values|
|
156
162
|
method_xsd_name = method_name.to_s.dasherize
|
157
163
|
if values.is_a?(Array) || values.is_a?(Hash)
|
158
|
-
builder.xs :element,
|
164
|
+
builder.xs :element, 'name' => method_xsd_name, 'minOccurs' => '0', 'maxOccurs' => '1' do |element|
|
159
165
|
element.xs :complexType do |complex_type|
|
160
166
|
if values.is_a?(Array)
|
161
167
|
complex_type.xs :sequence do |nested_sequence|
|
162
168
|
if values.present?
|
163
169
|
values.each do |value|
|
164
|
-
nested_sequence.xs :element,
|
170
|
+
nested_sequence.xs :element, 'name' => value.to_s.dasherize, 'minOccurs' => '0', 'maxOccurs' => 'unbounded' do |sequence_element|
|
165
171
|
generate_inclusion_value_restrictions(sequence_element, value)
|
166
172
|
end
|
167
173
|
end
|
168
174
|
else
|
169
|
-
nested_sequence.xs :any,
|
175
|
+
nested_sequence.xs :any, 'processContents' => 'skip', 'minOccurs' => '0', 'maxOccurs' => 'unbounded'
|
170
176
|
end
|
171
177
|
end
|
172
178
|
elsif values.is_a?(Hash)
|
@@ -174,9 +180,9 @@ module Schematic
|
|
174
180
|
generate_additional_methods(nested_all, values)
|
175
181
|
end
|
176
182
|
else
|
177
|
-
raise
|
183
|
+
raise 'Additional methods must be a hash of hashes or hash of arrays'
|
178
184
|
end
|
179
|
-
complex_type.xs :attribute,
|
185
|
+
complex_type.xs :attribute, 'name' => 'type', 'type' => 'xs:string', 'fixed' => 'array', 'use' => 'optional'
|
180
186
|
end
|
181
187
|
end
|
182
188
|
else
|
@@ -203,7 +209,7 @@ module Schematic
|
|
203
209
|
def nested_attribute_name(name, options={})
|
204
210
|
pluralized = options.delete(:pluralized)
|
205
211
|
pluralized = true if pluralized.nil?
|
206
|
-
name = name.to_s.gsub(
|
212
|
+
name = name.to_s.gsub('_', '-')
|
207
213
|
name = name.pluralize if pluralized
|
208
214
|
"#{name}-attributes"
|
209
215
|
end
|
@@ -1,11 +1,12 @@
|
|
1
|
+
require 'schematic/generator/sandbox'
|
2
|
+
require 'schematic/exceptions'
|
3
|
+
|
1
4
|
module Schematic
|
2
5
|
module Serializers
|
3
6
|
module Xsd
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
raise ClassMissingAttributes unless klass.instance_methods.include?(:attributes)
|
8
|
-
end
|
7
|
+
def self.extended(klass)
|
8
|
+
raise ClassMissingXmlSerializer unless klass.ancestors.include?(ActiveModel::Serializers::Xml)
|
9
|
+
raise ClassMissingAttributes unless klass.instance_methods.include?(:attributes)
|
9
10
|
end
|
10
11
|
|
11
12
|
def schematic(&block)
|
@@ -19,7 +20,6 @@ module Schematic
|
|
19
20
|
def to_xsd(options = {})
|
20
21
|
schematic_sandbox.to_xsd(options)
|
21
22
|
end
|
22
|
-
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/schematic/version.rb
CHANGED
data/schematic.gemspec
CHANGED
@@ -1,29 +1,28 @@
|
|
1
|
-
#
|
2
|
-
$:.push File.expand_path(
|
3
|
-
require
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'schematic/version'
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'schematic'
|
7
|
+
spec.version = Schematic::VERSION
|
8
|
+
spec.authors = ['Case Commons, LLC']
|
9
|
+
spec.email = ['casecommons-dev@googlegroups.com', 'andrew@johnandrewmarshall.com']
|
10
|
+
spec.homepage = 'https://github.com/Casecommons/schematic'
|
11
|
+
spec.summary = %q{Automatic XSD generation from ActiveRecord models}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.license = 'MIT'
|
14
14
|
|
15
|
-
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
s.add_development_dependency('rspec-rails', '= 2.7')
|
20
|
-
s.add_development_dependency('with_model', '>= 0.2.4')
|
21
|
-
s.add_development_dependency('nokogiri')
|
22
|
-
s.add_development_dependency('sqlite3')
|
23
|
-
s.add_development_dependency('autotest')
|
20
|
+
spec.add_dependency 'activerecord', '~> 4.0'
|
21
|
+
spec.add_dependency 'builder'
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
spec.add_development_dependency 'nokogiri'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
26
|
+
spec.add_development_dependency 'sqlite3'
|
27
|
+
spec.add_development_dependency 'with_model', '~> 1.0'
|
29
28
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Schematic::Generator::Restrictions::
|
3
|
+
describe "Schematic::Generator::Restrictions::Custom" do
|
4
4
|
describe ".to_xsd" do
|
5
5
|
context "with a model with custom validations" do
|
6
6
|
before do
|
7
7
|
class CrazyTownValidator < ActiveModel::EachValidator
|
8
8
|
def validate_each(record, attribute, value)
|
9
|
-
record.errors.add(attribute,
|
9
|
+
record.errors.add(attribute, 'must be crazy') unless value.match /.*crazy.*|\w/
|
10
10
|
end
|
11
11
|
|
12
12
|
def xsd_pattern_restrictions
|
@@ -18,30 +18,31 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
18
18
|
subject { sanitize_xml(CustomModel.to_xsd) }
|
19
19
|
with_model :custom_model do
|
20
20
|
table :id => false do |t|
|
21
|
-
t.string
|
21
|
+
t.string 'title'
|
22
22
|
end
|
23
23
|
|
24
24
|
model do
|
25
|
+
self.primary_key = :title
|
25
26
|
validates :title, :crazy_town => true
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
it "should validate against it's own XSD" do
|
30
|
-
invalid_instance = CustomModel.new(:title =>
|
31
|
+
invalid_instance = CustomModel.new(:title => 'happy today')
|
31
32
|
xml = [invalid_instance].to_xml
|
32
|
-
|
33
|
+
expect {
|
33
34
|
validate_xml_against_xsd(xml, subject)
|
34
|
-
}.
|
35
|
-
invalid_instance = CustomModel.new(:title =>
|
35
|
+
}.to raise_error
|
36
|
+
invalid_instance = CustomModel.new(:title => 'happytoday')
|
36
37
|
xml = [invalid_instance].to_xml
|
37
|
-
|
38
|
+
expect {
|
38
39
|
validate_xml_against_xsd(xml, subject)
|
39
|
-
}.
|
40
|
-
valid_instance = CustomModel.new(:title =>
|
40
|
+
}.to raise_error
|
41
|
+
valid_instance = CustomModel.new(:title => 'iamcrazytoday')
|
41
42
|
xml = [valid_instance].to_xml
|
42
|
-
|
43
|
+
expect {
|
43
44
|
validate_xml_against_xsd(xml, subject)
|
44
|
-
}.
|
45
|
+
}.not_to raise_error
|
45
46
|
end
|
46
47
|
|
47
48
|
it "should mark that the field with the allowed values" do
|
@@ -60,12 +61,8 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
60
61
|
XML
|
61
62
|
end
|
62
63
|
|
63
|
-
subject.
|
64
|
+
expect(subject).to eq(xsd)
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require
|
2
|
-
require "support/extensions/active_model/validations/inclusion"
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
|
-
describe Schematic::Generator::Restrictions::Enumeration do
|
3
|
+
describe "Schematic::Generator::Restrictions::Enumeration" do
|
5
4
|
describe ".to_xsd" do
|
6
5
|
context "with a model with inclusion validations" do
|
7
6
|
subject { sanitize_xml(EnumerationModel.to_xsd) }
|
8
7
|
with_model :enumeration_model do
|
9
8
|
table :id => false do |t|
|
10
|
-
t.string
|
11
|
-
t.string
|
12
|
-
t.string
|
13
|
-
t.string
|
14
|
-
t.boolean
|
15
|
-
t.string
|
16
|
-
t.string
|
17
|
-
t.integer
|
18
|
-
t.integer
|
19
|
-
t.integer
|
9
|
+
t.string 'title'
|
10
|
+
t.string 'should_be_skipped'
|
11
|
+
t.string 'should_also_be_skipped'
|
12
|
+
t.string 'and_also_be_skipped'
|
13
|
+
t.boolean 'active'
|
14
|
+
t.string 'options'
|
15
|
+
t.string 'more_options'
|
16
|
+
t.integer 'force_enumeration'
|
17
|
+
t.integer 'skip_enumeration'
|
18
|
+
t.integer 'skip_inclusion_set_lambda'
|
20
19
|
end
|
21
20
|
|
22
21
|
model do
|
23
|
-
|
24
|
-
validates :
|
25
|
-
validates :
|
26
|
-
validates :
|
22
|
+
self.primary_key = :title
|
23
|
+
validates :title, :inclusion => { :in => ['a', 'b', 'c'] }
|
24
|
+
validates :should_be_skipped, :inclusion => ['a', 'b', 'c'], :if => lambda { false }
|
25
|
+
validates :should_also_be_skipped, :inclusion => ['a', 'b', 'c'], :unless => lambda { false }
|
26
|
+
validates :and_also_be_skipped, :inclusion => ['a', 'b', 'c'], :if => lambda { true}, :unless => lambda { false }
|
27
27
|
validates :active, :inclusion => { :in => [true, false] }
|
28
|
-
validates :options, :inclusion => { :in => lambda { |f| [
|
29
|
-
validates :more_options, :inclusion => { :in => lambda { |f| f.title ==
|
28
|
+
validates :options, :inclusion => { :in => lambda { |f| ['some valid attribute'] } }
|
29
|
+
validates :more_options, :inclusion => { :in => lambda { |f| f.title == 'something' ? ['test'] : ['something else'] } }
|
30
30
|
validates :force_enumeration, :inclusion => { :in => [1, 2], :xsd => { :include => true} }, :if => lambda { false }
|
31
31
|
validates :skip_enumeration, :inclusion => { :in => [1, 2], :xsd => { :include => false} }, :if => lambda { true }
|
32
32
|
validates :skip_inclusion_set_lambda, :inclusion => { :in => lambda { |x| [1, 2] } }, :if => :some_method
|
@@ -38,25 +38,25 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should validate against it's own XSD" do
|
41
|
-
invalid_instance = EnumerationModel.new(:title =>
|
41
|
+
invalid_instance = EnumerationModel.new(:title => 'd')
|
42
42
|
xml = [invalid_instance].to_xml
|
43
|
-
|
43
|
+
expect {
|
44
44
|
validate_xml_against_xsd(xml, subject)
|
45
|
-
}.
|
46
|
-
valid_instance = EnumerationModel.new(:title =>
|
47
|
-
:should_be_skipped =>
|
48
|
-
:should_also_be_skipped =>
|
49
|
-
:and_also_be_skipped =>
|
45
|
+
}.to raise_error
|
46
|
+
valid_instance = EnumerationModel.new(:title => 'a',
|
47
|
+
:should_be_skipped => 'a',
|
48
|
+
:should_also_be_skipped => 'a',
|
49
|
+
:and_also_be_skipped => 'a',
|
50
50
|
:active => true,
|
51
|
-
:options =>
|
52
|
-
:more_options =>
|
51
|
+
:options => 'some valid attribute',
|
52
|
+
:more_options => 'something else',
|
53
53
|
:force_enumeration => 2,
|
54
54
|
:skip_enumeration => 2,
|
55
55
|
:skip_inclusion_set_lambda => 2)
|
56
56
|
xml = [valid_instance].to_xml
|
57
|
-
|
57
|
+
expect {
|
58
58
|
validate_xml_against_xsd(xml, subject)
|
59
|
-
}.
|
59
|
+
}.not_to raise_error
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should mark that the field with the allowed values" do
|
@@ -151,7 +151,7 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
151
151
|
XML
|
152
152
|
end
|
153
153
|
|
154
|
-
subject.
|
154
|
+
expect(subject).to eq(xsd)
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|