Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first version of *_news

  • Loading branch information...
commit 06fa895768ee22e684a09a53fae7cf6c6fdfe5e4 1 parent a65a1c2
@steveklabnik authored
Showing with 24 additions and 0 deletions.
  1. +11 −0 lib/extra/extra.rb
  2. +13 −0 spec/extraextra_spec.rb
View
11 lib/extra/extra.rb
@@ -75,6 +75,17 @@ def read_all_about_it user
# aliasing a shorter name
alias :the_scoop :read_all_about_it
+
+ # catches *_news to filter out the news
+ def method_missing(m, *args)
+ super unless m.to_s =~ /^(\w+)_news$/
+ user = args.first
+ params = {}
+ params = {who_id: user.id, who_class: user.class.to_s} unless user.nil?
+ params[:category] = $1
+ collection.find(params).collect{|args| Extra.new args }
+ end
+
end
end
View
13 spec/extraextra_spec.rb
@@ -75,4 +75,17 @@
end
end
+
+ describe "#*_news" do
+
+ it "should filter some news" do
+ user = Factory(:user)
+ Extra::Extra.source
+ extra = Extra::Extra::! :breaking, user, "hit a home run"
+ extra = Extra::Extra::! :boooring, user, "just ran a test"
+
+ Extra::Extra.breaking_news.length.should == 1
+
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.