schematic 0.1.4 → 0.1.5
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.
@@ -4,9 +4,10 @@ module Schematic
|
|
4
4
|
class Custom < Base
|
5
5
|
def generate(builder)
|
6
6
|
validators_for_column.each do |validator|
|
7
|
-
if validator.respond_to?(:
|
8
|
-
|
9
|
-
|
7
|
+
if validator.respond_to?(:xsd_pattern_restrictions)
|
8
|
+
validator.xsd_pattern_restrictions.each do |restriction|
|
9
|
+
builder.xs(:pattern, "value" => restriction.is_a?(Regexp) ? restriction.source : restriction)
|
10
|
+
end
|
10
11
|
return
|
11
12
|
end
|
12
13
|
end
|
data/lib/schematic/version.rb
CHANGED
@@ -6,11 +6,11 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
6
6
|
before do
|
7
7
|
class CrazyTownValidator < ActiveModel::EachValidator
|
8
8
|
def validate_each(record, attribute, value)
|
9
|
-
record.errors.add(attribute, "must be crazy") unless value.match /.*crazy
|
9
|
+
record.errors.add(attribute, "must be crazy") unless value.match /.*crazy.*|\w/
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
/.*crazy.*/
|
12
|
+
def xsd_pattern_restrictions
|
13
|
+
[/\w/, /.*crazy.*/]
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -27,7 +27,12 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should validate against it's own XSD" do
|
30
|
-
invalid_instance = CustomModel.new(:title => "happy")
|
30
|
+
invalid_instance = CustomModel.new(:title => "happy today")
|
31
|
+
xml = [invalid_instance].to_xml
|
32
|
+
lambda {
|
33
|
+
validate_xml_against_xsd(xml, subject)
|
34
|
+
}.should raise_error
|
35
|
+
invalid_instance = CustomModel.new(:title => "happytoday")
|
31
36
|
xml = [invalid_instance].to_xml
|
32
37
|
lambda {
|
33
38
|
validate_xml_against_xsd(xml, subject)
|
@@ -46,6 +51,7 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
46
51
|
<xs:complexType>
|
47
52
|
<xs:simpleContent>
|
48
53
|
<xs:restriction base="String">
|
54
|
+
<xs:pattern value="\\w"/>
|
49
55
|
<xs:pattern value=".*crazy.*"/>
|
50
56
|
</xs:restriction>
|
51
57
|
</xs:simpleContent>
|