pravangi 0.2.0 → 0.2.1

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: 17eb6808981135d07d9e82a9d813d026cdf9df54
4
- data.tar.gz: c89b505e48a2c4e5fb25f4dee867f2d9639a923f
3
+ metadata.gz: ee37830a1eff542a742a7b05f4e3f618dd4b1c51
4
+ data.tar.gz: 098bcfb5a9843dc7ee860f77a62996213d031f06
5
5
  SHA512:
6
- metadata.gz: 13addedda080733c3dd64f99eb5a7f9232b2adb8f532f7adb8b5dc2635a7c07f885d4ba4488bd63c4d20da959202f06007941d595b5007e56046ec6fb76d78b6
7
- data.tar.gz: af3da5a09ace4ab69ce06e499a98ed85506484bf3f214fae8a6ce4e282090334362516bf259f747ae43d846ea146e3695beade288b17266abd917443bf66b44d
6
+ metadata.gz: 9d40df6d4ca7736cce7d3cdfb75f14735b683a7edb17c6dcacf780dff9fb8432d8a9a2aa82699b088c6af1c75bea880c4b5935fd0310bd9abc0e09cdf7d481e3
7
+ data.tar.gz: cba37201cf7d63ce00b85484dfd7e5636f9307583ecedd5e23815b8921093f8d00bc3d06709805b996808de3edadadf0fdf17816282dc4083604f0d04559685f
@@ -5,6 +5,8 @@ class CreatePendingApprovals < ActiveRecord::Migration
5
5
  t.integer :resource_id, null: false
6
6
  t.text :object_changes
7
7
  t.text :raw_object, null: false
8
+ t.boolean :is_approved, null: false, default: false
9
+ t.boolean :is_rejected, null: false, default: false
8
10
  t.timestamps null: false
9
11
  end
10
12
  end
@@ -7,6 +7,8 @@ module Pravangi
7
7
  serialize :object_changes, Hash
8
8
  before_save :skip_attributes
9
9
 
10
+ default_scope { where(is_approved: false, is_rejected: false) }
11
+
10
12
  def as_object
11
13
  @object ||= YAML.load(raw_object)
12
14
  end
@@ -16,16 +18,19 @@ module Pravangi
16
18
  end
17
19
 
18
20
  def approve_changes
19
- resource.skip_approval = true
20
- object_changes.each do |k,v|
21
- resource[k] = v[1]
21
+ PendingApproval.transaction do
22
+ resource.skip_approval = true
23
+ object_changes.each do |k,v|
24
+ resource[k] = v[1]
25
+ end
26
+ self.update_attribute(:is_approved, true)
27
+ resource.save
28
+ resource.reload
22
29
  end
23
- resource.save
24
- resource.reload
25
30
  end
26
31
 
27
32
  def reject_changes
28
- self.destroy
33
+ self.update_attribute(:is_rejected, true)
29
34
  end
30
35
 
31
36
  def skip_attributes
@@ -58,5 +58,15 @@ module Pravangi
58
58
  pending_approvals.present?
59
59
  end
60
60
 
61
+ def approve_pending_changes
62
+ self.pending_approvals.each(&:approve_changes)
63
+ self.reload
64
+ end
65
+
66
+ def reject_pending_changes
67
+ self.pending_approvals.each(&:reject_changes)
68
+ self.reload
69
+ end
70
+
61
71
  end
62
72
  end
@@ -1,3 +1,3 @@
1
1
  module Pravangi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -243,4 +243,46 @@ describe Pravangi do
243
243
 
244
244
  end
245
245
 
246
+ context 'approval queue is cleared after accepting changes' do
247
+
248
+ let(:post) { Post.create(title: 'metaware', state: 'approved') }
249
+
250
+ before(:each) do
251
+ post.title = 'metaware 2'
252
+ post.save
253
+ post.title = 'metaware 3'
254
+ post.save
255
+ post.reload
256
+ end
257
+
258
+ it 'should clear approval queue after accepting changes' do
259
+ expect(post.pending_approvals.count).to eq(2)
260
+ post.approve_pending_changes
261
+ expect(post.pending_approvals.count).to eq(0)
262
+ expect(post.pending_approval?).to eq(false)
263
+ end
264
+
265
+ end
266
+
267
+ context 'approval queue is cleared after rejecting changes' do
268
+
269
+ let(:post) { Post.create(title: 'metaware', state: 'approved') }
270
+
271
+ before(:each) do
272
+ post.title = 'metaware 2'
273
+ post.save
274
+ post.title = 'metaware 3'
275
+ post.save
276
+ post.reload
277
+ end
278
+
279
+ it 'should clear approval queue after accepting changes' do
280
+ expect(post.pending_approvals.count).to eq(2)
281
+ post.reject_pending_changes
282
+ expect(post.pending_approvals.count).to eq(0)
283
+ expect(post.pending_approval?).to eq(false)
284
+ end
285
+
286
+ end
287
+
246
288
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pravangi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jasdeep Singh