Browse Source

Redirect to url given at return param, when provided.

tags/v0.2.0^2
Bèr Kessels 2 years ago
parent
commit
7b82f7f00d
3 changed files with 26 additions and 14 deletions
  1. 13
    13
      Capfile
  2. 6
    1
      lib/contact.rb
  3. 7
    0
      test/integration/create_message_test.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 }

+ 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', {}

Loading…
Cancel
Save