acts_as_approvable 0.1.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Appraisals +22 -0
- data/CHANGELOG +76 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +84 -0
- data/MIT-LICENSE +2 -2
- data/README.md +146 -0
- data/Rakefile +90 -7
- data/TODO.md +30 -0
- data/VERSION +1 -0
- data/acts_as_approvable.gemspec +40 -0
- data/features/create_approval.feature +36 -0
- data/features/destroy_approval.feature +19 -0
- data/features/reset_approval.feature +13 -0
- data/features/step_definitions/cucumber_steps.rb +132 -0
- data/features/support/env.rb +14 -0
- data/features/support/large.txt +29943 -0
- data/features/support/second_large.txt +31798 -0
- data/features/update_approval.feature +48 -0
- data/gemfiles/Gemfile.ci +14 -0
- data/gemfiles/Gemfile.ci.lock +98 -0
- data/gemfiles/mysql2.gemfile +7 -0
- data/gemfiles/mysql2.gemfile.lock +86 -0
- data/gemfiles/rails2.gemfile +8 -0
- data/gemfiles/rails2.gemfile.lock +86 -0
- data/gemfiles/rails30.gemfile +9 -0
- data/gemfiles/rails30.gemfile.lock +124 -0
- data/gemfiles/rails31.gemfile +9 -0
- data/gemfiles/rails31.gemfile.lock +135 -0
- data/gemfiles/sqlite.gemfile +7 -0
- data/generators/acts_as_approvable/USAGE +3 -0
- data/generators/acts_as_approvable/acts_as_approvable_generator.rb +81 -0
- data/generators/acts_as_approvable/templates/approvals.js +71 -0
- data/generators/acts_as_approvable/templates/approvals_controller.rb +91 -0
- data/generators/acts_as_approvable/templates/create_approvals.rb +27 -0
- data/generators/acts_as_approvable/templates/initializer.rb +3 -0
- data/generators/acts_as_approvable/templates/jquery.form.js +101 -0
- data/generators/acts_as_approvable/templates/views/erb/_owner_select.html.erb +4 -0
- data/generators/acts_as_approvable/templates/views/erb/_table.html.erb +26 -0
- data/generators/acts_as_approvable/templates/views/erb/index.html.erb +17 -0
- data/generators/acts_as_approvable/templates/views/haml/_owner_select.html.haml +3 -0
- data/generators/acts_as_approvable/templates/views/haml/_table.html.haml +19 -0
- data/generators/acts_as_approvable/templates/views/haml/index.html.haml +15 -0
- data/init.rb +1 -0
- data/lib/acts_as_approvable.rb +96 -2
- data/lib/acts_as_approvable/approval.rb +205 -11
- data/lib/acts_as_approvable/error.rb +34 -0
- data/lib/acts_as_approvable/model.rb +60 -0
- data/lib/acts_as_approvable/model/class_methods.rb +63 -0
- data/lib/acts_as_approvable/model/create_instance_methods.rb +88 -0
- data/lib/acts_as_approvable/model/destroy_instance_methods.rb +38 -0
- data/lib/acts_as_approvable/model/instance_methods.rb +107 -0
- data/lib/acts_as_approvable/model/update_instance_methods.rb +61 -0
- data/lib/acts_as_approvable/ownership.rb +141 -0
- data/lib/acts_as_approvable/railtie.rb +7 -0
- data/lib/acts_as_approvable/version.rb +1 -8
- data/lib/generators/acts_as_approvable/USAGE +1 -0
- data/lib/generators/acts_as_approvable/acts_as_approvable_generator.rb +68 -0
- data/lib/generators/acts_as_approvable/base.rb +30 -0
- data/lib/generators/acts_as_approvable/templates/approvals.js +71 -0
- data/lib/generators/acts_as_approvable/templates/approvals_controller.rb +91 -0
- data/lib/generators/acts_as_approvable/templates/create_approvals.rb +27 -0
- data/lib/generators/acts_as_approvable/templates/jquery.form.js +101 -0
- data/lib/generators/erb/acts_as_approvable_generator.rb +33 -0
- data/lib/generators/erb/templates/_owner_select.html.erb +4 -0
- data/lib/generators/erb/templates/_table.html.erb +26 -0
- data/lib/generators/erb/templates/index.html.erb +17 -0
- data/lib/generators/haml/acts_as_approvable_generator.rb +33 -0
- data/lib/generators/haml/templates/_owner_select.html.haml +3 -0
- data/lib/generators/haml/templates/_table.html.haml +19 -0
- data/lib/generators/haml/templates/index.html.haml +15 -0
- data/lib/tasks/acts_as_approvable.rake +4 -0
- data/rails/init.rb +1 -0
- data/spec/acts_as_approvable/approval_spec.rb +614 -0
- data/spec/acts_as_approvable/model/class_methods_spec.rb +219 -0
- data/spec/acts_as_approvable/model/create_instance_methods_spec.rb +169 -0
- data/spec/acts_as_approvable/model/destroy_instance_methods_spec.rb +71 -0
- data/spec/acts_as_approvable/model/instance_methods_spec.rb +328 -0
- data/spec/acts_as_approvable/model/update_instance_methods_spec.rb +111 -0
- data/spec/acts_as_approvable/model_spec.rb +113 -0
- data/spec/acts_as_approvable/ownership/class_methods_spec.rb +134 -0
- data/spec/acts_as_approvable/ownership/instance_methods_spec.rb +32 -0
- data/spec/acts_as_approvable/ownership_spec.rb +52 -0
- data/spec/acts_as_approvable_spec.rb +31 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/database.rb +49 -0
- data/spec/support/database.yml +12 -0
- data/spec/support/matchers.rb +87 -0
- data/spec/support/models.rb +67 -0
- data/spec/support/schema.rb +54 -0
- metadata +375 -58
- data/README.rdoc +0 -38
- data/lib/acts_as_approvable/approver.rb +0 -76
- data/lib/generators/acts_as_approvable/install_generator.rb +0 -28
- data/lib/generators/acts_as_approvable/templates/install.rb +0 -16
@@ -0,0 +1,328 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsApprovable::Model::InstanceMethods do
|
4
|
+
subject { DefaultApprovable.new }
|
5
|
+
|
6
|
+
describe '#approvals_enabled?' do
|
7
|
+
before(:each) do
|
8
|
+
subject.stub(:global_approvals_on? => true)
|
9
|
+
subject.stub(:model_approvals_on? => true)
|
10
|
+
subject.stub(:approvals_on? => true)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when approvals are globally disabled' do
|
14
|
+
before(:each) do
|
15
|
+
subject.stub(:global_approvals_on? => false)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns false' do
|
19
|
+
subject.approvals_enabled?.should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'checks the global status' do
|
23
|
+
subject.should_receive(:global_approvals_on?).and_return(false)
|
24
|
+
subject.approvals_enabled?
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'does not check the model status' do
|
28
|
+
subject.should_not_receive(:model_approvals_on?)
|
29
|
+
subject.approvals_enabled?
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'does not check the record status' do
|
33
|
+
subject.should_not_receive(:approvals_on?)
|
34
|
+
subject.approvals_enabled?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when approvals are disabled for the Model' do
|
39
|
+
before(:each) do
|
40
|
+
subject.stub(:model_approvals_on? => false)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns false' do
|
44
|
+
subject.approvals_enabled?.should be_false
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'checks the global status' do
|
48
|
+
subject.should_receive(:global_approvals_on?).and_return(true)
|
49
|
+
subject.approvals_enabled?
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'checks the model status' do
|
53
|
+
subject.should_receive(:model_approvals_on?).and_return(false)
|
54
|
+
subject.approvals_enabled?
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'does not check the record status' do
|
58
|
+
subject.should_not_receive(:approvals_on?)
|
59
|
+
subject.approvals_enabled?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when approvals are disabled for the Record' do
|
64
|
+
before(:each) do
|
65
|
+
subject.stub(:approvals_on? => false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns false' do
|
69
|
+
subject.approvals_enabled?.should be_false
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'checks the global status' do
|
73
|
+
subject.should_receive(:global_approvals_on?).and_return(true)
|
74
|
+
subject.approvals_enabled?
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'checks the model status' do
|
78
|
+
subject.should_receive(:model_approvals_on?).and_return(true)
|
79
|
+
subject.approvals_enabled?
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'checks the record status' do
|
83
|
+
subject.should_receive(:approvals_on?).and_return(false)
|
84
|
+
subject.approvals_enabled?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#approvals_disabled?' do
|
90
|
+
before(:each) do
|
91
|
+
subject.stub(:approvals_enabled? => true)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns the inverse of the approval queue status' do
|
95
|
+
subject.approvals_disabled?.should == !subject.approvals_enabled?
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'calls #approvals_enabled? for the status' do
|
99
|
+
subject.should_receive(:approvals_enabled?).and_return(true)
|
100
|
+
subject.approvals_disabled?
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#approvals_off' do
|
105
|
+
before(:each) do
|
106
|
+
subject.approvals_off
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'disables the record level approval queue' do
|
110
|
+
subject.approvals_on?.should be_false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#approvals_on' do
|
115
|
+
before(:each) do
|
116
|
+
subject.approvals_on
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'enables the record level approval queue' do
|
120
|
+
subject.approvals_on?.should be_true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#approvals_on?' do
|
125
|
+
context 'when approval queues are enabled locally' do
|
126
|
+
before(:each) do
|
127
|
+
subject.instance_variable_set('@approvals_disabled', false)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'returns true' do
|
131
|
+
subject.approvals_on?.should be_true
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'ignores the model level status' do
|
135
|
+
subject.stub(:model_approvals_on? => false)
|
136
|
+
subject.approvals_on?.should be_true
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'ignores the global level status' do
|
140
|
+
subject.stub(:global_approvals_on? => false)
|
141
|
+
subject.approvals_on?.should be_true
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when approval queues are disabled locally' do
|
146
|
+
before(:each) do
|
147
|
+
subject.instance_variable_set('@approvals_disabled', true)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'returns false' do
|
151
|
+
subject.approvals_on?.should be_false
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'ignores the model level status' do
|
155
|
+
subject.stub(:model_approvals_on? => true)
|
156
|
+
subject.approvals_on?.should be_false
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'ignores the global level status' do
|
160
|
+
subject.stub(:global_approvals_on? => true)
|
161
|
+
subject.approvals_on?.should be_false
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#approvable_on?' do
|
167
|
+
it { should be_approvable_on(:create) }
|
168
|
+
it { should be_approvable_on(:update) }
|
169
|
+
|
170
|
+
context 'when the model is approvable on :create events' do
|
171
|
+
subject { CreatesApprovable.new }
|
172
|
+
|
173
|
+
it { should be_approvable_on(:create) }
|
174
|
+
it { should_not be_approvable_on(:update) }
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when the model is approvable on :update events' do
|
178
|
+
subject { UpdatesApprovable.new }
|
179
|
+
|
180
|
+
it { should be_approvable_on(:update) }
|
181
|
+
it { should_not be_approvable_on(:create) }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'with approval and rejection hooks' do
|
186
|
+
before(:each) do
|
187
|
+
@record = CreatesApprovable.create
|
188
|
+
|
189
|
+
@approval = @record.approval
|
190
|
+
@approval.stub(:item => @record)
|
191
|
+
end
|
192
|
+
|
193
|
+
describe '#before_approve' do
|
194
|
+
before(:each) do
|
195
|
+
@record.stub(:before_approve => true)
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'is called when approving a record' do
|
199
|
+
@record.should_receive(:before_approve).and_return(true)
|
200
|
+
@approval.approve!
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'is not called when rejecting a record' do
|
204
|
+
@record.should_not_receive(:before_approve)
|
205
|
+
@approval.reject!
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'receives the approval as an argument' do
|
209
|
+
@record.should_receive(:before_approve).with(@approval).and_return(true)
|
210
|
+
@approval.approve!
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'when it returns false' do
|
214
|
+
before(:each) do
|
215
|
+
@record.stub(:before_approve => false)
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'prevents the approval from proceeding' do
|
219
|
+
@approval.approve!
|
220
|
+
@approval.state.should == 'pending'
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe '#before_reject' do
|
226
|
+
before(:each) do
|
227
|
+
@record.stub(:before_reject => true)
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'is called when rejecting a record' do
|
231
|
+
@record.should_receive(:before_reject).and_return(true)
|
232
|
+
@approval.reject!
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'is not called when approving a record' do
|
236
|
+
@record.should_not_receive(:before_reject)
|
237
|
+
@approval.approve!
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'receives the approval as an argument' do
|
241
|
+
@record.should_receive(:before_reject).with(@approval).and_return(true)
|
242
|
+
@approval.reject!
|
243
|
+
end
|
244
|
+
|
245
|
+
context 'when it returns false' do
|
246
|
+
before(:each) do
|
247
|
+
@record.stub(:before_reject => false)
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'prevents the rejection from proceeding' do
|
251
|
+
@approval.reject!
|
252
|
+
@approval.state.should == 'pending'
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe '#after_approve' do
|
258
|
+
it 'is called when approving a record' do
|
259
|
+
@record.should_receive(:before_approve)
|
260
|
+
@approval.approve!
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'is not called when rejecting a record' do
|
264
|
+
@record.should_not_receive(:after_approve)
|
265
|
+
@approval.reject!
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'receives the approval as an argument' do
|
269
|
+
@record.should_receive(:after_approve).with(@approval).and_return(true)
|
270
|
+
@approval.approve!
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe '#after_reject' do
|
275
|
+
it 'is called when rejecting a record' do
|
276
|
+
@record.should_receive(:after_reject).and_return(true)
|
277
|
+
@approval.reject!
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'is not called when approving a record' do
|
281
|
+
@record.should_not_receive(:after_reject)
|
282
|
+
@approval.approve!
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'receives the approval as an argument' do
|
286
|
+
@record.should_receive(:after_reject).with(@approval).and_return(true)
|
287
|
+
@approval.reject!
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
describe '#without_approval' do
|
293
|
+
around(:each) do
|
294
|
+
subject.approvals_on
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'disables approval queues' do
|
298
|
+
subject.without_approval { |r| r.update_attributes(:title => 'no review') }
|
299
|
+
subject.update_approvals.should be_empty
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'enables the approval queue after running' do
|
303
|
+
subject.should be_approvals_on
|
304
|
+
subject.without_approval { |r| r.update_attributes(:title => 'no review') }
|
305
|
+
subject.should be_approvals_on
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'returns the approval queue to the previous state' do
|
309
|
+
subject.approvals_off
|
310
|
+
subject.without_approval { |r| r.update_attributes(:title => 'no review') }
|
311
|
+
subject.should_not be_approvals_on
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe '#save_without_approval' do
|
316
|
+
it 'calls #without_approval' do
|
317
|
+
subject.should_receive(:without_approval)
|
318
|
+
subject.save_without_approval
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
describe '#save_without_approval!' do
|
323
|
+
it 'calls #without_approval' do
|
324
|
+
subject.should_receive(:without_approval)
|
325
|
+
subject.save_without_approval!
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsApprovable::Model::UpdateInstanceMethods do
|
4
|
+
subject { UpdatesApprovable.create }
|
5
|
+
|
6
|
+
describe '#update_approvals' do
|
7
|
+
before(:each) do
|
8
|
+
subject.update_attributes(:title => 'review')
|
9
|
+
@approval1 = subject.approvals.last
|
10
|
+
@approval1.approve!
|
11
|
+
|
12
|
+
subject.update_attributes(:title => 'review2')
|
13
|
+
@approval2 = subject.approvals.last
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'retreives all :update approvals' do
|
17
|
+
subject.update_approvals.should == [@approval1, @approval2]
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when requesting only pending records' do
|
21
|
+
it 'retreives pending :update approvals' do
|
22
|
+
subject.update_approvals(false).should == [@approval2]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#pending_changes?' do
|
28
|
+
it 'returns false with no pending approvals' do
|
29
|
+
subject.should_not be_pending_changes
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with pending approvals' do
|
33
|
+
before(:each) do
|
34
|
+
subject.update_attributes(:title => 'review')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns true' do
|
38
|
+
subject.should be_pending_changes
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with approved and rejected approvals' do
|
43
|
+
before(:each) do
|
44
|
+
subject.update_attributes(:title => 'review')
|
45
|
+
subject.approvals.last.approve!
|
46
|
+
|
47
|
+
subject.update_attributes(:title => 'review')
|
48
|
+
subject.approvals.last.reject!
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns false' do
|
52
|
+
subject.should_not be_pending_changes
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#changed_notably?' do
|
58
|
+
it 'returns true if #notably_changed returns values' do
|
59
|
+
subject.stub(:notably_changed => [1])
|
60
|
+
subject.should be_changed_notably
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns false if #notably_changed does not return values' do
|
64
|
+
subject.stub(:notably_changed => [])
|
65
|
+
subject.should_not be_changed_notably
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#notably_changed' do
|
70
|
+
before(:each) do
|
71
|
+
subject.title = 'review'
|
72
|
+
subject.updated_at += 60
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'includes fields that should be approved' do
|
76
|
+
subject.changed.should include('title')
|
77
|
+
subject.notably_changed.should include('title')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'does not include fields that should be ignored' do
|
81
|
+
subject.changed.should include('updated_at')
|
82
|
+
subject.notably_changed.should_not include('updated_at')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'gets a list of approvable fields from #approvable_fields' do
|
86
|
+
subject.should_receive(:approvable_fields).and_return([])
|
87
|
+
subject.notably_changed
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#approvable_fields' do
|
92
|
+
it 'proxies to the class level' do
|
93
|
+
subject.class.should_receive(:approvable_fields)
|
94
|
+
subject.approvable_fields
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when a record is updated' do
|
99
|
+
before(:each) do
|
100
|
+
subject.update_attribute(:body, 'updated')
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'saves the updated values to the approval record' do
|
104
|
+
subject.update_approvals.last.object.should == {'body' => 'updated'}
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'saves the original values to the approval record' do
|
108
|
+
subject.update_approvals.last.original.should == {'body' => nil}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsApprovable::Model do
|
4
|
+
context 'when acts_as_approvable is not configured' do
|
5
|
+
subject { NotApprovable }
|
6
|
+
|
7
|
+
it { subject.new.should_not have_many(:approvals) }
|
8
|
+
|
9
|
+
it { should_not extend(ActsAsApprovable::Model::ClassMethods) }
|
10
|
+
it { should_not extend(ActsAsApprovable::Model::InstanceMethods) }
|
11
|
+
it { should_not extend(ActsAsApprovable::Model::CreateInstanceMethods) }
|
12
|
+
it { should_not extend(ActsAsApprovable::Model::UpdateInstanceMethods) }
|
13
|
+
it { should_not extend(ActsAsApprovable::Model::DestroyInstanceMethods) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with default configuration options' do
|
17
|
+
subject { DefaultApprovable }
|
18
|
+
|
19
|
+
it { should be_approvable_on(:create) }
|
20
|
+
it { should be_approvable_on(:update) }
|
21
|
+
it { should be_approvable_on(:destroy) }
|
22
|
+
it { should be_approvals_enabled }
|
23
|
+
it { subject.new.should have_many(:approvals) }
|
24
|
+
|
25
|
+
it { should extend(ActsAsApprovable::Model::ClassMethods) }
|
26
|
+
it { should extend(ActsAsApprovable::Model::InstanceMethods) }
|
27
|
+
it { should extend(ActsAsApprovable::Model::CreateInstanceMethods) }
|
28
|
+
it { should extend(ActsAsApprovable::Model::UpdateInstanceMethods) }
|
29
|
+
it { should extend(ActsAsApprovable::Model::DestroyInstanceMethods) }
|
30
|
+
|
31
|
+
it 'has no approvable_field' do
|
32
|
+
subject.approvable_field.should_not be
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'ignores timestamps' do
|
36
|
+
subject.approvable_ignore.should include('created_at')
|
37
|
+
subject.approvable_ignore.should include('updated_at')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'ignores the primary key' do
|
41
|
+
subject.approvable_ignore.should include(subject.primary_key)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with :create as the only event' do
|
46
|
+
context 'and no other options' do
|
47
|
+
subject { CreatesApprovable }
|
48
|
+
|
49
|
+
it { should be_approvable_on(:create) }
|
50
|
+
it { should_not be_approvable_on(:update) }
|
51
|
+
it { should_not be_approvable_on(:destroy) }
|
52
|
+
|
53
|
+
it { should extend(ActsAsApprovable::Model::ClassMethods) }
|
54
|
+
it { should extend(ActsAsApprovable::Model::InstanceMethods) }
|
55
|
+
it { should extend(ActsAsApprovable::Model::CreateInstanceMethods) }
|
56
|
+
it { should_not extend(ActsAsApprovable::Model::UpdateInstanceMethods) }
|
57
|
+
it { should_not extend(ActsAsApprovable::Model::DestroyInstanceMethods) }
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'and a :state_field' do
|
61
|
+
subject { CreatesWithStateApprovable }
|
62
|
+
|
63
|
+
it 'has an approvable_field' do
|
64
|
+
subject.approvable_field.should be
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'ignores the approvable_field' do
|
68
|
+
subject.approvable_ignore.should include(subject.approvable_field.to_s)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'ignores timestamps' do
|
72
|
+
subject.approvable_ignore.should include('created_at')
|
73
|
+
subject.approvable_ignore.should include('updated_at')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'ignores the primary key' do
|
77
|
+
subject.approvable_ignore.should include(subject.primary_key)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'with :update as the only event' do
|
83
|
+
context 'and no other options' do
|
84
|
+
subject { UpdatesApprovable }
|
85
|
+
|
86
|
+
it { should be_approvable_on(:update) }
|
87
|
+
it { should_not be_approvable_on(:create) }
|
88
|
+
it { should_not be_approvable_on(:destroy) }
|
89
|
+
|
90
|
+
it { should extend(ActsAsApprovable::Model::ClassMethods) }
|
91
|
+
it { should extend(ActsAsApprovable::Model::InstanceMethods) }
|
92
|
+
it { should extend(ActsAsApprovable::Model::UpdateInstanceMethods) }
|
93
|
+
it { should_not extend(ActsAsApprovable::Model::CreateInstanceMethods) }
|
94
|
+
it { should_not extend(ActsAsApprovable::Model::DestroyInstanceMethods) }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with :destroy as the only event' do
|
99
|
+
context 'and no other options' do
|
100
|
+
subject { DestroysApprovable }
|
101
|
+
|
102
|
+
it { should be_approvable_on(:destroy) }
|
103
|
+
it { should_not be_approvable_on(:create) }
|
104
|
+
it { should_not be_approvable_on(:update) }
|
105
|
+
|
106
|
+
it { should extend(ActsAsApprovable::Model::ClassMethods) }
|
107
|
+
it { should extend(ActsAsApprovable::Model::InstanceMethods) }
|
108
|
+
it { should extend(ActsAsApprovable::Model::DestroyInstanceMethods) }
|
109
|
+
it { should_not extend(ActsAsApprovable::Model::CreateInstanceMethods) }
|
110
|
+
it { should_not extend(ActsAsApprovable::Model::UpdateInstanceMethods) }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|