Skip to content
Browse files

Added all which is sorted by id.

  • Loading branch information...
1 parent 98471b8 commit 8c8e207fcb8a9d8ae86888c1014ac5b5f7203f81 @jnunemaker committed
Showing with 15 additions and 0 deletions.
  1. +4 −0 lib/scam.rb
  2. +11 −0 spec/scam_spec.rb
View
4 lib/scam.rb
@@ -8,6 +8,10 @@ def self.included(base)
end
module ClassMethods
+ def all
+ instances.sort_by { |i| i.id }
+ end
+
def create(attrs={})
new(attrs).tap { |i| instances << i }
end
View
11 spec/scam_spec.rb
@@ -20,6 +20,17 @@
end
end
+ describe ".all" do
+ before do
+ FeedTemplate.create(:id => 2)
+ FeedTemplate.create(:id => 1)
+ end
+
+ it "returns all instances sorted by id" do
+ FeedTemplate.all.map(&:id).should == [1, 2]
+ end
+ end
+
describe ".initialize" do
before do
@template = FeedTemplate.new(:id => 5)

0 comments on commit 8c8e207

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