Permalink
Browse files

Adding in read_all_about_it

  • Loading branch information...
steveklabnik committed Sep 1, 2010
1 parent 584201b commit f4a105f00be1b7993502340fcf909bb900496fe0
Showing with 46 additions and 15 deletions.
  1. +5 −1 README.md
  2. +27 −14 lib/extra/extra.rb
  3. +14 −0 spec/extra_spec.rb
View
@@ -43,7 +43,11 @@ To record something newsworthy, just do this:
To find out what interesting things a particular user has done:
- $ user.read_all_about_it
+ $ Extra::Extra.read_all_about_it user
+
+or
+
+ $ Extra::Extra.the_scoop user
This returns an array of Extra objects. To find out more about a particular
Extra:
View
@@ -1,24 +1,37 @@
require 'candy'
module Extra
+ class Extras
+ include Candy::Collection
+ collects :extra
+ end
+
class Extra
include Candy::Piece
- def self.source opts={}
- opts[:host] ||= "localhost"
- Candy.host = opts[:host]
- opts[:port] ||= 27017
- Candy.port = opts[:port]
- end
+ class << self
+
+ def source opts={}
+ opts[:host] ||= "localhost"
+ Candy.host = opts[:host]
+ opts[:port] ||= 27017
+ Candy.port = opts[:port]
+ end
+
+ def !(category, user, text)
+ extra = Extra.new
+ extra.category = category
+ extra.who_id = user.id
+ extra.who_name = user.username
+ extra.who_class = user.class
+ extra.what = text
+ extra.when = Time.now
+ end
+
+ def read_all_about_it user
+ Extras.new(:who_id => user.id, :who_class => user.class)
+ end
- def self.!(category, user, text)
- extra = Extra.new
- extra.category = category
- extra.who_id = user.id
- extra.who_name = user.username
- extra.who_class = user.class
- extra.what = text
- extra.when = Time.now
end
end
View
@@ -34,4 +34,18 @@
Extra::Extra::! :breaking, user, "hit a home run"
end
end
+
+ describe "#read_all_about_it" do
+
+ it "should exist" do
+ Extra::Extra.respond_to?(:read_all_about_it).should == true
+ end
+
+ it "should return Extras for the user" do
+ user = mock("User", :id => 1, :class => "User")
+ Extra::Extras.should_receive(:new).with(:who_id => 1, :who_class => "User")
+
+ Extra::Extra.read_all_about_it(user)
+ end
+ end
end

0 comments on commit f4a105f

Please sign in to comment.