Created
December 28, 2011 23:57
-
-
Save JonKernPA/1530542 to your computer and use it in GitHub Desktop.
Sample RSpec for MongoMapper showing data cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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