devise_masquerade 0.6.4 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of devise_masquerade might be problematic. Click here for more details.

Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +2 -4
  5. data/Gemfile +14 -10
  6. data/Gemfile.lock +303 -0
  7. data/Makefile +6 -1
  8. data/README.md +25 -1
  9. data/app/controllers/devise/masquerades_controller.rb +70 -54
  10. data/devise_masquerade.gemspec +4 -4
  11. data/features/back.feature +0 -1
  12. data/features/multiple_masquerading_models.feature +17 -0
  13. data/features/step_definitions/auth_steps.rb +1 -0
  14. data/features/step_definitions/back_steps.rb +18 -3
  15. data/features/support/env.rb +23 -4
  16. data/lib/devise_masquerade/controllers/helpers.rb +26 -7
  17. data/lib/devise_masquerade/controllers/url_helpers.rb +19 -4
  18. data/lib/devise_masquerade/models/masqueradable.rb +47 -0
  19. data/lib/devise_masquerade/models.rb +9 -0
  20. data/lib/devise_masquerade/rails.rb +14 -4
  21. data/lib/devise_masquerade/routes.rb +10 -8
  22. data/lib/devise_masquerade/version.rb +1 -1
  23. data/lib/devise_masquerade.rb +3 -9
  24. data/spec/controllers/admin/dashboard_controller_spec.rb +5 -4
  25. data/spec/controllers/dashboard_controller_spec.rb +4 -4
  26. data/spec/controllers/devise/masquerades_controller_spec.rb +60 -36
  27. data/spec/controllers/{masquerades_controller_spec.rb → masquerades_tests_controller_spec.rb} +11 -8
  28. data/spec/dummy/app/controllers/admin/dashboard_controller.rb +1 -2
  29. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  30. data/spec/dummy/app/controllers/dashboard_controller.rb +1 -2
  31. data/spec/dummy/app/controllers/masquerades_tests_controller.rb +7 -0
  32. data/spec/dummy/app/controllers/students_controller.rb +8 -0
  33. data/spec/dummy/app/models/admin/user.rb +0 -7
  34. data/spec/dummy/app/models/student.rb +3 -0
  35. data/spec/dummy/app/models/user.rb +1 -10
  36. data/spec/dummy/app/views/admin/dashboard/index.html.erb +0 -2
  37. data/spec/dummy/app/views/dashboard/index.html.erb +0 -2
  38. data/spec/dummy/app/views/layouts/application.html.erb +7 -1
  39. data/spec/dummy/app/views/students/_student.html.erb +6 -0
  40. data/spec/dummy/app/views/students/index.html.erb +1 -0
  41. data/spec/dummy/app/views/users/_user.html.erb +1 -1
  42. data/spec/dummy/config/application.rb +2 -0
  43. data/spec/dummy/config/environment.rb +1 -0
  44. data/spec/dummy/config/routes.rb +6 -4
  45. data/spec/dummy/db/.gitignore +1 -0
  46. data/spec/dummy/db/migrate/20121119085620_devise_create_users.rb +1 -1
  47. data/spec/dummy/db/migrate/20140418160449_create_admin_users.rb +1 -1
  48. data/spec/dummy/db/migrate/20191022100000_create_students.rb +14 -0
  49. data/spec/dummy/db/schema.rb +37 -31
  50. data/spec/models/user_spec.rb +1 -1
  51. data/spec/orm/active_record.rb +5 -2
  52. data/spec/spec_helper.rb +3 -3
  53. data/spec/support/factories.rb +13 -9
  54. metadata +31 -16
  55. data/lib/devise_masquerade/model.rb +0 -42
  56. data/spec/dummy/app/controllers/masquerades_controller.rb +0 -5
@@ -1,3 +1 @@
1
- <h1>Users</h1>
2
-
3
1
  <%= render @users %>
@@ -1,3 +1 @@
1
- <h1>Users</h1>
2
-
3
1
  <%= render @users %>
@@ -8,7 +8,13 @@
8
8
  </head>
9
9
  <body>
10
10
  <% if signed_in? %>
11
- <h1 class='current_user'><%= current_user.email %></h1>
11
+ <% if user_signed_in? %>
12
+ <h1 class='current_user'><%= current_user.email %></h1>
13
+ <% end %>
14
+
15
+ <% if student_signed_in? %>
16
+ <h1 class='current_student'><%= current_student.email %></h1>
17
+ <% end %>
12
18
 
13
19
  <% if user_masquerade? %>
14
20
  <%= link_to "Back masquerade", back_masquerade_path(current_user) %>
