purgatory 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmFiMzhlMmYwYjI4ZGVlMWM3N2E1MTFjZjc0YmU1YzU5MGI3MDc2ZA==
4
+ NGY3YmJjZTM5ZTc0ZWU3NWQ4MTQxNTc3MDVkNzdlZjQ2ZDkzZmJkMg==
5
5
  data.tar.gz: !binary |-
6
- ZGFlYjYxM2IxMWIzMjU0ZWI1MTNmN2ViZjgzMGYxZGE5OWYxNGE4Yg==
6
+ NTMxMTZkMTYxMzZmNGJmY2M0NzNiMjc4YTgyODExNzdkNWE2NzE4Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2NjNTkxYjgzZTk1ZmNlOGE4YWUxZmE2MzZjOGFlYmJhMWZjNmQ5ODk1ZTJh
10
- NWU1MWIzYTZmNGRjZDM2YzE1ZDYyMmQ4NWIzZWY0NjRiNTc3ZDlhZWM5MTI4
11
- MTJhNzk5ZDgzMzM4MTFiN2I0ZTMxMjMxOGI0ZTg5NWIxMmU1M2Y=
9
+ OTMzNjlhY2YwMWQyYTBiMmUxMjE1MmJjYzM5MWIzMjI1OWZjOGVkZGI3ZGZm
10
+ NTc1YzkzN2E1YmU5NGZkNTE2MWIzMzU5MWJiNDkzYTI5MDZmOThkZWYxOWVl
11
+ ZGIxZTA5NTBiNGE1YTRiYTA3OGZhMWYxYWEzMGY5NzAyN2FmMDQ=
12
12
  data.tar.gz: !binary |-
13
- OTZjNDRkYWYyZWRmODMxMmExODRlMjMxY2UxMDQwN2MxODc2YjJlMGRhZDAz
14
- NzI1ZjM0NDJmYTNkMzIxMzA5MTViNGUyM2EzZTQ4ZmViN2E1MDUyZmViZjlj
15
- YjdlMDg1MmM5ZDI0ODJjODI2ZjlmYmZlYmQxZjk3OTFmMTA0ZTA=
13
+ Njk0M2Q2ZWQyMTEzYTVkZDY0NzdlOGZkMzk0MDBlYTY1MzA1NTZjMTA2ZTJj
14
+ NWFlYzRlNWY2ZWE0MmM4MjJhYjk3YjhjMjBjNjIzNDY0YmQ5ZjdmM2Q2ZDZm
15
+ N2M3NjkzMDllYTBiNTBmOTZiMGNhMzY0OTZmOTJmMWFjY2I0OWY=
data/README.markdown CHANGED
@@ -24,6 +24,10 @@ To put your changes to an ActiveRecord class into Purgatory, simply make your ch
24
24
  item.price = 200
25
25
  purgatory = item.purgatory!(current_user) # returns the newly created purgatory or nil if the item is changes are invalid
26
26
 
27
+ By default, if you call purgatory! on an object then any pending purgatories whose soul is that same object will be destroyed. If you'd prefer this not to happen then you can pass fail_if_matching_soul as a parameter and this will make it so if there are pending purgatories with a matching soul then purgatory! will return nil and nothing will happen:
28
+
29
+ purgatory = item.purgatory!(current_user, fail_if_matching_soul: true) # Returns nil and does nothing if there is already a pending purgatory on same soul
30
+
27
31
  To apply the changes, simply call the approve! method on the associated Pergatory instance. You can pass in the approving user as an optional parameter
28
32
 
29
33
  purgatory = item.purgatories.last
@@ -43,13 +47,15 @@ The following are some attributes of a purgatory:
43
47
  purgatory.approver # The user who approved the purgatory
44
48
  purgatory.approved_at # The time when the purgatory was approved
45
49
 
46
- Here are some handy scopes and methods available to you:
50
+ Here are some handy class and instance methods available to you:
47
51
 
48
- ### Scopes
52
+ ### Class methods
49
53
  Purgatory.pending # Returns a relation of all pending purgatories
50
54
  Purgatory.approved # Returns a relation of all approved purgatories
55
+ Purgatory.pending_with_matching_soul(soul) # Returns a relation of
56
+ all pending purgatories with soul matching the object passed in
51
57
 
52
- ### Methods
58
+ ### Instance methods
53
59
  purgatory.pending? # Returns true if the purgatory is pending, false otherwise
54
60
  purgatory.approved? # Returns true if the purgatory has been approved, false otherwise
55
61
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.4.0
@@ -5,6 +5,7 @@ class Purgatory < ActiveRecord::Base
5
5
  belongs_to :requester, class_name: PurgatoryModule.configuration.user_class_name
