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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -8
  3. data/.travis.yml +17 -0
  4. data/Gemfile +6 -1
  5. data/LICENSE +1 -1
  6. data/README.md +106 -0
  7. data/Rakefile +3 -8
  8. data/lib/schematic.rb +3 -42
  9. data/lib/schematic/exceptions.rb +13 -0
  10. data/lib/schematic/generator/column.rb +17 -11
  11. data/lib/schematic/generator/namespaces.rb +3 -3
  12. data/lib/schematic/generator/restrictions/base.rb +5 -5
  13. data/lib/schematic/generator/restrictions/custom.rb +3 -2
  14. data/lib/schematic/generator/restrictions/enumeration.rb +5 -2
  15. data/lib/schematic/generator/restrictions/length.rb +4 -2
  16. data/lib/schematic/generator/restrictions/numericality.rb +3 -1
  17. data/lib/schematic/generator/restrictions/pattern.rb +4 -3
  18. data/lib/schematic/generator/sandbox.rb +4 -1
  19. data/lib/schematic/generator/types.rb +14 -13
  20. data/lib/schematic/generator/uniqueness.rb +7 -8
  21. data/lib/schematic/generator/xsd.rb +32 -26
  22. data/lib/schematic/serializers/xsd.rb +6 -6
  23. data/lib/schematic/version.rb +1 -1
  24. data/schematic.gemspec +23 -24
  25. data/spec/schematic/generator/restrictions/custom_spec.rb +15 -18
  26. data/spec/schematic/generator/restrictions/enumeration_spec.rb +31 -31
  27. data/spec/schematic/generator/restrictions/length_spec.rb +35 -30
  28. data/spec/schematic/generator/restrictions/mixin_spec.rb +11 -15
  29. data/spec/schematic/generator/restrictions/numericality_spec.rb +11 -11
  30. data/spec/schematic/generator/restrictions/pattern_spec.rb +20 -21
  31. data/spec/schematic/generator/sandbox_spec.rb +17 -17
  32. data/spec/schematic/generator/uniqueness_spec.rb +38 -37
  33. data/spec/schematic/serializers/xsd_extend_spec.rb +11 -11
  34. data/spec/schematic/serializers/xsd_validation_presence_spec.rb +16 -11
  35. data/spec/schematic/serializers/xsd_xsd_ignore_methods_spec.rb +3 -3
  36. data/spec/schematic/serializers/xsd_xsd_methods_spec.rb +27 -24
  37. data/spec/schematic/serializers/xsd_xsd_minimum_occurrences_for_spec.rb +13 -8
  38. data/spec/schematic_serializers_xsd_spec.rb +70 -67
  39. data/spec/spec_helper.rb +8 -113
  40. data/spec/support/database.rb +9 -0
  41. data/spec/support/helpers.rb +111 -0
  42. data/spec/support/with_model.rb +5 -0
  43. data/spec/{xsd → support/xsd}/XMLSchema.xsd +0 -0
  44. data/spec/{xsd → support/xsd}/xml.xsd +0 -0
  45. metadata +54 -69
  46. data/.rspec +0 -1
  47. data/.rvmrc +0 -1
  48. data/README.rdoc +0 -103
  49. data/spec/support/extensions/active_model/validations/inclusion.rb +0 -69
@@ -1,31 +1,32 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe Schematic::Generator::Uniqueness do
3
+ describe "Schematic::Generator::Uniqueness" do
4
4
  describe ".to_xsd" do
5
5
  context "with a model with a uniqueness validation" 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 "some_field"
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, :uniqueness => true
14
15
  end
15
16
  end
16
17
 
17
18
  it "should validate against it's own XSD" do
18
- first_instance = TestModel.new(:some_field => "first")
19
- another_instance = TestModel.new(:some_field => "second")
20
- duplicate_instance = TestModel.new(:some_field => "first")
19
+ first_instance = TestModel.new(:some_field => 'first')
20
+ another_instance = TestModel.new(:some_field => 'second')
21
+ duplicate_instance = TestModel.new(:some_field => 'first')
21
22
  xml = [first_instance, duplicate_instance, another_instance].to_xml
22
- lambda {
23
+ expect {
23
24
  validate_xml_against_xsd(xml, subject)
24
- }.should raise_error
25
+ }.to raise_error
25
26
  xml = [first_instance, another_instance].to_xml
