mongoid-undo 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mongoid/undo/version.rb +1 -1
- data/mongoid-undo.gemspec +2 -1
- data/spec/spec_helper.rb +6 -2
- data/spec/support/connection.rb +1 -0
- data/spec/support/document.rb +13 -0
- data/spec/support/mongoid.yml +8 -0
- data/spec/undo_spec.rb +100 -120
- metadata +5 -2
data/lib/mongoid/undo/version.rb
CHANGED
data/mongoid-undo.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
$: << File.expand_path('../../lib', __FILE__)
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'minitest/pride'
|
3
5
|
require 'minitest/spec'
|
4
6
|
|
5
|
-
require '
|
7
|
+
require 'mongoid/undo'
|
8
|
+
|
9
|
+
# Load support *.rb files in ./support
|
10
|
+
Dir[File.expand_path('../support/*.rb', __FILE__)].each { |file| require_relative file }
|
6
11
|
|
7
|
-
Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), 'test')
|
@@ -0,0 +1 @@
|
|
1
|
+
Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), 'test')
|
data/spec/undo_spec.rb
CHANGED
@@ -1,193 +1,173 @@
|
|
1
1
|
require File.expand_path('../spec_helper', __FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe self do
|
6
|
-
class Document
|
7
|
-
include Mongoid::Document
|
8
|
-
include Mongoid::Undo
|
9
|
-
|
10
|
-
field :name, type: String
|
11
|
-
end
|
12
|
-
|
3
|
+
describe Mongoid::Undo do
|
4
|
+
subject { Document.new(name: 'foo') }
|
13
5
|
|
14
|
-
subject { Document.new(name: 'foo') }
|
15
6
|
|
7
|
+
describe 'creating' do
|
8
|
+
before { subject.save }
|
16
9
|
|
17
|
-
describe 'creating' do
|
18
|
-
before { subject.save }
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
11
|
+
it 'sets action to :create' do
|
12
|
+
subject.action.must_equal :create
|
13
|
+
end
|
24
14
|
|
25
15
|
|
26
|
-
|
27
|
-
|
16
|
+
describe 'undoing' do
|
17
|
+
before { subject.undo }
|
28
18
|
|
29
19
|
|
30
|
-
|
31
|
-
|
32
|
-
|
20
|
+
it 'deletes' do
|
21
|
+
subject.persisted?.wont_equal true
|
22
|
+
end
|
33
23
|
|
34
24
|
|
35
|
-
|
36
|
-
|
37
|
-
|
25
|
+
it 'keeps :create action' do
|
26
|
+
subject.action.must_equal :create
|
27
|
+
end
|
38
28
|
|
39
29
|
|
40
|
-
|
41
|
-
|
30
|
+
describe 'redoing' do
|
31
|
+
before { subject.redo }
|
42
32
|
|
43
33
|
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
it 'restores' do
|
35
|
+
subject.persisted?.must_equal true
|
36
|
+
end
|
47
37
|
|
48
38
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
39
|
+
it 'keeps :create action' do
|
40
|
+
subject.action.must_equal :create
|
53
41
|
end
|
42
|
+
end
|
43
|
+
end
|
54
44
|
|
55
45
|
|
56
|
-
|
57
|
-
|
46
|
+
describe 'updating' do
|
47
|
+
before { subject.update_attributes(name: 'bar') }
|
58
48
|
|
59
49
|
|
60
|
-
|
61
|
-
|
62
|
-
|
50
|
+
it 'sets action to :update' do
|
51
|
+
subject.action.must_equal :update
|
52
|
+
end
|
63
53
|
|
64
54
|
|
65
|
-
|
66
|
-
|
55
|
+
describe 'undoing' do
|
56
|
+
before { subject.undo }
|
67
57
|
|
68
58
|
|
69
|
-
|
70
|
-
|
71
|
-
|
59
|
+
it 'retrieves' do
|
60
|
+
subject.name.must_equal 'foo'
|
61
|
+
end
|
72
62
|
|
73
63
|
|
74
|
-
|
75
|
-
|
76
|
-
|
64
|
+
it 'saves a new version' do
|
65
|
+
subject.version.must_equal 3
|
66
|
+
end
|
77
67
|
|
78
68
|
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
it 'keeps :update action' do
|
70
|
+
subject.action.must_equal :update
|
71
|
+
end
|
82
72
|
|
83
73
|
|
84
|
-
|
85
|
-
|
74
|
+
describe 'redoing' do
|
75
|
+
before { subject.redo }
|
86
76
|
|
87
77
|
|
88
|
-
|
89
|
-
|
90
|
-
|
78
|
+
it 'retrieves' do
|
79
|
+
subject.name.must_equal 'bar'
|
80
|
+
end
|
91
81
|
|
92
82
|
|
93
|
-
|
94
|
-
|
95
|
-
|
83
|
+
it 'saves a new version' do
|
84
|
+
subject.version.must_equal 4
|
85
|
+
end
|
96
86
|
|
97
87
|
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
88
|
+
it 'keeps :update action' do
|
89
|
+
subject.action.must_equal :update
|
102
90
|
end
|
103
91
|
end
|
92
|
+
end
|
93
|
+
end
|
104
94
|
|
105
95
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
it 'sets action to :destroy' do
|
111
|
-
subject.action.must_equal :destroy
|
112
|
-
end
|
96
|
+
describe 'destroying' do
|
97
|
+
before { subject.destroy }
|
113
98
|
|
114
99
|
|
115
|
-
|
116
|
-
|
117
|
-
|
100
|
+
it 'sets action to :destroy' do
|
101
|
+
subject.action.must_equal :destroy
|
102
|
+
end
|
118
103
|
|
119
104
|
|
120
|
-
|
121
|
-
|
105
|
+
it 'marks as destroyed' do
|
106
|
+
subject.persisted?.must_equal false
|
107
|
+
end
|
122
108
|
|
123
109
|
|
124
|
-
|
125
|
-
|
126
|
-
end
|
110
|
+
describe 'undoing' do
|
111
|
+
before { subject.undo }
|
127
112
|
|
128
113
|
|
129
|
-
|
130
|
-
|
131
|
-
|
114
|
+
it 'restores' do
|
115
|
+
subject.persisted?.wont_equal false
|
116
|
+
end
|
132
117
|
|
133
118
|
|
134
|
-
|
135
|
-
|
119
|
+
it 'keeps :destroy action' do
|
120
|
+
subject.action.must_equal :destroy
|
121
|
+
end
|
136
122
|
|
137
123
|
|
138
|
-
|
139
|
-
|
140
|
-
end
|
124
|
+
describe 'redoing' do
|
125
|
+
before { subject.redo }
|
141
126
|
|
142
127
|
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
-
end
|
128
|
+
it 'deletes' do
|
129
|
+
subject.persisted?.must_equal false
|
147
130
|
end
|
148
|
-
end
|
149
|
-
end
|
150
131
|
|
151
132
|
|
152
|
-
|
153
|
-
|
154
|
-
|
133
|
+
it 'keeps :destroy action' do
|
134
|
+
subject.action.must_equal :destroy
|
135
|
+
end
|
155
136
|
end
|
156
137
|
end
|
138
|
+
end
|
139
|
+
end
|
157
140
|
|
158
141
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
142
|
+
describe :redo do
|
143
|
+
it 'is a convenient alias for undo' do
|
144
|
+
subject.method(:redo).must_equal subject.method(:undo)
|
145
|
+
end
|
146
|
+
end
|
163
147
|
|
164
148
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
149
|
+
describe :action do
|
150
|
+
it 'is a symbol' do
|
151
|
+
subject.fields['action'].options[:type].must_equal Symbol
|
152
|
+
end
|
169
153
|
|
170
154
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
field :language, localize: true
|
177
|
-
end
|
155
|
+
it 'is versionless' do
|
156
|
+
subject.fields['action'].options[:versioned].must_equal false
|
157
|
+
end
|
158
|
+
end
|
178
159
|
|
179
160
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
161
|
+
describe 'localization' do
|
162
|
+
it 'works too with localized fields' do
|
163
|
+
subject = Localized.create(language: 'English')
|
164
|
+
|
165
|
+
subject.update_attributes(language: 'English Updated')
|
166
|
+
subject.undo
|
167
|
+
subject.language.must_equal 'English'
|
168
|
+
|
169
|
+
subject.redo
|
170
|
+
subject.language.must_equal 'English Updated'
|
191
171
|
end
|
192
172
|
end
|
193
173
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: mongoid-undo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.4.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mario Uher
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -60,6 +60,9 @@ files:
|
|
60
60
|
- mongoid-undo.gemspec
|
61
61
|
- spec/mongoid.yml
|
62
62
|
- spec/spec_helper.rb
|
63
|
+
- spec/support/connection.rb
|
64
|
+
- spec/support/document.rb
|
65
|
+
- spec/support/mongoid.yml
|
63
66
|
- spec/undo_spec.rb
|
64
67
|
homepage: https://github.com/haihappen/mongoid-undo
|
65
68
|
licenses: []
|