devise-guests 0.6.0 → 0.8.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.
- checksums.yaml +5 -5
- data/.github/workflows/tests.yml +64 -0
- data/.standard.yml +2 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +4 -7
- data/README.md +75 -2
- data/Rakefile +13 -13
- data/config.ru +5 -3
- data/devise-guests.gemspec +10 -11
- data/lib/devise-guests/controllers/helpers.rb +19 -23
- data/lib/devise-guests/controllers/url_helpers.rb +0 -1
- data/lib/devise-guests/engine.rb +5 -7
- data/lib/devise-guests/version.rb +1 -1
- data/lib/devise-guests.rb +5 -5
- data/lib/generators/active_record/devise_guests_generator.rb +10 -11
- data/lib/generators/devise_guests/devise_guests_generator.rb +1 -2
- data/lib/railties/devise_guests.rake +2 -3
- data/spec/controllers/application_controller_spec.rb +25 -6
- data/spec/helpers/devise_guests_helpers_spec.rb +2 -3
- data/spec/integration/simple_integration_spec.rb +2 -2
- data/spec/internal/app/assets/config/manifest.js +0 -0
- data/spec/internal/app/controllers/application_controller.rb +0 -1
- data/spec/internal/app/models/user.rb +1 -2
- data/spec/internal/config/initializers/devise.rb +3 -3
- data/spec/internal/config/storage.yml +3 -0
- data/spec/internal/db/schema.rb +9 -9
- data/spec/spec_helper.rb +9 -15
- metadata +29 -10
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7944106e6394d186fa877f614689e47b1059488d6e3d5400ed2eb2204e324f3b
|
4
|
+
data.tar.gz: 817faf49e6a0ad620f2fe35014f1adf1783f3f5177cc7579e4f9bc4cb2872ecd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98e77fdda01fa6982fb3f2851eb84870ab0a9aeaae60e0bba91c98f55454a705056953738559caad400a162aa7d6d55b3e0b510427f573e094c16eb05d85b181
|
7
|
+
data.tar.gz: 4e9d799034284f840332366ae2d79f87c72a1eeaf1f4526287cd76fd8f50126a51d74749977b0c31479e0c6ab8ff377b9ef2a4e932ec2feb9ada9f6901074e7b
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Tests
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
types:
|
16
|
+
- opened
|
17
|
+
- synchronize
|
18
|
+
- reopened
|
19
|
+
- ready_for_review
|
20
|
+
- labeled
|
21
|
+
- unlabeled
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
changelog:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- id: read-version
|
29
|
+
run: |
|
30
|
+
echo "::set-output name=VERSION::`cat lib/devise-guests/version.rb | grep -i version | awk '{ print $3 }' | sed -e 's/\"//g'`"
|
31
|
+
- uses: dangoslen/changelog-enforcer@v2.3.1
|
32
|
+
with:
|
33
|
+
skipLabels: 'skip-changelog'
|
34
|
+
expectedLatestVersion: ${{ steps.read-version.outputs.VERSION }}
|
35
|
+
lint:
|
36
|
+
runs-on: ubuntu-latest
|
37
|
+
steps:
|
38
|
+
- uses: actions/checkout@v2
|
39
|
+
- uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
ruby-version: '2.6'
|
42
|
+
bundler-cache: true
|
43
|
+
- run: bundle exec standardrb
|
44
|
+
test:
|
45
|
+
needs:
|
46
|
+
- changelog
|
47
|
+
- lint
|
48
|
+
runs-on: ubuntu-latest
|
49
|
+
strategy:
|
50
|
+
matrix:
|
51
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
52
|
+
|
53
|
+
steps:
|
54
|
+
- uses: actions/checkout@v2
|
55
|
+
- name: Set up Ruby
|
56
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
57
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
58
|
+
# uses: ruby/setup-ruby@v1
|
59
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
60
|
+
with:
|
61
|
+
ruby-version: ${{ matrix.ruby-version }}
|
62
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
63
|
+
- name: Run tests
|
64
|
+
run: bundle exec rspec
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [0.8.1] - 2021-10-26
|
8
|
+
### Changed
|
9
|
+
- Simplify guest transfer ([#38](https://github.com/cbeer/devise-guests/pull/38))
|
10
|
+
|
11
|
+
## [0.8.0] - 2021-10-25
|
12
|
+
### Added
|
13
|
+
- Allow setting of custom params on guest model ([#31](https://github.com/cbeer/devise-guests/pull/31)) by [@pacso](https://github.com/pacso)
|
14
|
+
- Allow deletion of guest records to optionally be skipped ([#32](https://github.com/cbeer/devise-guests/pull/32)) by [@pacso](https://github.com/pacso)
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
- Switch to SecureRandom.uuid for guest_user_unique_suffix ([#28](https://github.com/cbeer/devise-guests/pull/28)) by [@notch8](https://github.com/notch8)
|
18
|
+
- Update combustion gem ([#29](https://github.com/cbeer/devise-guests/pull/29)) by [@notch8](https://github.com/notch8)
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
- Defining the logging_in callback when the controller loads ([#34](https://github.com/cbeer/devise-guests/pull/34)) by [@davidkuz](https://github.com/davidkuz)
|
22
|
+
|
23
|
+
[Unreleased]: https://github.com/cbeer/devise-guests/compare/v0.8.1...HEAD
|
24
|
+
[0.8.1]: https://github.com/cbeer/devise-guests/compare/v0.8.0...v0.8.1
|
25
|
+
[0.8.0]: https://github.com/cbeer/devise-guests/compare/v0.7.0...v0.8.0
|
data/Gemfile
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem
|
6
|
-
gem 'simplecov', :platform => :ruby_19
|
5
|
+
gem "sqlite3"
|
7
6
|
|
8
7
|
group :test do
|
9
|
-
gem
|
10
|
-
gem
|
8
|
+
gem "activerecord"
|
9
|
+
gem "actionmailer"
|
11
10
|
end
|
12
|
-
|
13
|
-
gem 'transpec'
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Devise Guests
|
2
|
-
[](https://badge.fury.io/rb/devise-guests)
|
3
|
+
[](https://github.com/cbeer/devise-guests/actions/workflows/tests.yml)
|
4
|
+
[](https://github.com/testdouble/standard)
|
3
5
|
|
4
6
|
A drop-in guest user implementation for devise
|
5
7
|
|
@@ -33,6 +35,77 @@ current_user # (for logged in users)
|
|
33
35
|
|
34
36
|
guest_user # ( for anonymous users)
|
35
37
|
|
36
|
-
=> User<id:
|
38
|
+
=> User<id: 2, email: guest_RANDOMENOUGHSTRING_@example.com, guest: true>
|
37
39
|
|
38
40
|
```
|
41
|
+
|
42
|
+
### Transferring Guest to User on Login
|
43
|
+
|
44
|
+
During the login process you may want to transfer things from your guest user to the account the logged into.
|
45
|
+
To do so, add the following method to your ApplicationController:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
private
|
49
|
+
def transfer_guest_to_user
|
50
|
+
# At this point you have access to:
|
51
|
+
# * current_user - the user they've just logged in as
|
52
|
+
# * guest_user - the guest user they were previously identified by
|
53
|
+
#
|
54
|
+
# After this block runs, the guest_user will be destroyed!
|
55
|
+
|
56
|
+
if current_user.cart
|
57
|
+
guest_user.cart.line_items.update_all(cart_id: current_user.cart.id)
|
58
|
+
else
|
59
|
+
guest_user.cart.update!(user: current_user)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
### Custom attribute
|
65
|
+
|
66
|
+
If you have added additional authentication_keys, or have other attributes on your Devise model that you need to set
|
67
|
+
when creating a guest user, you can do so by overriding the set_guest_user_params method in your ApplicationController:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
private
|
71
|
+
def guest_user_params
|
72
|
+
{ site_id: current_site.id }
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
### Non-standard authentication keys
|
77
|
+
|
78
|
+
By default Devise will use `:email` as the authentication key for your model. If for some reason you have modified your
|
79
|
+
Devise config to use an alternative attribute (such as `:phone_number`) you will need to provide a method to generate
|
80
|
+
the value of this attribute for any guest users which are created.
|
81
|
+
|
82
|
+
Sticking with the `:phone_number` example, you should define the following method in your `application_controller.rb`:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
private
|
86
|
+
def guest_phone_number_authentication_key(key)
|
87
|
+
key &&= nil unless key.to_s.match(/^guest/)
|
88
|
+
key ||= "guest_447" + 9.times.map { SecureRandom.rand(0..9) }.join
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
Validations are skipped when creating guest users, but if you need to rely on future modifications to the guest record
|
93
|
+
passing validations, then you should ensure that this default value for guests is generated in such a way as to be
|
94
|
+
valid.
|
95
|
+
|
96
|
+
### Prevent deletion of guest records
|
97
|
+
|
98
|
+
By default, when signing in from a guest account to an authenticated account, the guest user is destroyed. You have an
|
99
|
+
opportunity through the `logging_in_user` callback (or `logging_in_MODEL` if you're not using `User`) to transfer data
|
100
|
+
from the guest to the main account before destruction occurs.
|
101
|
+
|
102
|
+
However, for some situations such as guest-checkout, you may desire that any guest account which makes a purchase does
|
103
|
+
not get destroyed. In that case you can use the `skip_destroy_guest_user` method to identify when to skip deleting these
|
104
|
+
records. By default this method returns `false`, indicating that every record is acceptable for destruction, but you
|
105
|
+
could use something like the following to optionally prevent it:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
def skip_destroy_guest_user
|
109
|
+
guest_user.orders.any?
|
110
|
+
end
|
111
|
+
```
|
data/Rakefile
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "standard/rake"
|
4
5
|
|
5
6
|
begin
|
6
7
|
Bundler.setup(:default, :development)
|
7
8
|
rescue Bundler::BundlerError => e
|
8
|
-
|
9
|
-
|
9
|
+
warn e.message
|
10
|
+
warn "Run `bundle install` to install missing gems"
|
10
11
|
exit e.status_code
|
11
12
|
end
|
12
13
|
|
13
|
-
task :
|
14
|
+
task default: :ci
|
14
15
|
|
15
|
-
require
|
16
|
+
require "rspec/core/rake_task"
|
16
17
|
desc "Run specs"
|
17
18
|
RSpec::Core::RakeTask.new do |t|
|
18
|
-
|
19
|
-
if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.8/
|
19
|
+
if ENV["COVERAGE"] && RUBY_VERSION =~ (/^1.8/)
|
20
20
|
t.rcov = true
|
21
|
-
t.rcov_opts = %w
|
21
|
+
t.rcov_opts = %w[--exclude spec\/*,gems\/*,ruby\/* --aggregate coverage.data]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
require
|
25
|
+
require "yard"
|
26
26
|
YARD::Rake::YardocTask.new do |t|
|
27
27
|
t.options = ["--readme", "README.md"]
|
28
28
|
end
|
29
29
|
|
30
30
|
desc "Continuous Integration build"
|
31
31
|
task :ci do
|
32
|
-
Rake::Task[
|
33
|
-
Rake::Task[
|
32
|
+
Rake::Task["spec"].invoke
|
33
|
+
Rake::Task["yard"].invoke
|
34
34
|
end
|
data/config.ru
CHANGED
data/devise-guests.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
require "devise-guests/version"
|
4
3
|
|
@@ -7,24 +6,25 @@ Gem::Specification.new do |s|
|
|
7
6
|
s.version = DeviseGuests::VERSION
|
8
7
|
s.platform = Gem::Platform::RUBY
|
9
8
|
s.authors = ["Chris Beer"]
|
10
|
-
s.email =
|
11
|
-
s.homepage =
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
9
|
+
s.email = "chris@cbeer.info"
|
10
|
+
s.homepage = "http://github.com/cbeer/devise-guests"
|
11
|
+
s.summary = " Guest user implementation for devise "
|
12
|
+
s.description = " Guest user implementation for devise "
|
14
13
|
s.license = "MIT"
|
15
14
|
|
16
|
-
s.add_dependency
|
15
|
+
s.add_dependency "devise"
|
17
16
|
|
18
17
|
s.add_development_dependency "rspec", "~> 3.0"
|
19
18
|
s.add_development_dependency "rake"
|
20
|
-
s.add_development_dependency "combustion",
|
19
|
+
s.add_development_dependency "combustion", "~> 1.0"
|
21
20
|
s.add_development_dependency "rspec-rails"
|
22
21
|
s.add_development_dependency "capybara"
|
22
|
+
s.add_development_dependency "standard"
|
23
23
|
s.add_development_dependency "yard"
|
24
24
|
|
25
|
-
s.files
|
26
|
-
s.test_files
|
27
|
-
s.executables
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
28
28
|
s.extra_rdoc_files = [
|
29
29
|
"LICENSE",
|
30
30
|
"README.md"
|
@@ -32,4 +32,3 @@ Gem::Specification.new do |s|
|
|
32
32
|
|
33
33
|
s.require_paths = ["lib"]
|
34
34
|
end
|
35
|
-
|
@@ -4,37 +4,22 @@ module DeviseGuests::Controllers
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
include ActiveSupport::Callbacks
|
7
|
-
(DeviseGuests::Controllers::Helpers.callbacks || []).each do |c|
|
8
|
-
define_callbacks *c
|
9
|
-
end
|
10
|
-
|
11
7
|
end
|
12
8
|
|
13
|
-
mattr_reader :callbacks
|
14
|
-
|
15
9
|
module ClassMethods
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.define_concern_callbacks *args
|
20
|
-
@@callbacks ||= []
|
21
|
-
@@callbacks << args
|
22
10
|
end
|
23
11
|
|
24
|
-
def self.define_helpers(mapping)
|
12
|
+
def self.define_helpers(mapping) # :nodoc:
|
25
13
|
class_name = mapping.class_name
|
26
14
|
mapping = mapping.name
|
27
15
|
|
28
16
|
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
29
|
-
define_concern_callbacks :logging_in_#{mapping}
|
30
|
-
|
31
|
-
|
32
17
|
def guest_#{mapping}
|
33
18
|
return @guest_#{mapping} if @guest_#{mapping}
|
34
19
|
|
35
20
|
if session[:guest_#{mapping}_id]
|
36
21
|
@guest_#{mapping} = #{class_name}.find_by(#{class_name}.authentication_keys.first => session[:guest_#{mapping}_id]) rescue nil
|
37
|
-
@guest_#{mapping} = nil if @guest_#{mapping}.respond_to? :guest and !@guest_#{mapping}.guest
|
22
|
+
@guest_#{mapping} = nil if @guest_#{mapping}.respond_to? :guest and !@guest_#{mapping}.guest
|
38
23
|
end
|
39
24
|
|
40
25
|
@guest_#{mapping} ||= begin
|
@@ -50,7 +35,7 @@ module DeviseGuests::Controllers
|
|
50
35
|
if current_#{mapping}
|
51
36
|
if session[:guest_#{mapping}_id]
|
52
37
|
run_callbacks :logging_in_#{mapping} do
|
53
|
-
guest_#{mapping}.destroy
|
38
|
+
guest_#{mapping}.destroy unless send(:"skip_destroy_guest_#{mapping}")
|
54
39
|
session[:guest_#{mapping}_id] = nil
|
55
40
|
end
|
56
41
|
end
|
@@ -65,6 +50,7 @@ module DeviseGuests::Controllers
|
|
65
50
|
auth_key = #{class_name}.authentication_keys.first
|
66
51
|
#{class_name}.new do |g|
|
67
52
|
g.send("\#{auth_key}=", send(:"guest_\#{auth_key}_authentication_key", key))
|
53
|
+
g.assign_attributes(send(:"guest_#{mapping}_params"))
|
68
54
|
g.guest = true if g.respond_to? :guest
|
69
55
|
g.skip_confirmation! if g.respond_to?(:skip_confirmation!)
|
70
56
|
g.save(validate: false)
|
@@ -76,19 +62,29 @@ module DeviseGuests::Controllers
|
|
76
62
|
key ||= "guest_" + guest_#{mapping}_unique_suffix + "@example.com"
|
77
63
|
end
|
78
64
|
|
65
|
+
def guest_#{mapping}_params
|
66
|
+
{}
|
67
|
+
end
|
68
|
+
|
79
69
|
def guest_#{mapping}_unique_suffix
|
80
|
-
|
70
|
+
SecureRandom.uuid
|
81
71
|
end
|
82
72
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
73
|
+
def skip_destroy_guest_#{mapping}
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
77
|
+
def transfer_guest_to_#{mapping}
|
86
78
|
end
|
87
79
|
|
88
80
|
METHODS
|
89
81
|
|
90
82
|
ActiveSupport.on_load(:action_controller) do
|
91
|
-
helper_method
|
83
|
+
if respond_to?(:helper_method)
|
84
|
+
helper_method "guest_#{mapping}", "current_or_guest_#{mapping}"
|
85
|
+
end
|
86
|
+
define_callbacks "logging_in_#{mapping}"
|
87
|
+
set_callback :"logging_in_#{mapping}", :"transfer_guest_to_#{mapping}"
|
92
88
|
end
|
93
89
|
end
|
94
90
|
end
|
data/lib/devise-guests/engine.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rails"
|
2
|
+
require "devise"
|
3
3
|
|
4
4
|
module DeviseGuests
|
5
5
|
class Engine < ::Rails::Engine
|
6
|
-
|
7
6
|
initializer "devise_guests.add_helpers" do
|
8
7
|
Devise.include_helpers(DeviseGuests::Controllers)
|
9
8
|
Devise.helpers << DeviseGuests::Controllers::Helpers
|
10
9
|
end
|
11
10
|
|
12
|
-
|
11
|
+
# This makes our rake tasks visible.
|
13
12
|
rake_tasks do
|
14
|
-
Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__),
|
15
|
-
Dir.glob(File.join(
|
13
|
+
Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), ".."))) do
|
14
|
+
Dir.glob(File.join("railties", "*.rake")).each do |railtie|
|
16
15
|
load railtie
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
end
|
data/lib/devise-guests.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "devise"
|
2
2
|
|
3
3
|
module DeviseGuests
|
4
|
-
require
|
4
|
+
require "devise-guests/version"
|
5
5
|
|
6
6
|
module Controllers
|
7
|
-
autoload :Helpers,
|
8
|
-
autoload :UrlHelpers,
|
7
|
+
autoload :Helpers, "devise-guests/controllers/helpers"
|
8
|
+
autoload :UrlHelpers, "devise-guests/controllers/url_helpers"
|
9
9
|
end
|
10
10
|
|
11
|
-
require
|
11
|
+
require "devise-guests/engine"
|
12
12
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rails/generators/active_record"
|
2
|
+
require "generators/devise/orm_helpers"
|
3
3
|
|
4
4
|
module ActiveRecord
|
5
5
|
module Generators
|
@@ -8,26 +8,25 @@ module ActiveRecord
|
|
8
8
|
source_root File.expand_path("../templates", __FILE__)
|
9
9
|
|
10
10
|
def copy_devise_migration
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
migration_template "migration_existing.rb",
|
12
|
+
"db/migrate/add_devise_guests_to_#{table_name}.rb",
|
13
|
+
migration_version: migration_version
|
14
14
|
end
|
15
15
|
|
16
16
|
def migration_data
|
17
|
-
<<RUBY
|
17
|
+
<<RUBY
|
18
18
|
## Database authenticatable
|
19
19
|
t.boolean :guest, :default => false
|
20
20
|
RUBY
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
Rails.version.start_with?
|
23
|
+
def rails4?
|
24
|
+
Rails.version.start_with? "4"
|
25
25
|
end
|
26
26
|
|
27
27
|
def migration_version
|
28
|
-
if
|
29
|
-
|
30
|
-
end
|
28
|
+
return if rails4?
|
29
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
namespace :devise_guests do
|
2
2
|
# task to clean out old guest users
|
3
3
|
# rake devise_guests:delete_old_guest_users[days_old]
|
4
|
-
# example cron entry to delete users older than 7 days at 2:00 AM every day:
|
4
|
+
# example cron entry to delete users older than 7 days at 2:00 AM every day:
|
5
5
|
# 0 2 * * * cd /path/to/your/app && /path/to/rake devise_guests:delete_old_guest_users[7] RAILS_ENV=your_env
|
6
6
|
desc "Removes entries in the users table for guest users that are older than the number of days given."
|
7
7
|
task :delete_old_guest_users, [:days_old] => [:environment] do |t, args|
|
8
|
-
args.with_defaults(:
|
8
|
+
args.with_defaults(days_old: 7)
|
9
9
|
User.where("guest = ? and updated_at < ?", true, Time.now - args[:days_old].to_i.days).each { |x| x.destroy }
|
10
10
|
end
|
11
|
-
|
12
11
|
end
|
@@ -1,14 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "ostruct"
|
3
3
|
|
4
|
-
describe ApplicationController, :
|
4
|
+
describe ApplicationController, type: :controller do
|
5
5
|
controller do
|
6
|
-
|
7
6
|
end
|
8
7
|
|
9
8
|
before(:each) do
|
10
9
|
@mock_warden = OpenStruct.new
|
11
|
-
@controller.request.env[
|
10
|
+
@controller.request.env["warden"] = @mock_warden
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should create an anonymous user for a guest" do
|
@@ -18,10 +17,30 @@ describe ApplicationController, :type => :controller do
|
|
18
17
|
end
|
19
18
|
|
20
19
|
it "should use the current user when available" do
|
21
|
-
m = double
|
20
|
+
m = double
|
22
21
|
allow(@mock_warden).to receive(:authenticate).with(anything).and_return(m)
|
23
22
|
|
24
23
|
expect(@controller.current_or_guest_user).to eq(m)
|
25
24
|
end
|
26
25
|
|
26
|
+
it "should run the 'logging_in' callbacks" do
|
27
|
+
# A user is logged in
|
28
|
+
current_user = double
|
29
|
+
allow(@controller).to receive(:current_user) { current_user }
|
30
|
+
|
31
|
+
# There is a guest user instance
|
32
|
+
guest_user = double
|
33
|
+
allow(guest_user).to receive(:destroy)
|
34
|
+
allow(@controller).to receive(:guest_user) { guest_user }
|
35
|
+
allow(@controller).to receive(:session) { {guest_user_id: 123} }
|
36
|
+
|
37
|
+
expect(@controller).to receive(:run_callbacks).with(:logging_in_user).and_call_original
|
38
|
+
expect(@controller).to receive(:transfer_guest_to_user).and_call_original
|
39
|
+
|
40
|
+
@controller.current_or_guest_user
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should define a 'logging_in' callback" do
|
44
|
+
expect(@controller).to respond_to(:_logging_in_user_callbacks)
|
45
|
+
end
|
27
46
|
end
|
File without changes
|
@@ -3,6 +3,5 @@ class User < ActiveRecord::Base
|
|
3
3
|
# :token_authenticatable, :confirmable,
|
4
4
|
# :lockable, :timeoutable and :omniauthable
|
5
5
|
devise :database_authenticatable, :registerable,
|
6
|
-
|
6
|
+
:recoverable, :rememberable, :trackable, :validatable
|
7
7
|
end
|
8
|
-
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Devise.setup do |config|
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "devise/orm/active_record"
|
3
|
+
require "devise-guests"
|
4
4
|
|
5
5
|
config.helpers << DeviseGuests::Controllers::Helpers
|
6
|
-
config.secret_key =
|
6
|
+
config.secret_key = "71da52cff5ef1a77c9ccdc5153993e0e58054c288c86e005d9f7eca6ac7a9279825c7903f1de5960e900543ab0cf7f85b6d307c43b53719bebcdb9cdcfe8b7e7"
|
7
7
|
end
|
data/spec/internal/db/schema.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
ActiveRecord::Schema.define do
|
2
|
-
create_table "users", :
|
3
|
-
t.string
|
4
|
-
t.string
|
5
|
-
t.string
|
2
|
+
create_table "users", force: true do |t|
|
3
|
+
t.string "email", default: "", null: false
|
4
|
+
t.string "encrypted_password", default: "", null: false
|
5
|
+
t.string "reset_password_token"
|
6
6
|
t.datetime "reset_password_sent_at"
|
7
7
|
t.datetime "remember_created_at"
|
8
|
-
t.integer
|
8
|
+
t.integer "sign_in_count", default: 0
|
9
9
|
t.datetime "current_sign_in_at"
|
10
10
|
t.datetime "last_sign_in_at"
|
11
|
-
t.string
|
12
|
-
t.string
|
13
|
-
t.datetime "created_at",
|
14
|
-
t.datetime "updated_at",
|
11
|
+
t.string "current_sign_in_ip"
|
12
|
+
t.string "last_sign_in_ip"
|
13
|
+
t.datetime "created_at", null: false
|
14
|
+
t.datetime "updated_at", null: false
|
15
15
|
end
|
16
16
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,22 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
SimpleCov.start
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'combustion'
|
10
|
-
require 'capybara/rspec'
|
4
|
+
require "combustion"
|
5
|
+
require "capybara/rspec"
|
11
6
|
|
12
|
-
require
|
13
|
-
require
|
14
|
-
Combustion.initialize!(:active_record
|
7
|
+
require "devise"
|
8
|
+
require "devise-guests"
|
9
|
+
Combustion.initialize!(:active_record, :action_mailer)
|
15
10
|
|
16
|
-
require
|
17
|
-
require
|
11
|
+
require "rspec/rails"
|
12
|
+
require "capybara/rails"
|
18
13
|
|
19
14
|
RSpec.configure do |config|
|
20
15
|
config.infer_spec_type_from_file_location!
|
21
16
|
end
|
22
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-guests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '1.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
68
|
+
version: '1.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: standard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: yard
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,8 +130,10 @@ extra_rdoc_files:
|
|
116
130
|
- LICENSE
|
117
131
|
- README.md
|
118
132
|
files:
|
133
|
+
- ".github/workflows/tests.yml"
|
119
134
|
- ".gitignore"
|
120
|
-
- ".
|
135
|
+
- ".standard.yml"
|
136
|
+
- CHANGELOG.md
|
121
137
|
- Gemfile
|
122
138
|
- LICENSE
|
123
139
|
- README.md
|
@@ -136,11 +152,13 @@ files:
|
|
136
152
|
- spec/controllers/application_controller_spec.rb
|
137
153
|
- spec/helpers/devise_guests_helpers_spec.rb
|
138
154
|
- spec/integration/simple_integration_spec.rb
|
155
|
+
- spec/internal/app/assets/config/manifest.js
|
139
156
|
- spec/internal/app/controllers/application_controller.rb
|
140
157
|
- spec/internal/app/models/user.rb
|
141
158
|
- spec/internal/config/database.yml
|
142
159
|
- spec/internal/config/initializers/devise.rb
|
143
160
|
- spec/internal/config/routes.rb
|
161
|
+
- spec/internal/config/storage.yml
|
144
162
|
- spec/internal/db/schema.rb
|
145
163
|
- spec/internal/log/.gitignore
|
146
164
|
- spec/internal/public/favicon.ico
|
@@ -149,7 +167,7 @@ homepage: http://github.com/cbeer/devise-guests
|
|
149
167
|
licenses:
|
150
168
|
- MIT
|
151
169
|
metadata: {}
|
152
|
-
post_install_message:
|
170
|
+
post_install_message:
|
153
171
|
rdoc_options: []
|
154
172
|
require_paths:
|
155
173
|
- lib
|
@@ -164,20 +182,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
182
|
- !ruby/object:Gem::Version
|
165
183
|
version: '0'
|
166
184
|
requirements: []
|
167
|
-
|
168
|
-
|
169
|
-
signing_key:
|
185
|
+
rubygems_version: 3.0.9
|
186
|
+
signing_key:
|
170
187
|
specification_version: 4
|
171
188
|
summary: Guest user implementation for devise
|
172
189
|
test_files:
|
173
190
|
- spec/controllers/application_controller_spec.rb
|
174
191
|
- spec/helpers/devise_guests_helpers_spec.rb
|
175
192
|
- spec/integration/simple_integration_spec.rb
|
193
|
+
- spec/internal/app/assets/config/manifest.js
|
176
194
|
- spec/internal/app/controllers/application_controller.rb
|
177
195
|
- spec/internal/app/models/user.rb
|
178
196
|
- spec/internal/config/database.yml
|
179
197
|
- spec/internal/config/initializers/devise.rb
|
180
198
|
- spec/internal/config/routes.rb
|
199
|
+
- spec/internal/config/storage.yml
|
181
200
|
- spec/internal/db/schema.rb
|
182
201
|
- spec/internal/log/.gitignore
|
183
202
|
- spec/internal/public/favicon.ico
|