devise_masquerade 0.6.4 → 1.3.1

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.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/brakeman-analysis.yml +44 -0
  4. data/.github/workflows/rubocop-analysis.yml +39 -0
  5. data/.gitignore +1 -2
  6. data/.ruby-version +1 -1
  7. data/.travis.yml +3 -4
  8. data/Gemfile +16 -10
  9. data/Gemfile.lock +307 -0
  10. data/Makefile +6 -1
  11. data/README.md +33 -1
  12. data/app/controllers/devise/masquerades_controller.rb +75 -59
  13. data/devise_masquerade.gemspec +5 -4
  14. data/features/back.feature +0 -1
  15. data/features/multiple_masquerading_models.feature +17 -0
  16. data/features/step_definitions/auth_steps.rb +1 -0
  17. data/features/step_definitions/back_steps.rb +18 -3
  18. data/features/step_definitions/url_helpers_steps.rb +11 -0
  19. data/features/support/env.rb +23 -4
  20. data/features/url_helpers.feature +14 -0
  21. data/lib/devise_masquerade/controllers/helpers.rb +27 -8
  22. data/lib/devise_masquerade/controllers/url_helpers.rb +18 -4
  23. data/lib/devise_masquerade/models/masqueradable.rb +13 -0
  24. data/lib/devise_masquerade/models.rb +9 -0
  25. data/lib/devise_masquerade/rails.rb +14 -4
  26. data/lib/devise_masquerade/routes.rb +11 -8
  27. data/lib/devise_masquerade/version.rb +1 -1
  28. data/lib/devise_masquerade.rb +3 -9
  29. data/spec/controllers/admin/dashboard_controller_spec.rb +3 -4
  30. data/spec/controllers/dashboard_controller_spec.rb +3 -5
  31. data/spec/controllers/devise/masquerades_controller_spec.rb +62 -38
  32. data/spec/controllers/masquerades_tests_controller_spec.rb +41 -0
  33. data/spec/dummy/app/controllers/admin/dashboard_controller.rb +1 -2
  34. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  35. data/spec/dummy/app/controllers/dashboard_controller.rb +5 -2
  36. data/spec/dummy/app/controllers/masquerades_tests_controller.rb +7 -0
  37. data/spec/dummy/app/controllers/students_controller.rb +8 -0
  38. data/spec/dummy/app/models/admin/user.rb +0 -7
  39. data/spec/dummy/app/models/student.rb +3 -0
  40. data/spec/dummy/app/models/user.rb +1 -10
  41. data/spec/dummy/app/views/admin/dashboard/index.html.erb +0 -2
  42. data/spec/dummy/app/views/dashboard/extra_params.html.erb +7 -0
  43. data/spec/dummy/app/views/dashboard/index.html.erb +0 -2
  44. data/spec/dummy/app/views/layouts/application.html.erb +7 -1
  45. data/spec/dummy/app/views/students/_student.html.erb +6 -0
  46. data/spec/dummy/app/views/students/index.html.erb +1 -0
  47. data/spec/dummy/app/views/users/_user.html.erb +1 -1
  48. data/spec/dummy/config/application.rb +2 -0
  49. data/spec/dummy/config/environment.rb +1 -0
  50. data/spec/dummy/config/routes.rb +9 -5
  51. data/spec/dummy/db/.gitignore +1 -0
  52. data/spec/dummy/db/migrate/20121119085620_devise_create_users.rb +1 -1
  53. data/spec/dummy/db/migrate/20140418160449_create_admin_users.rb +1 -1
  54. data/spec/dummy/db/migrate/20191022100000_create_students.rb +14 -0
  55. data/spec/dummy/db/schema.rb +37 -31
  56. data/spec/models/user_spec.rb +3 -30
  57. data/spec/orm/active_record.rb +5 -2
  58. data/spec/spec_helper.rb +3 -3
  59. data/spec/support/factories.rb +13 -9
  60. metadata +57 -19
  61. data/lib/devise_masquerade/model.rb +0 -42
  62. data/spec/controllers/masquerades_controller_spec.rb +0 -42
  63. data/spec/dummy/app/controllers/masquerades_controller.rb +0 -5
