Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding scope_the_scene

  • Loading branch information...
commit 3429296b2b6071b0aae75a6e803de457c066560b 1 parent 9145358
@steveklabnik authored
View
5 README.rdoc
@@ -29,9 +29,8 @@ It can be cloned via
== Requirements
-* *Ruby-1.9* Sorry for you 1.8 people, 1.9 is the current version of Ruby.
-I test with 1.9.2.
-* *mongo* If you're going to use MongoDB...
+* Ruby 1.9: Sorry for you 1.8 people, 1.9 is the current version of Ruby. I test with 1.9.2.
+* mongo: If you're going to use MongoDB...
== Usage
View
11 lib/extra/extra.rb
@@ -86,7 +86,16 @@ def method_missing(m, *args)
collection.find(params).collect{|args| Extra.new args }
end
- end
+ # gets friend stuff
+ def scope_the_scene user
+ params = {
+ who_id: {"$in" => user.my_peeps},
+ who_class: user.class.to_s
+ }
+ collection.find(params).collect{|args| Extra.new args }
+ end
+
+ end #end the class << self
end
end
View
23 spec/extraextra_spec.rb
@@ -89,7 +89,7 @@
it "should filter some breaking news with a user" do
steve = Factory(:user)
- nobody = Factory(:user, :id => "2", :username => "nobody")
+ nobody = Factory(:user, :id => 2, :username => "nobody")
Extra::Extra.source
extra = Extra::Extra::! :breaking, steve, "hit a home run"
extra = Extra::Extra::! :breaking, nobody, "hit a home run"
@@ -98,4 +98,25 @@
end
end
+
+ describe "self#scope_the_scene" do
+ it "should exist" do
+ Extra::Extra.respond_to?(:scope_the_scene).should == true
+ end
+
+ it "should properly filter news" do
+ steve = Factory(:user)
+ maria = Factory(:user, :id => 2, :username => "maria")
+ nobody = Factory(:user, :id => 3, :username => "nobody")
+ steve.friends = [2]
+ Extra::Extra.source
+ extra = Extra::Extra::! :breaking, nobody, "hit a home run"
+ extra = Extra::Extra::! :breaking, nobody, "hit a home run"
+ extra = Extra::Extra::! :breaking, maria, "hit a home run"
+ extra = Extra::Extra::! :breaking, maria, "hit a home run"
+ extra = Extra::Extra::! :breaking, maria, "hit a home run"
+
+ Extra::Extra.scope_the_scene(steve).length.should == 3
+ end
+ end
end
View
10 spec/factories/user.rb
@@ -2,9 +2,17 @@
class User
attr_accessor :id
attr_accessor :username
+ attr_accessor :friends
def save!; end
- def self.find(id); User.new(:id => id, :username => "somebody") end
+
+ def self.find(id)
+ User.new(:id => id, :username => "somebody", :friends => [])
+ end
+
+ def my_peeps
+ friends
+ end
end

0 comments on commit 3429296

Please sign in to comment.
Something went wrong with that request. Please try again.