Skip to content

Commit

Permalink
Fixed format for regular expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Aug 10, 2010
1 parent b9ad3c0 commit 43f3114
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/client_side_validations/adapters/orm_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_validation_options(validation)
options.delete(:maximum) if options.has_key?(:minimum)
options.delete_if { |k, v| deleteable_keys.include?(k) }
if options[:with].kind_of?(Regexp)
options[:with] = options[:with].inspect.to_s.sub("\\A","^").sub("\\Z","$").sub(%r{/i?$}, "/")
options[:with] = options[:with].inspect.to_s.sub("\\A","^").sub("\\Z","$").sub(%r{^/},"").sub(%r{/i?$}, "")
end
if options[:only_integer] == false
options.delete(:only_integer)
Expand Down
6 changes: 3 additions & 3 deletions spec/shared_examples/active_model_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it "should support validates_format_of of" do
Klass.class_eval { validates_format_of :string, :with => /\A\d\Z/i }
instance = Klass.new
expected_hash = { "format" => { "message" => "is invalid", "with" => "/^\\d$/" } }
expected_hash = { "format" => { "message" => "is invalid", "with" => "^\\d$" } }
result_hash = ClientSideValidations::ORM::ValidateOptions.new(instance).validations_for(:string)
result_hash.should == expected_hash
end
Expand All @@ -23,8 +23,8 @@
validates_format_of :string_2, :with => /\d/
end
instance = Klass.new
expected_hash_1 = { "format" => { "message" => "is invalid", "with" => "/^\\d$/" } }
expected_hash_2 = { "format" => { "message" => "is invalid", "with" => "/\\d/" } }
expected_hash_1 = { "format" => { "message" => "is invalid", "with" => "^\\d$" } }
expected_hash_2 = { "format" => { "message" => "is invalid", "with" => "\\d" } }
result_hash_1 = ClientSideValidations::ORM::ValidateOptions.new(instance).validations_for(:string)
result_hash_2 = ClientSideValidations::ORM::ValidateOptions.new(instance).validations_for(:string_2)
result_hash_1.should == expected_hash_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

it 'should translate the rule' do
@result['rules']['string']['format'].should == /\w/.inspect
@result['rules']['string']['format'].should == %{\\w}
@result['rules']['string']['required'].should be_true
end

Expand All @@ -29,7 +29,7 @@
end

it 'should translate the rule' do
@result['rules']['string']['format'].should == /\w/.inspect
@result['rules']['string']['format'].should == %{\\w}
@result['rules']['string']['required'].should be_true
end

Expand All @@ -49,7 +49,7 @@
end

it 'should translate the rule' do
@result['rules']['string']['format'].should == /\w/.inspect
@result['rules']['string']['format'].should == %{\\w}
@result['rules']['string']['required'].should be_nil
end

Expand Down

0 comments on commit 43f3114

Please sign in to comment.