Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX: Fixed the class method random

  • Loading branch information...
commit fdee1986576236e1426a0985507e8496843e76ee 1 parent 26ccdb3
Luke Brown authored
Showing with 20 additions and 1 deletion.
  1. +1 −1  app/models/testimonial.rb
  2. +19 −0 test/unit/testimonial_test.rb
View
2  app/models/testimonial.rb
@@ -11,6 +11,6 @@ def flash_name
end
def self.random
- self.find :first, :offset => ( Model.count * rand ).to_i
+ self.find :first, :offset => ( Testimonial.count * rand ).to_i
end
end
View
19 test/unit/testimonial_test.rb
@@ -7,6 +7,25 @@ class TestimonialTest < ActiveSupport::TestCase
should_validate_presence_of :name, :quote
should_have_instance_methods :flash_name
should_have_class_methods :random
+
+ context "the class method 'random'" do
+ should "call find" do
+ Testimonial.expects(:find)
+ Testimonial.random
+ end
+ should "return nil when there are no testimonials" do
+ assert_nil Testimonial.random
+ end
+ context "with some Testimonials in the database" do
+ setup do
+ Testimonial.create(:name => "Luke", :quote => "Foo")
+ Testimonial.create(:name => "Lee", :quote => "Bar")
+ end
+ should "return an instance of a testimonal when there is one to find" do
+ assert_equal(Testimonial, Testimonial.random.class)
+ end
+ end
+ end
end
context "A valid instance of a Testimonial" do
Please sign in to comment.
Something went wrong with that request. Please try again.