token_action 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/README.md +11 -18
  4. data/Rakefile +13 -4
  5. data/app/controllers/token_action/tokens_controller.rb +19 -11
  6. data/config/routes.rb +1 -1
  7. data/lib/generators/active_record/templates/migration.rb +1 -1
  8. data/lib/generators/templates/README +1 -1
  9. data/lib/token_action.rb +2 -2
  10. data/lib/token_action/{mixins → concerns}/model.rb +0 -0
  11. data/lib/token_action/{mixins → concerns}/token_generator.rb +0 -0
  12. data/lib/token_action/orm/mongoid.rb +6 -6
  13. data/lib/token_action/version.rb +1 -1
  14. data/spec/controllers/token_action/tokens_controller_spec.rb +159 -157
  15. data/spec/dummy/Rakefile +1 -2
  16. data/spec/dummy/app/assets/javascripts/application.js +4 -4
  17. data/spec/dummy/app/assets/stylesheets/application.css +6 -4
  18. data/spec/dummy/app/controllers/application_controller.rb +3 -1
  19. data/spec/dummy/app/controllers/hello_controller.rb +6 -6
  20. data/spec/dummy/app/mongoid/cat.rb +1 -1
  21. data/spec/dummy/app/views/layouts/application.html.erb +2 -2
  22. data/spec/dummy/bin/bundle +3 -0
  23. data/spec/dummy/bin/rails +4 -0
  24. data/spec/dummy/bin/rake +4 -0
  25. data/spec/dummy/bin/setup +29 -0
  26. data/spec/dummy/config.ru +2 -2
  27. data/spec/dummy/config/application.rb +11 -42
  28. data/spec/dummy/config/boot.rb +4 -9
  29. data/spec/dummy/config/database.yml +14 -7
  30. data/spec/dummy/config/environment.rb +3 -3
  31. data/spec/dummy/config/environments/development.rb +22 -18
  32. data/spec/dummy/config/environments/production.rb +46 -34
  33. data/spec/dummy/config/environments/test.rb +18 -17
  34. data/spec/dummy/config/initializers/assets.rb +11 -0
  35. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  36. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  37. data/spec/dummy/config/initializers/session_store.rb +1 -6
  38. data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
  39. data/spec/dummy/config/locales/en.yml +20 -2
  40. data/spec/dummy/config/mongoid.yml +4 -60
  41. data/spec/dummy/config/routes.rb +6 -6
  42. data/spec/dummy/config/secrets.yml +22 -0
  43. data/spec/dummy/db/migrate/20130104151630_create_token_action_tokens.rb +1 -1
  44. data/spec/dummy/db/schema.rb +32 -0
  45. data/spec/dummy/{db/development.sqlite3 → log/.keep} +0 -0
  46. data/spec/dummy/public/404.html +54 -13
  47. data/spec/dummy/public/422.html +54 -13
  48. data/spec/dummy/public/500.html +53 -12
  49. data/spec/factories.rb +1 -1
  50. data/spec/rails_helper.rb +102 -0
  51. data/spec/routing/token_action/tokens_routing_spec.rb +23 -23
  52. data/spec/spec_helper.rb +85 -87
  53. data/spec/token_action/concerns/model_spec.rb +14 -0
  54. data/spec/token_action/concerns/token_generator_spec.rb +13 -0
  55. data/spec/token_action/orm/active_record_spec.rb +4 -2
  56. data/spec/token_action/orm/mongoid_spec.rb +4 -2
  57. data/spec/token_action_spec.rb +9 -9
  58. metadata +109 -158
  59. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  60. data/spec/dummy/log/development.log +0 -16
  61. data/spec/dummy/log/test.log +0 -4739
  62. data/spec/dummy/script/rails +0 -6
  63. data/spec/token_action/mixins/model_spec.rb +0 -13
  64. data/spec/token_action/mixins/token_generator_spec.rb +0 -11
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85d900369c77734a24aa10bc37527ce4bb7a47c5
4
+ data.tar.gz: 0dafd5321105460b8eb6dec7179406dfd024ffe2
5
+ SHA512:
6
+ metadata.gz: f44e1b756a0917db2b7a65d4e9852cd2d86a40b977f4fdb2756bedde6edfefe961cbfb1da0b2e854b655cef11f5ea8bac84e8b74d8a4c10ad747ce07f5188bb8
7
+ data.tar.gz: c0f1dd85cdd3d9f4a7e7446ef3bfc2886bb28e4ad038310fb5b526f02de37454e44f8065b7187223535c5652e4ec148b452c2d44e103486ab296dedd943a2acb
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Open North Inc.
1
+ Copyright (c) 2013 James McKinney
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # TokenAction
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/opennorth/token_action.png)](http://travis-ci.org/opennorth/token_action)
4
- [![Dependency Status](https://gemnasium.com/opennorth/token_action.png)](https://gemnasium.com/opennorth/token_action)
5
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/opennorth/token_action)
3
+ [![Gem Version](https://badge.fury.io/rb/token_action.svg)](https://badge.fury.io/rb/token_action)
4
+ [![Build Status](https://secure.travis-ci.org/jpmckinney/token_action.png)](https://travis-ci.org/jpmckinney/token_action)
5
+ [![Dependency Status](https://gemnasium.com/jpmckinney/token_action.png)](https://gemnasium.com/jpmckinney/token_action)
6
+ [![Coverage Status](https://coveralls.io/repos/jpmckinney/token_action/badge.png)](https://coveralls.io/r/jpmckinney/token_action)
7
+ [![Code Climate](https://codeclimate.com/github/jpmckinney/token_action.png)](https://codeclimate.com/github/jpmckinney/token_action)
6
8
 
7
9
  TokenAction lets you create tokens to be used to authenticate actions. For example:
8
10
 
@@ -29,7 +31,7 @@ If you are using ActiveRecord, run the migration:
29
31
 
30
32
  Create a shared secret to confirm a user account, for example:
31
33
 
32
- token = TokenAction::Token.create! :kind => 'User', :args => [1, :confirm]
34
+ token = TokenAction::Token.create! kind: 'User', args: [1, :confirm]
33
35
  token.token # a 20-character alphanumeric string like "j7NtCaYfUpZXyDCseKG2"
34
36
 
35
37
  You can then send the token with instructions to the user via email. When the user visits `/tokens/j7NtCaYfUpZXyDCseKG2/confirm`, TokenAction will look up the token. If not found, it will log an informational message to the Rails logger, set `flash[:alert]` and redirect to the `root_path`. If found, it will call the `redeem_token` method on the `User` class, passing in the arguments `1` and `:confirm`. You must implement the public `redeem_token` method. For example:
@@ -54,7 +56,7 @@ You can customize the redirect URLs, the routes, the flash messages and the toke
54
56
 
55
57
  To change the default success and failure URLs from `root_path`, edit the `config/initializers/token_action.rb` file created by `rails generate token_action`. You may also set success and failure URLs for each token, by creating tokens with `:success_url` and `:failure_url` arguments:
56
58
 
57
- token = TokenAction::Token.create! :kind => 'Cat', :success_url => cat_path(1), :failure_url => '/oops'
59
+ token = TokenAction::Token.create! kind: 'Cat', success_url: cat_path(1), failure_url: '/oops'
58
60
 
59
61
  **Note:** If you change your URL structure after creating tokens, TokenAction may attempt to redirect to an unroutable path. If a path is unroutable, TokenAction will redirect to another URL in this order of precedence:
60
62
 
@@ -72,13 +74,13 @@ If an exception was raised and a path is unroutable, it will redirect in this or
72
74
 
73
75
  The TokenAction generator will add `mount TokenAction::Engine => '/token_action'` to your routes, which defines:
74
76
 
75
- get 'tokens/:token/*path', :to => 'tokens#redeem'
77
+ get 'tokens/:token/*path', to: 'tokens#redeem'
76
78
 
77
79
  As such, you can write URLs like `tokens/xxx/confirm` or `tokens/xxx/unsubscribe` or `tokens/xxx/a/b/c`.
78
80
 
79
81
  To customize the first part of the route, replace `mount TokenAction::Engine => '/token_action'` with something like:
80
82
 
81
- get 'jetons/:token/*path', :to => 'token_action/tokens#redeem'
83
+ get 'jetons/:token/*path', to: 'token_action/tokens#redeem'
82
84
 
83
85
  ### Flash messages
84
86
 
@@ -110,7 +112,7 @@ To customize the controller without monkey patching, create a new controller lik
110
112
 
111
113
  And replace the route with something like:
112
114
 
113
- get 'tokens/:token/*path', :to => 'tokens#redeem'
115
+ get 'tokens/:token/*path', to: 'tokens#redeem'
114
116
 
115
117
  You can then override the `redeem` method in your new controller.
116
118
 
@@ -131,13 +133,4 @@ If using Sequel, you will want to use the [orm_adapter-sequel](https://github.co
131
133
  * If you change the name of a class, update the `kind` attribute on its tokens to avoid making them unprocessable.
132
134
  * Be careful when changing the behavior of a `redeem_token` method, to avoid making tokens unprocessable.
133
135
 
134
- ## Roadmap
135
-
136
- * The tokens controller only responds to HTML requests. Pull requests to add JSON and XML responders are welcome!
137
- * The generators do not have specs.
138
-
139
- ## Bugs? Questions?
140
-
141
- This engine's main repository is on GitHub: [http://github.com/opennorth/token_action](http://github.com/opennorth/token_action), where your contributions, forks, bug reports, feature requests, and feedback are greatly welcomed.
142
-
143
- Copyright (c) 2012 Open North Inc., released under the MIT license
136
+ Copyright (c) 2012 James McKinney, released under the MIT license
data/Rakefile CHANGED
@@ -1,10 +1,19 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ require 'thor'
11
+ helper = Bundler::GemHelper.new
12
+ helper.install
3
13
 
4
14
  require 'rspec/core/rake_task'
5
15
  RSpec::Core::RakeTask.new(:spec)
6
-
7
- task :default => :spec
16
+ task default: :spec
8
17
 
9
18
  begin
10
19
  require 'yard'
@@ -1,20 +1,22 @@
1
+ require_dependency 'token_action/application_controller'
2
+
1
3
  module TokenAction
2
4
  class TokensController < ApplicationController
3
5
  def redeem
4
- @token = TokenAction::Token.to_adapter.find_first(:token => params[:token])
6
+ @token = TokenAction::Token.to_adapter.find_first(token: params[:token])
5
7
  if @token
6
8
  begin
7
9
  # Do this in the controller's scope to allow access to request methods.
8
10
  ActiveSupport::Inflector.constantize(@token.kind).redeem_token(*@token.args)
9
- redirect_to success_url, :notice => translate(:success)
11
+ redirect_to success_url, notice: translate(:success)
10
12
  rescue => e
11
- key = ActiveSupport::Inflector.underscore(e.class).gsub('/', I18n.default_separator)
13
+ key = ActiveSupport::Inflector.underscore(e.class.name).gsub('/', I18n.default_separator)
12
14
  logger.warn "TokenAction failed to perform the action for the token '#{params[:token]}': #{e.message}"
13
- redirect_to failure_url, :alert => translate(key, :failure)
15
+ redirect_to failure_url, alert: translate(key, :failure)
14
16
  end
15
17
  else
16
18
  logger.info "TokenAction failed to find the token '#{params[:token]}'"
17
- redirect_to failure_url, :alert => translate(:not_found)
19
+ redirect_to failure_url, alert: translate(:not_found)
18
20
  end
19
21
  end
20
22
 
@@ -39,23 +41,29 @@ module TokenAction
39
41
  end
40
42
 
41
43
  key, *default = *keys
42
- I18n.translate(key, :default => default)
44
+ I18n.translate(key, default: default)
43
45
  end
44
46
 
45
47
  # Returns the success URL.
46
48
  #
47
49
  # @return [String] a URL
48
50
  def success_url
49
- [@token && @token.success_url, TokenAction.success_url].find do |url|
50
- url.present? && routable?(url)
51
- end || main_app.root_path
51
+ redirect_url([@token && @token.success_url, TokenAction.success_url])
52
52
  end
53
53
 
54
54
  # Returns the failure URL.
55
55
  #
56
56
  # @return [String] a URL
57
57
  def failure_url
58
- [@token && @token.failure_url, TokenAction.failure_url].find do |url|
58
+ redirect_url([@token && @token.failure_url, TokenAction.failure_url])
59
+ end
60
+
61
+ # Returns the routeable URL with the highest preference.
62
+ #
63
+ # @param [Array<String>] a list of URLs in order of preference
64
+ # @return [String] the routable URL with the highest preference
65
+ def redirect_url(urls)
66
+ urls.find do |url|
59
67
  url.present? && routable?(url)
60
68
  end || main_app.root_path
61
69
  end
@@ -65,7 +73,7 @@ module TokenAction
65
73
  # @param [String] path a path
66
74
  # @return [Boolean] whether the path is routable
67
75
  def routable?(path)
68
- !!Rails.application.routes.recognize_path(path, :method => :get)
76
+ !!Rails.application.routes.recognize_path(path, method: :get)
69
77
  rescue ActionController::RoutingError
70
78
  false
71
79
  end
@@ -1,3 +1,3 @@
1
1
  TokenAction::Engine.routes.draw do
2
- get 'tokens/:token/*path', :to => 'tokens#redeem'
2
+ get 'tokens/:token/*path', to: 'tokens#redeem'
3
3
  end
@@ -10,6 +10,6 @@ class CreateTokenActionTokens < ActiveRecord::Migration
10
10
  t.timestamps
11
11
  end
12
12
 
13
- add_index :token_action_tokens, :token, :unique => true
13
+ add_index :token_action_tokens, :token, unique: true
14
14
  end
15
15
  end
@@ -2,7 +2,7 @@ To complete the installation of TokenAction:
2
2
 
3
3
  1. Define a root route in config/routes.rb. For example:
4
4
 
5
- root :to => 'home#index'
5
+ root to: 'home#index'
6
6
 
7
7
  2. Add flash messages to app/views/layouts/application.html.erb. For example:
8
8
 
@@ -67,5 +67,5 @@ module TokenAction
67
67
  end
68
68
  end
69
69
 
70
- require 'token_action/mixins/token_generator'
71
- require 'token_action/mixins/model'
70
+ require 'token_action/concerns/token_generator'
71
+ require 'token_action/concerns/model'
@@ -10,25 +10,25 @@ module TokenAction
10
10
 
11
11
  # A shared secret.
12
12
  # @return [String] a token
13
- field :token, :type => String
13
+ field :token, type: String
14
14
 
15
15
  # The class on which to perform the action.
16
16
  # @return [String] a class name
17
17
  # @note `class` clashes with `Object#class` and Mongoid reserves `klass`.
18
- field :kind, :type => String
18
+ field :kind, type: String
19
19
 
20
20
  # Any additional arguments for the action.
21
21
  # @return [Array] a list of arguments
22
- field :args, :type => Array
22
+ field :args, type: Array
23
23
 
24
24
  # The URL to redirect to after performing the action successfully.
25
25
  # @return [String] a URL or path
26
- field :success_url, :type => String
26
+ field :success_url, type: String
27
27
 
28
28
  # The URL to redirect to after failing to perform the action.
29
29
  # @return [String] a URL or path
30
- field :failure_url, :type => String
30
+ field :failure_url, type: String
31
31
 
32
- index({:token => 1}, :unique => true)
32
+ index({token: 1}, unique: true)
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module TokenAction
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,171 +1,173 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
- describe TokenAction::TokensController do
4
- before :each do
5
- @routes = TokenAction::Engine.routes
6
- end
3
+ module TokenAction
4
+ RSpec.describe TokensController, type: :controller do
5
+ before :each do
6
+ @routes = TokenAction::Engine.routes
7
+ end
7
8
 
8
- describe 'GET redeem' do
9
- context 'after failing to perform the action' do
10
- let :token_with_failure_url do
11
- FactoryGirl.create(:token, :args => ['upgrade'], :failure_url => '/hello/token_failure').token
12
- end
13
- let :token_with_unroutable_failure_url do
14
- FactoryGirl.create(:token, :args => ['upgrade'], :failure_url => '/missing').token
15
- end
16
- let :token_without_failure_url do
17
- FactoryGirl.create(:token, :args => ['upgrade']).token
18
- end
19
- let :token_with_error do
20
- FactoryGirl.create(:token, :args => ['metamorphose']).token
21
- end
22
- let :token_with_namespaced_error do
23
- FactoryGirl.create(:token, :args => ['fly']).token
24
- end
9
+ describe 'GET redeem' do
10
+ context 'after failing to perform the action' do
11
+ let :token_with_failure_url do
12
+ FactoryGirl.create(:token, args: ['upgrade'], failure_url: '/hello/token_failure').token
13
+ end
14
+ let :token_with_unroutable_failure_url do
15
+ FactoryGirl.create(:token, args: ['upgrade'], failure_url: '/missing').token
16
+ end
17
+ let :token_without_failure_url do
18
+ FactoryGirl.create(:token, args: ['upgrade']).token
19
+ end
20
+ let :token_with_error do
21
+ FactoryGirl.create(:token, args: ['metamorphose']).token
22
+ end
23
+ let :token_with_namespaced_error do
24
+ FactoryGirl.create(:token, args: ['fly']).token
25
+ end
25
26
 
26
- it "redirects to the token's failure URL" do
27
- TokenAction.failure_url = '/hello/failure'
28
- get :redeem, :token => token_with_failure_url, :path => 'redeem'
29
- response.should redirect_to '/hello/token_failure'
30
- end
31
- it "redirects to the default failure URL if the token's failure URL is not routable" do
32
- TokenAction.failure_url = '/hello/failure'
33
- get :redeem, :token => token_with_unroutable_failure_url, :path => 'redeem'
34
- response.should redirect_to '/hello/failure'
35
- end
36
- it "redirects to the default failure URL if the token's failure URL is not set" do
37
- TokenAction.failure_url = '/hello/failure'
38
- get :redeem, :token => token_without_failure_url, :path => 'redeem'
39
- response.should redirect_to '/hello/failure'
40
- end
41
- it "redirects to the application's root_path if the default failure URL is not routable" do
42
- TokenAction.failure_url = '/missing'
43
- get :redeem, :token => token_without_failure_url, :path => 'redeem'
44
- response.should redirect_to Rails.application.routes.url_for(:controller => 'hello', :action => 'hello')
45
- end
46
- it "redirects to the application's root_path if the default failure URL is not set" do
47
- TokenAction.failure_url = nil
48
- get :redeem, :token => token_without_failure_url, :path => 'redeem'
49
- response.should redirect_to Rails.application.routes.url_for(:controller => 'hello', :action => 'hello')
50
- end
27
+ it "redirects to the token's failure URL" do
28
+ TokenAction.failure_url = '/hello/failure'
29
+ get :redeem, token: token_with_failure_url, path: 'redeem'
30
+ expect(response).to redirect_to('/hello/token_failure')
31
+ end
32
+ it "redirects to the default failure URL if the token's failure URL is not routable" do
33
+ TokenAction.failure_url = '/hello/failure'
34
+ get :redeem, token: token_with_unroutable_failure_url, path: 'redeem'
35
+ expect(response).to redirect_to('/hello/failure')
36
+ end
37
+ it "redirects to the default failure URL if the token's failure URL is not set" do
38
+ TokenAction.failure_url = '/hello/failure'
39
+ get :redeem, token: token_without_failure_url, path: 'redeem'
40
+ expect(response).to redirect_to('/hello/failure')
41
+ end
42
+ it "redirects to the application's root_path if the default failure URL is not routable" do
43
+ TokenAction.failure_url = '/missing'
44
+ get :redeem, token: token_without_failure_url, path: 'redeem'
45
+ expect(response).to redirect_to(Rails.application.routes.url_for(controller: 'hello', action: 'hello', only_path: true))
46
+ end
47
+ it "redirects to the application's root_path if the default failure URL is not set" do
48
+ TokenAction.failure_url = nil
49
+ get :redeem, token: token_without_failure_url, path: 'redeem'
50
+ expect(response).to redirect_to(Rails.application.routes.url_for(controller: 'hello', action: 'hello', only_path: true))
51
+ end
51
52
 
52
- it 'flashes a path-based, error-based failure message' do
53
- get :redeem, :token => token_with_error, :path => 'confirm'
54
- flash[:notice].should be_nil
55
- flash[:alert].should == 'This is an path-based, error-based failure message.'
56
- end
57
- it 'flashes a error-based failure message' do
58
- get :redeem, :token => token_with_error, :path => 'redeem'
59
- flash[:notice].should be_nil
60
- flash[:alert].should == 'This is an error-based failure message.'
61
- end
62
- it 'flashes a long error-based failure message' do
63
- get :redeem, :token => token_with_namespaced_error, :path => 'redeem'
64
- flash[:notice].should be_nil
65
- flash[:alert].should == 'This is another error-based failure message.'
66
- end
67
- it 'flashes a path-based failure message' do
68
- get :redeem, :token => token_without_failure_url, :path => 'confirm'
69
- flash[:notice].should be_nil
70
- flash[:alert].should == 'This is a path-based failure message.'
71
- end
72
- it 'flashes a long path-based failure message' do
73
- get :redeem, :token => token_without_failure_url, :path => 'a/b/c'
74
- flash[:notice].should be_nil
75
- flash[:alert].should == 'This is another path-based failure message.'
76
- end
77
- it 'flashes the default failure message' do
78
- get :redeem, :token => token_without_failure_url, :path => 'redeem'
79
- flash[:notice].should be_nil
80
- flash[:alert].should == 'An error occurred while processing your request.'
53
+ it 'flashes a path-based, error-based failure message' do
54
+ get :redeem, token: token_with_error, path: 'confirm'
55
+ expect(flash[:notice]).to eq(nil)
56
+ expect(flash[:alert]).to eq('This is an path-based, error-based failure message.')
57
+ end
58
+ it 'flashes a error-based failure message' do
59
+ get :redeem, token: token_with_error, path: 'redeem'
60
+ expect(flash[:notice]).to eq(nil)
61
+ expect(flash[:alert]).to eq('This is an error-based failure message.')
62
+ end
63
+ it 'flashes a long error-based failure message' do
64
+ get :redeem, token: token_with_namespaced_error, path: 'redeem'
65
+ expect(flash[:notice]).to eq(nil)
66
+ expect(flash[:alert]).to eq('This is another error-based failure message.')
67
+ end
68
+ it 'flashes a path-based failure message' do
69
+ get :redeem, token: token_without_failure_url, path: 'confirm'
70
+ expect(flash[:notice]).to eq(nil)
71
+ expect(flash[:alert]).to eq('This is a path-based failure message.')
72
+ end
73
+ it 'flashes a long path-based failure message' do
74
+ get :redeem, token: token_without_failure_url, path: 'a/b/c'
75
+ expect(flash[:notice]).to eq(nil)
76
+ expect(flash[:alert]).to eq('This is another path-based failure message.')
77
+ end
78
+ it 'flashes the default failure message' do
79
+ get :redeem, token: token_without_failure_url, path: 'redeem'
80
+ expect(flash[:notice]).to eq(nil)
81
+ expect(flash[:alert]).to eq('An error occurred while processing your request.')
82
+ end
81
83
  end
82
- end
83
84
 
84
- context 'when the token is not found' do
85
- it 'redirects to the default failure URL' do
86
- TokenAction.failure_url = '/hello/not_found'
87
- get :redeem, :token => 'missing', :path => 'redeem'
88
- response.should redirect_to '/hello/not_found'
89
- end
90
- it "redirects to the application's root_path if the default failure URL is not routable" do
91
- TokenAction.failure_url = '/missing'
92
- get :redeem, :token => 'missing', :path => 'redeem'
93
- response.should redirect_to Rails.application.routes.url_for(:controller => 'hello', :action => 'hello')
94
- end
95
- it "redirects to the application's root_path if the default failure URL is not set" do
96
- TokenAction.failure_url = nil
97
- get :redeem, :token => 'missing', :path => 'redeem'
98
- response.should redirect_to Rails.application.routes.url_for(:controller => 'hello', :action => 'hello')
99
- end
85
+ context 'when the token is not found' do
86
+ it 'redirects to the default failure URL' do
87
+ TokenAction.failure_url = '/hello/not_found'
88
+ get :redeem, token: 'missing', path: 'redeem'
89
+ expect(response).to redirect_to('/hello/not_found')
90
+ end
91
+ it "redirects to the application's root_path if the default failure URL is not routable" do
92
+ TokenAction.failure_url = '/missing'
93
+ get :redeem, token: 'missing', path: 'redeem'
94
+ expect(response).to redirect_to(Rails.application.routes.url_for(controller: 'hello', action: 'hello', only_path: true))
95
+ end
96
+ it "redirects to the application's root_path if the default failure URL is not set" do
97
+ TokenAction.failure_url = nil
98
+ get :redeem, token: 'missing', path: 'redeem'
99
+ expect(response).to redirect_to(Rails.application.routes.url_for(controller: 'hello', action: 'hello', only_path: true))
100
+ end
100
101
 
101
- it 'flashes a path-based failure message' do
102
- get :redeem, :token => 'missing', :path => 'confirm'
103
- flash[:notice].should be_nil
104
- flash[:alert].should == 'This is a path-based not found message.'
105
- end
106
- it 'flashes a long path-based failure message' do
107
- get :redeem, :token => 'missing', :path => 'a/b/c'
108
- flash[:notice].should be_nil
109
- flash[:alert].should == 'This is another path-based not found message.'
102
+ it 'flashes a path-based failure message' do
103
+ get :redeem, token: 'missing', path: 'confirm'
104
+ expect(flash[:notice]).to eq(nil)
105
+ expect(flash[:alert]).to eq('This is a path-based not found message.')
106
+ end
107
+ it 'flashes a long path-based failure message' do
108
+ get :redeem, token: 'missing', path: 'a/b/c'
109
+ expect(flash[:notice]).to eq(nil)
110
+ expect(flash[:alert]).to eq('This is another path-based not found message.')
111
+ end
112
+ it 'flashes the default failure message if no path-based failure message is set' do
113
+ get :redeem, token: 'missing', path: 'redeem'
114
+ expect(flash[:notice]).to eq(nil)
115
+ expect(flash[:alert]).to eq('Sorry, your request could not be processed.')
116
+ end
110
117
  end
111
- it 'flashes the default failure message if no path-based failure message is set' do
112
- get :redeem, :token => 'missing', :path => 'redeem'
113
- flash[:notice].should be_nil
114
- flash[:alert].should == 'Sorry, your request could not be processed.'
115
- end
116
- end
117
118
 
118
- context 'after performing the action successfully' do
119
- let :token_with_success_url do
120
- FactoryGirl.create(:token, :success_url => '/hello/token_success').token
121
- end
122
- let :token_with_unroutable_success_url do
123
- FactoryGirl.create(:token, :success_url => '/missing').token
124
- end
125
- let :token_without_success_url do
126
- FactoryGirl.create(:token).token
127
- end
119
+ context 'after performing the action successfully' do
120
+ let :token_with_success_url do
121
+ FactoryGirl.create(:token, success_url: '/hello/token_success').token
122
+ end
123
+ let :token_with_unroutable_success_url do
124
+ FactoryGirl.create(:token, success_url: '/missing').token
125
+ end
126
+ let :token_without_success_url do
127
+ FactoryGirl.create(:token).token
128
+ end
128
129
 
129
- it "redirects to the token's success URL" do
130
- TokenAction.success_url = '/hello/success'
131
- get :redeem, :token => token_with_success_url, :path => 'redeem'
132
- response.should redirect_to '/hello/token_success'
133
- end
134
- it "redirects to the default success URL if the token's success URL is not routable" do
135
- TokenAction.success_url = '/hello/success'
136
- get :redeem, :token => token_with_unroutable_success_url, :path => 'redeem'
137
- response.should redirect_to '/hello/success'
138
- end
139
- it "redirects to the default success URL if the token's success URL is not set" do
140
- TokenAction.success_url = '/hello/success'
141
- get :redeem, :token => token_without_success_url, :path => 'redeem'
142
- response.should redirect_to '/hello/success'
143
- end
144
- it "redirects to the application's root_path if the default success URL is not routable" do
145
- TokenAction.success_url = '/missing'
146
- get :redeem, :token => token_without_success_url, :path => 'redeem'
147
- response.should redirect_to Rails.application.routes.url_for(:controller => 'hello', :action => 'hello')
148
- end
149
- it "redirects to the application's root_path if the default success URL is not set" do
150
- TokenAction.success_url = nil
151
- get :redeem, :token => token_without_success_url, :path => 'redeem'
152
- response.should redirect_to Rails.application.routes.url_for(:controller => 'hello', :action => 'hello')
153
- end
130
+ it "redirects to the token's success URL" do
131
+ TokenAction.success_url = '/hello/success'
132
+ get :redeem, token: token_with_success_url, path: 'redeem'
133
+ expect(response).to redirect_to('/hello/token_success')
134
+ end
135
+ it "redirects to the default success URL if the token's success URL is not routable" do
136
+ TokenAction.success_url = '/hello/success'
137
+ get :redeem, token: token_with_unroutable_success_url, path: 'redeem'
138
+ expect(response).to redirect_to('/hello/success')
139
+ end
140
+ it "redirects to the default success URL if the token's success URL is not set" do
141
+ TokenAction.success_url = '/hello/success'
142
+ get :redeem, token: token_without_success_url, path: 'redeem'
143
+ expect(response).to redirect_to('/hello/success')
144
+ end
145
+ it "redirects to the application's root_path if the default success URL is not routable" do
146
+ TokenAction.success_url = '/missing'
147
+ get :redeem, token: token_without_success_url, path: 'redeem'
148
+ expect(response).to redirect_to(Rails.application.routes.url_for(controller: 'hello', action: 'hello', only_path: true))
149
+ end
150
+ it "redirects to the application's root_path if the default success URL is not set" do
151
+ TokenAction.success_url = nil
152
+ get :redeem, token: token_without_success_url, path: 'redeem'
153
+ expect(response).to redirect_to(Rails.application.routes.url_for(controller: 'hello', action: 'hello', only_path: true))
154
+ end
154
155
 
155
- it 'flashes a path-based success message' do
156
- get :redeem, :token => token_without_success_url, :path => 'confirm'
157
- flash[:notice].should == 'This is a path-based success message.'
158
- flash[:alert].should be_nil
159
- end
160
- it 'flashes a long path-based success message' do
161
- get :redeem, :token => token_without_success_url, :path => 'a/b/c'
162
- flash[:notice].should == 'This is another path-based success message.'
163
- flash[:alert].should be_nil
164
- end
165
- it 'flashes the default success message if no path-based success message is set' do
166
- get :redeem, :token => token_without_success_url, :path => 'redeem'
167
- flash[:notice].should == 'Your request was successfully processed.'
168
- flash[:alert].should be_nil
156
+ it 'flashes a path-based success message' do
157
+ get :redeem, token: token_without_success_url, path: 'confirm'
158
+ expect(flash[:notice]).to eq('This is a path-based success message.')
159
+ expect(flash[:alert]).to eq(nil)
160
+ end
161
+ it 'flashes a long path-based success message' do
162
+ get :redeem, token: token_without_success_url, path: 'a/b/c'
163
+ expect(flash[:notice]).to eq('This is another path-based success message.')
164
+ expect(flash[:alert]).to eq(nil)
165
+ end
166
+ it 'flashes the default success message if no path-based success message is set' do
167
+ get :redeem, token: token_without_success_url, path: 'redeem'
168
+ expect(flash[:notice]).to eq('Your request was successfully processed.')
169
+ expect(flash[:alert]).to eq(nil)
170
+ end
169
171
  end
170
172
  end
171
173
  end