Permalink
Browse files

Putting stuff in the db works.

  • Loading branch information...
1 parent 55c83b1 commit 584201b6c0cfcaf8a4707b30400a93271e549858 @steveklabnik committed Sep 1, 2010
Showing with 24 additions and 8 deletions.
  1. +10 −4 lib/extra/extra.rb
  2. +14 −4 spec/extra_spec.rb
View
@@ -4,16 +4,22 @@ module Extra
class Extra
include Candy::Piece
- class << self
- alias_method :'!', :new
- end
-
def self.source opts={}
opts[:host] ||= "localhost"
Candy.host = opts[:host]
opts[:port] ||= 27017
Candy.port = opts[:port]
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
end
View
@@ -18,10 +18,20 @@
end
describe "self#!" do
- it "should call #new" do
- #this doesn't work. ideas?
- #Extra::Extra.should_receive(:new)
- #Extra::Extra::!
+
+ it "should take three args and save them" do
+ #holy setup batman
+ extra = mock("Extra")
+ Extra::Extra.should_receive(:new).and_return(extra)
+ extra.should_receive(:category=).with(:breaking)
+ extra.should_receive(:who_id=).with(1)
+ extra.should_receive(:who_name=).with("steve")
+ extra.should_receive(:who_class=).with('User')
+ extra.should_receive(:what=).with("hit a home run")
+ extra.should_receive(:when=)
+
+ user = mock("User", :id => 1, :class => 'User', :username => "steve")
+ Extra::Extra::! :breaking, user, "hit a home run"
end
end
end

0 comments on commit 584201b

Please sign in to comment.