pravangi 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pravangi/models/pending_approval.rb +5 -1
- data/lib/pravangi/version.rb +1 -1
- data/spec/lib/pravangi_spec.rb +26 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17eb6808981135d07d9e82a9d813d026cdf9df54
|
4
|
+
data.tar.gz: c89b505e48a2c4e5fb25f4dee867f2d9639a923f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13addedda080733c3dd64f99eb5a7f9232b2adb8f532f7adb8b5dc2635a7c07f885d4ba4488bd63c4d20da959202f06007941d595b5007e56046ec6fb76d78b6
|
7
|
+
data.tar.gz: af3da5a09ace4ab69ce06e499a98ed85506484bf3f214fae8a6ce4e282090334362516bf259f747ae43d846ea146e3695beade288b17266abd917443bf66b44d
|
@@ -15,7 +15,7 @@ module Pravangi
|
|
15
15
|
self.object_changes.keys
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def approve_changes
|
19
19
|
resource.skip_approval = true
|
20
20
|
object_changes.each do |k,v|
|
21
21
|
resource[k] = v[1]
|
@@ -24,6 +24,10 @@ module Pravangi
|
|
24
24
|
resource.reload
|
25
25
|
end
|
26
26
|
|
27
|
+
def reject_changes
|
28
|
+
self.destroy
|
29
|
+
end
|
30
|
+
|
27
31
|
def skip_attributes
|
28
32
|
if self.resource.class.pravangi_options[:skip_attributes]
|
29
33
|
object_changes.except(*self.resource.class.pravangi_options[:skip_attributes])
|
data/lib/pravangi/version.rb
CHANGED
data/spec/lib/pravangi_spec.rb
CHANGED
@@ -134,7 +134,7 @@ describe Pravangi do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'should be able to apply all changes to bring the object to desired state' do
|
137
|
-
post.pending_approvals.each(&:
|
137
|
+
post.pending_approvals.each(&:approve_changes)
|
138
138
|
post.reload
|
139
139
|
expect(post.title).to eq('metaware 3')
|
140
140
|
end
|
@@ -161,7 +161,7 @@ describe Pravangi do
|
|
161
161
|
|
162
162
|
end
|
163
163
|
|
164
|
-
context '#
|
164
|
+
context '#approve_changes' do
|
165
165
|
|
166
166
|
before(:each) do
|
167
167
|
post.title = 'metaware 2'
|
@@ -170,44 +170,52 @@ describe Pravangi do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
it 'should be able to revert the object back to the requested state' do
|
173
|
-
post.pending_approvals.last.
|
173
|
+
post.pending_approvals.last.approve_changes
|
174
174
|
post.reload
|
175
175
|
expect(post.title).to eq('metaware 2')
|
176
176
|
end
|
177
177
|
|
178
178
|
end
|
179
179
|
|
180
|
-
context '
|
180
|
+
context '#reject_changes' do
|
181
181
|
|
182
182
|
before(:each) do
|
183
|
-
|
183
|
+
post.title = 'metaware 2'
|
184
184
|
post.save
|
185
185
|
post.reload
|
186
186
|
end
|
187
187
|
|
188
|
-
it 'should
|
189
|
-
|
188
|
+
it 'should be able to revert the object back to the requested state' do
|
189
|
+
post.pending_approvals.last.reject_changes
|
190
|
+
post.reload
|
191
|
+
expect(post.title).to eq('metaware')
|
190
192
|
end
|
191
193
|
|
192
|
-
it 'should
|
194
|
+
it 'should clear any pending approvals in the queue' do
|
195
|
+
post.pending_approvals.last.reject_changes
|
196
|
+
post.reload
|
193
197
|
expect(post.pending_approval?).to eq(false)
|
198
|
+
expect(post.pending_approvals).to be_empty
|
194
199
|
end
|
195
200
|
|
196
201
|
end
|
197
202
|
|
198
|
-
|
203
|
+
context 'does not requires approval' do
|
199
204
|
|
200
|
-
|
205
|
+
before(:each) do
|
206
|
+
expect(post).to receive(:approved?).and_return(false)
|
207
|
+
post.save
|
208
|
+
post.reload
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should just commit the changes' do
|
212
|
+
expect(post.title).to eq('new metaware')
|
213
|
+
end
|
201
214
|
|
202
|
-
|
215
|
+
it 'should return false when approval is not required' do
|
216
|
+
expect(post.pending_approval?).to eq(false)
|
217
|
+
end
|
203
218
|
|
204
|
-
it 'should trigger approval tracking only when the object is in a satisfying state' do
|
205
|
-
skip('the following is a failing test case, however not an immediate concern as we are doing state change as an isolated action on our objects')
|
206
|
-
# post.title = 'metaware draft'
|
207
|
-
# post.state = 'approved'
|
208
|
-
# post.save
|
209
|
-
# post.reload
|
210
|
-
# expect(post.title).to eq('metaware draft')
|
211
219
|
end
|
212
220
|
|
213
221
|
end
|