Browse Source

Merge branch 'feature/redirect' into develop

* feature/redirect:
  Cleanup Rubocop offences created by Capistrano Boilerplate
  Redirect to url given at return param, when provided.
  Ensiure the test mailer queue is emptied before each test.
tags/v0.2.0^2
Bèr Kessels 2 years ago
parent
commit
ff3606d9c4
7 changed files with 40 additions and 85 deletions
  1. 13
    13
      Capfile
  2. 12
    9
      config/deploy.rb
  3. 1
    1
      config/deploy/production.rb
  4. 0
    61
      config/deploy/staging.rb
  5. 6
    1
      lib/contact.rb
  6. 7
    0
      test/integration/create_message_test.rb
  7. 1
    0
      test/test_helper.rb

+ 13
- 13
Capfile View File

@@ -1,22 +1,22 @@
# Load DSL and set up stages
require "capistrano/setup"
require 'capistrano/setup'

# Include default deployment tasks
require "capistrano/deploy"
require 'capistrano/deploy'

# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# require 'capistrano/scm/hg'
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# require 'capistrano/scm/svn'
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

# Bundle during deploy
require "capistrano/bundler"
require 'capistrano/bundler'

# Include tasks from other gems included in your Gemfile
#
@@ -29,12 +29,12 @@ require "capistrano/bundler"
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
# require "capistrano/rvm"
# require "capistrano/rbenv"
# require "capistrano/chruby"
# require "capistrano/rails/assets"
# require "capistrano/rails/migrations"
# require "capistrano/passenger"
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
# require 'capistrano/passenger'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

+ 12
- 9
config/deploy.rb View File

@@ -1,33 +1,35 @@
# config valid for current version and patch releases of Capistrano
lock "~> 3.10.2"
lock '~> 3.10.2'

set :application, "placebazaar_contact"
set :repo_url, "git@github.com:placebazaar/contact.git"
set :application, 'placebazaar_contact'
set :repo_url, 'git@github.com:placebazaar/contact.git'

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/u/apps/placebazaar_contact"
set :deploy_to, '/u/apps/placebazaar_contact'

# Default value for :format is :airbrussh.
# set :format, :airbrussh

# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# set :format_options, command_output: true, log_file: 'log/capistrano.log',
# color: :auto, truncate: :auto

# Default value for :pty is false
set :pty, true

# Default value for :linked_files is []
# append :linked_files, "config/database.yml"
# append :linked_files, 'config/database.yml'

# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets',
# 'public/system'

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# set :default_env, { path: '/opt/ruby/bin:$PATH' }

# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }
@@ -35,5 +37,6 @@ set :pty, true
# Default value for keep_releases is 5
# set :keep_releases, 5

# Uncomment the following to require manually verifying the host key before first deploy.
# Uncomment the following to require manually verifying the host key before
# first deploy.
# set :ssh_options, verify_host_key: :secure

+ 1
- 1
config/deploy/production.rb View File

@@ -1 +1 @@
server "contact.placebazaar.org", user: "deploy", roles: %w{app db web}
server 'contact.placebazaar.org', user: 'deploy', roles: %w[app db web]

+ 0
- 61
config/deploy/staging.rb View File

@@ -1,61 +0,0 @@
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:

# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
# server "db.example.com", user: "deploy", roles: %w{db}



# role-based syntax
# ==================

# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.

# role :app, %w{deploy@example.com}, my_property: :my_value
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
# role :db, %w{deploy@example.com}



# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.



# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server "example.com",
# user: "user_name",
# roles: %w{web app},
# ssh_options: {
# user: "user_name", # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: "please use keys"
# }

+ 6
- 1
lib/contact.rb View File

@@ -25,7 +25,12 @@ post '/messages' do
Pony.mail(reply_to: @email,
subject: "[Contactform PlaceBazaar] #{@name}",
body: erb(:mail_text))
status 201

if params['return']
redirect params['return']
else
status 201
end
end

def validate(params)

+ 7
- 0
test/integration/create_message_test.rb View File

@@ -26,6 +26,13 @@ describe 'add message through REST' do
end
end

it 'redirects to return url when set' do
return_url = 'https://example.com/return'
post '/messages', params.merge(return: return_url)
assert_response 302
assert_equal return_url, last_response.headers['Location']
end

it 'validates that all fields are set' do
assert_no_changes 'Mail::TestMailer.deliveries.length' do
post '/messages', {}

+ 1
- 0
test/test_helper.rb View File

@@ -25,6 +25,7 @@ module Minitest

before do
Pony.override_options = { via: :test }
Mail::TestMailer.deliveries.clear
end
end
end

Loading…
Cancel
Save