schematic 0.1.2 → 0.1.3
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.
@@ -9,7 +9,12 @@ module Schematic
|
|
9
9
|
|
10
10
|
def generate(builder)
|
11
11
|
for_validator ActiveModel::Validations::FormatValidator do |validator|
|
12
|
-
|
12
|
+
if pattern = validator.options[:with]
|
13
|
+
value = pattern.source
|
14
|
+
value.gsub!(/^(?:\^|\\A|\\a)?/, '')
|
15
|
+
value.gsub!(/(?:\$|\\Z|\\z)?$/, '')
|
16
|
+
builder.xs(:pattern, "value" => value)
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
data/lib/schematic/version.rb
CHANGED
@@ -45,6 +45,32 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
45
45
|
subject.should == xsd
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
context "with a model with a complex format" do
|
50
|
+
subject { sanitize_xml(PatternModel.to_xsd) }
|
51
|
+
with_model :pattern_model do
|
52
|
+
table :id => false do |t|
|
53
|
+
t.string "email"
|
54
|
+
end
|
55
|
+
|
56
|
+
model do
|
57
|
+
validates :email, :format => { :with => /\A([\w\.%\+\-`']+)@([\w\-]+\.)+([\w]{2,})\Z/ }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should validate against it's own XSD" do
|
62
|
+
invalid_instance = PatternModel.new(:email => "@blah")
|
63
|
+
xml = [invalid_instance].to_xml
|
64
|
+
lambda {
|
65
|
+
validate_xml_against_xsd(xml, subject)
|
66
|
+
}.should raise_error
|
67
|
+
valid_instance = PatternModel.new(:email => "foo@bar.com")
|
68
|
+
xml = [valid_instance].to_xml
|
69
|
+
lambda {
|
70
|
+
validate_xml_against_xsd(xml, subject)
|
71
|
+
}.should_not raise_error
|
72
|
+
end
|
73
|
+
end
|
48
74
|
end
|
49
75
|
end
|
50
76
|
|