@@ -0,0 +1,6 @@
1
+ <p>
2
+ <%= student.email %>
3
+
4
+ <%= link_to "Login as", masquerade_path(student), class: 'login_as' %>
5
+ </p>
6
+
@@ -0,0 +1 @@
1
+ <%= render @students %>
@@ -1,6 +1,6 @@
1
1
  <p>
2
2
  <%= user.email %>
3
3
 
4
- <%= link_to "Login as", masquerade_path(user) %>
4
+ <%= link_to "Login as", masquerade_path(user), class: 'login_as' %>
5
5
  </p>
6
6
 
@@ -16,6 +16,8 @@ module Dummy
16
16
  config.encoding = "utf-8"
17
17
 
18
18
  config.filter_parameters += [:password]
19
+
20
+ config.eager_load = false
19
21
  end
20
22
  end
21
23
 
@@ -2,4 +2,5 @@
2
2
  require File.expand_path('../application', __FILE__)
3
3
 
4
4
  # Initialize the rails application
5
+ #
5
6
  Dummy::Application.initialize!
@@ -1,12 +1,14 @@
1
1
  Dummy::Application.routes.draw do
2
2
  devise_for :users, controllers: { masquerades: "users/masquerades" }
3
- devise_for :admin_users, :class_name => 'Admin::User'
3
+ devise_for :admin_users, class_name: Admin::User.name
4
+ devise_for :students, class_name: Student.name
4
5
 
5
- root :to => 'dashboard#index'
6
+ root to: 'dashboard#index'
6
7
 
7
- resources :masquerades
8
+ resources :masquerades_tests
9
+ resources :students, only: :index
8
10
 
9
11
  namespace :admin do
10
- root :to => 'dashboard#index'
12
+ root to: 'dashboard#index'
11
13
  end
12
14
  end
@@ -0,0 +1 @@
1
+ test.sqlite3*
@@ -1,4 +1,4 @@
1
- class DeviseCreateUsers < ActiveRecord::Migration
1
+ class DeviseCreateUsers < ActiveRecord::Migration[5.2]
2
2
  def change
3
3
  create_table(:users) do |t|
4
4
  ## Database authenticatable
@@ -1,4 +1,4 @@
1
- class CreateAdminUsers < ActiveRecord::Migration
1
+ class CreateAdminUsers < ActiveRecord::Migration[5.2]
2
2
  def change
3
3
  create_table(:admin_users) do |t|
4
4
  ## Database authenticatable
@@ -0,0 +1,14 @@
1
+ class CreateStudents < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table(:students) do |t|
4
+ t.string :email, null: false, default: ''
5
+ t.string :encrypted_password, null: false, default: ''
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :students, :email, unique: true
11
+ add_index :students, :reset_password_token, unique: true
12
+ end
13
+ end
14
+
@@ -1,52 +1,58 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
5
4
  #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
11
10
  #
12
- # It's strongly recommended to check this file into your version control system.
11
+ # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(:version => 20140418160449) do
13
+ ActiveRecord::Schema.define(version: 2019_10_22_100000) do
15
14
 
16
- create_table "admin_users", :force => true do |t|
17
- t.string "email", :default => "", :null => false
18
- t.string "encrypted_password", :default => "", :null => false
19
- t.string "reset_password_token"
15
+ create_table "admin_users", force: :cascade do |t|
16
+ t.string "email", default: "", null: false
17
+ t.string "encrypted_password", default: "", null: false
18
+ t.string "reset_password_token"
20
19
  t.datetime "reset_password_sent_at"
21
20
  t.datetime "remember_created_at"
22
- t.integer "sign_in_count", :default => 0
21
+ t.integer "sign_in_count", default: 0
23
22
  t.datetime "current_sign_in_at"
24
23
  t.datetime "last_sign_in_at"
25
- t.string "current_sign_in_ip"
26
- t.string "last_sign_in_ip"
27
- t.datetime "created_at", :null => false
28
- t.datetime "updated_at", :null => false
24
+ t.string "current_sign_in_ip"
25
+ t.string "last_sign_in_ip"
26
+ t.datetime "created_at", null: false
27
+ t.datetime "updated_at", null: false
28
+ t.index ["email"], name: "index_admin_users_on_email", unique: true
29
+ t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
29
30
  end
30
31
 
