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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a09307107064389ab36ef69a4d6ff7490b40f6f
4
- data.tar.gz: ba31d99c253efc7c138c4d1e819d8cbd250f6679
3
+ metadata.gz: e9dae14b747e2f9014cf5d327f82b6d877cb9e5e
4
+ data.tar.gz: 056735a6f8c8b797d1c33889bc2863e7d7e116e2
5
5
  SHA512:
6
- metadata.gz: 873ae9b22cfa77be022429a35a7a00d835362af63df14b0cf691418e947ea769231f092a756008dedef09abde16045c109881422272bbcdb093be7e4ba8a5e3c
7
- data.tar.gz: 478c1dced270ddcb7a660b03df60d7bb7daeae59a78df32d561e8b4b2a7b347999999639aa45971d7da340c7b7ba2e4f0f7568386a2b8c61f957e2b1c31f531a
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
- self.created_by = Mongoid::Userstamps::Config.current
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
- self.updated_by = Mongoid::Userstamps::Config.current
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
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Userstamps
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -13,32 +13,59 @@ describe 'Mongoid::Userstamp' do
13
13
  field :title
14
14
  end
15
15
 
16
- before :all do
17
- @user = User.create
18
- Mongoid::Userstamps::Config.set_current(@user)
19
- end
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
- context 'when include Mongoid::Userstamps::Model' do
22
- it 'add user stamps relations' do
23
- post = Post.new
24
- expect(post.created_by).to eq nil
25
- expect(post.updated_by).to eq nil
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
- context 'when create Post' do
30
- it 'should save user stamps relations' do
31
- post = Post.create
32
- expect(post.created_by).to eq(@user)
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 update Post' do
37
- it 'should save user stamps relations' do
38
- post = Post.create
39
- post.title = "title"
40
- post.save
41
- expect(post.updated_by).to eq(@user)
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.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-09 00:00:00.000000000 Z
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler