schematic 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,12 @@ module Schematic
9
9
 
10
10
  def generate(builder)
11
11
  for_validator ActiveModel::Validations::FormatValidator do |validator|
12
- builder.xs(:pattern, "value" => validator.options[:with].source) if validator.options[:with]
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
@@ -1,3 +1,3 @@
1
1
  module Schematic
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: schematic
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Case Commons, LLC