Permalink
Browse files

generate/generate! can now be thought of as analogs for create/create!

  • Loading branch information...
ymendel committed Apr 16, 2008
1 parent eaf1e4b commit e80c7b309481106b672252f55bd483620f4cf053
Showing with 20 additions and 8 deletions.
  1. +20 −8 spec/object_daddy_spec.rb
View
@@ -436,19 +436,31 @@ class Blah < ActiveRecord::Base
end
it "should return an unsaved record if spawning" do
- Frobnitz.spawn.should be_new_record
+ Thing.spawn.should be_new_record
end
- it "should fail if trying to generate and save an invalid object" do
- lambda { Frobnitz.generate!(:title => 'bob') }.should raise_error(ActiveRecord::RecordInvalid)
+ it "should return a saved record if generating" do
+ Thing.generate.should_not be_new_record
end
- it "should return a valid object if generate and save succeeds" do
- Frobnitz.generate!(:title => '5', :name => 'blah').should be_valid
+ it 'should return a saved record if generating while raising exceptions' do
+ Thing.generate!.should_not be_new_record
+ end
+
+ it "should not fail if trying to generate and save an invalid object" do
+ lambda { Frobnitz.generate(:title => 'bob') }.should_not raise_error(ActiveRecord::RecordInvalid)
end
- it "should return a saved object if generate and save succeeds" do
- Frobnitz.generate!(:title => '5', :name => 'blah').should_not be_new_record
+ it "should return an invalid object if trying to generate and save an invalid object" do
+ Frobnitz.generate(:title => 'bob').should_not be_valid
+ end
+
+ it "should fail if trying to generate and save an invalid object while raising acceptions" do
+ lambda { Frobnitz.generate!(:title => 'bob') }.should raise_error(ActiveRecord::RecordInvalid)
+ end
+
+ it "should return a valid object if generate and save succeeds" do
+ Frobnitz.generate(:title => '5', :name => 'blah').should be_valid
end
end
-end
+end

1 comment on commit e80c7b3

@chris

This comment has been minimized.

Show comment
Hide comment
@chris

chris Apr 23, 2008

Thank you!

chris commented on e80c7b3 Apr 23, 2008

Thank you!

Please sign in to comment.