Skip to content

Commit

Permalink
Merging in 2.3.0 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Oct 31, 2011
2 parents ff0580c + 6b412f0 commit 64f1e83
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 48 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ For instructions on upgrading to newer versions, visit

### Resolved Issues

* \#1386 Lowered mongo/bson dependency to 1.3

* \#1377 Fix aggregation functions to properly handle nil or indefined values.
(Maxime Garcia)

* \#1373 Warn if a scope overrides another scope.

* \#1372 Never persist when binding inside of a read attribute for validation.

* \#1364 Fixed reloading of documents with non bson object id ids.

* \#1360 Fixed performance of Mongoid's observer instantiation by hooking into
Expand All @@ -32,6 +41,9 @@ For instructions on upgrading to newer versions, visit
* \#1350, \#1351 Fixed errors in the string conversions of double quotes and
tilde when paramterizing keys.

* \#1349 Mongoid documents should not blow up when including Enumerable.
(Jonas Nicklas)

## 2.3.2

### Resolved Issues
Expand Down
5 changes: 1 addition & 4 deletions lib/mongoid/extensions/object/checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ module Checks #:nodoc:
# @example Is the array vacant?
# [].vacant?
#
# @example Is the hash vacant?
# {}.vacant?
#
# @example Is the object vacant?
# nil.vacant?
#
# @return [ true, false ] True if empty or nil, false if not.
#
# @since 2.0.2
def _vacant?
is_a?(::Enumerable) || is_a?(::String) ? empty? : !self
is_a?(::Array) || is_a?(::String) ? empty? : !self
end
end
end
Expand Down
12 changes: 7 additions & 5 deletions lib/mongoid/javascript/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ group:

max:
"function(obj, prev) {
if (prev.max == 'start') {
if (obj.[field] && prev.max == 'start') {
prev.max = obj.[field];
}
if (prev.max < obj.[field]) {
if (obj.[field] && prev.max < obj.[field]) {
prev.max = obj.[field];
}
}"

min:
"function(obj, prev) {
if (prev.min == 'start') {
if (obj.[field] && prev.min == 'start') {
prev.min = obj.[field];
}
if (prev.min > obj.[field]) {
if (obj.[field] && prev.min > obj.[field]) {
prev.min = obj.[field];
}
}"
Expand All @@ -33,5 +33,7 @@ sum:
if (prev.sum == 'start') {
prev.sum = 0;
}
prev.sum += obj.[field];
if (obj.[field]) {
prev.sum += obj.[field];
}
}"
8 changes: 7 additions & 1 deletion lib/mongoid/named_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ def with_scope(criteria)

protected

# Warns if overriding another scope or method.
#
# @example Warn if name exists.
# Model.valid_scope_name?("test")
#
# @param [ String, Symbol ] name The name of the scope.
def valid_scope_name?(name)
if !scopes[name] && respond_to?(name, true)
if scopes[name] || respond_to?(name, true)
if Mongoid.logger
Mongoid.logger.warn(
"Creating scope :#{name}. " +
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/relations/referenced/many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def <<(*args)
args.flatten.each do |doc|
next unless doc
append(doc)
doc.save if persistable?
doc.save if persistable? && !doc.validated?
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/mongoid/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def exit_validate
# @since 2.0.0.rc.1
def read_attribute_for_validation(attr)
if relations[attr.to_s]
begin_validate
relation = send(attr)
exit_validate
relation.do_or_do_not(:in_memory) || relation
else
send(attr)
Expand Down
4 changes: 2 additions & 2 deletions mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Gem::Specification.new do |s|

s.add_dependency("activemodel", ["~> 3.1"])
s.add_dependency("tzinfo", ["~> 0.3.22"])
s.add_dependency("mongo", ["~> 1.4"])
s.add_dependency("mongo", ["~> 1.3"])

s.add_development_dependency("rdoc", ["~> 3.5.0"])
s.add_development_dependency("bson_ext", ["~> 1.4"])
s.add_development_dependency("bson_ext", ["~> 1.3"])
s.add_development_dependency("mocha", ["~> 0.9.12"])
s.add_development_dependency("rspec", ["~> 2.6"])
s.add_development_dependency("watchr", ["~> 0.6"])
Expand Down
40 changes: 38 additions & 2 deletions spec/functional/mongoid/contexts/mongo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
end

it "returns nil" do
Person.avg(:score).should be_nil
Person.avg(:score).should eq(0)
end
end
end
Expand Down Expand Up @@ -216,6 +216,18 @@
it "returns the maximum for the field" do
Person.max(:age).should == 40
end

context "when the field is not defined" do

before do
Person.create(:ssn => "123-22-1111")
Person.create(:ssn => "123-22-1112", :no_definition => 5)
end

it "returns the sum" do
Person.max(:no_definition).should eq(5)
end
end
end
end

Expand Down Expand Up @@ -244,6 +256,18 @@
it "returns the minimum for the field" do
Person.min(:age).should == 10.0
end

context "when the field is not defined" do

before do
Person.create(:ssn => "123-22-1111")
Person.create(:ssn => "123-22-1112", :no_definition => 5)
end

it "returns the sum" do
Person.min(:no_definition).should eq(5)
end
end
end

context "when the returned value is not a number" do
Expand Down Expand Up @@ -298,7 +322,19 @@
end

it "returns nil" do
Person.sum(:score).should be_nil
Person.sum(:score).should eq(0)
end
end

context "when the field is not defined" do

before do
Person.create(:ssn => "123-22-1111")
Person.create(:ssn => "123-22-1112", :no_definition => 5)
end

it "returns the sum" do
Person.sum(:no_definition).should eq(5)
end
end
end
Expand Down
25 changes: 0 additions & 25 deletions spec/unit/mongoid/extensions/object/checks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,6 @@
end
end

context "when the object is a hash" do

context "when the object is empty" do

let(:object) do
{}
end

it "returns true" do
object.should be__vacant
end
end

context "when the object is not empty" do

let(:object) do
{ :testing => "first" }
end

it "returns false" do
object.should_not be__vacant
end
end
end

context "when the object is nil" do

it "returns true" do
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/mongoid/javascript_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@
describe ".max" do

it "returns the max function" do
js.max.should == "function(obj, prev) { if (prev.max == 'start') { " +
"prev.max = obj.[field]; } if (prev.max < obj.[field]) { prev.max = obj.[field];" +
" } }"
js.max.should == "function(obj, prev) { if (obj.[field] && prev.max == 'start') { " +
"prev.max = obj.[field]; } if (obj.[field] && prev.max < obj.[field]) { prev.max = " +
"obj.[field]; } }"
end
end

describe ".min" do

it "returns the min function" do
js.min.should == "function(obj, prev) { if (prev.min == 'start') { " +
"prev.min = obj.[field]; } if (prev.min > obj.[field]) { prev.min = obj.[field];" +
" } }"
js.min.should == "function(obj, prev) { if (obj.[field] && prev.min == 'start') { " +
"prev.min = obj.[field]; } if (obj.[field] && prev.min > obj.[field]) { prev.min " +
"= obj.[field]; } }"
end
end

describe ".sum" do

it "returns the sum function" do
js.sum.should == "function(obj, prev) { if (prev.sum == 'start') { prev.sum = 0; " +
"} prev.sum += obj.[field]; }"
js.sum.should == "function(obj, prev) { if (prev.sum == 'start') " +
"{ prev.sum = 0; } if (obj.[field]) { prev.sum += obj.[field]; } }"
end
end
end

0 comments on commit 64f1e83

Please sign in to comment.