26
- lambda {
27
+ expect {
27
28
  validate_xml_against_xsd(xml, subject)
28
- }.should_not raise_error
29
+ }.not_to raise_error
29
30
  end
30
31
 
31
32
  it "should mark that the field with the allowed values" do
@@ -48,7 +49,7 @@ describe Schematic::Generator::Uniqueness do
48
49
  XML
49
50
  end
50
51
 
51
- subject.should == xsd
52
+ expect(subject).to eq(xsd)
52
53
  end
53
54
  end
54
55
 
@@ -57,28 +58,29 @@ describe Schematic::Generator::Uniqueness do
57
58
 
58
59
  shared_examples_for "single field in scope" do
59
60
  it "should validate against it's own XSD" do
60
- first_instance = TestModel.new(:some_field => "first", :other_field => "unique")
61
- another_instance = TestModel.new(:some_field => "first", :other_field => "alsounique")
62
- duplicate_instance = TestModel.new(:some_field => "first", :other_field => "unique")
61
+ first_instance = TestModel.new(:some_field => 'first', :other_field => 'unique')
62
+ another_instance = TestModel.new(:some_field => 'first', :other_field => 'alsounique')
63
+ duplicate_instance = TestModel.new(:some_field => 'first', :other_field => 'unique')
63
64
  xml = [first_instance, duplicate_instance, another_instance].to_xml
64
- lambda {
65
+ expect {
65
66
  validate_xml_against_xsd(xml, subject)
66
- }.should raise_error
67
+ }.to raise_error
67
68
  xml = [first_instance, another_instance].to_xml
68
- lambda {
69
+ expect {
69
70
  validate_xml_against_xsd(xml, subject)
70
- }.should_not raise_error
71
+ }.not_to raise_error
71
72
  end
72
73
  end
73
74
 
74
75
  context "when the scope is a symbol" do
75
76
  with_model :test_model do
76
77
  table :id => false do |t|
77
- t.string "some_field"
78
- t.string "other_field"
78
+ t.string 'some_field'
79
+ t.string 'other_field'
79
80
  end
80
81
 
81
82
  model do
83
+ self.primary_key = :some_field
82
84
  validates :some_field, :uniqueness => { :scope => :other_field }
83
85
  end
84
86
  end
@@ -89,11 +91,12 @@ describe Schematic::Generator::Uniqueness do
89
91
  context "when the scope is an array" do
90
92
  with_model :test_model do
91
93
  table :id => false do |t|
92
- t.string "some_field"
93
- t.string "other_field"
94
+ t.string 'some_field'
95
+ t.string 'other_field'
94
96
  end
95
97
 
96
98
  model do
99
+ self.primary_key = :some_field
97
100
  validates :some_field, :uniqueness => { :scope => [:other_field] }
98
101
  end
99
102
  end
@@ -106,40 +109,38 @@ describe Schematic::Generator::Uniqueness do
106
109
  subject { sanitize_xml(TestModel.to_xsd) }
107
110
  with_model :test_model do
108
111
  table :id => false do |t|
109
- t.string "some_field"
110
- t.string "other_field"
112
+ t.string 'some_field'
113
+ t.string 'other_field'
111
114
  end
112
115
 
113
116
  model do
117
+ self.primary_key = :some_field
114
118
  validates :some_field, :uniqueness => true
115
119
  validates :other_field, :uniqueness => true
116
120
  end
117
121
  end
118
122
 
119
123
  it "should validate against it's own XSD" do
120
- first_instance = TestModel.new(:some_field => "first", :other_field => "unique")
121
- another_instance = TestModel.new(:some_field => "another", :other_field => "alsounique")
122
- duplicate_instance = TestModel.new(:some_field => "first", :other_field => "duplicate")
123
- other_duplicate_instance = TestModel.new(:some_field => "fourth", :other_field => "unique")
124
+ first_instance = TestModel.new(:some_field => 'first', :other_field => 'unique')
125
+ another_instance = TestModel.new(:some_field => 'another', :other_field => 'alsounique')
126
+ duplicate_instance = TestModel.new(:some_field => 'first', :other_field => 'duplicate')
127
+ other_duplicate_instance = TestModel.new(:some_field => 'fourth', :other_field => 'unique')
124
128
 
