Skip to content

Commit

Permalink
Merge pull request #4230 from estolfo/MONGOID-3652-geo-near-scope
Browse files Browse the repository at this point in the history
MONGOID-3652 Allow scopes with geo near queries
  • Loading branch information
estolfo committed Jan 21, 2016
2 parents e516ff9 + cd64624 commit 8847b32
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/mongoid/contextual/geo_near.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ def time
stats["time"]
end

# Is this context's criteria considered empty?
#
# @example Is this context's criteria considered empty?
# geo_near.empty_and_chainable?
#
# @return [ true ] Always true.
#
# @since 5.1.0
def empty_and_chainable?
true
end

private

# Apply criteria specific options - query, limit.
Expand Down
19 changes: 19 additions & 0 deletions spec/mongoid/contextual/geo_near_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,23 @@
expect(geo_near.time).to_not be_nil
end
end

describe "#empty_and_chainable" do

let!(:collection) do
Bar.collection
end

let(:criteria) do
Bar.all
end

let(:geo_near) do
described_class.new(collection, criteria, [ 52, 13 ])
end

it "returns true" do
expect(geo_near.empty_and_chainable?).to be(true)
end
end
end
19 changes: 19 additions & 0 deletions spec/mongoid/scopable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,25 @@

context "when provided a criteria" do

context "when the lambda includes a geo_near query" do

before do
Bar.scope(:near_by, lambda{ |location| geo_near(location) })
end

after do
class << Bar
undef_method :near_by
end
Bar._declared_scopes.clear
end

it "allows the scope to be defined" do
expect(Bar.near_by([ 51.545099, -0.0106 ])).to be_a(Mongoid::Contextual::GeoNear)
end

end

context "when a block is provided" do

before do
Expand Down

0 comments on commit 8847b32

Please sign in to comment.