mongoid-simple-userstamps 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongoid-simple-userstamps/model.rb +6 -2
- data/lib/mongoid-simple-userstamps/version.rb +1 -1
- data/spec/userstamps_spec.rb +47 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9dae14b747e2f9014cf5d327f82b6d877cb9e5e
|
4
|
+
data.tar.gz: 056735a6f8c8b797d1c33889bc2863e7d7e116e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08ec3e77b51a57cbe1c85726d8484f61a91ea3a6de90a919a87e24609b8ff26adc55436544fd6ad1add8274eb8db05e92a2dcbe477d930c5ae6d02bea4af9f83
|
7
|
+
data.tar.gz: 3cfc48ddf7ee5ed014fd891928b8250a0e11655540c4e4b1dfe013638d45f12ba1717b51bce861a3afc7103a156ffded58a1fd29492626222c8ff9725961241c
|
@@ -9,11 +9,15 @@ module Mongoid
|
|
9
9
|
base.send(:belongs_to, :updated_by, {polymorphic: true})
|
10
10
|
|
11
11
|
base.send(:before_create) do
|
12
|
-
|
12
|
+
if Mongoid::Userstamps::Config.current && !self.created_by
|
13
|
+
self.created_by = Mongoid::Userstamps::Config.current
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
base.send(:before_update) do
|
16
|
-
|
18
|
+
if Mongoid::Userstamps::Config.current
|
19
|
+
self.updated_by = Mongoid::Userstamps::Config.current
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
data/spec/userstamps_spec.rb
CHANGED
@@ -13,32 +13,59 @@ describe 'Mongoid::Userstamp' do
|
|
13
13
|
field :title
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
context 'when current is defined' do
|
17
|
+
before :all do
|
18
|
+
@user = User.create
|
19
|
+
Mongoid::Userstamps::Config.set_current(@user)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
context 'when include Mongoid::Userstamps::Model' do
|
23
|
+
it 'add user stamps relations' do
|
24
|
+
post = Post.new
|
25
|
+
expect(post.created_by).to eq nil
|
26
|
+
expect(post.updated_by).to eq nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when create Post' do
|
31
|
+
it 'should save user stamps relations' do
|
32
|
+
post = Post.create
|
33
|
+
expect(post.created_by).to eq(@user)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should not overwrite created_by' do
|
37
|
+
user = User.create
|
38
|
+
post = Post.create(created_by: user)
|
39
|
+
expect(post.created_by).to eq(user)
|
40
|
+
end
|
26
41
|
end
|
27
|
-
end
|
28
42
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
43
|
+
context 'when update Post' do
|
44
|
+
it 'should save user stamps relations' do
|
45
|
+
post = Post.create
|
46
|
+
post.title = "title"
|
47
|
+
post.save
|
48
|
+
expect(post.updated_by).to eq(@user)
|
49
|
+
end
|
33
50
|
end
|
34
51
|
end
|
35
52
|
|
36
|
-
context 'when
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
53
|
+
context 'when current is not defined' do
|
54
|
+
before :all do
|
55
|
+
Mongoid::Userstamps::Config.set_current(nil)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should not set created_by' do
|
59
|
+
user = User.create
|
60
|
+
post = Post.create!(created_by: user)
|
61
|
+
expect(post.created_by).to eq(user)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should not set updated_by' do
|
65
|
+
user = User.create
|
66
|
+
post = Post.create!
|
67
|
+
post.update_attributes(title: 'title', updated_by: user)
|
68
|
+
expect(post.updated_by).to eq(user)
|
42
69
|
end
|
43
70
|
end
|
44
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-simple-userstamps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Jurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|