31
- add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
32
- add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
32
+ create_table "students", force: :cascade do |t|
33
+ t.string "email", default: "", null: false
34
+ t.string "encrypted_password", default: "", null: false
35
+ t.datetime "created_at", null: false
36
+ t.datetime "updated_at", null: false
37
+ t.index "\"reset_password_token\"", name: "index_students_on_reset_password_token", unique: true
38
+ t.index ["email"], name: "index_students_on_email", unique: true
39
+ end
33
40
 
34
- create_table "users", :force => true do |t|
35
- t.string "email", :default => "", :null => false
36
- t.string "encrypted_password", :default => "", :null => false
37
- t.string "reset_password_token"
41
+ create_table "users", force: :cascade do |t|
42
+ t.string "email", default: "", null: false
43
+ t.string "encrypted_password", default: "", null: false
44
+ t.string "reset_password_token"
38
45
  t.datetime "reset_password_sent_at"
39
46
  t.datetime "remember_created_at"
40
- t.integer "sign_in_count", :default => 0
47
+ t.integer "sign_in_count", default: 0
41
48
  t.datetime "current_sign_in_at"
42
49
  t.datetime "last_sign_in_at"
43
- t.string "current_sign_in_ip"
44
- t.string "last_sign_in_ip"
45
- t.datetime "created_at", :null => false
46
- t.datetime "updated_at", :null => false
50
+ t.string "current_sign_in_ip"
51
+ t.string "last_sign_in_ip"
52
+ t.datetime "created_at", null: false
53
+ t.datetime "updated_at", null: false
54
+ t.index ["email"], name: "index_users_on_email", unique: true
55
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
47
56
  end
48
57
 
49
- add_index "users", ["email"], :name => "index_users_on_email", :unique => true
50
- add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
51
-
52
58
  end
@@ -31,7 +31,7 @@ describe User do
31
31
  allow(Rails.cache).to receive(:read).with("users:#{user.masquerade_key}:masquerade") { user.id }
32
32
  allow(Rails.cache).to receive(:delete).with("users:#{user.masquerade_key}:masquerade")
33
33
 
34
- new_user = User.find_by_masquerade_key(user.masquerade_key)
34
+ new_user = User.find_by_masquerade_key(user.masquerade_key).first
35
35
 
36
36
  expect(new_user).to eq(user)
37
37
  end
@@ -1,5 +1,8 @@
1
1
  ActiveRecord::Migration.verbose = false
2
2
  ActiveRecord::Base.logger = Logger.new(nil)
3
3
 
4
- ActiveRecord::Migrator.migrate(File.expand_path("../dummy/db/migrate/", __FILE__))
5
-
4
+ ActiveRecord::MigrationContext.
5
+ new(
6
+ File.expand_path("../../dummy/db/migrate/", __FILE__),
7
+ ActiveRecord::Base.connection.schema_migration
8
+ ).migrate
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,7 @@ require 'devise_masquerade'
6
6
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
7
7
  require 'rails/test_help'
8
8
  require 'rspec/rails'
9
- require 'factory_girl'
9
+ require 'factory_bot'
10
10
  require 'database_cleaner'
11
11
 
12
12
  Rails.backtrace_cleaner.remove_silencers!
@@ -18,9 +18,9 @@ RSpec.configure do |config|
18
18
  require 'rspec/expectations'
19
19
  config.include RSpec::Matchers
20
20
 
21
- config.include Devise::TestHelpers, :type => :controller
21
+ config.include Devise::Test::ControllerHelpers, :type => :controller
22
22
  config.include Warden::Test::Helpers
23
- config.include FactoryGirl::Syntax::Methods
23
+ config.include FactoryBot::Syntax::Methods
24
24
  config.include Authentication
25
25
 
26
26
  config.raise_errors_for_deprecations!
@@ -1,16 +1,20 @@
1
- FactoryGirl.define do
2
- sequence(:email) { |i| "john#{i}@example.com" }
3
-
1
+ FactoryBot.define do
4
2
  factory :user do
5
- email
6
- password 'password'
7
- password_confirmation 'password'
3
+ sequence(:email) { |i| "user#{i}@example.com" }
4
+ password { 'password' }
5
+ password_confirmation { 'password' }
8
6
  end
9
7
 
10
8
  factory :admin_user, :class => 'Admin::User' do
11
- email
12
- password 'password'
13
- password_confirmation 'password'
9
+ sequence(:email) { |i| "admin#{i}@example.com" }
10
+ password { 'password' }
11
+ password_confirmation { 'password' }
12
+ end
13
+
14
+ factory :student do
15
+ sequence(:email) { |i| "student#{i}@example.com" }
16
+ password { 'password' }
17
+ password_confirmation { 'password' }
14
18
  end