6
6
  belongs_to :approver, class_name: PurgatoryModule.configuration.user_class_name
7
7
  before_create :store_changes
8
+ before_create :destroy_pending_with_same_soul
8
9
 
9
10
  validates :soul_type, presence: true
10
11
 
@@ -42,9 +43,17 @@ class Purgatory < ActiveRecord::Base
42
43
  false
43
44
  end
44
45
 
46
+ def self.pending_with_matching_soul(soul)
47
+ pending.where("soul_id IS NOT NULL AND soul_id = ? AND soul_type = ?", soul.id, soul.class.name)
48
+ end
49
+
45
50
  private
46
51
 
47
52
  def store_changes
48
53
  self.requested_changes = soul.changes
49
54
  end
55
+
56
+ def destroy_pending_with_same_soul
57
+ Purgatory.pending_with_matching_soul(soul).destroy_all
58
+ end
50
59
  end
@@ -7,8 +7,9 @@ module PurgatoryModule
7
7
  end
8
8
  end
9
9
 
10
- def purgatory!(requester = nil)
10
+ def purgatory!(requester = nil, options = {})
11
11
  return nil if self.invalid?
12
+ return nil if Purgatory.pending_with_matching_soul(self).any? && options[:fail_if_matching_soul]
12
13
  Purgatory.create soul: self, requester: requester
13
14
  end
14
15
 
@@ -26,4 +27,4 @@ module PurgatoryModule
26
27
  @_configuration ||= Configuration.new
27
28
  end
28
29
  end
29
- end
30
+ end
data/purgatory.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: purgatory 2.3.0 ruby lib
5
+ # stub: purgatory 2.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "purgatory"
9
- s.version = "2.3.0"
9
+ s.version = "2.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Elan Dubrofsky"]
13
- s.date = "2013-11-25"
13
+ s.date = "2013-11-26"
14
14
  s.description = "Put your model changes in purgatory and allow them to remain lost souls until they are approved"
15
15
  s.email = "elan.dubrofsky@gmail.com"
16
16
  s.extra_rdoc_files = [
@@ -38,6 +38,34 @@ describe Purgatory do
38
38
  @widget.purgatories.count.should == 1
39
39
  @widget.purgatories.first.should == @purgatory
40
40
  end
41
+
42
+ it "should delete old pending purgatories with same soul" do
43
+ @widget2 = Widget.create name: 'toy', price: 500
44
+ @widget2.name = 'Big Toy'
45
+ widget2_purgatory = @widget2.purgatory! user1
46
+ @widget.name = 'baz'
47
+ new_purgatory = @widget.purgatory! user1
48
+ Purgatory.find_by_id(@purgatory.id).should be_nil
49
+ Purgatory.find_by_id(widget2_purgatory.id).should be_present
50
+ Purgatory.pending.count.should == 2
51
+ Purgatory.last.requested_changes['name'].should == ['foo', 'baz']
52
+ end
53
+
54
+ it "should fail to create purgatory if matching pending Purgatory exists and fail_if_matching_soul is passed in" do
55
+ @widget.name = 'baz'
56
+ new_purgatory = @widget.purgatory! user1, fail_if_matching_soul: true
57
+ new_purgatory.should be_nil
58
+ Purgatory.find_by_id(@purgatory.id).should be_present
59
+ Purgatory.pending.count.should == 1
60
+ end
61
+
62
+ it "should succeed to create purgatory if matching approved Purgatory exists and fail_if_matching_soul is passed in" do
63
+ @purgatory.approve!
64
+ @widget.name = 'baz'
65
+ new_purgatory = @widget.purgatory! user1, fail_if_matching_soul: true
66
+ new_purgatory.should be_present
67
+ Purgatory.count.should == 2
68
+ end
41
69
  end
42
70
 
43
71
  it "should not allow invalid changes to be put into purgatory" do
@@ -153,14 +181,14 @@ describe Purgatory do
153
181
  @widget = Widget.create name: 'foo', price: 100
154
182
  @widget.name = 'bar'
155
183
  @widget.price = 200
156
- @purgatory = @widget.purgatory! user1
184
+ purgatory = @widget.purgatory! user1
185
+ @purgatory = Purgatory.find(purgatory.id)
157
186
  @widget.reload
158
- @purgatory.reload
159
187
  end
160
188
 
161
189
  def create_new_object_purgatory
162
190
  widget = Widget.new name: 'foo', price: 100
163
- @purgatory = widget.purgatory! user1
164
- @purgatory.reload
191
+ purgatory = widget.purgatory! user1
192
+ @purgatory = Purgatory.find(purgatory.id)
165
193
  end
166
194
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purgatory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elan Dubrofsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-25 00:00:00.000000000 Z
11
+ date: 2013-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc