Browse Source

Redirect to url given at return param, when provided.

tags/v0.2.0^2
Bèr Kessels 1 year 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 @@
1 1
 # Load DSL and set up stages
2
-require "capistrano/setup"
2
+require 'capistrano/setup'
3 3
 
4 4
 # Include default deployment tasks
5
-require "capistrano/deploy"
5
+require 'capistrano/deploy'
6 6
 
7 7
 # Load the SCM plugin appropriate to your project:
8 8
 #
9
-# require "capistrano/scm/hg"
9
+# require 'capistrano/scm/hg'
10 10
 # install_plugin Capistrano::SCM::Hg
11 11
 # or
12
-# require "capistrano/scm/svn"
12
+# require 'capistrano/scm/svn'
13 13
 # install_plugin Capistrano::SCM::Svn
14 14
 # or
15
-require "capistrano/scm/git"
15
+require 'capistrano/scm/git'
16 16
 install_plugin Capistrano::SCM::Git
17 17
 
18 18
 # Bundle during deploy
19
-require "capistrano/bundler"
19
+require 'capistrano/bundler'
20 20
 
21 21
 # Include tasks from other gems included in your Gemfile
22 22
 #
@@ -29,12 +29,12 @@ require "capistrano/bundler"
29 29
 #   https://github.com/capistrano/rails
30 30
 #   https://github.com/capistrano/passenger
31 31
 #
32
-# require "capistrano/rvm"
33
-# require "capistrano/rbenv"
34
-# require "capistrano/chruby"
35
-# require "capistrano/rails/assets"
36
-# require "capistrano/rails/migrations"
37
-# require "capistrano/passenger"
32
+# require 'capistrano/rvm'
33
+# require 'capistrano/rbenv'
34
+# require 'capistrano/chruby'
35
+# require 'capistrano/rails/assets'
36
+# require 'capistrano/rails/migrations'
37
+# require 'capistrano/passenger'
38 38
 
39 39
 # Load custom tasks from `lib/capistrano/tasks` if you have any defined
40
-Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
40
+Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

+ 6
- 1
lib/contact.rb View File

@@ -25,7 +25,12 @@ post '/messages' do
25 25
   Pony.mail(reply_to: @email,
26 26
             subject: "[Contactform PlaceBazaar] #{@name}",
27 27
             body: erb(:mail_text))
28
-  status 201
28
+
29
+  if params['return']
30
+    redirect params['return']
31
+  else
32
+    status 201
33
+  end
29 34
 end
30 35
 
31 36
 def validate(params)

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

@@ -26,6 +26,13 @@ describe 'add message through REST' do
26 26
       end
27 27
     end
28 28
 
29
+    it 'redirects to return url when set' do
30
+      return_url = 'https://example.com/return'
31
+      post '/messages', params.merge(return: return_url)
32
+      assert_response 302
33
+      assert_equal return_url, last_response.headers['Location']
34
+    end
35
+
29 36
     it 'validates that all fields are set' do
30 37
       assert_no_changes 'Mail::TestMailer.deliveries.length' do
31 38
         post '/messages', {}

Loading…
Cancel
Save