@@ -7,73 +7,97 @@ describe Devise::MasqueradesController, type: :controller do
7
7
  context 'when logged in' do
8
8
  before { logged_in }
9
9
 
10
+ context 'with masqueradable_class param' do
11
+ let(:mask) { create(:student) }
12
+
13
+ before do
14
+ get :show, params: { id: mask.to_param, masqueraded_resource_class: mask.class.name, masquerade: mask.masquerade_key }
15
+ end
16
+
17
+ it { expect(Rails.cache.read('devise_masquerade_student')).to be }
18
+
19
+ it 'should have warden keys defined' do
20
+ expect(session["warden.user.student.key"].first.first).to eq(mask.id)
21
+ end
22
+
23
+ it { should redirect_to('/') }
24
+ end
25
+
10
26
  describe '#masquerade user' do
11
27
  let(:mask) { create(:user) }
12
28
 
13
29
  before do
14
- expect(SecureRandom).to receive(:urlsafe_base64) { "secure_key" }
15
- get :show, :id => mask.to_param
30
+ get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key }
16
31
  end
17
32
 
18
- it { expect(session.keys).to include('devise_masquerade_user') }
33
+ it { expect(Rails.cache.read('devise_masquerade_user')).to be }
19
34
  it { expect(session["warden.user.user.key"].first.first).to eq(mask.id) }
20
- it { should redirect_to("/?masquerade=secure_key") }
35
+ it { should redirect_to('/') }
21
36
 
22
37
  context 'and back' do
23
38
  before { get :back }
24
39
 
25
40
  it { should redirect_to(masquerade_page) }
26
41
  it { expect(current_user.reload).to eq(@user) }
27
- it { expect(session.keys).not_to include('devise_masquerade_user') }
42
+ it { expect(Rails.cache.read('devise_masquerade_user')).not_to be }
28
43
  end
44
+ end
29
45
 
30
- # Configure masquerade_routes_back setting
31
- describe 'config#masquerade_routes_back' do
32
- before { Devise.setup {|c| c.masquerade_routes_back = true } }
46
+ # Configure masquerade_routes_back setting
47
+ describe 'config#masquerade_routes_back' do
48
+ let(:mask) { create(:user) }
33
49
 
34
- context 'show' do
35
- before { expect(SecureRandom).to receive(:urlsafe_base64) { "secure_key" } }
50
+ before { Devise.setup { |c| c.masquerade_routes_back = true } }
36
51
 
37
- context '< Rails 5 version' do
38
- before do
39
- @request.env['HTTP_REFERER'] = 'previous_location'
40
- get :show, id: mask.to_param
41
- end # before
52
+ after { Devise.masquerade_routes_back = false }
42
53
 
43
- it { should redirect_to('previous_location') }
44
- end # context
54
+ context 'show' do
55
+ context 'with http referrer' do
56
+ before do
57
+ @request.env['HTTP_REFERER'] = 'previous_location'
58
+ get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key }
59
+ end # before
45
60
 
46
- context '< Rails 5, fallback if http_referer not present' do
47
- before do
48
- allow_any_instance_of(described_class).to receive(:after_masquerade_path_for).and_return("/dashboard?color=red")
49
- end
61
+ it { should redirect_to('previous_location') }
62
+ end # context
50
63
 
51
- before { get :show, id: mask.to_param }
64
+ context 'no http referrer' do
65
+ before do
66
+ allow_any_instance_of(described_class).to(
67
+ receive(:after_masquerade_path_for).and_return("/dashboard?color=red"))
68
+ end
52
69
 
53
- it { should redirect_to("/dashboard?color=red&masquerade=secure_key") }
54
- end # context
70
+ before { get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key } }
71
+
72
+ it { should redirect_to("/dashboard?color=red") }
55
73
  end # context
74
+ end # context
56
75
 
57
- context '< Rails 5, and back' do
58
- before { get :back }
76
+ context 'and back' do
77
+ before do
78
+ get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key }
59
79
 
