def create @contact = Contact.new(params[:contact]) if @contact.valid? # Code to send the contact mail else render 'new' end end end Tuesday, August 28, 12
it "is valid with valid attributes" do should be_valid end it "is not valid without name" do subject.name = nil should_not be_valid end it "is not valid without (or with invalid) email" do subject.email = nil should_not be_valid subject.email = "invalid email" should_not be_valid end it "is not valid without body" do subject.body = nil should_not be_valid end end Tuesday, August 28, 12
# #new removed for briefness def create @contact = Contact.new(contact_params) if @contact.valid? # blabla else render 'new' end end private def contact_params params[:contact] ||= {} sanitize_for_mass_assignment(params[:contact]) end end Tuesday, August 28, 12