Permalink
Browse files

Added [] access to stuff.

  • Loading branch information...
1 parent 3979196 commit 98471b8b352e6bfbdcd3a98f52c13a8d129d5f9d @jnunemaker committed Dec 28, 2010
Showing with 24 additions and 0 deletions.
  1. +2 −0 lib/scam.rb
  2. +22 −0 spec/scam_spec.rb
View
@@ -20,6 +20,8 @@ def find(id)
detect { |i| i.id == id.to_i }
end
+ alias [] find
+
def instances
@instances ||= []
end
View
@@ -52,6 +52,28 @@
end
end
+ describe ".[]" do
+ before do
+ @template = FeedTemplate.create(:id => 1)
+ end
+
+ context "with integer id" do
+ it "returns instance if found" do
+ FeedTemplate[1].should == @template
+ end
+ end
+
+ context "with string id" do
+ it "returns instance if found" do
+ FeedTemplate['1'].should == @template
+ end
+ end
+
+ it "returns nil if not found" do
+ FeedTemplate[1111122].should be_nil
+ end
+ end
+
describe ".create" do
before do
@template = FeedTemplate.create(:id => 1)

0 comments on commit 98471b8

Please sign in to comment.