mongoid-userstamps 3.1.3 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +9 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +12 -4
- data/Rakefile +9 -10
- data/init.rb +1 -2
- data/lib/mongoid-userstamps.rb +1 -4
- data/lib/mongoid/userstamps.rb +8 -11
- data/lib/mongoid/userstamps/config.rb +9 -15
- data/lib/mongoid/userstamps/config/model.rb +12 -6
- data/lib/mongoid/userstamps/config/user.rb +0 -3
- data/lib/mongoid/userstamps/created.rb +4 -7
- data/lib/mongoid/userstamps/deleted.rb +4 -7
- data/lib/mongoid/userstamps/model.rb +0 -1
- data/lib/mongoid/userstamps/railtie.rb +0 -3
- data/lib/mongoid/userstamps/updated.rb +4 -7
- data/lib/mongoid/userstamps/user.rb +2 -4
- data/lib/mongoid/userstamps/version.rb +1 -4
- data/mongoid-userstamps.gemspec +17 -19
- data/spec/spec_helper.rb +9 -10
- data/spec/support/admin.rb +1 -2
- data/spec/support/book.rb +2 -3
- data/spec/support/post.rb +2 -3
- data/spec/support/user.rb +0 -1
- data/spec/unit/gem_config_spec.rb +8 -11
- data/spec/unit/model_config_spec.rb +15 -14
- data/spec/unit/model_spec.rb +41 -36
- data/spec/unit/user_config_spec.rb +5 -8
- data/spec/unit/user_spec.rb +38 -34
- data/spec/unit/userstamp_spec.rb +48 -51
- data/test/config_test.rb +13 -10
- data/test/model_test.rb +12 -13
- data/test/models/archive.rb +0 -1
- data/test/models/comment.rb +1 -2
- data/test/models/person.rb +0 -1
- data/test/models/post.rb +1 -2
- data/test/models/user.rb +0 -1
- data/test/paranoia_test.rb +2 -3
- data/test/test_helper.rb +9 -8
- data/test/user_test.rb +9 -10
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: abd89e19a087c09f663588c80c5007cdc781985db52dffbc9af426574c161a76
|
4
|
+
data.tar.gz: fe286c80e6bf99589b02811a90eafa8026ab79d18ea39352f5144606df8236a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7018b8e7ad31ff0f96f53a208dba6db14efd4c7e20bf4b9011a8cb66661104b7dfd9ce91038f63f810af8b47386635487d2bda7aaea5042b5f20dad0912dbd33
|
7
|
+
data.tar.gz: 32145a486f3d28690d69bd1d1d4ddfdd2703f760af8d5f7e2882b84853577224aa2cfa4e6bb118261340af6b853046eefd2265dd3271ad8a30688f8182a72200
|
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
rvm:
|
4
|
+
- 2.4.9
|
5
|
+
- 2.5.7
|
6
|
+
- 2.6.5
|
7
|
+
before_install:
|
8
|
+
- gem install bundler
|
9
|
+
install: bundle update --jobs=3 --retry=3
|
10
|
+
services:
|
11
|
+
- mongodb
|
12
|
+
env:
|
13
|
+
- "MONGOID_VERSION=6.2.0"
|
14
|
+
- "MONGOID_VERSION=6.3.0"
|
15
|
+
- "MONGOID_VERSION=6.4.0"
|
16
|
+
- "MONGOID_VERSION=7.0.0"
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
-
source
|
1
|
+
source "http://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
5
|
+
mongoid_version = ENV["MONGOID_VERSION"] || "7.0.0"
|
6
6
|
|
7
|
-
gem
|
8
|
-
gem
|
7
|
+
gem "rake"
|
8
|
+
gem "mongoid", "~> #{mongoid_version}"
|
9
|
+
gem "request_store", require: false
|
9
10
|
|
11
|
+
group :development do
|
12
|
+
gem "simplecov", require: false
|
13
|
+
gem "pry-nav", "~> 0.2.4"
|
14
|
+
gem "standard", "~> 0.1.0"
|
15
|
+
gem "rubocop"
|
16
|
+
gem "rubocop-performance"
|
17
|
+
end
|
data/Rakefile
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rake/testtask"
|
4
4
|
|
5
|
-
desc
|
6
|
-
task :
|
5
|
+
desc "Default: run unit tests"
|
6
|
+
task default: :test
|
7
7
|
|
8
|
-
desc
|
8
|
+
desc "Run tests"
|
9
9
|
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs <<
|
11
|
-
t.libs <<
|
12
|
-
t.pattern =
|
13
|
-
t.
|
10
|
+
t.libs << "lib"
|
11
|
+
t.libs << "test"
|
12
|
+
t.pattern = "test/**/*_test.rb"
|
13
|
+
t.warning = false
|
14
14
|
end
|
15
|
-
|
data/init.rb
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
require 'mongoid_userstamp'
|
1
|
+
require "mongoid_userstamp"
|
data/lib/mongoid-userstamps.rb
CHANGED
data/lib/mongoid/userstamps.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require 'mongoid/userstamps/deleted'
|
10
|
-
require 'mongoid/userstamps/railtie' if defined? Rails
|
1
|
+
require "mongoid/userstamps/version"
|
2
|
+
require "mongoid/userstamps/config"
|
3
|
+
require "mongoid/userstamps/user"
|
4
|
+
require "mongoid/userstamps/model"
|
5
|
+
require "mongoid/userstamps/created"
|
6
|
+
require "mongoid/userstamps/updated"
|
7
|
+
require "mongoid/userstamps/deleted"
|
8
|
+
require "mongoid/userstamps/railtie" if defined? Rails
|
11
9
|
|
12
10
|
module Mongoid
|
13
11
|
module Userstamps
|
@@ -27,4 +25,3 @@ module Mongoid
|
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'mongoid/userstamps/config/model'
|
4
|
-
require 'mongoid/userstamps/config/user'
|
1
|
+
require "mongoid/userstamps/config/model"
|
2
|
+
require "mongoid/userstamps/config/user"
|
5
3
|
|
6
4
|
module Mongoid
|
7
5
|
module Userstamps
|
@@ -30,23 +28,20 @@ module Mongoid
|
|
30
28
|
model_classes << klass
|
31
29
|
end
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
31
|
+
attr_writer :created_name
|
32
|
+
|
36
33
|
def created_name
|
37
34
|
@created_name ||= DEFAULT_CREATED_NAME
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
37
|
+
attr_writer :updated_name
|
38
|
+
|
43
39
|
def updated_name
|
44
40
|
@updated_name ||= DEFAULT_UPDATED_NAME
|
45
41
|
end
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
43
|
+
attr_writer :deleted_name
|
44
|
+
|
50
45
|
def deleted_name
|
51
46
|
@deleted_name ||= DEFAULT_DELETED_NAME
|
52
47
|
end
|
@@ -60,7 +55,7 @@ module Mongoid
|
|
60
55
|
end
|
61
56
|
|
62
57
|
def store(model, value = false)
|
63
|
-
return
|
58
|
+
return unless model
|
64
59
|
key = "mongoid-userstamps/#{model.to_s.underscore}".to_sym
|
65
60
|
store = defined?(RequestStore) ? RequestStore.store : Thread.current
|
66
61
|
if value == false
|
@@ -79,4 +74,3 @@ module Mongoid
|
|
79
74
|
end
|
80
75
|
end
|
81
76
|
end
|
82
|
-
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
1
|
module Mongoid
|
4
2
|
module Userstamps
|
5
3
|
module Config
|
@@ -23,12 +21,20 @@ module Mongoid
|
|
23
21
|
end
|
24
22
|
|
25
23
|
def set_user_model!
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
if Mongoid::VERSION.to_f < 7.0
|
25
|
+
%i[created_name updated_name deleted_name].each do |attr|
|
26
|
+
@model.relations[config.send(attr).to_s].try(:[]=, :class_name, user_model)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
%i[created_name updated_name deleted_name].each do |attr|
|
30
|
+
if @model.relations[config.send(attr).to_s]
|
31
|
+
@model.relations[config.send(attr).to_s].instance_variable_set :@class_name, user_model
|
32
|
+
@model.relations[config.send(attr).to_s].options[:class_name] = user_model
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
34
|
-
|
@@ -1,19 +1,17 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
1
|
module Mongoid
|
4
2
|
module Userstamps
|
5
3
|
module Created
|
6
4
|
extend ActiveSupport::Concern
|
7
5
|
|
8
6
|
included do
|
9
|
-
|
7
|
+
unless included_modules.include?(Mongoid::Userstamps::Model)
|
10
8
|
include Mongoid::Userstamps::Model
|
11
9
|
end
|
12
10
|
|
13
11
|
belongs_to userstamps_config.created_name, {
|
14
12
|
class_name: userstamps_model.user_model,
|
15
13
|
inverse_of: nil,
|
16
|
-
optional: true
|
14
|
+
optional: true,
|
17
15
|
}
|
18
16
|
|
19
17
|
set_callback :create, :before, :set_created_by
|
@@ -21,10 +19,9 @@ module Mongoid
|
|
21
19
|
|
22
20
|
def set_created_by
|
23
21
|
user = self.class.current_user
|
24
|
-
return if !user ||
|
25
|
-
|
22
|
+
return if !user || public_send(userstamps_config.created_name)
|
23
|
+
public_send("#{userstamps_config.created_name}=", user)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
@@ -1,19 +1,17 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
1
|
module Mongoid
|
4
2
|
module Userstamps
|
5
3
|
module Deleted
|
6
4
|
extend ActiveSupport::Concern
|
7
5
|
|
8
6
|
included do
|
9
|
-
|
7
|
+
unless included_modules.include?(Mongoid::Userstamps::Model)
|
10
8
|
include Mongoid::Userstamps::Model
|
11
9
|
end
|
12
10
|
|
13
11
|
belongs_to userstamps_config.deleted_name, {
|
14
12
|
class_name: userstamps_model.user_model,
|
15
13
|
inverse_of: nil,
|
16
|
-
optional: true
|
14
|
+
optional: true,
|
17
15
|
}
|
18
16
|
|
19
17
|
set_callback :destroy, :before, :set_deleted_by
|
@@ -21,10 +19,9 @@ module Mongoid
|
|
21
19
|
|
22
20
|
def set_deleted_by
|
23
21
|
user = self.class.current_user
|
24
|
-
return if !user ||
|
25
|
-
|
22
|
+
return if !user || public_send("#{userstamps_config.deleted_name}_id_changed?")
|
23
|
+
public_send("#{userstamps_config.deleted_name}=", user)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
@@ -1,19 +1,17 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
1
|
module Mongoid
|
4
2
|
module Userstamps
|
5
3
|
module Updated
|
6
4
|
extend ActiveSupport::Concern
|
7
5
|
|
8
6
|
included do
|
9
|
-
|
7
|
+
unless included_modules.include?(Mongoid::Userstamps::Model)
|
10
8
|
include Mongoid::Userstamps::Model
|
11
9
|
end
|
12
10
|
|
13
11
|
belongs_to userstamps_config.updated_name, {
|
14
12
|
class_name: userstamps_model.user_model,
|
15
13
|
inverse_of: nil,
|
16
|
-
optional: true
|
14
|
+
optional: true,
|
17
15
|
}
|
18
16
|
|
19
17
|
set_callback :save, :before, :set_updated_by
|
@@ -21,10 +19,9 @@ module Mongoid
|
|
21
19
|
|
22
20
|
def set_updated_by
|
23
21
|
user = self.class.current_user
|
24
|
-
return if !user ||
|
25
|
-
|
22
|
+
return if !user || public_send("#{userstamps_config.updated_name}_id_changed?")
|
23
|
+
public_send("#{userstamps_config.updated_name}=", user)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
module Mongoid
|
3
2
|
module Userstamps
|
4
3
|
module User
|
@@ -9,7 +8,7 @@ module Mongoid
|
|
9
8
|
end
|
10
9
|
|
11
10
|
def current?
|
12
|
-
|
11
|
+
id == self.class.current.try(:id)
|
13
12
|
end
|
14
13
|
|
15
14
|
class_methods do
|
@@ -22,7 +21,7 @@ module Mongoid
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def sudo(user)
|
25
|
-
old =
|
24
|
+
old = current
|
26
25
|
self.current = user
|
27
26
|
yield
|
28
27
|
ensure
|
@@ -36,4 +35,3 @@ module Mongoid
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
data/mongoid-userstamps.gemspec
CHANGED
@@ -1,26 +1,24 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
|
4
|
-
require
|
3
|
+
require "mongoid/userstamps/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
s.authors
|
10
|
-
s.homepage
|
11
|
-
s.license
|
12
|
-
s.summary
|
13
|
-
s.description =
|
14
|
-
s.email
|
6
|
+
s.name = "mongoid-userstamps"
|
7
|
+
s.version = Mongoid::Userstamps::VERSION
|
8
|
+
s.authors = ["Geoffroy Planquart", "Thomas Boerger", "Johnny Shields", "Bharat Gupta"]
|
9
|
+
s.homepage = "https://github.com/tbpro/mongoid_userstamp"
|
10
|
+
s.license = "MIT"
|
11
|
+
s.summary = "Userstamps for Mongoid"
|
12
|
+
s.description = "Userstamps for creator and updater fields using Mongoid"
|
13
|
+
s.email = ["geoffroy@planquart.fr", "tboerger@tbpro.de"]
|
15
14
|
|
16
|
-
s.files
|
17
|
-
s.executables
|
18
|
-
s.test_files
|
19
|
-
s.require_paths = [
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ["lib"]
|
20
19
|
|
21
|
-
s.post_install_message = File.read(
|
20
|
+
s.post_install_message = File.read("UPGRADING") if File.exist?("UPGRADING")
|
22
21
|
|
23
|
-
s.add_dependency
|
24
|
-
s.add_dependency
|
22
|
+
s.add_dependency "mongoid", ">= 5.0.0", "< 7.1.0"
|
23
|
+
s.add_dependency "activesupport", ">= 4.2.0", "< 5.2.0"
|
25
24
|
end
|
26
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'ostruct'
|
1
|
+
require "rubygems"
|
2
|
+
require "ostruct"
|
4
3
|
|
5
|
-
$:.push File.expand_path(
|
4
|
+
$:.push File.expand_path("../../lib", __FILE__)
|
6
5
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
6
|
+
require "active_support/all"
|
7
|
+
require "mongoid"
|
8
|
+
require "mongoid_userstamp"
|
10
9
|
|
11
|
-
%w
|
10
|
+
%w[admin user book post].each do |file_name|
|
12
11
|
require "support/#{file_name}"
|
13
12
|
end
|
14
13
|
|
15
14
|
Mongoid.configure do |config|
|
16
|
-
config.connect_to
|
15
|
+
config.connect_to "mongoid_userstamp_test"
|
17
16
|
end
|
18
17
|
|
19
18
|
RSpec.configure do |config|
|
20
19
|
config.mock_with :rspec
|
21
|
-
|
20
|
+
|
22
21
|
config.after :suite do
|
23
22
|
Mongoid.purge!
|
24
23
|
end
|