Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: scudco/mongoid
...
head fork: scudco/mongoid
  • 12 commits
  • 7 files changed
  • 0 commit comments
  • 2 contributors
Commits on Feb 04, 2012
@i0rek i0rek Expand nested complex criteria.
Make sure even nested complex criterias were
expanded correct. Fixes #1665.
8c44bce
@i0rek i0rek Preserve milliseconds when persisting Time and DateTime.
This time stuff is a mess. I'm not happy with my solution.
Although it seems to work. One of the things that caused me trouble
was Time#usec which should return the microseconds but seem to return
the milliseconds:

t = Time.now        #=> 2007-11-19 08:03:26 -0600
"%10.6f" % t.to_f   #=> "1195481006.775195"
t.usec              #=> 775195

Thatswhy it is not usable in the examples.

Also I tried to archive the same behavior requested for
Time in issue #64 for DateTime because its really the same.

Any Feedback is really appreciated.
9beee1c
@i0rek i0rek Remove failing test.
This example just don't work any more since DateTime stores also
millisecond, because milliseconds aren't part of DateTime#to_s.
You could rewrite it to:

  Person.where(:lunch_time.gt => time).should eq([ person ])

but that doesn't fit very well imho.
1f3243e
Commits on Feb 05, 2012
@i0rek i0rek Wait a sec, why do we strip at all?? Its not worth it! 0b38edc
@i0rek i0rek Restore tests to ensure nothing is stripped. 44ad9b5
@durran durran Update travis to use 19mode jruby 8f15a1c
@durran durran Merge pull request #1673 from i0rek/time
Preserve milliseconds when storing Time/Datetime
71e3a78
@durran durran Fix the jruby exclude in travis config 35e3360
@durran durran Update changelog 3dca21c
@durran durran Merge pull request #1672 from i0rek/expand_complex_criteria
Expand nested complex criteria.
5bc0282
@durran durran Merge branch 'master' of github.com:mongoid/mongoid 5c8a998
@durran durran Travis config no longer needs 1.9 flag on jruby options b35631f
View
14 .travis.yml
@@ -2,10 +2,10 @@ rvm:
- 1.9.2
- 1.9.3
- ruby-head
- - jruby
+ - jruby-19mode
- jruby-head
env:
- - JRUBY_OPTS="--1.9 --server -Xinvokedynamic.constants=true"
+ - JRUBY_OPTS="--server -Xinvokedynamic.constants=true"
- RUBY_GC_MALLOC_LIMIT=60000000 RUBY_HEAP_FREE_MIN=100000 RUBY_HEAP_MIN_SLOTS=600000
-
branches:
@@ -14,16 +14,14 @@ branches:
matrix:
exclude:
- rvm: 1.9.2
- env: JRUBY_OPTS="--1.9 --server -Xinvokedynamic.constants=true"
+ env: JRUBY_OPTS="--server -Xinvokedynamic.constants=true"
- rvm: 1.9.2
env: RUBY_GC_MALLOC_LIMIT=60000000 RUBY_HEAP_FREE_MIN=100000 RUBY_HEAP_MIN_SLOTS=600000
- rvm: 1.9.3
- env: JRUBY_OPTS="--1.9 --server -Xinvokedynamic.constants=true"
+ env: JRUBY_OPTS="--server -Xinvokedynamic.constants=true"
- rvm: ruby-head
- env: JRUBY_OPTS="--1.9 --server -Xinvokedynamic.constants=true"
- - rvm: jruby
+ env: JRUBY_OPTS="--server -Xinvokedynamic.constants=true"
+ - rvm: jruby-19mode
env: RUBY_GC_MALLOC_LIMIT=60000000 RUBY_HEAP_FREE_MIN=100000 RUBY_HEAP_MIN_SLOTS=600000
- - rvm: jruby
- env:
- rvm: jruby-head
env: RUBY_GC_MALLOC_LIMIT=60000000 RUBY_HEAP_FREE_MIN=100000 RUBY_HEAP_MIN_SLOTS=600000
View
3  CHANGELOG.md
@@ -59,6 +59,9 @@ For instructions on upgrading to newer versions, visit
### Resolved Issues
+* \#1665/#1672 Expand complex criteria in nested criteria selectors, like
+ #matches. (Hans Hasselberg)
+
* \#1335 Don't add id sorting criteria to first/last is there is already
sorting options on the criteria.
View
1  lib/mongoid/extensions/hash/criteria_helpers.rb
@@ -19,6 +19,7 @@ def expand_complex_criteria
each_pair do |k,v|
if k.respond_to?(:key) && k.respond_to?(:to_mongo_query)
hsh[k.key] ||= {}
+ v = v.expand_complex_criteria if v.is_a?(::Hash)
hsh[k.key].merge!(k.to_mongo_query(v))
else
hsh[k] = v
View
2  lib/mongoid/fields/internal/timekeeping.rb
@@ -67,7 +67,7 @@ def selection(object)
def serialize(object)
return nil if object.blank?
begin
- ::Time.at(convert_to_time(object).to_i).utc
+ ::Time.at(convert_to_time(object).to_f).utc
rescue ArgumentError
raise Errors::InvalidTime.new(object)
end
View
8 spec/mongoid/criterion/inclusion_spec.rb
@@ -1269,14 +1269,14 @@
Person.where(:age => "33").should eq([ person ])
end
- it "typecasts datetimes" do
- Person.where(:lunch_time => lunch_time.to_s).should eq([ person ])
- end
-
it "typecasts dates" do
Person.where({:dob => dob.to_s}).should eq([ person ])
end
+ it "typecasts datetimes" do
+ Person.where({:lunch_time => lunch_time.to_f}).should eq([ person ])
+ end
+
it "typecasts times with zones" do
time = lunch_time.in_time_zone("Alaska")
Person.where(:lunch_time => time).should eq([ person ])
View
5 spec/mongoid/extensions/hash/criteria_helpers_spec.rb
@@ -13,5 +13,10 @@
hash = {:age.gt => 40, :age.lt => 45}
hash.expand_complex_criteria.should eq({:age => {"$gt" => 40, "$lt" => 45}})
end
+
+ it "expands a nested complex criteria to form a valid `where` hash" do
+ hash = { "person.videos".to_sym.matches => { :year.gt => 2000 } }
+ hash.expand_complex_criteria.should eq({:"person.videos"=>{"$elemMatch"=>{:year=>{"$gt"=>2000}}}})
+ end
end
end
View
18 spec/mongoid/fields/internal/time_spec.rb
@@ -115,12 +115,20 @@
context "when given a DateTime" do
+ let!(:time) do
+ Time.now
+ end
+
it "returns a time" do
field.serialize(time.to_datetime).should eq(
Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec)
)
end
+ it "doesn't strip milli- or microseconds" do
+ field.serialize(time).to_f.should eq(time.to_f)
+ end
+
context "when using the ActiveSupport time zone" do
let(:datetime) do
@@ -144,6 +152,7 @@
)
end
end
+
end
context "when given a Time" do
@@ -152,10 +161,6 @@
field.serialize(time).utc_offset.should eq(0)
end
- it "strips microseconds" do
- field.serialize(Time.now).usec.should eq(0)
- end
-
it "returns utc times unchanged" do
field.serialize(time.utc).should eq(time.utc)
end
@@ -163,6 +168,11 @@
it "returns the time as utc" do
field.serialize(time).should eq(time.utc)
end
+
+ it "doesn't strip milli- or microseconds" do
+ field.serialize(time).to_f.should eq(time.to_f)
+ end
+
end
context "when given an ActiveSupport::TimeWithZone" do

No commit comments for this range

Something went wrong with that request. Please try again.