15
19
  end
16
20
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_masquerade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandr Korsak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-03 00:00:00.000000000 Z
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0
19
+ version: 2.0.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.0
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: 5.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: 5.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: devise
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.0
47
+ version: 4.7.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.0
54
+ version: 4.7.0
55
55
  description: devise masquerade library
56
56
  email:
57
57
  - alex.korsak@gmail.com
@@ -65,6 +65,7 @@ files:
65
65
  - ".rvmrc"
66
66
  - ".travis.yml"
67
67
  - Gemfile
68
+ - Gemfile.lock
68
69
  - Guardfile
69
70
  - LICENSE.txt
70
71
  - Makefile
@@ -74,13 +75,15 @@ files:
74
75
  - config/environment.rb
75
76
  - devise_masquerade.gemspec
76
77
  - features/back.feature
78
+ - features/multiple_masquerading_models.feature
77
79
  - features/step_definitions/auth_steps.rb
78
80
  - features/step_definitions/back_steps.rb
79
81
  - features/support/env.rb
80
82
  - lib/devise_masquerade.rb
81
83
  - lib/devise_masquerade/controllers/helpers.rb
82
84
  - lib/devise_masquerade/controllers/url_helpers.rb
83
- - lib/devise_masquerade/model.rb
85
+ - lib/devise_masquerade/models.rb
86
+ - lib/devise_masquerade/models/masqueradable.rb
84
87
  - lib/devise_masquerade/rails.rb
85
88
  - lib/devise_masquerade/routes.rb
86
89
  - lib/devise_masquerade/version.rb
@@ -88,20 +91,24 @@ files:
88
91
  - spec/controllers/admin/dashboard_controller_spec.rb
89
92
  - spec/controllers/dashboard_controller_spec.rb
90
93
  - spec/controllers/devise/masquerades_controller_spec.rb
91
- - spec/controllers/masquerades_controller_spec.rb
94
+ - spec/controllers/masquerades_tests_controller_spec.rb
92
95
  - spec/dummy/Rakefile
93
96
  - spec/dummy/app/controllers/admin/dashboard_controller.rb
94
97
  - spec/dummy/app/controllers/application_controller.rb
95
98
  - spec/dummy/app/controllers/dashboard_controller.rb
96
- - spec/dummy/app/controllers/masquerades_controller.rb
99
+ - spec/dummy/app/controllers/masquerades_tests_controller.rb
100
+ - spec/dummy/app/controllers/students_controller.rb
97
101
  - spec/dummy/app/controllers/users/masquerades_controller.rb
98
102
  - spec/dummy/app/helpers/application_helper.rb
99
103
  - spec/dummy/app/models/admin.rb
100
104
  - spec/dummy/app/models/admin/user.rb
105
+ - spec/dummy/app/models/student.rb
101
106
  - spec/dummy/app/models/user.rb
102
107
  - spec/dummy/app/views/admin/dashboard/index.html.erb
103
108
  - spec/dummy/app/views/dashboard/index.html.erb
104
109
  - spec/dummy/app/views/layouts/application.html.erb
110
+ - spec/dummy/app/views/students/_student.html.erb
111
+ - spec/dummy/app/views/students/index.html.erb
105
112
  - spec/dummy/app/views/users/_user.html.erb
106
113
  - spec/dummy/config.ru
107
114
  - spec/dummy/config/application.rb
@@ -120,8 +127,10 @@ files:
120
127
  - spec/dummy/config/locales/devise.en.yml
121
128
  - spec/dummy/config/locales/en.yml
122
129
  - spec/dummy/config/routes.rb
130
+ - spec/dummy/db/.gitignore
123
131
  - spec/dummy/db/migrate/20121119085620_devise_create_users.rb
124
132
  - spec/dummy/db/migrate/20140418160449_create_admin_users.rb
133
+ - spec/dummy/db/migrate/20191022100000_create_students.rb
125
134
  - spec/dummy/db/schema.rb
126
135
  - spec/dummy/db/seeds.rb
127
136
  - spec/dummy/public/.empty
@@ -131,7 +140,7 @@ files:
131
140
  - spec/spec_helper.rb
132
141
  - spec/support/authentication.rb
133
142
  - spec/support/factories.rb
134
- homepage: http://github.com/oivoodoo/devise_masquerade/
143
+ homepage: http://github.com/oivoodoo/devise_masquerade
135
144
  licenses:
136
145
  - MIT
137
146
  metadata: {}
@@ -150,33 +159,37 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
159
  - !ruby/object:Gem::Version
