Skip to content

Instantly share code, notes, and snippets.

@leofrozenyogurt
Created November 7, 2013 00:11
Show Gist options
  • Save leofrozenyogurt/7346607 to your computer and use it in GitHub Desktop.
Save leofrozenyogurt/7346607 to your computer and use it in GitHub Desktop.
class ContactController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(params[:message])
if @message.valid?
Inquiry.reservation(@message).deliver
redirect_to request.referer, flash: { reservation_modal: true }
else
flash[:alert]= "PLEASE MAKE SURE YOU HAVE FILLED EVERYTHING OUT CORRECTLY"
redirect_to request.referer
end
end
end
require 'spec_helper'
describe ContactController do
it "redirects to the home page upon save" do
@message=FactoryGirl.create(:message)
expect(@message).to be_valid
# post :create, contact: FactoryGirl.attributes_for(:message)
# expect(response).to redirect_to root_path
post :create
expect(response).to redirect_to request.referer
end
end
class Message
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :first_name, :last_name, :email, :phone, :message
validates_presence_of :first_name , :email
validates :email, :format => { :with => %r{.+@.+\..+} }
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment