Created
May 3, 2009 05:15
-
-
Save dchelimsky/105857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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