125
129
  xml = [first_instance, duplicate_instance, another_instance].to_xml
126
- lambda {
130
+ expect {
127
131
  validate_xml_against_xsd(xml, subject)
128
- }.should raise_error
132
+ }.to raise_error
129
133
 
130
134
  xml = [first_instance, other_duplicate_instance, another_instance].to_xml
131
- lambda {
135
+ expect {
132
136
  validate_xml_against_xsd(xml, subject)
133
- }.should raise_error
137
+ }.to raise_error
134
138
 
135
139
  xml = [first_instance, another_instance].to_xml
136
- lambda {
140
+ expect {
137
141
  validate_xml_against_xsd(xml, subject)
138
- }.should_not raise_error
142
+ }.not_to raise_error
139
143
  end
140
144
  end
141
-
142
145
  end
143
146
  end
144
-
145
-
@@ -1,8 +1,8 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Schematic::Serializers::Xsd do
4
- with_model :empty_model do
5
- end
4
+ with_model :empty_model
5
+
6
6
  before do
7
7
  class EmptyClass
8
8
  include ActiveModel::Serializers::Xml
@@ -14,11 +14,11 @@ describe Schematic::Serializers::Xsd do
14
14
  subject { EmptyModel }
15
15
 
16
16
  it "should allow the model to be extended" do
17
- lambda {
17
+ expect {
18
18
  subject.class_eval do
19
19
  extend Schematic::Serializers::Xsd
20
20
  end
21
- }.should_not raise_error
21
+ }.not_to raise_error
22
22
  end
23
23
  end
24
24
 
@@ -26,11 +26,11 @@ describe Schematic::Serializers::Xsd do
26
26
  subject { EmptyClass }
27
27
 
28
28
  it "should raise an exception" do
29
- lambda {
29
+ expect {
30
30
  subject.class_eval do
31
31
  extend Schematic::Serializers::Xsd
32
32
  end
33
- }.should raise_error(Schematic::ClassMissingAttributes)
33
+ }.to raise_error(Schematic::ClassMissingAttributes)
34
34
  end
35
35
 
36
36
  context "and it implements #attributes" do
@@ -42,11 +42,11 @@ describe Schematic::Serializers::Xsd do
42
42
  end
43
43
  end
44
44
  it "should allow the model to be extended" do
45
- lambda {
45
+ expect {
46
46
  subject.class_eval do
47
47
  extend Schematic::Serializers::Xsd
48
48
  end
49
- }.should_not raise_error
49
+ }.not_to raise_error
50
50
  end
51
51
  end
52
52
  end
@@ -55,11 +55,11 @@ describe Schematic::Serializers::Xsd do
55
55
  subject { Object }
56
56
 
57
57
  it "should raise an exception" do
58
- lambda {
58
+ expect {
59
59
  subject.class_eval do
60
60
  extend Schematic::Serializers::Xsd
61
61
  end
62
- }.should raise_error(Schematic::ClassMissingXmlSerializer)
62
+ }.to raise_error(Schematic::ClassMissingXmlSerializer)
63
63
  end
64
64
  end
65
65
  end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Schematic::Serializers::Xsd do
4
4
  describe ".to_xsd" do
@@ -7,10 +7,11 @@ describe Schematic::Serializers::Xsd do
7
7
  context "when allow blank is true" do
8
8
  with_model :some_model do
9
9
  table :id => false do |t|
10
- t.string "title"
10
+ t.string 'title'
11
11
  end
12
12
 
13
13
  model do
14
+ self.primary_key = :title
14
15
  validate :title, :presence => true, :allow_blank => true
15
16
  end
16
17
  end
@@ -29,17 +30,18 @@ describe Schematic::Serializers::Xsd do
29
30
  XML
30
31
  end
31
32
 
32
- subject.should == xsd
33
+ expect(subject).to eq(xsd)
33
34
  end
34
35
  end
35
36
 
36
37
  context "when allow blank is false" do
37
38
  with_model :some_model do
38
39
  table :id => false do |t|
39
- t.string "title"
40
+ t.string 'title'
40
41
  end
41
42
 
42
43
  model do
44
+ self.primary_key = :title
43
45
  validates :title, :presence => true
44
46
  end
45
47
  end
