mongoid-undo 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@ Super simple undo for your Mongoid app, based on both great modules
8
8
 
9
9
  * `Mongoid::Paranoia` is used to mark documents as deleted, instead of deleting them really, otherwise restoring would be impossible ;).
10
10
  * `Mongoid::Versioning` is used to keep the older versions of your document, so we can restore them.
11
- * `Mongoid::Undo` adds an `_action` field to your documents, so we can easily determine whether it was created, updated, or destroyed.
11
+ * `Mongoid::Undo` adds an `action` field to your documents, so we can easily determine whether it was created, updated, or destroyed.
12
12
 
13
13
  But instead of explaining all the details, you should get the idea by looking at the Usage section.
14
14
 
data/lib/mongoid/undo.rb CHANGED
@@ -22,19 +22,19 @@ module Mongoid
22
22
  include Mongoid::Versioning
23
23
 
24
24
  included do
25
- field :_action, type: Symbol, versioned: false
25
+ field :action, type: Symbol, versioned: false
26
26
  index deleted_at: 1
27
27
 
28
28
  [:create, :update, :destroy].each do |action|
29
29
  set_callback action, :after do
30
- collection.find(atomic_selector).update('$set' => { _action: action })
30
+ collection.find(atomic_selector).update('$set' => { action: action })
31
31
  reload
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
36
  def undo
37
- case _action
37
+ case action
38
38
  when :create, :destroy
39
39
  deleted_at.present? ? restore : delete
40
40
  when :update
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Undo
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
data/spec/undo_spec.rb CHANGED
@@ -12,8 +12,6 @@ module Mongoid
12
12
 
13
13
 
14
14
  subject { Document.new(name: 'foo') }
15
- let(:name) { subject.name }
16
- let(:action) { subject.send(:_action) }
17
15
 
18
16
 
19
17
  describe 'creating' do
@@ -21,7 +19,7 @@ module Mongoid
21
19
 
22
20
 
23
21
  it 'sets action to :create' do
24
- action.must_equal :create
22
+ subject.action.must_equal :create
25
23
  end
26
24
 
27
25
 
@@ -35,7 +33,7 @@ module Mongoid
35
33
 
36
34
 
37
35
  it 'keeps :create action' do
38
- action.must_equal :create
36
+ subject.action.must_equal :create
39
37
  end
40
38
 
41
39
 
@@ -49,7 +47,7 @@ module Mongoid
49
47
 
50
48
 
51
49
  it 'keeps :create action' do
52
- action.must_equal :create
50
+ subject.action.must_equal :create
53
51
  end
54
52
  end
55
53
  end
@@ -60,7 +58,7 @@ module Mongoid
60
58
 
61
59
 
62
60
  it 'sets action to :update' do
63
- action.must_equal :update
61
+ subject.action.must_equal :update
64
62
  end
65
63
 
66
64
 
@@ -69,7 +67,7 @@ module Mongoid
69
67
 
70
68
 
71
69
  it 'retrieves' do
72
- name.must_equal 'foo'
70
+ subject.name.must_equal 'foo'
73
71
  end
74
72
 
75
73
 
@@ -79,7 +77,7 @@ module Mongoid
79
77
 
80
78
 
81
79
  it 'keeps :update action' do
82
- action.must_equal :update
80
+ subject.action.must_equal :update
83
81
  end
84
82
 
85
83
 
@@ -88,7 +86,7 @@ module Mongoid
88
86
 
89
87
 
90
88
  it 'retrieves' do
91
- name.must_equal 'bar'
89
+ subject.name.must_equal 'bar'
92
90
  end
93
91
 
94
92
 
@@ -98,7 +96,7 @@ module Mongoid
98
96
 
99
97
 
100
98
  it 'keeps :update action' do
101
- action.must_equal :update
99
+ subject.action.must_equal :update
102
100
  end
103
101
  end
104
102
  end
@@ -110,7 +108,7 @@ module Mongoid
110
108
 
111
109
 
112
110
  it 'sets action to :destroy' do
113
- action.must_equal :destroy
111
+ subject.action.must_equal :destroy
114
112
  end
115
113
 
116
114
 
@@ -129,7 +127,7 @@ module Mongoid
129
127
 
130
128
 
131
129
  it 'keeps :destroy action' do
132
- action.must_equal :destroy
130
+ subject.action.must_equal :destroy
133
131
  end
134
132
 
135
133
 
@@ -143,7 +141,7 @@ module Mongoid
143
141
 
144
142
 
145
143
  it 'keeps :destroy action' do
146
- action.must_equal :destroy
144
+ subject.action.must_equal :destroy
147
145
  end
148
146
  end
149
147
  end
@@ -158,14 +156,14 @@ module Mongoid
158
156
  end
159
157
 
160
158
 
161
- describe :_action do
159
+ describe :action do
162
160
  it 'is a symbol' do
163
- subject.fields['_action'].options[:type].must_equal Symbol
161
+ subject.fields['action'].options[:type].must_equal Symbol
164
162
  end
165
163
 
166
164
 
167
165
  it 'is versionless' do
168
- subject.fields['_action'].options[:versioned].must_equal false
166
+ subject.fields['action'].options[:versioned].must_equal false
169
167
  end
170
168
  end
171
169
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoid-undo
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mario Uher