spec/purgatory_spec.rb in purgatory-2.3.0 vs spec/purgatory_spec.rb in purgatory-2.4.0
- old
+ new
@@ -36,10 +36,38 @@
it "should allow the widget to access its purgatories" do
@widget.purgatories.count.should == 1
@widget.purgatories.first.should == @purgatory
end
+
+ it "should delete old pending purgatories with same soul" do
+ @widget2 = Widget.create name: 'toy', price: 500
+ @widget2.name = 'Big Toy'
+ widget2_purgatory = @widget2.purgatory! user1
+ @widget.name = 'baz'
+ new_purgatory = @widget.purgatory! user1
+ Purgatory.find_by_id(@purgatory.id).should be_nil
+ Purgatory.find_by_id(widget2_purgatory.id).should be_present
+ Purgatory.pending.count.should == 2
+ Purgatory.last.requested_changes['name'].should == ['foo', 'baz']
+ end
+
+ it "should fail to create purgatory if matching pending Purgatory exists and fail_if_matching_soul is passed in" do
+ @widget.name = 'baz'
+ new_purgatory = @widget.purgatory! user1, fail_if_matching_soul: true
+ new_purgatory.should be_nil
+ Purgatory.find_by_id(@purgatory.id).should be_present
+ Purgatory.pending.count.should == 1
+ end
+
+ it "should succeed to create purgatory if matching approved Purgatory exists and fail_if_matching_soul is passed in" do
+ @purgatory.approve!
+ @widget.name = 'baz'
+ new_purgatory = @widget.purgatory! user1, fail_if_matching_soul: true
+ new_purgatory.should be_present
+ Purgatory.count.should == 2
+ end
end
it "should not allow invalid changes to be put into purgatory" do
widget = Widget.create name: 'foo'
widget.name = ''
@@ -151,16 +179,16 @@
def create_object_change_purgatory
@widget = Widget.create name: 'foo', price: 100
@widget.name = 'bar'
@widget.price = 200
- @purgatory = @widget.purgatory! user1
+ purgatory = @widget.purgatory! user1
+ @purgatory = Purgatory.find(purgatory.id)
@widget.reload
- @purgatory.reload
end
def create_new_object_purgatory
widget = Widget.new name: 'foo', price: 100
- @purgatory = widget.purgatory! user1
- @purgatory.reload
+ purgatory = widget.purgatory! user1
+ @purgatory = Purgatory.find(purgatory.id)
end
end