Created
November 7, 2013 00:11
-
-
Save leofrozenyogurt/7346607 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
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