Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Parsing of integers and floats were not working properly and some str…

…ings with numbers were being converted to numbers
  • Loading branch information...
commit 4e3718d0b1bbb2088d0ba019b5cdc592332f5dfa 1 parent cf2f59b
@vicentemundim authored
View
4 lib/mongoid_query_string_interface.rb
@@ -87,7 +87,7 @@ def operator_from(key)
end
def parse_value(value, operator)
- parse_date(value) or parse_integer(value) or parse_array(value, operator) or parse_regex(value) or value
+ parse_date(value) or parse_integer(value) or parse_float(value) or parse_array(value, operator) or parse_regex(value) or value
end
def parse_date(date)
@@ -97,7 +97,7 @@ def parse_date(date)
end
def parse_integer(integer)
- if match = integer.match(/\d+/)
+ if match = integer.match(/^\d+$/)
match[0].to_i
end
end
View
2  lib/version.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
module Mongoid #:nodoc
module QueryStringInterface #:nodoc
- VERSION = "0.1.2"
+ VERSION = "0.1.3"
end
end
View
26 spec/mongoid_query_string_interface_spec.rb
@@ -43,7 +43,7 @@ class EmbeddedDocument
Document.create :title => 'Some Other Title', :some_integer => 2, :some_float => 2.2, :status => 'published',
:created_at => 2.days.ago.to_time, :tags => ['esportes', 'futebol', 'jabulani', 'flamengo'],
:embedded_document => { :name => 'other embedded document',
- :tags => ['yup', 'uhu', 'yeah'] }
+ :tags => ['yup', 'uhu', 'yeah', 'H4', '4H', '4H4', 'H4.1', '4.1H', '4.1H4.1'] }
end
before :each do
@@ -178,9 +178,33 @@ class EmbeddedDocument
Document.filter_by('some_integer.lt' => '2').should == [document]
end
+ it 'should not parse as an integer if it does not starts with a digit' do
+ Document.filter_by('embedded_document.tags' => 'H4').should == [other_document]
+ end
+
+ it 'should not parse as an integer if it does not ends with a digit' do
+ Document.filter_by('embedded_document.tags' => '4H').should == [other_document]
+ end
+
+ it 'should not parse as an integer if it has a non digit character in it' do
+ Document.filter_by('embedded_document.tags' => '4H4').should == [other_document]
+ end
+
it 'should parse a float correctly' do
Document.filter_by('some_float.lt' => '2.1').should == [document]
end
+
+ it 'should not parse as a float if it does not starts with a digit' do
+ Document.filter_by('embedded_document.tags' => 'H4.1').should == [other_document]
+ end
+
+ it 'should not parse as a float if it does not ends with a digit' do
+ Document.filter_by('embedded_document.tags' => '4.1H').should == [other_document]
+ end
+
+ it 'should not parse as a float if it has a non digit character in it' do
+ Document.filter_by('embedded_document.tags' => '4.1H4.1').should == [other_document]
+ end
end
context 'with regex values' do
Please sign in to comment.
Something went wrong with that request. Please try again.