@@ -58,18 +60,19 @@ describe Schematic::Serializers::Xsd do
58
60
  XML
59
61
  end
60
62
 
61
- subject.should == xsd
63
+ expect(subject).to eq(xsd)
62
64
  end
63
65
  end
64
66
 
65
67
  context "when there is a condition" do
66
68
  with_model :some_model do
67
69
  table :id => false do |t|
68
- t.string "title"
69
- t.string "description"
70
+ t.string 'title'
71
+ t.string 'description'
70
72
  end
71
73
 
72
74
  model do
75
+ self.primary_key = :title
73
76
  validates :title, :presence => true, :if => lambda { |model| false }
74
77
  validates :description, :presence => true, :unless => lambda { |model| true }
75
78
  end
@@ -97,7 +100,7 @@ describe Schematic::Serializers::Xsd do
97
100
  XML
98
101
  end
99
102
 
100
- subject.should == xsd
103
+ expect(subject).to eq(xsd)
101
104
  end
102
105
  end
103
106
  end
@@ -107,10 +110,11 @@ describe Schematic::Serializers::Xsd do
107
110
  context "when allow blank is true" do
108
111
  with_model :some_model do
109
112
  table :id => false do |t|
110
- t.boolean "current"
113
+ t.boolean 'current'
111
114
  end
112
115
 
113
116
  model do
117
+ self.primary_key = :current
114
118
  schematic do
115
119
  required :current
116
120
  end
@@ -131,7 +135,7 @@ describe Schematic::Serializers::Xsd do
131
135
  XML
132
136
  end
133
137
 
134
- subject.should == xsd
138
+ expect(subject).to eq(xsd)
135
139
  end
136
140
  end
137
141
  end
@@ -145,6 +149,7 @@ describe Schematic::Serializers::Xsd do
145
149
  end
146
150
 
147
151
  model do
152
+ self.primary_key = :some_field
148
153
  validates_presence_of :some_field
149
154
 
150
155
  schematic do
@@ -167,7 +172,7 @@ describe Schematic::Serializers::Xsd do
167
172
  XML
168
173
  end
169
174
 
170
- subject.should == xsd
175
+ expect(subject).to eq(xsd)
171
176
  end
172
177
  end
173
178
  end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Schematic::Serializers::Xsd do
4
4
  describe "schematic#ignore keyword" do
@@ -8,6 +8,7 @@ describe Schematic::Serializers::Xsd do
8
8
  end
9
9
 
10
10
  model do
11
+ self.primary_key = :title
11
12
  schematic do
12
13
  ignore :title
13
14
  end
@@ -18,8 +19,7 @@ describe Schematic::Serializers::Xsd do
18
19
  xsd = generate_xsd_for_model(SomeModel) do
19
20
  end
20
21
 
21
- sanitize_xml(SomeModel.to_xsd).should eq(xsd)
22
+ expect(sanitize_xml(SomeModel.to_xsd)).to eq(xsd)
22
23
  end
23
24
  end
24
-
25
25
  end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Schematic::Serializers::Xsd do
4
4
  describe "Adding additional methods" do
@@ -33,7 +33,7 @@ describe Schematic::Serializers::Xsd do
33
33
  XML
34
34
  end
35
35
 
36
- sanitize_xml(SomeModel.to_xsd).should eq(xsd)
36
+ expect(sanitize_xml(SomeModel.to_xsd)).to eq(xsd)
37
37
  end
38
38
  end
39
39
 
@@ -44,6 +44,7 @@ describe Schematic::Serializers::Xsd do
44
44
  end
45
45
 
46
46
  model do
47
+ self.primary_key = :foo
47
48
  validates :foo_bar, :inclusion => { :in => [1,2,3] }
48
49
 
49
50
  def foo_bar=(value)
@@ -90,7 +91,7 @@ describe Schematic::Serializers::Xsd do
90
91
  XML
91
92
  end
92
93
 
93
- sanitize_xml(SomeModel.to_xsd).should eq(xsd)
94
+ expect(sanitize_xml(SomeModel.to_xsd)).to eq(xsd)
94
95
  end
95
96
 
96
97
  it "should validate against the xsd" do
@@ -98,14 +99,14 @@ describe Schematic::Serializers::Xsd do
98
99
 
99
100
  invalid_instance = SomeModel.new(:foo_bar => "d")
