Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created May 3, 2009 05:15
Show Gist options
  • Save dchelimsky/105857 to your computer and use it in GitHub Desktop.
Save dchelimsky/105857 to your computer and use it in GitHub Desktop.
#These all pass the specs in post_create_with_stubble_spec.rb, but not necessarily the other ones
def create
@registration = Registration.new(params[:registration])
if @registration.save
redirect_to registrations_path
else
render :action => 'new'
end
end
def create
@registration = Registration.create(params[:registration])
if @registration.valid?
redirect_to registrations_path
else
render :action => 'new'
end
end
def create
begin
@registration = Registration.create!(params[:registration])
redirect_to registrations_path
rescue ActiveRecord::RecordInvalid
@registration = Registration.new(params[:registration])
render :action => 'new'
end
end
describe "POST create" do
describe "with valid attributes" do
it "redirects to list of registrations" do
registration = stub_model(Registration)
Registration.stub!(:new).and_return(registration)
registration.stub!(:save!).and_return(true)
post 'create'
response.should redirect_to(registrations_path)
end
end
describe "with invalid attributes" do
it "re-renders the new form" do
registration = stub_model(Registration)
Registration.stub!(:new).and_return(registration)
registration.stub!(:save!).and_raise(ActiveRecord::RecordInvalid.new(registration))
post 'create'
response.should render_template('new')
end
it "assigns the registration" do
registration = stub_model(Registration)
Registration.stub!(:new).and_return(registration)
registration.stub!(:save!).and_raise(ActiveRecord::RecordInvalid.new(registration))
post 'create'
assigns[:registration].should equal(registration)
end
end
end
describe "POST create" do
describe "with valid attributes" do
it "redirects to list of registrations" do
stubble(Registration)
post 'create'
response.should redirect_to(registrations_path)
end
end
describe "with invalid attributes" do
it "re-renders the new form" do
stubble(Registration, :savable => false)
post 'create'
response.should render_template('new')
end
it "assigns the registration" do
registration = stubble(Registration, :savable => false)
post 'create'
assigns[:registration].should equal(registration)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment