schematic 0.6.2 → 0.7.0
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.
- 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,30 +1,31 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Schematic::Generator::Restrictions::Length do
|
3
|
+
describe "Schematic::Generator::Restrictions::Length" do
|
4
4
|
describe ".to_xsd" do
|
5
5
|
context "with a model with range length validations" do
|
6
6
|
subject { sanitize_xml(LengthModelRange.to_xsd) }
|
7
7
|
with_model :length_model_range do
|
8
8
|
table :id => false do |t|
|
9
|
-
t.string
|
9
|
+
t.string 'title'
|
10
10
|
end
|
11
11
|
|
12
12
|
model do
|
13
|
+
self.primary_key = :title
|
13
14
|
validates :title, :length => { :within => 10..20 }
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should validate against it's own XSD" do
|
18
|
-
invalid_instance = LengthModelRange.new(:title =>
|
19
|
+
invalid_instance = LengthModelRange.new(:title => 'A' * 9)
|
19
20
|
xml = [invalid_instance].to_xml
|
20
|
-
|
21
|
+
expect {
|
21
22
|
validate_xml_against_xsd(xml, subject)
|
22
|
-
}.
|
23
|
-
invalid_instance = LengthModelRange.new(:title =>
|
23
|
+
}.to raise_error
|
24
|
+
invalid_instance = LengthModelRange.new(:title => 'A' * 21)
|
24
25
|
xml = [invalid_instance].to_xml
|
25
|
-
|
26
|
+
expect {
|
26
27
|
validate_xml_against_xsd(xml, subject)
|
27
|
-
}.
|
28
|
+
}.to raise_error
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
@@ -36,21 +37,22 @@ describe Schematic::Generator::Restrictions::Length do
|
|
36
37
|
end
|
37
38
|
|
38
39
|
model do
|
40
|
+
self.primary_key = :title
|
39
41
|
validates :title, :length => { :in => 10..20 }
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
it "should validate against it's own XSD" do
|
44
|
-
invalid_instance = LengthModelRange.new(:title =>
|
46
|
+
invalid_instance = LengthModelRange.new(:title => 'A' * 9)
|
45
47
|
xml = [invalid_instance].to_xml
|
46
|
-
|
48
|
+
expect {
|
47
49
|
validate_xml_against_xsd(xml, subject)
|
48
|
-
}.
|
49
|
-
invalid_instance = LengthModelRange.new(:title =>
|
50
|
+
}.to raise_error
|
51
|
+
invalid_instance = LengthModelRange.new(:title => 'A' * 21)
|
50
52
|
xml = [invalid_instance].to_xml
|
51
|
-
|
53
|
+
expect {
|
52
54
|
validate_xml_against_xsd(xml, subject)
|
53
|
-
}.
|
55
|
+
}.to raise_error
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
@@ -58,20 +60,21 @@ describe Schematic::Generator::Restrictions::Length do
|
|
58
60
|
subject { sanitize_xml(LengthModelMinimum.to_xsd) }
|
59
61
|
with_model :length_model_minimum do
|
60
62
|
table :id => false do |t|
|
61
|
-
t.string
|
63
|
+
t.string 'title'
|
62
64
|
end
|
63
65
|
|
64
66
|
model do
|
67
|
+
self.primary_key = :title
|
65
68
|
validates :title, :length => { :minimum => 10 }
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
69
72
|
it "should validate against it's own XSD" do
|
70
|
-
invalid_instance = LengthModelMinimum.new(:title =>
|
73
|
+
invalid_instance = LengthModelMinimum.new(:title => 'A' * 9)
|
71
74
|
xml = [invalid_instance].to_xml
|
72
|
-
|
75
|
+
expect {
|
73
76
|
validate_xml_against_xsd(xml, subject)
|
74
|
-
}.
|
77
|
+
}.to raise_error
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
@@ -80,20 +83,21 @@ describe Schematic::Generator::Restrictions::Length do
|
|
80
83
|
context "when allow blank is true" do
|
81
84
|
with_model :length_model_one do
|
82
85
|
table :id => false do |t|
|
83
|
-
t.string
|
86
|
+
t.string 'title'
|
84
87
|
end
|
85
88
|
|
86
89
|
model do
|
90
|
+
self.primary_key = :title
|
87
91
|
validates :title, :length => { :maximum => 100 }, :allow_blank => true
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
91
95
|
it "should validate against it's own XSD" do
|
92
|
-
invalid_instance = LengthModelOne.new(:title =>
|
96
|
+
invalid_instance = LengthModelOne.new(:title => 'A' * 201)
|
93
97
|
xml = [invalid_instance].to_xml
|
94
|
-
|
98
|
+
expect {
|
95
99
|
validate_xml_against_xsd(xml, subject)
|
96
|
-
}.
|
100
|
+
}.to raise_error
|
97
101
|
end
|
98
102
|
|
99
103
|
it "should mark that the field minimum occurrences is 0 but still list the length" do
|
@@ -111,7 +115,7 @@ describe Schematic::Generator::Restrictions::Length do
|
|
111
115
|
XML
|
112
116
|
end
|
113
117
|
|
114
|
-
subject.
|
118
|
+
expect(subject).to eq(xsd)
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
@@ -119,11 +123,12 @@ describe Schematic::Generator::Restrictions::Length do
|
|
119
123
|
subject { sanitize_xml(LengthModelTwo.to_xsd) }
|
120
124
|
with_model :length_model_two do
|
121
125
|
table :id => false do |t|
|
122
|
-
t.string
|
126
|
+
t.string 'title'
|
123
127
|
end
|
124
128
|
|
125
129
|
model do
|
126
|
-
|
130
|
+
self.primary_key = :title
|
131
|
+
validates :title, :length => { :maximum => 100 }
|
127
132
|
end
|
128
133
|
end
|
129
134
|
|
@@ -142,7 +147,7 @@ describe Schematic::Generator::Restrictions::Length do
|
|
142
147
|
XML
|
143
148
|
end
|
144
149
|
|
145
|
-
subject.
|
150
|
+
expect(subject).to eq(xsd)
|
146
151
|
end
|
147
152
|
end
|
148
153
|
|
@@ -150,10 +155,11 @@ describe Schematic::Generator::Restrictions::Length do
|
|
150
155
|
subject { sanitize_xml(LengthModelThree.to_xsd) }
|
151
156
|
with_model :length_model_three do
|
152
157
|
table :id => false do |t|
|
153
|
-
t.string
|
158
|
+
t.string 'title'
|
154
159
|
end
|
155
160
|
|
156
161
|
model do
|
162
|
+
self.primary_key = :title
|
157
163
|
validates :title, :length => { :maximum => 100 }, :if => lambda { |model| false }
|
158
164
|
end
|
159
165
|
end
|
@@ -172,10 +178,9 @@ describe Schematic::Generator::Restrictions::Length do
|
|
172
178
|
XML
|
173
179
|
end
|
174
180
|
|
175
|
-
subject.
|
181
|
+
expect(subject).to eq(xsd)
|
176
182
|
end
|
177
183
|
end
|
178
184
|
end
|
179
185
|
end
|
180
186
|
end
|
181
|
-
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Schematic::Generator::Restrictions::Mixin" do
|
4
4
|
describe ".to_xsd" do
|
@@ -7,7 +7,7 @@ describe "Schematic::Generator::Restrictions::Mixin" do
|
|
7
7
|
class MixedInRestriction < Schematic::Generator::Restrictions::Base
|
8
8
|
def generate(builder)
|
9
9
|
for_validator ActiveModel::BlockValidator do |validator|
|
10
|
-
builder.xs(:enumeration,
|
10
|
+
builder.xs(:enumeration, 'value' => 'cheese')
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -16,26 +16,27 @@ describe "Schematic::Generator::Restrictions::Mixin" do
|
|
16
16
|
subject { sanitize_xml(TestModel.to_xsd) }
|
17
17
|
with_model :test_model do
|
18
18
|
table :id => false do |t|
|
19
|
-
t.string
|
19
|
+
t.string 'title'
|
20
20
|
end
|
21
21
|
|
22
22
|
model do
|
23
|
+
self.primary_key = :title
|
23
24
|
validates_each :title do |object, attr, value|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should validate against it's own XSD" do
|
29
|
-
invalid_instance = TestModel.new(:title =>
|
30
|
+
invalid_instance = TestModel.new(:title => 'cake')
|
30
31
|
xml = [invalid_instance].to_xml
|
31
|
-
|
32
|
+
expect {
|
32
33
|
validate_xml_against_xsd(xml, subject)
|
33
|
-
}.
|
34
|
-
valid_instance = TestModel.new(:title =>
|
34
|
+
}.to raise_error
|
35
|
+
valid_instance = TestModel.new(:title => 'cheese')
|
35
36
|
xml = [valid_instance].to_xml
|
36
|
-
|
37
|
+
expect {
|
37
38
|
validate_xml_against_xsd(xml, subject)
|
38
|
-
}.
|
39
|
+
}.not_to raise_error
|
39
40
|
end
|
40
41
|
|
41
42
|
it "should mark that the field with the allowed values" do
|
@@ -53,13 +54,8 @@ describe "Schematic::Generator::Restrictions::Mixin" do
|
|
53
54
|
XML
|
54
55
|
end
|
55
56
|
|
56
|
-
subject.
|
57
|
+
expect(subject).to eq(xsd)
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
@@ -1,30 +1,31 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Schematic::Generator::Restrictions::Numericality do
|
3
|
+
describe "Schematic::Generator::Restrictions::Numericality" do
|
4
4
|
describe ".to_xsd" do
|
5
5
|
context "with a model with numericality validations" do
|
6
6
|
subject { sanitize_xml(TestModel.to_xsd) }
|
7
7
|
with_model :test_model do
|
8
8
|
table :id => false do |t|
|
9
|
-
t.string
|
9
|
+
t.string 'some_field'
|
10
10
|
end
|
11
11
|
|
12
12
|
model do
|
13
|
+
self.primary_key = :some_field
|
13
14
|
validates :some_field, :numericality => true
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should validate against it's own XSD" do
|
18
|
-
invalid_instance = TestModel.new(:some_field =>
|
19
|
+
invalid_instance = TestModel.new(:some_field => '1a2')
|
19
20
|
xml = [invalid_instance].to_xml
|
20
|
-
|
21
|
+
expect {
|
21
22
|
validate_xml_against_xsd(xml, subject)
|
22
|
-
}.
|
23
|
-
valid_instance = TestModel.new(:some_field =>
|
23
|
+
}.to raise_error
|
24
|
+
valid_instance = TestModel.new(:some_field => '123')
|
24
25
|
xml = [valid_instance].to_xml
|
25
|
-
|
26
|
+
expect {
|
26
27
|
validate_xml_against_xsd(xml, subject)
|
27
|
-
}.
|
28
|
+
}.not_to raise_error
|
28
29
|
end
|
29
30
|
|
30
31
|
it "should mark that the field with the allowed values" do
|
@@ -42,9 +43,8 @@ describe Schematic::Generator::Restrictions::Numericality do
|
|
42
43
|
XML
|
43
44
|
end
|
44
45
|
|
45
|
-
subject.
|
46
|
+
expect(subject).to eq(xsd)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
|
-
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Schematic::Generator::Restrictions::Pattern do
|
3
|
+
describe "Schematic::Generator::Restrictions::Pattern" do
|
4
4
|
describe ".to_xsd" do
|
5
5
|
context "with a model with format validations" do
|
6
6
|
subject { sanitize_xml(PatternModel.to_xsd) }
|
@@ -10,21 +10,22 @@ describe Schematic::Generator::Restrictions::Pattern do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
model do
|
13
|
+
self.primary_key = :title
|
13
14
|
validates :title, :format => { :with => /[a-z]#[0-9]/ }
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should validate against it's own XSD" do
|
18
|
-
invalid_instance = PatternModel.new(:title =>
|
19
|
+
invalid_instance = PatternModel.new(:title => '1-2')
|
19
20
|
xml = [invalid_instance].to_xml
|
20
|
-
|
21
|
+
expect {
|
21
22
|
validate_xml_against_xsd(xml, subject)
|
22
|
-
}.
|
23
|
-
valid_instance = PatternModel.new(:title =>
|
23
|
+
}.to raise_error
|
24
|
+
valid_instance = PatternModel.new(:title => 'a#5')
|
24
25
|
xml = [valid_instance].to_xml
|
25
|
-
|
26
|
+
expect {
|
26
27
|
validate_xml_against_xsd(xml, subject)
|
27
|
-
}.
|
28
|
+
}.not_to raise_error
|
28
29
|
end
|
29
30
|
|
30
31
|
it "should mark that the field with the allowed values" do
|
@@ -42,7 +43,7 @@ describe Schematic::Generator::Restrictions::Pattern do
|
|
42
43
|
XML
|
43
44
|
end
|
44
45
|
|
45
|
-
subject.
|
46
|
+
expect(subject).to eq(xsd)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -55,31 +56,29 @@ describe Schematic::Generator::Restrictions::Pattern do
|
|
55
56
|
end
|
56
57
|
|
57
58
|
model do
|
59
|
+
self.primary_key = :email
|
58
60
|
validates :email, :format => { :with => /\A([\w\.%\+\-`']+)@([\w\-]+\.)+([\w]{2,})\Z/ }
|
59
61
|
validates :money, :format => { :with => /\$?[,0-9]+(?:\.\d+)?/ }
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
65
|
it "should validate against it's own XSD" do
|
64
|
-
invalid_instance = PatternModel.new(:email =>
|
66
|
+
invalid_instance = PatternModel.new(:email => '@blah')
|
65
67
|
xml = [invalid_instance].to_xml
|
66
|
-
|
68
|
+
expect {
|
67
69
|
validate_xml_against_xsd(xml, subject)
|
68
|
-
}.
|
69
|
-
invalid_instance = PatternModel.new(:money =>
|
70
|
+
}.to raise_error
|
71
|
+
invalid_instance = PatternModel.new(:money => 'whatever')
|
70
72
|
xml = [invalid_instance].to_xml
|
71
|
-
|
73
|
+
expect {
|
72
74
|
validate_xml_against_xsd(xml, subject)
|
73
|
-
}.
|
74
|
-
valid_instance = PatternModel.new(:email =>
|
75
|
+
}.to raise_error
|
76
|
+
valid_instance = PatternModel.new(:email => 'foo@bar.com', :money => '$99.95')
|
75
77
|
xml = [valid_instance].to_xml
|
76
|
-
|
78
|
+
expect {
|
77
79
|
validate_xml_against_xsd(xml, subject)
|
78
|
-
}.
|
80
|
+
}.not_to raise_error
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Schematic::Generator::Sandbox do
|
4
4
|
subject { Schematic::Generator::Sandbox.new(klass) }
|
@@ -10,15 +10,15 @@ describe Schematic::Generator::Sandbox do
|
|
10
10
|
subject.run do
|
11
11
|
ignore :foo
|
12
12
|
end
|
13
|
-
subject.ignored_elements.
|
13
|
+
expect(subject.ignored_elements).to include(:foo)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "accepts multiple fields" do
|
17
17
|
subject.run do
|
18
18
|
ignore :foo, :bar
|
19
19
|
end
|
20
|
-
subject.ignored_elements.
|
21
|
-
subject.ignored_elements.
|
20
|
+
expect(subject.ignored_elements).to include(:foo)
|
21
|
+
expect(subject.ignored_elements).to include(:bar)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,7 +27,7 @@ describe Schematic::Generator::Sandbox do
|
|
27
27
|
subject.run do
|
28
28
|
ignore :foo => [:bar]
|
29
29
|
end
|
30
|
-
subject.ignored_elements[:foo].
|
30
|
+
expect(subject.ignored_elements[:foo]).to eq([:bar])
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -38,7 +38,7 @@ describe Schematic::Generator::Sandbox do
|
|
38
38
|
subject.run do
|
39
39
|
add :foo
|
40
40
|
end
|
41
|
-
subject.added_elements.keys.
|
41
|
+
expect(subject.added_elements.keys).to include(:foo)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -47,7 +47,7 @@ describe Schematic::Generator::Sandbox do
|
|
47
47
|
subject.run do
|
48
48
|
add :foo => { :bar => nil }
|
49
49
|
end
|
50
|
-
subject.added_elements[:foo].
|
50
|
+
expect(subject.added_elements[:foo]).to eq({ :bar => nil })
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -56,7 +56,7 @@ describe Schematic::Generator::Sandbox do
|
|
56
56
|
subject.run do
|
57
57
|
add :foo => [:bar]
|
58
58
|
end
|
59
|
-
subject.added_elements[:foo].
|
59
|
+
expect(subject.added_elements[:foo]).to eq([:bar])
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -66,15 +66,15 @@ describe Schematic::Generator::Sandbox do
|
|
66
66
|
subject.run do
|
67
67
|
required :foo
|
68
68
|
end
|
69
|
-
subject.required_elements.
|
69
|
+
expect(subject.required_elements).to include(:foo)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "accepts multiple fields" do
|
73
73
|
subject.run do
|
74
74
|
required :foo, :bar
|
75
75
|
end
|
76
|
-
subject.required_elements.
|
77
|
-
subject.required_elements.
|
76
|
+
expect(subject.required_elements).to include(:foo)
|
77
|
+
expect(subject.required_elements).to include(:bar)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -83,26 +83,26 @@ describe Schematic::Generator::Sandbox do
|
|
83
83
|
subject.run do
|
84
84
|
not_required :foo
|
85
85
|
end
|
86
|
-
subject.non_required_elements.
|
86
|
+
expect(subject.non_required_elements).to include(:foo)
|
87
87
|
end
|
88
88
|
|
89
89
|
it "accepts multiple fields" do
|
90
90
|
subject.run do
|
91
91
|
not_required :foo, :bar
|
92
92
|
end
|
93
|
-
subject.non_required_elements.
|
94
|
-
subject.non_required_elements.
|
93
|
+
expect(subject.non_required_elements).to include(:foo)
|
94
|
+
expect(subject.non_required_elements).to include(:bar)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
describe "setting the root" do
|
99
99
|
it "should change the root element name" do
|
100
100
|
subject.run do
|
101
|
-
root
|
101
|
+
root 'my_new_root'
|
102
102
|
end
|
103
103
|
|
104
|
-
subject.xsd_generator.names.element.
|
105
|
-
subject.xsd_generator.names.element_collection.
|
104
|
+
expect(subject.xsd_generator.names.element).to eq('my-new-root')
|
105
|
+
expect(subject.xsd_generator.names.element_collection).to eq('my-new-roots')
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|