mongoid-undo 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Undo
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
data/mongoid-undo.gemspec CHANGED
@@ -1,4 +1,5 @@
1
- require './lib/mongoid/undo/version'
1
+ $: << File.expand_path('../lib', __FILE__)
2
+ require 'mongoid/undo/version'
2
3
 
3
4
  Gem::Specification.new do |gem|
4
5
  gem.name = 'mongoid-undo'
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 './lib/mongoid/undo'
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')
@@ -0,0 +1,13 @@
1
+ class Document
2
+ include Mongoid::Document
3
+ include Mongoid::Undo
4
+
5
+ field :name, type: String
6
+ end
7
+
8
+ class Localized
9
+ include Mongoid::Document
10
+ include Mongoid::Undo
11
+
12
+ field :language, localize: true
13
+ end
@@ -0,0 +1,8 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ database: mongoid_tags_test
5
+ hosts:
6
+ - localhost:27017
7
+ options:
8
+ consistency: :strong
data/spec/undo_spec.rb CHANGED
@@ -1,193 +1,173 @@
1
1
  require File.expand_path('../spec_helper', __FILE__)
2
2
 
3
- module Mongoid
4
- module Undo
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
- it 'sets action to :create' do
22
- subject.action.must_equal :create
23
- end
11
+ it 'sets action to :create' do
12
+ subject.action.must_equal :create
13
+ end
24
14
 
25
15
 
26
- describe 'undoing' do
27
- before { subject.undo }
16
+ describe 'undoing' do
17
+ before { subject.undo }
28
18
 
29
19
 
30
- it 'deletes' do
31
- subject.persisted?.wont_equal true
32
- end
20
+ it 'deletes' do
21
+ subject.persisted?.wont_equal true
22
+ end
33
23
 
34
24
 
35
- it 'keeps :create action' do
36
- subject.action.must_equal :create
37
- end
25
+ it 'keeps :create action' do
26
+ subject.action.must_equal :create
27
+ end
38
28
 
39
29
 
40
- describe 'redoing' do
41
- before { subject.redo }
30
+ describe 'redoing' do
31
+ before { subject.redo }
42
32
 
43
33
 
44
- it 'restores' do
45
- subject.persisted?.must_equal true
46
- end
34
+ it 'restores' do
35
+ subject.persisted?.must_equal true
36
+ end
47
37
 
48
38
 
49
- it 'keeps :create action' do
50
- subject.action.must_equal :create
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
- describe 'updating' do
57
- before { subject.update_attributes(name: 'bar') }
46
+ describe 'updating' do
47
+ before { subject.update_attributes(name: 'bar') }
58
48
 
59
49
 
60
- it 'sets action to :update' do
61
- subject.action.must_equal :update
62
- end
50
+ it 'sets action to :update' do
51
+ subject.action.must_equal :update
52
+ end
63
53
 
64
54
 
65
- describe 'undoing' do
66
- before { subject.undo }
55
+ describe 'undoing' do
56
+ before { subject.undo }
67
57
 
68
58
 
69
- it 'retrieves' do
70
- subject.name.must_equal 'foo'
71
- end
59
+ it 'retrieves' do
60
+ subject.name.must_equal 'foo'
61
+ end
72
62
 
73
63
 
74
- it 'saves a new version' do
75
- subject.version.must_equal 3
76
- end
64
+ it 'saves a new version' do
65
+ subject.version.must_equal 3
66
+ end
77
67
 
78
68
 
79
- it 'keeps :update action' do
80
- subject.action.must_equal :update
81
- end
69
+ it 'keeps :update action' do
70
+ subject.action.must_equal :update
71
+ end
82
72
 
83
73
 
84
- describe 'redoing' do
85
- before { subject.redo }
74
+ describe 'redoing' do
75
+ before { subject.redo }
86
76
 
87
77
 
88
- it 'retrieves' do
89
- subject.name.must_equal 'bar'
90
- end
78
+ it 'retrieves' do
79
+ subject.name.must_equal 'bar'
80
+ end
91
81
 
92
82
 
93
- it 'saves a new version' do
94
- subject.version.must_equal 4
95
- end
83
+ it 'saves a new version' do
84
+ subject.version.must_equal 4
85
+ end
96
86
 
97
87
 
98
- it 'keeps :update action' do
99
- subject.action.must_equal :update
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
- describe 'destroying' do
107
- before { subject.destroy }
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
- it 'marks as destroyed' do
116
- subject.persisted?.must_equal false
117
- end
100
+ it 'sets action to :destroy' do
101
+ subject.action.must_equal :destroy
102
+ end
118
103
 
119
104
 
120
- describe 'undoing' do
121
- before { subject.undo }
105
+ it 'marks as destroyed' do
106
+ subject.persisted?.must_equal false
107
+ end
122
108
 
123
109
 
124
- it 'restores' do
125
- subject.persisted?.wont_equal false
126
- end
110
+ describe 'undoing' do
111
+ before { subject.undo }
127
112
 
128
113
 
129
- it 'keeps :destroy action' do
130
- subject.action.must_equal :destroy
131
- end
114
+ it 'restores' do
115
+ subject.persisted?.wont_equal false
116
+ end
132
117
 
133
118
 
134
- describe 'redoing' do
135
- before { subject.redo }
119
+ it 'keeps :destroy action' do
120
+ subject.action.must_equal :destroy
121
+ end
136
122
 
137
123
 
138
- it 'deletes' do
139
- subject.persisted?.must_equal false
140
- end
124
+ describe 'redoing' do
125
+ before { subject.redo }
141
126
 
142
127
 
143
- it 'keeps :destroy action' do
144
- subject.action.must_equal :destroy
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
- describe :redo do
153
- it 'is a convenient alias for undo' do
154
- subject.method(:redo).must_equal subject.method(:undo)
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
- describe :action do
160
- it 'is a symbol' do
161
- subject.fields['action'].options[:type].must_equal Symbol
162
- end
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
- it 'is versionless' do
166
- subject.fields['action'].options[:versioned].must_equal false
167
- end
168
- end
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
- describe 'localization' do
172
- class Localized
173
- include Mongoid::Document
174
- include Mongoid::Undo
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
- it 'works too with localized fields' do
181
- subject = Localized.create(language: 'English')
182
-
183
- subject.update_attributes(language: 'English Updated')
184
- subject.undo
185
- subject.language.must_equal 'English'
186
-
187
- subject.redo
188
- subject.language.must_equal 'English Updated'
189
- end
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.3.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-22 00:00:00.000000000 Z
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: []