mongoid_userstamp 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/{.rbenv-version → .ruby-version} +0 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +25 -3
- data/LICENSE.md +1 -1
- data/README.md +24 -8
- data/Rakefile +3 -3
- data/lib/mongoid/userstamp.rb +61 -29
- data/lib/mongoid/userstamp/config.rb +5 -7
- data/lib/mongoid/userstamp/railtie.rb +3 -3
- data/lib/mongoid/userstamp/user.rb +1 -1
- data/lib/mongoid/userstamp/version.rb +2 -2
- data/lib/mongoid_userstamp.rb +3 -0
- data/mongoid_userstamp.gemspec +9 -7
- data/spec/mongoid/userstamp_spec.rb +130 -29
- metadata +10 -21
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODA4YmMxOWYzZTRjMTQ3MzhjYTcwYjEyNTE3YjJkMzZmZjQzOGM4MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTIwZTFlMTM3YjEzODA0ZWUwMzliYzYwMWI1ODVmN2ZkZWJhZDFkNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmZiN2E0ODk1YWRhMWM5ODkzMzljOWM2NzVkZmVkOGFiM2UzNzcxYTA1YTBi
|
10
|
+
MzBlMmFlZWUyMGQ1NDhkNjY1YTdkMjUyZThjNjc4NTA2YzJlMGM1ZDZlODEy
|
11
|
+
MWFkOGEyMTYyM2Q4NDJiMmY3ZTllZWM5MTJlMjlhOWEyN2ZmMmY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDdlMmYyZWI2ZjA0MDA0ZTg0NmJjYTVhOTY2MWJkN2I4ZWVkMzdlZTIwZTM0
|
14
|
+
YzcyZDRjNDYxNmU4NzUyNjdjZGZiMWE2MWVhMDYzYmQ1NjdmNDRhZGYyZjY1
|
15
|
+
ZGZjOGUxOGY3YTIyMWE5ZDkzNTFlNzU4YmVmM2JmZjUwYjk1Mjc=
|
File without changes
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,26 @@
|
|
1
|
-
|
1
|
+
# Changelog
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
## [0.3.0](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.3.0) - 2013-10-02
|
4
|
+
|
5
|
+
* Improvement
|
6
|
+
* BREAKING: Default value for `updated_accessor` was `:updator`, is now `:updater` (@johnnyshields)
|
7
|
+
* DEPRECATION: `#configure` is now an alias for `#config` and is deprecated (@johnnyshields)
|
8
|
+
* Replace `Mongoid::Userstamp.configuration` and `Mongoid::Userstamp.configure` with `#config` (@johnnyshields)
|
9
|
+
* Replace usages of `id` with `_id`, since there are many gems which override the behavior of `id` (@johnnyshields)
|
10
|
+
* Do not overwrite creator if it has already been set manually (@johnnyshields)
|
11
|
+
* Define setter methods for updated_accessor/created_accessor which assign the user id. Accepts both `Mongoid::Document` and `BSON::ObjectID` types (@johnnyshields)
|
12
|
+
* Allow pass-in of Mongoid field options for updated_column/created_column. Useful to set field aliases, default value, etc. (@johnnyshields)
|
13
|
+
* Expose current_user as `Mongoid::Userstamp.current_user` (@johnnyshields)
|
14
|
+
* Field type is now `::Moped::BSON::ObjectID` instead of Object (@johnnyshields)
|
15
|
+
* Query for creator/updater user using `unscoped` (@johnnyshields)
|
16
|
+
* Improve code readability (@johnnyshields)
|
17
|
+
* Improve test coverage, including adding tests for config (@johnnyshields)
|
18
|
+
|
19
|
+
* Bugfix
|
20
|
+
* Catch error if creator/updater has been deleted and return nil (@johnnyshields)
|
21
|
+
|
22
|
+
## [0.2.1](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.2.1) - 2013-03-24
|
23
|
+
|
24
|
+
* Improvement
|
25
|
+
* Added some specs for test coverage (@johnnyshields)
|
26
|
+
* Removed dependecy for `Mongoid::Timestamps` (@johnnyshields)
|
data/LICENSE.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2013 Thomas Boerger Programmierung <http://www.tbpro.de>
|
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
@@ -14,7 +14,10 @@ version above 1.8, so i've written the gem on the new 1.9 hash syntax.
|
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
# Default config
|
17
|
-
Mongoid::Userstamp.
|
17
|
+
Mongoid::Userstamp.config do |c|
|
18
|
+
|
19
|
+
# Default config values
|
20
|
+
|
18
21
|
c.user_reader = :current_user
|
19
22
|
c.user_model = :user
|
20
23
|
|
@@ -22,7 +25,12 @@ version above 1.8, so i've written the gem on the new 1.9 hash syntax.
|
|
22
25
|
c.created_accessor = :creator
|
23
26
|
|
24
27
|
c.updated_column = :updated_by
|
25
|
-
c.updated_accessor = :
|
28
|
+
c.updated_accessor = :updater
|
29
|
+
|
30
|
+
# Optional config values
|
31
|
+
|
32
|
+
# c.created_alias = :c
|
33
|
+
# c.updated_alias = :u
|
26
34
|
end
|
27
35
|
|
28
36
|
# Example model
|
@@ -35,20 +43,28 @@ version above 1.8, so i've written the gem on the new 1.9 hash syntax.
|
|
35
43
|
p = Person.create
|
36
44
|
|
37
45
|
# Updater ObjectID or nil
|
38
|
-
p.
|
46
|
+
p.updated_by
|
39
47
|
# => BSON::ObjectId('4f7c719f476da850ba000039')
|
40
48
|
|
41
49
|
# Updater instance or nil
|
42
|
-
p.
|
50
|
+
p.updater
|
43
51
|
# => <User _id: 4f7c719f476da850ba000039>
|
44
52
|
|
45
|
-
#
|
46
|
-
p.
|
53
|
+
# Set updater manually (usually not required)
|
54
|
+
p.updater = my_user # can be a Mongoid::Document or a BSON::ObjectID
|
55
|
+
# => sets updated_by to my_user's ObjectID
|
56
|
+
|
57
|
+
# Creator ObjectID or nil
|
58
|
+
p.created_by
|
47
59
|
# => BSON::ObjectId('4f7c719f476da850ba000039')
|
48
60
|
|
49
|
-
#
|
50
|
-
p.
|
61
|
+
# Creator instance or nil
|
62
|
+
p.creator
|
51
63
|
# => <User _id: 4f7c719f476da850ba000039>
|
64
|
+
|
65
|
+
# Set creator manually (usually not required)
|
66
|
+
p.creator = my_user # can be a Mongoid::Document or a BSON::ObjectID
|
67
|
+
# => sets created_by to my_user._id
|
52
68
|
```
|
53
69
|
|
54
70
|
## Credits
|
data/Rakefile
CHANGED
@@ -22,12 +22,12 @@ Jeweler::Tasks.new do |gem|
|
|
22
22
|
gem.version = Mongoid::Userstamp::Version::STRING
|
23
23
|
gem.homepage = 'https://github.com/tbpro/mongoid_userstamp'
|
24
24
|
gem.license = 'MIT'
|
25
|
-
gem.summary = %Q{Userstamp for
|
25
|
+
gem.summary = %Q{Userstamp for mongoid}
|
26
|
+
gem.description = %Q{Userstamp for created and updated columns within mongoid}
|
26
27
|
gem.email = 'tboerger@tbpro.de'
|
27
|
-
gem.authors = ['Thomas Boerger']
|
28
|
+
gem.authors = ['Thomas Boerger', 'Johnny Shields']
|
28
29
|
end
|
29
30
|
|
30
|
-
Jeweler::RubygemsDotOrgTasks.new
|
31
31
|
YARD::Rake::YardocTask.new
|
32
32
|
|
33
33
|
require 'rspec/core'
|
data/lib/mongoid/userstamp.rb
CHANGED
@@ -1,53 +1,85 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
+
|
2
3
|
module Mongoid
|
3
4
|
module Userstamp
|
4
5
|
extend ActiveSupport::Concern
|
5
6
|
|
6
|
-
autoload :Version, 'mongoid/userstamp/version'
|
7
|
-
autoload :Railtie, 'mongoid/userstamp/railtie'
|
8
|
-
autoload :Config, 'mongoid/userstamp/config'
|
9
|
-
autoload :User, 'mongoid/userstamp/user'
|
10
|
-
|
11
7
|
included do
|
12
|
-
field
|
13
|
-
field
|
8
|
+
field Userstamp.config.updated_column, Userstamp.field_opts(Userstamp.config.updated_column_opts)
|
9
|
+
field Userstamp.config.created_column, Userstamp.field_opts(Userstamp.config.created_column_opts)
|
14
10
|
|
15
|
-
before_save :
|
11
|
+
before_save :set_updater
|
16
12
|
before_create :set_creator
|
17
13
|
|
18
|
-
define_method
|
19
|
-
|
20
|
-
updated_col ? Mongoid::Userstamp.configuration.user_model.find(updated_col) : nil
|
14
|
+
define_method Userstamp.config.updated_accessor do
|
15
|
+
Userstamp.find_user self.send(Userstamp.config.updated_column)
|
21
16
|
end
|
22
17
|
|
23
|
-
define_method
|
24
|
-
|
25
|
-
created_col ? Mongoid::Userstamp.configuration.user_model.find(created_col) : nil
|
18
|
+
define_method Userstamp.config.created_accessor do
|
19
|
+
Userstamp.find_user self.send(Userstamp.config.created_column)
|
26
20
|
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
column = "#{Mongoid::Userstamp.configuration.updated_column.to_s}=".to_sym
|
22
|
+
define_method "#{Userstamp.config.updated_accessor}=" do |user|
|
23
|
+
self.send("#{Userstamp.config.updated_column}=", Userstamp.extract_bson_id(user))
|
24
|
+
end
|
32
25
|
|
33
|
-
|
34
|
-
|
26
|
+
define_method "#{Userstamp.config.created_accessor}=" do |user|
|
27
|
+
self.send("#{Userstamp.config.created_column}=", Userstamp.extract_bson_id(user))
|
28
|
+
end
|
35
29
|
|
36
|
-
|
37
|
-
return unless Mongoid::Userstamp.configuration.user_model.respond_to? :current
|
38
|
-
column = "#{Mongoid::Userstamp.configuration.created_column.to_s}=".to_sym
|
30
|
+
protected
|
39
31
|
|
40
|
-
|
41
|
-
|
32
|
+
def set_updater
|
33
|
+
return if !Userstamp.has_current_user?
|
34
|
+
self.send("#{Userstamp.config.updated_accessor}=", Userstamp.current_user)
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_creator
|
38
|
+
return if !Userstamp.has_current_user? || self.send(Userstamp.config.created_column)
|
39
|
+
self.send("#{Userstamp.config.created_accessor}=", Userstamp.current_user)
|
40
|
+
end
|
42
41
|
end
|
43
42
|
|
44
43
|
class << self
|
45
|
-
def
|
46
|
-
|
44
|
+
def config(&block)
|
45
|
+
if block_given?
|
46
|
+
@@config = Userstamp::Config.new(&block)
|
47
|
+
else
|
48
|
+
@@config ||= Userstamp::Config.new
|
49
|
+
end
|
47
50
|
end
|
48
51
|
|
49
|
-
|
50
|
-
|
52
|
+
# @deprecated Use {#config} instead
|
53
|
+
alias :configure :config
|
54
|
+
|
55
|
+
def field_opts(opts)
|
56
|
+
{type: ::Moped::BSON::ObjectId}.reverse_merge(opts || {})
|
57
|
+
end
|
58
|
+
|
59
|
+
def has_current_user?
|
60
|
+
config.user_model.respond_to?(:current)
|
61
|
+
end
|
62
|
+
|
63
|
+
def current_user
|
64
|
+
config.user_model.try(:current)
|
65
|
+
end
|
66
|
+
|
67
|
+
def extract_bson_id(value)
|
68
|
+
if value.respond_to?(:_id)
|
69
|
+
value.try(:_id)
|
70
|
+
elsif value.present?
|
71
|
+
::Moped::BSON::ObjectId.from_string(value.to_s)
|
72
|
+
else
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def find_user(user_id)
|
78
|
+
begin
|
79
|
+
user_id ? Userstamp.config.user_model.unscoped.find(user_id) : nil
|
80
|
+
rescue Mongoid::Errors::DocumentNotFound => e
|
81
|
+
nil
|
82
|
+
end
|
51
83
|
end
|
52
84
|
end
|
53
85
|
end
|
@@ -2,24 +2,22 @@
|
|
2
2
|
module Mongoid
|
3
3
|
module Userstamp
|
4
4
|
class Config
|
5
|
+
attr_writer :user_model
|
5
6
|
attr_accessor :user_reader
|
6
|
-
attr_accessor :user_model
|
7
|
-
|
8
7
|
attr_accessor :created_column
|
8
|
+
attr_accessor :created_column_opts
|
9
9
|
attr_accessor :created_accessor
|
10
|
-
|
11
10
|
attr_accessor :updated_column
|
11
|
+
attr_accessor :updated_column_opts
|
12
12
|
attr_accessor :updated_accessor
|
13
13
|
|
14
14
|
def initialize(&block)
|
15
|
-
@user_reader = :current_user
|
16
15
|
@user_model = :user
|
17
|
-
|
16
|
+
@user_reader = :current_user
|
18
17
|
@created_column = :created_by
|
19
18
|
@created_accessor = :creator
|
20
|
-
|
21
19
|
@updated_column = :updated_by
|
22
|
-
@updated_accessor = :
|
20
|
+
@updated_accessor = :updater
|
23
21
|
|
24
22
|
instance_eval(&block) if block_given?
|
25
23
|
end
|
@@ -4,14 +4,14 @@ module Mongoid
|
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
ActiveSupport.on_load :action_controller do
|
6
6
|
before_filter do |c|
|
7
|
-
unless Mongoid::Userstamp.
|
8
|
-
Mongoid::Userstamp.
|
7
|
+
unless Mongoid::Userstamp.config.user_model.respond_to? :current
|
8
|
+
Mongoid::Userstamp.config.user_model.send(
|
9
9
|
:include,
|
10
10
|
Mongoid::Userstamp::User
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
|
-
Mongoid::Userstamp.
|
14
|
+
Mongoid::Userstamp.config.user_model.current = c.send(Mongoid::Userstamp.config.user_reader)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/mongoid_userstamp.rb
CHANGED
data/mongoid_userstamp.gemspec
CHANGED
@@ -2,21 +2,23 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: mongoid_userstamp 0.3.0 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "mongoid_userstamp"
|
8
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Thomas Boerger"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.authors = ["Thomas Boerger", "Johnny Shields"]
|
13
|
+
s.date = "2013-10-02"
|
14
|
+
s.description = "Userstamp for created and updated columns within mongoid"
|
13
15
|
s.email = "tboerger@tbpro.de"
|
14
16
|
s.extra_rdoc_files = [
|
15
17
|
"LICENSE.md",
|
16
18
|
"README.md"
|
17
19
|
]
|
18
20
|
s.files = [
|
19
|
-
".
|
21
|
+
".ruby-version",
|
20
22
|
".travis.yml",
|
21
23
|
"CHANGELOG.md",
|
22
24
|
"Gemfile",
|
@@ -40,11 +42,11 @@ Gem::Specification.new do |s|
|
|
40
42
|
s.homepage = "https://github.com/tbpro/mongoid_userstamp"
|
41
43
|
s.licenses = ["MIT"]
|
42
44
|
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = "1.
|
44
|
-
s.summary = "Userstamp for
|
45
|
+
s.rubygems_version = "2.1.5"
|
46
|
+
s.summary = "Userstamp for mongoid"
|
45
47
|
|
46
48
|
if s.respond_to? :specification_version then
|
47
|
-
s.specification_version =
|
49
|
+
s.specification_version = 4
|
48
50
|
|
49
51
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
52
|
s.add_runtime_dependency(%q<mongoid>, [">= 3.0.4"])
|
@@ -1,62 +1,163 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
subject {
|
6
|
-
|
7
|
-
|
8
|
-
)
|
9
|
-
}
|
4
|
+
describe Mongoid::Userstamp do
|
5
|
+
subject { Book.new(name: 'Crafting Rails Applications') }
|
6
|
+
let(:user_1) { User.create!(name: 'Charles Dikkens') }
|
7
|
+
let(:user_2) { User.create!(name: 'Edmund Wells') }
|
10
8
|
|
11
9
|
it { should respond_to :created_by }
|
12
10
|
it { should respond_to :creator }
|
13
11
|
it { should respond_to :updated_by }
|
14
|
-
it { should respond_to :
|
12
|
+
it { should respond_to :updater }
|
13
|
+
|
14
|
+
describe '#current_user' do
|
15
|
+
subject{ Mongoid::Userstamp.current_user }
|
16
|
+
|
17
|
+
context 'when current user is not set' do
|
18
|
+
before { User.current = nil }
|
19
|
+
it { should be_nil }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when current user is set' do
|
23
|
+
before{ User.current = user_1 }
|
24
|
+
it { should eq user_1 }
|
25
|
+
end
|
26
|
+
end
|
15
27
|
|
16
28
|
context 'when created without a user' do
|
17
|
-
before
|
29
|
+
before do
|
30
|
+
User.current = nil
|
18
31
|
subject.save!
|
19
|
-
|
32
|
+
end
|
20
33
|
|
21
34
|
it { subject.created_by.should be_nil }
|
22
35
|
it { subject.creator.should be_nil }
|
23
36
|
it { subject.updated_by.should be_nil }
|
24
|
-
it { subject.
|
37
|
+
it { subject.updater.should be_nil }
|
25
38
|
end
|
26
39
|
|
27
|
-
context 'when
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
40
|
+
context 'when creator is manually set' do
|
41
|
+
before{ User.current = user_1 }
|
42
|
+
|
43
|
+
context 'set by id' do
|
44
|
+
before do
|
45
|
+
subject.created_by = user_2._id
|
46
|
+
subject.save!
|
47
|
+
end
|
33
48
|
|
34
|
-
|
49
|
+
it 'should not be overridden when saved' do
|
50
|
+
subject.created_by.should eq user_2.id
|
51
|
+
subject.creator.should eq user_2
|
52
|
+
subject.updated_by.should eq user_1.id
|
53
|
+
subject.updater.should eq user_1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
context 'set by model' do
|
57
|
+
before do
|
58
|
+
subject.creator = user_2
|
59
|
+
subject.save!
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should not be overridden when saved' do
|
63
|
+
subject.created_by.should eq user_2.id
|
64
|
+
subject.creator.should eq user_2
|
65
|
+
subject.updated_by.should eq user_1.id
|
66
|
+
subject.updater.should eq user_1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when created by a user' do
|
72
|
+
before do
|
35
73
|
User.current = user_1
|
36
|
-
subject.save
|
37
|
-
|
74
|
+
subject.save!
|
75
|
+
end
|
38
76
|
|
39
77
|
it { subject.created_by.should == user_1.id }
|
40
78
|
it { subject.creator.should == user_1 }
|
41
79
|
it { subject.updated_by.should == user_1.id }
|
42
|
-
it { subject.
|
80
|
+
it { subject.updater.should == user_1 }
|
43
81
|
|
44
82
|
context 'when updated by a user' do
|
45
|
-
|
46
|
-
User.create!(
|
47
|
-
name: 'Edmund Wells'
|
48
|
-
)
|
49
|
-
}
|
50
|
-
|
51
|
-
before {
|
83
|
+
before do
|
52
84
|
User.current = user_2
|
53
85
|
subject.save!
|
54
|
-
|
86
|
+
end
|
55
87
|
|
56
88
|
it { subject.created_by.should == user_1.id }
|
57
89
|
it { subject.creator.should == user_1 }
|
58
90
|
it { subject.updated_by.should == user_2.id }
|
59
|
-
it { subject.
|
91
|
+
it { subject.updater.should == user_2 }
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when user has been destroyed' do
|
95
|
+
before do
|
96
|
+
User.current = user_2
|
97
|
+
subject.save!
|
98
|
+
user_1.destroy
|
99
|
+
user_2.destroy
|
100
|
+
end
|
101
|
+
|
102
|
+
it { subject.created_by.should == user_1.id }
|
103
|
+
it { subject.creator.should == nil }
|
104
|
+
it { subject.updated_by.should == user_2.id }
|
105
|
+
it { subject.updater.should == nil }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#config' do
|
110
|
+
before do
|
111
|
+
Mongoid::Userstamp.config do |c|
|
112
|
+
c.user_reader = :current_user
|
113
|
+
c.user_model = :user
|
114
|
+
|
115
|
+
c.created_column = :c_by
|
116
|
+
c.created_column_opts = {as: :created_by_id}
|
117
|
+
c.created_accessor = :created_by
|
118
|
+
|
119
|
+
c.updated_column = :u_by
|
120
|
+
c.updated_column_opts = {as: :updated_by_id}
|
121
|
+
c.updated_accessor = :updated_by
|
122
|
+
end
|
123
|
+
|
124
|
+
# class definition must come after config
|
125
|
+
class Novel
|
126
|
+
include Mongoid::Document
|
127
|
+
include Mongoid::Userstamp
|
128
|
+
|
129
|
+
field :name
|
130
|
+
end
|
131
|
+
end
|
132
|
+
subject { Novel.new(name: 'Ethyl the Aardvark goes Quantity Surveying') }
|
133
|
+
|
134
|
+
context 'when created by a user' do
|
135
|
+
before do
|
136
|
+
User.current = user_1
|
137
|
+
subject.save!
|
138
|
+
end
|
139
|
+
|
140
|
+
it { subject.c_by.should == user_1.id }
|
141
|
+
it { subject.created_by_id.should == user_1.id }
|
142
|
+
it { subject.created_by.should == user_1 }
|
143
|
+
it { subject.u_by.should == user_1.id }
|
144
|
+
it { subject.updated_by_id.should == user_1.id }
|
145
|
+
it { subject.updated_by.should == user_1 }
|
146
|
+
|
147
|
+
context 'when updated by a user' do
|
148
|
+
before do
|
149
|
+
User.current = user_2
|
150
|
+
subject.save!
|
151
|
+
end
|
152
|
+
|
153
|
+
it { subject.c_by.should == user_1.id }
|
154
|
+
it { subject.created_by_id.should == user_1.id }
|
155
|
+
it { subject.created_by.should == user_1 }
|
156
|
+
it { subject.u_by.should == user_2.id }
|
157
|
+
it { subject.updated_by_id.should == user_2.id }
|
158
|
+
it { subject.updated_by.should == user_2 }
|
159
|
+
end
|
60
160
|
end
|
61
161
|
end
|
162
|
+
|
62
163
|
end
|
metadata
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_userstamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Thomas Boerger
|
8
|
+
- Johnny Shields
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
17
|
requirements:
|
19
18
|
- - ! '>='
|
20
19
|
- !ruby/object:Gem::Version
|
@@ -22,7 +21,6 @@ dependencies:
|
|
22
21
|
type: :runtime
|
23
22
|
prerelease: false
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ! '>='
|
28
26
|
- !ruby/object:Gem::Version
|
@@ -30,7 +28,6 @@ dependencies:
|
|
30
28
|
- !ruby/object:Gem::Dependency
|
31
29
|
name: rspec
|
32
30
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
31
|
requirements:
|
35
32
|
- - ! '>='
|
36
33
|
- !ruby/object:Gem::Version
|
@@ -38,7 +35,6 @@ dependencies:
|
|
38
35
|
type: :development
|
39
36
|
prerelease: false
|
40
37
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
38
|
requirements:
|
43
39
|
- - ! '>='
|
44
40
|
- !ruby/object:Gem::Version
|
@@ -46,7 +42,6 @@ dependencies:
|
|
46
42
|
- !ruby/object:Gem::Dependency
|
47
43
|
name: yard
|
48
44
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
45
|
requirements:
|
51
46
|
- - ! '>='
|
52
47
|
- !ruby/object:Gem::Version
|
@@ -54,7 +49,6 @@ dependencies:
|
|
54
49
|
type: :development
|
55
50
|
prerelease: false
|
56
51
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
52
|
requirements:
|
59
53
|
- - ! '>='
|
60
54
|
- !ruby/object:Gem::Version
|
@@ -62,7 +56,6 @@ dependencies:
|
|
62
56
|
- !ruby/object:Gem::Dependency
|
63
57
|
name: jeweler
|
64
58
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
59
|
requirements:
|
67
60
|
- - ! '>='
|
68
61
|
- !ruby/object:Gem::Version
|
@@ -70,12 +63,11 @@ dependencies:
|
|
70
63
|
type: :development
|
71
64
|
prerelease: false
|
72
65
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
66
|
requirements:
|
75
67
|
- - ! '>='
|
76
68
|
- !ruby/object:Gem::Version
|
77
69
|
version: 1.8.3
|
78
|
-
description:
|
70
|
+
description: Userstamp for created and updated columns within mongoid
|
79
71
|
email: tboerger@tbpro.de
|
80
72
|
executables: []
|
81
73
|
extensions: []
|
@@ -83,7 +75,7 @@ extra_rdoc_files:
|
|
83
75
|
- LICENSE.md
|
84
76
|
- README.md
|
85
77
|
files:
|
86
|
-
- .
|
78
|
+
- .ruby-version
|
87
79
|
- .travis.yml
|
88
80
|
- CHANGELOG.md
|
89
81
|
- Gemfile
|
@@ -106,29 +98,26 @@ files:
|
|
106
98
|
homepage: https://github.com/tbpro/mongoid_userstamp
|
107
99
|
licenses:
|
108
100
|
- MIT
|
101
|
+
metadata: {}
|
109
102
|
post_install_message:
|
110
103
|
rdoc_options: []
|
111
104
|
require_paths:
|
112
105
|
- lib
|
113
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
107
|
requirements:
|
116
108
|
- - ! '>='
|
117
109
|
- !ruby/object:Gem::Version
|
118
110
|
version: '0'
|
119
|
-
segments:
|
120
|
-
- 0
|
121
|
-
hash: 1819917974665948435
|
122
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
112
|
requirements:
|
125
113
|
- - ! '>='
|
126
114
|
- !ruby/object:Gem::Version
|
127
115
|
version: '0'
|
128
116
|
requirements: []
|
129
117
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.
|
118
|
+
rubygems_version: 2.1.5
|
131
119
|
signing_key:
|
132
|
-
specification_version:
|
133
|
-
summary: Userstamp for
|
120
|
+
specification_version: 4
|
121
|
+
summary: Userstamp for mongoid
|
134
122
|
test_files: []
|
123
|
+
has_rdoc:
|