Permalink
Browse files

Merge commit 'abedra/master'

  • Loading branch information...
2 parents 8a3c790 + 3842a05 commit 05ce4af1e9aee82e19bdcd3b1a8a83b3db2d72b7 @rsanheim committed Jan 9, 2009
Showing with 32 additions and 9 deletions.
  1. +2 −1 .gitignore
  2. +15 −7 lib/brain_buster.rb
  3. +15 −1 spec/brain_buster_functional_spec.rb
View
@@ -1 +1,2 @@
-spec/test.log
+spec/test.log
+TAGS
View
@@ -15,19 +15,27 @@ def attempt?(string)
end
def self.find_random_or_previous(id = nil)
- id.nil? ? self.find(random_id(first_id, count)) : find(id)
+ # Buggy code referenced in
+ # http://relevance.lighthouseapp.com/projects/20527/tickets/4-ensure-the-random-id-we-find-is-always-really-in-the-db
+ # id.nil? ? self.find(random_id(first_id, count)) : find(id)
+ id.nil? ? find(:first, :order => random_function) : self.smart_find(id)
end
private
- def self.random_id(first_id, count)
- Kernel.rand(count) + first_id
+ def self.smart_find(id)
+ find(id) || find(:first, :order => random_function)
end
+
+ # No longer needed with above fix
+ # def self.random_id(first_id, count)
+ # Kernel.rand(count) + first_id
+ # end
- # return first valid id
- def self.first_id
- @first_id ||= find(:all, :order => "id").first.id
- end
+ # return first valid id : no longer needed
+ # def self.first_id
+ # @first_id ||= find(:all, :order => "id").first.id
+ # end
def answer_is_integer?
int_answer = answer.to_i
@@ -124,4 +124,18 @@ def rescue_action(e) raise e end;
@response.body.should == "Success!"
end
-end
+ describe "User manually deletes a record from the db", ActionController::TestCase do
+ tests StubController
+ include SpecHelper
+
+ xit "successfully returns a record when the requested id does not exist in the db" do
+ stub_default_brain_buster
+ BrainBuster.expects(:smart_find).with('123789')
+
+ get :new, :captcha_id => '123789'
+ assigns(:captcha).should.not.be nil
+ end
+
+ end
+
+end

0 comments on commit 05ce4af

Please sign in to comment.