diff --git a/Gemfile b/Gemfile index 9784b5b..12807a4 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 7208fcd..9eb2483 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 @@ -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) @@ -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) @@ -313,6 +319,7 @@ DEPENDENCIES coffee-rails (~> 4.0.0) devise dotenv-rails + email_spec fog fog-aws font-awesome-rails diff --git a/app/assets/javascripts/contact_form.js.coffee b/app/assets/javascripts/contact_form.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/contact_form.js.coffee @@ -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/ diff --git a/app/assets/stylesheets/contact_form.css.scss b/app/assets/stylesheets/contact_form.css.scss new file mode 100644 index 0000000..d3f44be --- /dev/null +++ b/app/assets/stylesheets/contact_form.css.scss @@ -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/ diff --git a/app/controllers/contact_forms_controller.rb b/app/controllers/contact_forms_controller.rb new file mode 100644 index 0000000..4bba28e --- /dev/null +++ b/app/controllers/contact_forms_controller.rb @@ -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 diff --git a/app/helpers/contact_form_helper.rb b/app/helpers/contact_form_helper.rb new file mode 100644 index 0000000..603a2a7 --- /dev/null +++ b/app/helpers/contact_form_helper.rb @@ -0,0 +1,2 @@ +module ContactFormHelper +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..d25d889 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout 'mailer' +end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb new file mode 100644 index 0000000..db9ca6d --- /dev/null +++ b/app/mailers/user_mailer.rb @@ -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 diff --git a/app/views/contact_form/create.html.erb b/app/views/contact_form/create.html.erb new file mode 100644 index 0000000..073bf14 --- /dev/null +++ b/app/views/contact_form/create.html.erb @@ -0,0 +1,2 @@ +

ContactForm#create

+

Find me in app/views/contact_form/create.html.erb

diff --git a/app/views/contact_form/new.html.erb b/app/views/contact_form/new.html.erb new file mode 100644 index 0000000..dcdc05e --- /dev/null +++ b/app/views/contact_form/new.html.erb @@ -0,0 +1,29 @@ +<%= form_for @contact_form do |f| %> + <% if @contact_form.errors.any? %> +
+

<%= pluralize(@contact_form.errors.count, "error") %> prohibited this form from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :name, "Name:" %> + <%= f.text_area :name %> +
+
+ <%= f.label :email, "Name:" %> + <%= f.text_area :email %> +
+
+ <%= f.label :message, "Name:" %> + <%= f.text_area :message %> +
+
+ <%= f.submit "Send"%> +
+<% end %> diff --git a/app/views/user_mailer/contact_email.html.erb b/app/views/user_mailer/contact_email.html.erb new file mode 100644 index 0000000..8f0d87d --- /dev/null +++ b/app/views/user_mailer/contact_email.html.erb @@ -0,0 +1,15 @@ + + + + + + +

Contact from <%= @user.name %>

+

+ <%= @message %> +

+

+ Reply to: <%= @email %>. +

+ + diff --git a/app/views/user_mailer/contact_email.text.erb b/app/views/user_mailer/contact_email.text.erb new file mode 100644 index 0000000..1f4bb93 --- /dev/null +++ b/app/views/user_mailer/contact_email.text.erb @@ -0,0 +1,6 @@ +Contact from <%= @user.name %> +============================== + +<%= @message %> + +Reply to: <%= @email %>. diff --git a/config/environments/development.rb b/config/environments/development.rb index 34c267f..c722ecd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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 } diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index e980d8b..1e2848b 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index c5081b3..98cc184 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000..89ac3af Binary files /dev/null and b/dump.rdb differ diff --git a/test/controllers/contact_form_controller_test.rb b/test/controllers/contact_form_controller_test.rb new file mode 100644 index 0000000..6073cac --- /dev/null +++ b/test/controllers/contact_form_controller_test.rb @@ -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 diff --git a/test/features/mailer_test.rb b/test/features/mailer_test.rb new file mode 100644 index 0000000..116bb2d --- /dev/null +++ b/test/features/mailer_test.rb @@ -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 diff --git a/test/helpers/contact_form_helper_test.rb b/test/helpers/contact_form_helper_test.rb new file mode 100644 index 0000000..48fb9be --- /dev/null +++ b/test/helpers/contact_form_helper_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe ContactFormHelper do + + it "must be a real test" do + flunk "Need real tests" + end + +end diff --git a/test/mailers/previews/user_mailer_preview.rb b/test/mailers/previews/user_mailer_preview.rb new file mode 100644 index 0000000..957e12b --- /dev/null +++ b/test/mailers/previews/user_mailer_preview.rb @@ -0,0 +1,4 @@ +# Preview all emails at http://localhost:3000/rails/mailers/user_mailer +class UserMailerPreview < ActionMailer::Preview + +end diff --git a/test/mailers/user_mailer_test.rb b/test/mailers/user_mailer_test.rb new file mode 100644 index 0000000..5085d95 --- /dev/null +++ b/test/mailers/user_mailer_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe UserMailer do + it "must be a real test" do + flunk "Need real tests" + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index ee2fa14..6976de1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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!