Rspec lets you assert that data has changed in the scope of a particular block.
it "should delete existing statistics" do
lambda do
@structure_updater.update_structure
end.should change(SeAccount, :count).by(3)
end
...or some such depending on what your schema looks like, etc. Not sure what exactly is going on in delete_existing_statistics so modify the change clause accordingly.
EDIT: Didn't understand the question at first, my apologies. You could try asserting the following to make sure these calls occur in a given order (again, using RSpec):
EDIT: You can't assert an expectation against a transaction in a test that has expectations for calls within that transaction. The closest I could come up with off the cuff was:
describe StructureUpdater do
before(:each) do
@structure_updater = StructureUpdater.new(Structure.new)
end
it "should update the model within a Transaction" do
SeAccount.should_receive(:transaction)
@structure_updater.update_structure
end
it "should do these other things" do
@structure_updater.should_receive(:delete_existing_statistics).ordered
@structure_updater.should_receive(:delete_existing_structure).ordered
@structure_updater.should_receive(:add_campaigns).ordered
@structure_updater.update_structure
end
end
ONE MORE TRY: Another minor hack would be to force one of the later method calls in the transaction block to raise, and assert that nothing has changed in the DB. For instance, assuming Statistic is a model, and delete_existing_statistics would change the count of Statistic in the DB, you could know that call occurred in a transaction if an exception thrown later in the transaction rolled back that change. Something like:
it "should happen in a transaction" do
@structure_updater.stub!(:add_campaigns).and_raise
lambda {@structure_updater.update_structure}.should_not change(Statistic, :count)
end