Permalink
Browse files

make tests run over 2x faster by creating the test db just once

  • Loading branch information...
1 parent 0581928 commit 05e95f8a3b9dfa069799522881ae9beedbee129b @technoweenie technoweenie committed Sep 1, 2008
Showing with 9 additions and 15 deletions.
  1. +1 −2 spec/database.rb
  2. +3 −4 spec/delayed_method_spec.rb
  3. +1 −4 spec/job_spec.rb
  4. +4 −5 spec/story_spec.rb
View
@@ -10,7 +10,7 @@
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => '/tmp/jobs.sqlite')
ActiveRecord::Migration.verbose = false
-def reset_db
+
ActiveRecord::Schema.define do
create_table :delayed_jobs, :force => true do |table|
@@ -29,7 +29,6 @@ def reset_db
end
end
-end
# Purely useful for test cases...
class Story < ActiveRecord::Base
@@ -37,8 +37,7 @@ def read(story)
end
describe 'random ruby objects' do
-
- before { reset_db }
+ before { Delayed::Job.delete_all }
it "should respond_to :send_later method" do
@@ -87,7 +86,7 @@ def read(story)
job = Delayed::Job.find(:first)
job.payload_object.class.should == Delayed::PerformableMethod
- job.payload_object.object.should == 'AR:Story:1'
+ job.payload_object.object.should == "AR:Story:#{story.id}"
job.payload_object.method.should == :tell
job.payload_object.args.should == []
job.payload_object.perform.should == 'Once upon...'
@@ -103,7 +102,7 @@ def read(story)
job = Delayed::Job.find(:first)
job.payload_object.class.should == Delayed::PerformableMethod
job.payload_object.method.should == :read
- job.payload_object.args.should == ['AR:Story:1']
+ job.payload_object.args.should == ["AR:Story:#{story.id}"]
job.payload_object.perform.should == 'Epilog: Once upon...'
end
View
@@ -11,10 +11,7 @@ def perform; raise 'did not work'; end
end
describe Delayed::Job do
-
- before :each do
- reset_db
- end
+ before { Delayed::Job.delete_all }
it "should set run_at automatically" do
Delayed::Job.create(:payload_object => ErrorJob.new ).run_at.should_not == nil
View
@@ -2,17 +2,16 @@
describe "A story" do
- before do
- reset_db
- Story.create :text => "Once upon a time..."
+ before(:all) do
+ @story = Story.create :text => "Once upon a time..."
end
it "should be shared" do
- Story.find(:first).tell.should == 'Once upon a time...'
+ @story.tell.should == 'Once upon a time...'
end
it "should not return its result if it storytelling is delayed" do
- Story.find(:first).send_later(:tell).should_not == 'Once upon a time...'
+ @story.send_later(:tell).should_not == 'Once upon a time...'
end
end

0 comments on commit 05e95f8

Please sign in to comment.