purgatory 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/purgatory/purgatory.rb +5 -1
- data/purgatory.gemspec +3 -2
- data/spec/purgatory_spec.rb +65 -0
- data/spec/support/active_record.rb +9 -1
- data/spec/support/animal.rb +26 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjNjNzY3NWYxY2FlZDdhOGU4YzU4NTU0ZjQ5ZmI5Y2I0NmUwMTg1MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjdlNGQ1MDhmMDFmNDUyZWM2MTRiMWQ4NTYzYWRmOGM1Y2EzNDE1Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzNjMjdhNDk4NzUyMzU0NDMxNDQxNDZlNGJjZTE4Y2RhZmQ2YjM4NDA1ZTFl
|
10
|
+
MDQyODhhMTZjMmQ3NGEyYjBlNjM5NjVkOTRhYWQ2ODg5MDQ1NjIzMjhkMTll
|
11
|
+
MzJhYjNkMDg4ZGM3NWM2NDZmMTA4OTkzNmE4ZTU5Y2Y0N2IzMTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjQ0OWRlMTFiZDY0YzhkNzYzNTZjOGJkNmU1YzQ2ZjczODVlMjA3MmJkYTc0
|
14
|
+
MWNjZjIxNjQ2ODg0ZmM1MmU4YWZiY2QyMDRiYTZkMTliNDA5MzRhNWY5OGIy
|
15
|
+
OTNhY2MzZDUzMzE4NzdjNGIzNjM0MjY5Y2ZiNjk3Y2ZlMjIxODM=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0
|
data/lib/purgatory/purgatory.rb
CHANGED
@@ -28,7 +28,11 @@ class Purgatory < ActiveRecord::Base
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def soul
|
31
|
-
@soul ||= (super || soul_type.constantize.new)
|
31
|
+
@soul ||= (super || (sti_class || soul_type).constantize.new)
|
32
|
+
end
|
33
|
+
|
34
|
+
def sti_class
|
35
|
+
requested_changes['type'].try(:last)
|
32
36
|
end
|
33
37
|
|
34
38
|
def approve!(approver = nil)
|
data/purgatory.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
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.
|
5
|
+
# stub: purgatory 2.5.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "purgatory"
|
9
|
-
s.version = "2.
|
9
|
+
s.version = "2.5.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"]
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"purgatory.gemspec",
|
35
35
|
"spec/purgatory_spec.rb",
|
36
36
|
"spec/support/active_record.rb",
|
37
|
+
"spec/support/animal.rb",
|
37
38
|
"spec/support/user.rb",
|
38
39
|
"spec/support/widget.rb"
|
39
40
|
]
|
data/spec/purgatory_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'support/active_record'
|
2
2
|
require 'support/widget'
|
3
3
|
require 'support/user'
|
4
|
+
require 'support/animal'
|
4
5
|
require 'purgatory/purgatory'
|
5
6
|
|
6
7
|
describe Purgatory do
|
@@ -109,6 +110,35 @@ describe Purgatory do
|
|
109
110
|
Widget.count.should be_zero
|
110
111
|
end
|
111
112
|
end
|
113
|
+
|
114
|
+
context "valid object using STI (single table inheritance)" do
|
115
|
+
before {create_new_object_purgatory_with_sti}
|
116
|
+
|
117
|
+
it "should create and return pending Purgatory object" do
|
118
|
+
@purgatory.should be_present
|
119
|
+
@purgatory.should_not be_approved
|
120
|
+
@purgatory.should be_pending
|
121
|
+
Purgatory.pending.count.should == 1
|
122
|
+
Purgatory.pending.first.should == @purgatory
|
123
|
+
Purgatory.approved.count.should be_zero
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return the soul as a new instance of the purgatoried class" do
|
127
|
+
dog = @purgatory.soul
|
128
|
+
dog.class.should == Dog
|
129
|
+
dog.should be_new_record
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should store the requester and requested changes" do
|
133
|
+
@purgatory.requester.should == user1
|
134
|
+
@purgatory.requested_changes['name'].first.should == nil
|
135
|
+
@purgatory.requested_changes['name'].last.should == 'doggy'
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not create a dog" do
|
139
|
+
Dog.count.should be_zero
|
140
|
+
end
|
141
|
+
end
|
112
142
|
|
113
143
|
it "should not allow invalid object creation to be put into purgatory" do
|
114
144
|
widget = Widget.new name: ''
|
@@ -173,6 +203,34 @@ describe Purgatory do
|
|
173
203
|
@purgatory.approve!(user2).should be_false
|
174
204
|
end
|
175
205
|
end
|
206
|
+
|
207
|
+
context "approving new object creation using STI" do
|
208
|
+
before do
|
209
|
+
create_new_object_purgatory_with_sti
|
210
|
+
@purgatory.approve!(user2).should be_true
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should create the new object and apply any callbacks" do
|
214
|
+
Dog.count.should == 1
|
215
|
+
dog = Dog.first
|
216
|
+
dog.name.should == 'doggy'
|
217
|
+
dog.original_name.should == 'doggy'
|
218
|
+
dog.price.should == Dog::DEFAULT_PRICE
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should mark purgatory as approved and store approver" do
|
222
|
+
@purgatory.approver.should == user2
|
223
|
+
@purgatory.should be_approved
|
224
|
+
@purgatory.should_not be_pending
|
225
|
+
Purgatory.pending.count.should be_zero
|
226
|
+
Purgatory.approved.count.should == 1
|
227
|
+
Purgatory.approved.first.should == @purgatory
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should fail if you try to approve again" do
|
231
|
+
@purgatory.approve!(user2).should be_false
|
232
|
+
end
|
233
|
+
end
|
176
234
|
end
|
177
235
|
|
178
236
|
private
|
@@ -191,4 +249,11 @@ describe Purgatory do
|
|
191
249
|
purgatory = widget.purgatory! user1
|
192
250
|
@purgatory = Purgatory.find(purgatory.id)
|
193
251
|
end
|
252
|
+
|
253
|
+
def create_new_object_purgatory_with_sti
|
254
|
+
dog = Dog.new name: 'doggy'
|
255
|
+
purgatory = dog.purgatory! user1
|
256
|
+
@purgatory = Purgatory.find(purgatory.id)
|
257
|
+
end
|
258
|
+
|
194
259
|
end
|
@@ -16,6 +16,14 @@ ActiveRecord::Migration.create_table :users do |t|
|
|
16
16
|
t.timestamps
|
17
17
|
end
|
18
18
|
|
19
|
+
ActiveRecord::Migration.create_table :animals do |t|
|
20
|
+
t.string :name
|
21
|
+
t.string :type
|
22
|
+
t.integer :price
|
23
|
+
t.string :original_name
|
24
|
+
t.timestamps
|
25
|
+
end
|
26
|
+
|
19
27
|
CreatePurgatories.new.migrate(:up)
|
20
28
|
|
21
29
|
PurgatoryModule.configure do |config|
|
@@ -29,4 +37,4 @@ RSpec.configure do |config|
|
|
29
37
|
raise ActiveRecord::Rollback
|
30
38
|
end
|
31
39
|
end
|
32
|
-
end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'purgatory'
|
2
|
+
|
3
|
+
class Animal < ActiveRecord::Base
|
4
|
+
before_create :set_original_name
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def set_original_name
|
9
|
+
self.original_name = name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Dog < Animal
|
14
|
+
use_purgatory
|
15
|
+
validates :name, presence: true
|
16
|
+
|
17
|
+
DEFAULT_PRICE = 100
|
18
|
+
|
19
|
+
before_create :set_price
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def set_price
|
24
|
+
self.price = DEFAULT_PRICE unless self.price
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purgatory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elan Dubrofsky
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- purgatory.gemspec
|
78
78
|
- spec/purgatory_spec.rb
|
79
79
|
- spec/support/active_record.rb
|
80
|
+
- spec/support/animal.rb
|
80
81
|
- spec/support/user.rb
|
81
82
|
- spec/support/widget.rb
|
82
83
|
homepage: http://github.com/financeit/purgatory
|