Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ gem 'fog-aws'
gem 'carrierwave_direct'
gem 'sidekiq'

group :test do
gem 'email_spec'
end

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.3.8)
arel (5.0.1.20140414130214)
autoprefixer-rails (2.2.0.20140727)
execjs
Expand Down Expand Up @@ -71,6 +72,9 @@ GEM
dotenv (2.0.0)
dotenv-rails (2.0.0)
dotenv (= 2.0.0)
email_spec (1.6.0)
launchy (~> 2.1)
mail (~> 2.2)
erubis (2.7.0)
excon (0.45.1)
execjs (2.3.0)
Expand Down Expand Up @@ -174,6 +178,8 @@ GEM
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.2)
launchy (2.4.3)
addressable (~> 2.3)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
Expand Down Expand Up @@ -313,6 +319,7 @@ DEPENDENCIES
coffee-rails (~> 4.0.0)
devise
dotenv-rails
email_spec
fog
fog-aws
font-awesome-rails
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/contact_form.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/contact_form.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the contact_form controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
19 changes: 19 additions & 0 deletions app/controllers/contact_forms_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class ContactFormsController < ApplicationController
def new
@contact_form = ContactForm.new
end

def create
begin
@contact_form = ContactForm.new(params[:contact_form])
@contact_form.request = request
if @contact_form.deliver
flash.now[:notice] = "Thank you for your message!"
else
render :new
end
rescue ScriptError
flash[:error] = "Sorry, this image appears to be spam and was not delivered."
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/contact_form_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ContactFormHelper
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
12 changes: 12 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class UserMailer < ApplicationMailer
default from: 'mandakomrodrigues@gmail.com'

def contact_me(user)
@user = user
@email = email
@message = message
mail(to: "mandareneekom@gmail.com",
from: @email,
subject: "Contact from #{@user}")
end
end
2 changes: 2 additions & 0 deletions app/views/contact_form/create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>ContactForm#create</h1>
<p>Find me in app/views/contact_form/create.html.erb</p>
29 changes: 29 additions & 0 deletions app/views/contact_form/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%= form_for @contact_form do |f| %>
<% if @contact_form.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@contact_form.errors.count, "error") %> prohibited this form from being saved:</h2>

<ul>
<% @contact_form.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :name, "Name:" %>
<%= f.text_area :name %>
</div>
<div class="field">
<%= f.label :email, "Name:" %>
<%= f.text_area :email %>
</div>
<div class="field">
<%= f.label :message, "Name:" %>
<%= f.text_area :message %>
</div>
<div class="actions">
<%= f.submit "Send"%>
</div>
<% end %>
15 changes: 15 additions & 0 deletions app/views/user_mailer/contact_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Contact from <%= @user.name %></h1>
<p>
<%= @message %>
</p>
<p>
Reply to: <%= @email %>.
</p>
</body>
</html>
6 changes: 6 additions & 0 deletions app/views/user_mailer/contact_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Contact from <%= @user.name %>
==============================

<%= @message %>

Reply to: <%= @email %>.
12 changes: 11 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "mandakom.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

Expand Down
2 changes: 2 additions & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
<<<<<<< HEAD
# config.secret_key = 'd256155b9e876f5dd6ab1f7391d7e74bab439451b987c8de3da64a4787efc4c8571a0e27735f22003d33bd0f2f0a6a3366536d16d2e6be970d04822b06663901'
config.secret_key = ENV["DEVISE_KEY"]

# ==> Mailer Configuration
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Rails.application.routes.draw do

resources :contact_forms

get 'contact_form/create'

devise_for :users, path_names: {sign_in: "Sign In", sign_out: "Sign Out"},
controllers: {omniauth_callbacks: "omniauth_callbacks"}
resources :users
Expand Down
Binary file added dump.rdb
Binary file not shown.
14 changes: 14 additions & 0 deletions test/controllers/contact_form_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "test_helper"

describe ContactFormController do
it "should get new" do
get :new
assert_response :success
end

it "should get create" do
get :create
assert_response :success
end

end
18 changes: 18 additions & 0 deletions test/features/mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "test_helper"

feature SignupMailer do
include EmailSpec::Helpers
include EmailSpec::Matchers
# if it doesn't work, move below scenario
scenario "the test is sound" do
visit root_path
click_on "Contact me"
fill_in "Name", with: "Peter Piper"
fill_in "Email", with: "me@example.com"
fill_in "Message", with: "Cool website. Can I hire you?"
click_on "Submit"
page.must_have_content "Thank you for your email"
email = UserMailer.create_signup "mandareneekom@gmail.com", "Manda Kom"
email.must deliver_to "mandareneekom@gmail.com"
end
end
9 changes: 9 additions & 0 deletions test/helpers/contact_form_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "test_helper"

describe ContactFormHelper do

it "must be a real test" do
flunk "Need real tests"
end

end
4 changes: 4 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
class UserMailerPreview < ActionMailer::Preview

end
7 changes: 7 additions & 0 deletions test/mailers/user_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

describe UserMailer do
it "must be a real test" do
flunk "Need real tests"
end
end
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "rails/test_help"
require "minitest/rails/capybara"
require "minitest/pride"
require "minitest-matchers"
require "email_spec"

class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!
Expand Down