60
- it { should redirect_to(masquerade_page) }
61
- end # context
80
+ get :back
81
+ end
62
82
 
63
- context '< Rails 5, and back fallback if http_referer not present' do
64
- before do
65
- @request.env['HTTP_REFERER'] = 'previous_location'
66
- get :back
67
- end
83
+ it { should redirect_to(masquerade_page) }
84
+ end # context
68
85
 
69
- it { should redirect_to('previous_location') }
70
- end # context
71
- end # describe
72
- end
86
+ context 'and back fallback if http_referer not present' do
87
+ before do
88
+ get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key }
89
+
90
+ @request.env['HTTP_REFERER'] = 'previous_location'
91
+ get :back
92
+ end
93
+
94
+ it { should redirect_to('previous_location') }
95
+ end # context
96
+ end # describe
73
97
  end
74
98
 
75
99
  context 'when not logged in' do
76
- before { get :show, :id => 'any_id' }
100
+ before { get :show, params: { id: 'any_id' } }
77
101
 
78
102
  it { should redirect_to(new_user_session_path) }
79
103
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe MasqueradesTestsController, type: :controller do
4
+ before { @request.env['devise.mapping'] = Devise.mappings[:user] }
5
+
6
+ context 'no access for masquerade' do
7
+ before do
8
+ session.clear
9
+ allow_any_instance_of(MasqueradesTestsController).to receive(:masquerade_authorized?) { false }
10
+ end
11
+
12
+ before { logged_in }
13
+
14
+ let(:mask) { create(:user) }
15
+
16
+ before { get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key } }
17
+
18
+ it { expect(response.status).to eq(403) }
19
+ it { expect(Rails.cache.read('devise_masquerade_user')).not_to be }
20
+ it { expect(session['warden.user.user.key'].first.first).not_to eq(mask.id) }
21
+ end
22
+
23
+ context 'access for masquerade' do
24
+ before do
25
+ session.clear
26
+ allow_any_instance_of(MasqueradesTestsController).to receive(:masquerade_authorized?) { true }
27
+ end
28
+
29
+ before { logged_in }
30
+
31
+ let(:mask) { create(:user) }
32
+
33
+ before do
34
+ get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key }
35
+ end
36
+
37
+ it { expect(response.status).to eq(302) }
38
+ it { expect(Rails.cache.read('devise_masquerade_user')).to be }
39
+ it { expect(session['warden.user.user.key'].first.first).to eq(mask.id) }
40
+ end
41
+ end
@@ -1,6 +1,5 @@
1
1
  class Admin::DashboardController < ApplicationController
2
- before_filter :authenticate_admin_user!
3
- before_filter :masquerade_admin_user!
2
+ before_action :authenticate_admin_user!
4
3
 
5
4
  def index
6
5
  @users = Admin::User.where("admin_users.id != ?", current_admin_user.id).all
@@ -1,4 +1,6 @@
1
1
  class ApplicationController < ActionController::Base
2
+ before_action :masquerade!
3
+
2
4
  protect_from_forgery
3
5
  end
4
6
 
@@ -1,9 +1,12 @@
1
1
  class DashboardController < ApplicationController
2
- before_filter :authenticate_user!
3
- before_filter :masquerade_user!
2
+ before_action :authenticate_user!
4
3
 
5
4
  def index
6
5
  @users = User.where("users.id != ?", current_user.id).all
7
6
  end
7
+
8
+ def extra_params
9
+ @users = User.where("users.id != ?", current_user.id).all
10
+ end
8
11
  end
9
12
 
@@ -0,0 +1,7 @@
1
+ class MasqueradesTestsController < Devise::MasqueradesController
2
+ before_action :authenticate_user!
3
+
4
+ def show
5
+ super
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class StudentsController < ApplicationController
2
+ before_action :authenticate_user!
3
+
4
+ def index
5
+ @students = Student.all
6
+ end
7
+ end
8
+
@@ -1,13 +1,6 @@
1
1
  class Admin::User < ActiveRecord::Base