151
160
  version: '0'
152
161
  requirements: []
153
- rubyforge_project:
154
- rubygems_version: 2.5.2
162
+ rubygems_version: 3.0.1
155
163
  signing_key:
156
164
  specification_version: 4
157
165
  summary: use for login as functionallity on your admin users pages
158
166
  test_files:
159
167
  - features/back.feature
168
+ - features/multiple_masquerading_models.feature
160
169
  - features/step_definitions/auth_steps.rb
161
170
  - features/step_definitions/back_steps.rb
162
171
  - features/support/env.rb
163
172
  - spec/controllers/admin/dashboard_controller_spec.rb
164
173
  - spec/controllers/dashboard_controller_spec.rb
165
174
  - spec/controllers/devise/masquerades_controller_spec.rb
166
- - spec/controllers/masquerades_controller_spec.rb
175
+ - spec/controllers/masquerades_tests_controller_spec.rb
167
176
  - spec/dummy/Rakefile
168
177
  - spec/dummy/app/controllers/admin/dashboard_controller.rb
169
178
  - spec/dummy/app/controllers/application_controller.rb
170
179
  - spec/dummy/app/controllers/dashboard_controller.rb
171
- - spec/dummy/app/controllers/masquerades_controller.rb
180
+ - spec/dummy/app/controllers/masquerades_tests_controller.rb
181
+ - spec/dummy/app/controllers/students_controller.rb
172
182
  - spec/dummy/app/controllers/users/masquerades_controller.rb
173
183
  - spec/dummy/app/helpers/application_helper.rb
174
184
  - spec/dummy/app/models/admin.rb
175
185
  - spec/dummy/app/models/admin/user.rb
186
+ - spec/dummy/app/models/student.rb
176
187
  - spec/dummy/app/models/user.rb
177
188
  - spec/dummy/app/views/admin/dashboard/index.html.erb
178
189
  - spec/dummy/app/views/dashboard/index.html.erb
179
190
  - spec/dummy/app/views/layouts/application.html.erb
191
+ - spec/dummy/app/views/students/_student.html.erb
192
+ - spec/dummy/app/views/students/index.html.erb
180
193
  - spec/dummy/app/views/users/_user.html.erb
181
194
  - spec/dummy/config.ru
182
195
  - spec/dummy/config/application.rb
@@ -195,8 +208,10 @@ test_files:
195
208
  - spec/dummy/config/locales/devise.en.yml
196
209
  - spec/dummy/config/locales/en.yml
197
210
  - spec/dummy/config/routes.rb
211
+ - spec/dummy/db/.gitignore
198
212
  - spec/dummy/db/migrate/20121119085620_devise_create_users.rb
199
213
  - spec/dummy/db/migrate/20140418160449_create_admin_users.rb
214
+ - spec/dummy/db/migrate/20191022100000_create_students.rb
200
215
  - spec/dummy/db/schema.rb
201
216
  - spec/dummy/db/seeds.rb
202
217
  - spec/dummy/public/.empty
@@ -1,42 +0,0 @@
1
- module Devise
2
- module Models
3
- module Masqueradable
4
- def self.included(base)
5
- base.class_eval do
6
- attr_reader :masquerade_key
7
-
8
- include InstanceMethods
9
- extend ClassMethods
10
- end
11
- end
12
-
13
- module InstanceMethods
14
- def masquerade!
15
- @masquerade_key = SecureRandom.urlsafe_base64(Devise.masquerade_key_size)
16
- cache_key = self.class.cache_masquerade_key_by(@masquerade_key)
17
- Rails.cache.write(cache_key, id, :expires_in => Devise.masquerade_expires_in)
18
- end
19
- end
20
-
21
- module ClassMethods
22
- def cache_masquerade_key_by(key)
23
- "#{self.name.pluralize.underscore}:#{key}:masquerade"
24
- end
25
-
26
- def remove_masquerade_key!(key)
27
- Rails.cache.delete(cache_masquerade_key_by(key))
28
- end
29
-
30
- def find_by_masquerade_key(key)
31
- id = Rails.cache.read(cache_masquerade_key_by(key))
32
-
33
- # clean up the cached masquerade key value
34
- remove_masquerade_key!(key)
35
-
36
- where(id: id).first
37
- end
38
- end # ClassMethods
39
- end
40
- end
41
- end
42
-
@@ -1,5 +0,0 @@
1
- class MasqueradesController < Devise::MasqueradesController
2
- def show
3
- super
4
- end
5
- end