Permalink
Browse files

Added Collection#[] and Collection#[]=.

  • Loading branch information...
1 parent eafcd47 commit 0d8df34d37910bf85ec0bbad6d3fe1958f7805a9 @jnunemaker jnunemaker committed May 3, 2010
Showing with 19 additions and 1 deletion.
  1. +5 −1 lib/plucky/collection.rb
  2. +14 −0 test/test_collection.rb
View
@@ -15,7 +15,11 @@ def initialize(collection)
@collection = collection
end
- query_delegator :fields, :filter, :limit, :reverse, :skip, :sort, :where
+ query_delegator :fields, :filter, :limit, :reverse, :skip, :sort, :where, :[]=
+
+ def [](key)
+ query[key]
+ end
def all(options={})
query.options(options)
View
@@ -116,5 +116,19 @@ class CollectionTest < Test::Unit::TestCase
@collection.where('this.name == "John"').all.should == [@john]
end
end
+
+ context "#[]" do
+ should "work" do
+ @collection.filter(:name => 'John')
+ @collection[:name].should == 'John'
+ end
+ end
+
+ context "#[]=" do
+ should "work" do
+ @collection[:name] = 'John'
+ @collection.all.should == [@john]
+ end
+ end
end
end

0 comments on commit 0d8df34

Please sign in to comment.