2
- # Include default devise modules. Others available are:
3
- # :token_authenticatable, :confirmable,
4
- # :lockable, :timeoutable and :omniauthable
5
2
  devise :database_authenticatable, :registerable,
6
3
  :recoverable, :rememberable, :trackable, :validatable,
7
4
  :masqueradable
8
-
9
- # Setup accessible (or protected) attributes for your model
10
- attr_accessible :email, :password, :password_confirmation, :remember_me
11
- # attr_accessible :title, :body
12
5
  end
13
6
 
@@ -0,0 +1,3 @@
1
+ class Student < ActiveRecord::Base
2
+ devise :database_authenticatable, :validatable, :masqueradable
3
+ end
@@ -1,12 +1,3 @@
1
1
  class User < ActiveRecord::Base
2
- # Include default devise modules. Others available are:
3
- # :token_authenticatable, :confirmable,
4
- # :lockable, :timeoutable and :omniauthable
5
- devise :database_authenticatable, :registerable,
6
- :recoverable, :rememberable, :trackable, :validatable,
7
- :masqueradable
8
-
9
- # Setup accessible (or protected) attributes for your model
10
- attr_accessible :email, :password, :password_confirmation, :remember_me
11
- # attr_accessible :title, :body
2
+ devise :database_authenticatable, :validatable, :masqueradable
12
3
  end
@@ -1,3 +1 @@
1
- <h1>Users</h1>
2
-
3
1
  <%= render @users %>
@@ -0,0 +1,7 @@
1
+ <% @users.each do |user| %>
2
+ <p>
3
+ <%= user.email %>
4
+
5
+ <%= link_to "Login as", masquerade_path(user, key1: 'value1'), class: 'login_as' %>
6
+ </p>
7
+ <% end %>
@@ -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,16 @@
1
1
  Dummy::Application.routes.draw do
2
- devise_for :users, controllers: { masquerades: "users/masquerades" }
3
- devise_for :admin_users, :class_name => 'Admin::User'
2
+ devise_for :users, controllers: { masquerades: 'users/masquerades' }
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
+ get '/extra_params', to: 'dashboard#extra_params'
9
+
10
+ resources :masquerades_tests
11
+ resources :students, only: :index
8
12
 
9
13
  namespace :admin do
10
- root :to => 'dashboard#index'
14
+ root to: 'dashboard#index'
11
15
  end
12
16
  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
@@ -3,37 +3,10 @@ require 'spec_helper'
3
3
  describe User do
4
4
  let!(:user) { create(:user) }
5
5
 
6
- describe '#masquerade!' do
6
+ describe '#masquerade_key' do
7
7
  it 'should cache special key on masquerade' do
8
- expect(SecureRandom).to receive(:urlsafe_base64).with(16) { "secure_key" }
9
- user.masquerade!
10
- end
11
- end
12
-
13
- describe '#remove_masquerade_key' do
14
- before { allow(SecureRandom).to receive(:urlsafe_base64) { "secure_key" } }
15
-
16
- let(:key) { 'users:secure_key:masquerade' }
17
-
18
- it 'should be possible to remove cached masquerade key' do
19
- user.masquerade!
20
- expect(Rails.cache.exist?(key)).to eq(true)
21
-
22
- User.remove_masquerade_key!('secure_key')
23
- expect(Rails.cache.exist?(key)).to eq(false)
24
- end
25
- end
26
-
27
- describe '#find_by_masquerade_key' do
28
- it 'should be possible to find user by generate masquerade key' do
29
- user.masquerade!
30
-
31
- allow(Rails.cache).to receive(:read).with("users:#{user.masquerade_key}:masquerade") { user.id }
32
- allow(Rails.cache).to receive(:delete).with("users:#{user.masquerade_key}:masquerade")
33
-
34
- new_user = User.find_by_masquerade_key(user.masquerade_key)
35
-
36
- expect(new_user).to eq(user)
8
+ expect(user).to receive(:to_sgid).with(expires_in: 1.minute, for: 'masquerade') { "secure_key" }
9
+ user.masquerade_key
37
10
  end
38
11
  end
39
12
  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