Skip to content

Commit

Permalink
generate/generate! can now be thought of as analogs for create/create!
Browse files Browse the repository at this point in the history
  • Loading branch information
ymendel committed Apr 16, 2008
1 parent eaf1e4b commit e80c7b3
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions spec/object_daddy_spec.rb
Expand Up @@ -436,19 +436,31 @@ class Blah < ActiveRecord::Base
end end


it "should return an unsaved record if spawning" do it "should return an unsaved record if spawning" do
Frobnitz.spawn.should be_new_record Thing.spawn.should be_new_record
end end


it "should fail if trying to generate and save an invalid object" do it "should return a saved record if generating" do
lambda { Frobnitz.generate!(:title => 'bob') }.should raise_error(ActiveRecord::RecordInvalid) Thing.generate.should_not be_new_record
end end


it "should return a valid object if generate and save succeeds" do it 'should return a saved record if generating while raising exceptions' do
Frobnitz.generate!(:title => '5', :name => 'blah').should be_valid 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 end


it "should return a saved object if generate and save succeeds" do it "should return an invalid object if trying to generate and save an invalid object" do
Frobnitz.generate!(:title => '5', :name => 'blah').should_not be_new_record 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
end end

1 comment on commit e80c7b3

@chris
Copy link

@chris chris commented on e80c7b3 Apr 23, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.