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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e16f61a50c9e552b723ae85b71904f7ce8ff7cd
4
- data.tar.gz: 30df35bd5528144a319186b452378a0c3e7d67d1
3
+ metadata.gz: 17eb6808981135d07d9e82a9d813d026cdf9df54
4
+ data.tar.gz: c89b505e48a2c4e5fb25f4dee867f2d9639a923f
5
5
  SHA512:
6
- metadata.gz: dfa893d9870564f6c8e932e80fd9afd069f2d9ae468a1ed60e74fb09acc0a0d088bb53093a818e52c6079dcd44cf4ae94de853ab37e800ad413dd532631a047e
7
- data.tar.gz: 33a428a1cbcb62fdbad0065f748fe58e096d868736413b7c8089937d20fc4d05b3ad0897cac06125e08d717669885d3b68b853d54d54fa87fa5a2ae57fa11434
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 commit
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])
@@ -1,3 +1,3 @@
1
1
  module Pravangi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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(&:commit)
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 '#commit' do
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.commit
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 'does not requires approval' do
180
+ context '#reject_changes' do
181
181
 
182
182
  before(:each) do
183
- expect(post).to receive(:approved?).and_return(false)
183
+ post.title = 'metaware 2'
184
184
  post.save
185
185
  post.reload
186
186
  end
187
187
 
188
- it 'should just commit the changes' do
189
- expect(post.title).to eq('new metaware')
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 return false when approval is not required' do
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
- end
203
+ context 'does not requires approval' do
199
204
 
200
- context 'when taking an object to satisfying if condition' do
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
- let(:post) { Post.create(title: 'metaware', state: 'draft') }
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
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jasdeep Singh