Browse files

Changing from #filter to #where. I just like it better. If you want t…

…o use $where just use it in a #where. Put that in your #where and smoke it!
  • Loading branch information...
1 parent 7410796 commit 39f87b761227b5e243494273b811f51af1aa83a6 @jnunemaker jnunemaker committed May 7, 2010
Showing with 10 additions and 29 deletions.
  1. +1 −1 lib/plucky/collection.rb
  2. +3 −8 lib/plucky/query.rb
  3. +3 −9 test/test_collection.rb
  4. +3 −11 test/test_query.rb
View
2 lib/plucky/collection.rb
@@ -15,7 +15,7 @@ def initialize(collection)
@collection = collection
end
- query_delegator :fields, :filter, :limit, :reverse, :skip, :sort, :where, :[]=
+ query_delegator :fields, :limit, :reverse, :skip, :sort, :where, :[]=
def [](key)
query[key]
View
11 lib/plucky/query.rb
@@ -25,11 +25,6 @@ def fields(*args)
self
end
- def filter(hash={})
- @criteria.update(CriteriaMerger.merge(@criteria, normalized_criteria(hash)))
- self
- end
-
def limit(count=nil)
@options[:limit] = count.nil? ? nil : count.to_i
self
@@ -50,8 +45,8 @@ def sort(*args)
self
end
- def where(js)
- @criteria['$where'] = js
+ def where(hash={})
+ @criteria.update(CriteriaMerger.merge(@criteria, normalized_criteria(hash)))
self
end
@@ -64,7 +59,7 @@ def []=(key, value)
end
def merge(other)
- clone.options(other.options).filter(other.criteria)
+ clone.options(other.options).where(other.criteria)
end
private
View
12 test/test_collection.rb
@@ -81,9 +81,9 @@ class CollectionTest < Test::Unit::TestCase
end
end
- context "#filter" do
+ context "#where" do
should "work" do
- @collection.filter(:age.lt => 29).filter(:name => 'Chris').all.should == [@chris]
+ @collection.where(:age.lt => 29).where(:name => 'Chris').all.should == [@chris]
end
end
@@ -111,15 +111,9 @@ class CollectionTest < Test::Unit::TestCase
end
end
- context "#where" do
- should "work" do
- @collection.where('this.name == "John"').all.should == [@john]
- end
- end
-
context "#[]" do
should "work" do
- @collection.filter(:name => 'John')
+ @collection.where(:name => 'John')
@collection[:name].should == 'John'
end
end
View
14 test/test_query.rb
@@ -147,26 +147,18 @@ class QueryTest < Test::Unit::TestCase
end
end
- context "#filter" do
+ context "#where" do
should "update criteria" do
- Query.new(:moo => 'cow').filter(:foo => 'bar').criteria.should == {:foo => 'bar', :moo => 'cow'}
+ Query.new(:moo => 'cow').where(:foo => 'bar').criteria.should == {:foo => 'bar', :moo => 'cow'}
end
should "get normalized" do
- Query.new(:moo => 'cow').filter(:foo.in => ['bar']).criteria.should == {
+ Query.new(:moo => 'cow').where(:foo.in => ['bar']).criteria.should == {
:moo => 'cow', :foo => {'$in' => ['bar']}
}
end
end
- context "#where" do
- should "update criteria with $where statement" do
- Query.new.where('this.writer_id == 1 || this.editor_id == 1').criteria.should == {
- '$where' => 'this.writer_id == 1 || this.editor_id == 1'
- }
- end
- end
-
context "#fields" do
should "update options (with array)" do
Query.new.fields([:foo, :bar, :baz]).options[:fields].should == [:foo, :bar, :baz]

0 comments on commit 39f87b7

Please sign in to comment.