spec/hornsby_spec.rb in sinsiliux-hornsby-0.2.2 vs spec/hornsby_spec.rb in sinsiliux-hornsby-0.2.3
- old
+ new
@@ -72,34 +72,59 @@
end
it "should create big cherry" do
@big_cherry.species.should == 'cherry'
end
+
+ it "should clear scenarios when calling hornsby_clear" do
+ hornsby_clear
+ Fruit.count.should == 0
+ end
end
describe Hornsby, 'with many apples scenario' do
before do
hornsby_scenario :many_apples, :cherry, :cherry_basket
end
it "should create only one apple" do
- Fruit.all(:conditions => 'species = "apple"').count.should == 1
+ Fruit.all(:conditions => 'species = "apple"').size.should == 1
end
it "should create only two cherries even if they were preloaded" do
- Fruit.all(:conditions => 'species = "cherry"').count.should == 2
+ Fruit.all(:conditions => 'species = "cherry"').size.should == 2
end
it "should contain cherries in basket if basket is loaded in test and cherries preloaded" do
@basket.should == [@cherry, @big_cherry]
end
end
+describe Hornsby, 'transactions' do
+ before do
+ hornsby_scenario :just_apple
+ end
+
+ it "should drop only inner transaction" do
+ @apple.reload.should_not be_nil
+ begin
+ ActiveRecord::Base.transaction do
+ f = Fruit.create(:species => 'orange')
+ f.reload.should_not be_nil
+ raise 'some error'
+ end
+ rescue
+ end
+ @apple.reload.should_not be_nil
+ Fruit.find_by_species('orange').should be_nil
+ end
+end
+
#describe Hornsby, "with pitted namespace" do
# before do
# Hornsby.build('pitted:peach').copy_ivars(self)
# end
# it "should have @peach" do
# @peach.species.should == 'peach'
# end
-#end
\ No newline at end of file
+#end