Skip to content

Instantly share code, notes, and snippets.

@JonKernPA
Created December 28, 2011 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonKernPA/1530542 to your computer and use it in GitHub Desktop.
Save JonKernPA/1530542 to your computer and use it in GitHub Desktop.
Sample RSpec for MongoMapper showing data cleanup
require File.dirname(__FILE__) + '/../spec_helper'
describe "ResourceLog" do
@@debug = false
before :all do
puts "--------------------"
ResourceLog.destroy_all
ResourceLog.count().should == 0
end
describe "handle multiple resource types" do
before :all do
ResourceLog.add( :type => ResourceLog::Type::PDF_MOUNT, :state => true, :time => 15.minutes.ago)
ResourceLog.add( :type => ResourceLog::Type::LDAP, :state => true, :time => 14.minutes.ago)
ResourceLog.add( :type => ResourceLog::Type::PDF_MOUNT, :state => false, :time => 10.minutes.ago)
ResourceLog.add( :type => ResourceLog::Type::LDAP, :state => false, :time => 9.minutes.ago)
ResourceLog.add( :type => ResourceLog::Type::PDF_MOUNT, :state => true, :time => 8.minutes.ago)
ResourceLog.add( :type => ResourceLog::Type::PDF_MOUNT, :state => false, :time => 6.minutes.ago)
end
it "should ADD another entry with NEW state" do
#puts self.method_name
log = nil
expect {
ResourceLog.add( :type => ResourceLog::Type::PDF_MOUNT, :state => true, :time => 5.minutes.ago)
ResourceLog.add( :type => ResourceLog::Type::LDAP, :state => true, :time => 5.minutes.ago)
#puts "2ND: #{@log}";puts
}.to change {ResourceLog.count}.by(2)
end
it "should show all types" do
text = ResourceLog.show_all
text.should_not be_empty
end
it "should calculate duration from prior entry for PDF_MOUNT" do
logs = ResourceLog.where(:type => ResourceLog::Type::PDF_MOUNT).sort('time desc').all
log = logs[1]
log.should_not be_nil
log.duration.should == 1.minutes
end
it "should calculate duration from prior entry for LDAP" do
logs = ResourceLog.where(:type => ResourceLog::Type::LDAP).sort('time desc').all
log = logs[1]
log.should_not be_nil
log.duration.should == 4.minutes
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment