spec/object_spec.rb in brightbox-object-factory-0.1.3 vs spec/object_spec.rb in brightbox-object-factory-0.2.2

- old
+ new

@@ -95,10 +95,11 @@ end it "should raise an exception if the auto-saved object cannot be saved" do @test_instance = mock('Test Instance') TestClass.should_receive(:new).with({:some => :values}).and_return(@test_instance) + @test_instance.should_receive(:errors).and_return(['errors']) @test_instance.should_receive(:save).and_return(false) lambda { Object.factory.create_and_save_a(TestClass, :some => :values) }.should raise_error(Object::Factory::CannotSaveError) @@ -296,7 +297,41 @@ Object.factory.when_creating_a TestClass, :generate => { :field => lambda { "poop" }, :another_field => lambda { Date.today.to_s } } @instance = Object.factory.create_a TestClass @instance.field.should == 'poop' @instance.another_field.should == Date.today.to_s + end +end + +describe Object::Factory, "generating sequential numbers" do + before :each do + Object.factory.reset + end + + it "should generate a sequential number" do + first = Object.factory.next_number + second = Object.factory.next_number + + second.should == first + 1 + end + + it "should use the shortcut to generate a sequential number" do + Object.factory.should_receive(:next_number).and_return(1) + number = a_number + end +end + +describe Object::Factory, "cleaning up ActiveRecord models" do + before :each do + Object.factory.reset + end + + it "should delete all instances for registered classes" do + Object.factory.when_creating_a TestClass, :auto_confirm => :password, :clean_up => true + Object.factory.when_creating_an AnotherTestClass, :clean_up => true + + TestClass.should_receive(:delete_all).and_return(0) + AnotherTestClass.should_receive(:delete_all).and_return(0) + + Object.factory.clean_up end end \ No newline at end of file