100
101
  xml = [invalid_instance].to_xml
101
- lambda {
102
+ expect {
102
103
  validate_xml_against_xsd(xml, xsd)
103
- }.should raise_error
104
+ }.to raise_error
104
105
  valid_instance = SomeModel.new(:foo_bar => 1)
105
106
  xml = [valid_instance].to_xml
106
- lambda {
107
+ expect {
107
108
  validate_xml_against_xsd(xml, xsd)
108
- }.should_not raise_error
109
+ }.not_to raise_error
109
110
  end
110
111
  end
111
112
 
@@ -116,6 +117,7 @@ describe Schematic::Serializers::Xsd do
116
117
  end
117
118
 
118
119
  model do
120
+ self.primary_key = :foo
119
121
 
120
122
  attr_accessor :bar
121
123
 
@@ -157,22 +159,22 @@ describe Schematic::Serializers::Xsd do
157
159
  </xs:element>
158
160
  XML
159
161
  end
160
- sanitize_xml(SomeModel.to_xsd).should eq(xsd)
162
+ expect(sanitize_xml(SomeModel.to_xsd)).to eq(xsd)
161
163
  end
162
164
 
163
165
  it "should validate against the xsd" do
164
166
  xsd = SomeModel.to_xsd
165
167
 
166
- invalid_instance = SomeModel.new(:bar => "invalid option")
168
+ invalid_instance = SomeModel.new(:bar => 'invalid option')
167
169
  xml = [invalid_instance].to_xml
168
- lambda {
170
+ expect {
169
171
  validate_xml_against_xsd(xml, xsd)
170
- }.should raise_error
171
- valid_instance = SomeModel.new(:bar => "b")
172
+ }.to raise_error
173
+ valid_instance = SomeModel.new(:bar => 'b')
172
174
  xml = [valid_instance].to_xml
173
- lambda {
175
+ expect {
174
176
  validate_xml_against_xsd(xml, xsd)
175
- }.should_not raise_error
177
+ }.not_to raise_error
176
178
  end
177
179
  end
178
180
 
@@ -183,6 +185,8 @@ describe Schematic::Serializers::Xsd do
183
185
  end
184
186
 
185
187
  model do
188
+ self.primary_key = :bar
189
+
186
190
  def foo=(value)
187
191
  @foo = value
188
192
  end
@@ -192,7 +196,7 @@ describe Schematic::Serializers::Xsd do
192
196
  end
193
197
 
194
198
  def self.xsd_foo_enumeration_restrictions
195
- ["1", "2", "3"]
199
+ ['1', '2', '3']
196
200
  end
197
201
 
198
202
  schematic do
@@ -236,21 +240,21 @@ describe Schematic::Serializers::Xsd do
236
240
  </xs:element>
237
241
  XML
238
242
  end
239
- sanitize_xml(SomeModel.to_xsd).should eq(xsd)
243
+ expect(sanitize_xml(SomeModel.to_xsd)).to eq(xsd)
240
244
  end
241
245
 
242
246
  it "should validate against its own XSD" do
243
- invalid_instance = SomeModel.new(:foo => ["a", "b"])
247
+ invalid_instance = SomeModel.new(:foo => ['a', 'b'])
244
248
  xml = [invalid_instance].to_xml
245
- lambda {
249
+ expect {
246
250
  validate_xml_against_xsd(xml, SomeModel.to_xsd)
247
- }.should raise_error
251
+ }.to raise_error
248
252
 
249
- instance = SomeModel.new(:foo => ["1", "2"])
253
+ instance = SomeModel.new(:foo => ['1', '2'])
250
254
  xml = [instance].to_xml
251
- lambda {
255
+ expect {
252
256
  validate_xml_against_xsd(xml, SomeModel.to_xsd)
253
- }.should_not raise_error
257
+ }.not_to raise_error
254
258
  end
255
259
  end
256
260
 
@@ -308,9 +312,8 @@ describe Schematic::Serializers::Xsd do
308
312
  XML
309
313
  end
310
314
 
311
- sanitize_xml(SomeModel.to_xsd).should eq(xsd)
315
+ expect(sanitize_xml(SomeModel.to_xsd)).to eq(xsd)
312
316
  end
313
317
  end
314
318
  end
315
319
  end
316
-