acts-as-approvable 0.6.7 → 0.6.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -5
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Appraisals +14 -10
- data/CHANGELOG +16 -0
- data/Gemfile.lock +60 -20
- data/README.md +1 -2
- data/Rakefile +44 -16
- data/VERSION +1 -1
- data/acts-as-approvable.gemspec +21 -11
- data/features/create_approval.feature +26 -0
- data/features/step_definitions/cucumber_steps.rb +86 -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 +34 -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 +92 -0
- data/gemfiles/rails2.gemfile +1 -0
- data/gemfiles/rails2.gemfile.lock +59 -17
- data/gemfiles/rails30.gemfile +1 -0
- data/gemfiles/rails30.gemfile.lock +54 -14
- data/gemfiles/rails31.gemfile +1 -0
- data/gemfiles/rails31.gemfile.lock +54 -14
- data/gemfiles/sqlite.gemfile +7 -0
- data/generators/acts_as_approvable/templates/create_approvals.rb +8 -7
- data/lib/acts-as-approvable.rb +2 -3
- data/lib/acts_as_approvable/approval.rb +3 -2
- data/lib/acts_as_approvable/model.rb +55 -0
- data/lib/acts_as_approvable/model/class_methods.rb +63 -0
- data/lib/acts_as_approvable/model/create_instance_methods.rb +83 -0
- data/lib/acts_as_approvable/model/instance_methods.rb +89 -0
- data/lib/acts_as_approvable/model/update_instance_methods.rb +61 -0
- data/lib/acts_as_approvable/railtie.rb +1 -1
- data/lib/generators/acts_as_approvable/templates/create_approvals.rb +8 -7
- data/spec/acts_as_approvable/approval_spec.rb +475 -0
- data/spec/acts_as_approvable/model/class_methods_spec.rb +219 -0
- data/spec/acts_as_approvable/model/create_instance_methods_spec.rb +149 -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 +90 -0
- data/spec/acts_as_approvable/ownership/class_methods_spec.rb +101 -0
- data/spec/acts_as_approvable/ownership/instance_methods_spec.rb +32 -0
- data/spec/acts_as_approvable/ownership_spec.rb +51 -0
- data/spec/acts_as_approvable_spec.rb +29 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/database.rb +46 -0
- data/spec/support/database.yml +12 -0
- data/spec/support/matchers.rb +87 -0
- data/spec/support/models.rb +60 -0
- data/{test → spec/support}/schema.rb +15 -9
- metadata +156 -53
- data/gemfiles/rails32.gemfile +0 -8
- data/gemfiles/rails32.gemfile.lock +0 -99
- data/lib/acts_as_approvable/acts_as_approvable.rb +0 -291
- data/test/acts_as_approvable_model_test.rb +0 -459
- data/test/acts_as_approvable_ownership_test.rb +0 -132
- data/test/acts_as_approvable_schema_test.rb +0 -13
- data/test/acts_as_approvable_test.rb +0 -8
- data/test/database.yml +0 -7
- data/test/support.rb +0 -19
- data/test/test_helper.rb +0 -62
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsApprovable::Model::ClassMethods do
|
4
|
+
subject { DefaultApprovable }
|
5
|
+
|
6
|
+
describe '.acts_as_approvable' do
|
7
|
+
subject { CleanApprovable }
|
8
|
+
|
9
|
+
it 'includes InstanceMethods into the class' do
|
10
|
+
subject.should_not extend(ActsAsApprovable::Model::InstanceMethods)
|
11
|
+
subject.acts_as_approvable
|
12
|
+
subject.should extend(ActsAsApprovable::Model::InstanceMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'includes ClassMethods into the class' do
|
16
|
+
subject.should_not extend(ActsAsApprovable::Model::ClassMethods)
|
17
|
+
subject.acts_as_approvable
|
18
|
+
subject.should extend(ActsAsApprovable::Model::ClassMethods)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.approvals_enabled?' do
|
23
|
+
before(:each) do
|
24
|
+
subject.stub(:global_approvals_on? => true)
|
25
|
+
subject.stub(:approvals_on? => true)
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when approvals are globally disabled' do
|
29
|
+
before(:each) do
|
30
|
+
subject.stub(:global_approvals_on? => false)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns false' do
|
34
|
+
subject.approvals_enabled?.should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'checks the global status' do
|
38
|
+
subject.should_receive(:global_approvals_on?).and_return(false)
|
39
|
+
subject.approvals_enabled?
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'does not check the model status' do
|
43
|
+
subject.should_not_receive(:approvals_on?)
|
44
|
+
subject.approvals_enabled?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when approvals are disabled for the Model' do
|
49
|
+
before(:each) do
|
50
|
+
subject.stub(:approvals_on? => false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns false' do
|
54
|
+
subject.approvals_enabled?.should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'checks the global status' do
|
58
|
+
subject.should_receive(:global_approvals_on?).and_return(true)
|
59
|
+
subject.approvals_enabled?
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'checks the model status' do
|
63
|
+
subject.should_receive(:approvals_on?).and_return(false)
|
64
|
+
subject.approvals_enabled?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '.approvals_disabled?' do
|
70
|
+
before(:each) do
|
71
|
+
subject.stub(:approvals_enabled? => true)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns the inverse of the approval queue status' do
|
75
|
+
subject.approvals_disabled?.should == !subject.approvals_enabled?
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'calls .approvals_enabled? for the status' do
|
79
|
+
subject.should_receive(:approvals_enabled?).and_return(true)
|
80
|
+
subject.approvals_disabled?
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '.approvals_off' do
|
85
|
+
before(:each) do
|
86
|
+
subject.approvals_off
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'disables the model level approval queue' do
|
90
|
+
subject.approvals_on?.should be_false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '.approvals_on' do
|
95
|
+
before(:each) do
|
96
|
+
subject.approvals_on
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'enables the model level approval queue' do
|
100
|
+
subject.approvals_on?.should be_true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '.approvals_on?' do
|
105
|
+
context 'when approval queues are enabled locally' do
|
106
|
+
before(:each) do
|
107
|
+
subject.approvals_disabled = false
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns true' do
|
111
|
+
subject.approvals_on?.should be_true
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'ignores the global level status' do
|
115
|
+
subject.stub(:global_approvals_on? => false)
|
116
|
+
subject.approvals_on?.should be_true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when approval queues are disabled locally' do
|
121
|
+
before(:each) do
|
122
|
+
subject.approvals_disabled = true
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns false' do
|
126
|
+
subject.approvals_on?.should be_false
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'ignores the global level status' do
|
130
|
+
subject.stub(:global_approvals_on? => true)
|
131
|
+
subject.approvals_on?.should be_false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '.global_approvals_on?' do
|
137
|
+
it 'checks the global approval status' do
|
138
|
+
ActsAsApprovable.should_receive(:enabled?)
|
139
|
+
subject.global_approvals_on?
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '.approvable_on?' do
|
144
|
+
it { should be_approvable_on(:create) }
|
145
|
+
it { should be_approvable_on(:update) }
|
146
|
+
|
147
|
+
context 'when the model is approvable on :create events' do
|
148
|
+
subject { CreatesApprovable }
|
149
|
+
|
150
|
+
it { should be_approvable_on(:create) }
|
151
|
+
it { should_not be_approvable_on(:update) }
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when the model is approvable on :update events' do
|
155
|
+
subject { UpdatesApprovable }
|
156
|
+
|
157
|
+
it { should be_approvable_on(:update) }
|
158
|
+
it { should_not be_approvable_on(:create) }
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '.approvable_fields' do
|
163
|
+
subject { CleanApprovable }
|
164
|
+
|
165
|
+
context 'with :only fields configured' do
|
166
|
+
before(:each) do
|
167
|
+
subject.acts_as_approvable :only => [:body, :extra]
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'returns the configured fields' do
|
171
|
+
subject.approvable_fields.should == ['body', 'extra']
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'with :ignore fields configured' do
|
176
|
+
before(:each) do
|
177
|
+
subject.acts_as_approvable :ignore => [:title, :extra]
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'returns the available fields minus whats ignored' do
|
181
|
+
subject.approvable_fields.should include('body')
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'ignores timestamps' do
|
185
|
+
subject.approvable_fields.should_not include('created_at')
|
186
|
+
subject.approvable_fields.should_not include('updated_at')
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'ignores primary keys' do
|
190
|
+
subject.approvable_fields.should_not include(subject.primary_key)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '.without_approval' do
|
196
|
+
around(:each) do |example|
|
197
|
+
subject.approvals_on
|
198
|
+
example.run
|
199
|
+
subject.approvals_on
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'disables approval queues' do
|
203
|
+
@record = subject.without_approval { |m| m.create(:title => 'title', :body => 'the body') }
|
204
|
+
@record.approval.should_not be
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'enables the approval queue after running' do
|
208
|
+
subject.should be_approvals_on
|
209
|
+
subject.without_approval { |m| m.create(:title => 'title', :body => 'the body') }
|
210
|
+
subject.should be_approvals_on
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'returns the approval queue to the previous state' do
|
214
|
+
subject.approvals_off
|
215
|
+
subject.without_approval { |m| m.create(:title => 'title', :body => 'the body') }
|
216
|
+
subject.should_not be_approvals_on
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsApprovable::Model::CreateInstanceMethods do
|
4
|
+
subject { CreatesApprovable.create }
|
5
|
+
|
6
|
+
describe '#approval' do
|
7
|
+
subject { CreatesApprovable.create } # Reverse the mocking for #approval
|
8
|
+
|
9
|
+
it 'returns a :create approval' do
|
10
|
+
subject.approval.event == :create
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns the first :create approval' do
|
14
|
+
duplicate = Approval.create(:item_id => subject.id, :item_type => 'CreatesApprovable', :event => 'create')
|
15
|
+
subject.approval != duplicate
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context do
|
20
|
+
before(:each) do
|
21
|
+
@approval = subject.approvals.first
|
22
|
+
subject.stub(:approval => @approval)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#approval_state' do
|
26
|
+
it 'gets the state from the approval record' do
|
27
|
+
@approval.should_receive(:state)
|
28
|
+
subject.approval_state
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when a :state_field is configured' do
|
32
|
+
subject { CreatesWithStateApprovable.create }
|
33
|
+
|
34
|
+
it 'gets the state from the configured field' do
|
35
|
+
subject.should_receive(:state)
|
36
|
+
subject.approval_state
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'does not get the state from the approval record' do
|
40
|
+
subject.should_not_receive(:approval)
|
41
|
+
subject.approval_state
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#set_approval_state' do
|
47
|
+
it 'does nothing if no :state_field is configured' do
|
48
|
+
subject.should_not_receive(:state=)
|
49
|
+
subject.set_approval_state('pending')
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when a :state_field is configured' do
|
53
|
+
subject { CreatesWithStateApprovable.create }
|
54
|
+
|
55
|
+
it 'sets the configured field' do
|
56
|
+
subject.should_receive(:state=)
|
57
|
+
subject.set_approval_state('pending')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#pending?' do
|
63
|
+
it 'gets the status from the approval record' do
|
64
|
+
subject.should_receive(:approval)
|
65
|
+
subject.pending?
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when a :state_field is configured' do
|
69
|
+
subject { CreatesWithStateApprovable.create }
|
70
|
+
|
71
|
+
it 'gets the state from the configured field' do
|
72
|
+
subject.should_receive(:state)
|
73
|
+
subject.pending?
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'does not get the state from the approval record' do
|
77
|
+
subject.should_not_receive(:approval)
|
78
|
+
subject.pending?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#approved?' do
|
84
|
+
it 'gets the status from the approval record' do
|
85
|
+
subject.should_receive(:approval)
|
86
|
+
subject.approved?
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when a :state_field is configured' do
|
90
|
+
subject { CreatesWithStateApprovable.create }
|
91
|
+
|
92
|
+
it 'gets the state from the configured field' do
|
93
|
+
subject.should_receive(:state)
|
94
|
+
subject.approved?
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'does not get the state from the approval record' do
|
98
|
+
subject.should_not_receive(:approval)
|
99
|
+
subject.approved?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#rejected?' do
|
105
|
+
it 'gets the status from the approval record' do
|
106
|
+
subject.should_receive(:approval)
|
107
|
+
subject.rejected?
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when a :state_field is configured' do
|
111
|
+
subject { CreatesWithStateApprovable.create }
|
112
|
+
|
113
|
+
it 'gets the state from the configured field' do
|
114
|
+
subject.should_receive(:state)
|
115
|
+
subject.rejected?
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'does not get the state from the approval record' do
|
119
|
+
subject.should_not_receive(:approval)
|
120
|
+
subject.rejected?
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#approve!' do
|
126
|
+
it 'approves the record' do
|
127
|
+
subject.approve!
|
128
|
+
subject.should be_approved
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'proxies to the approval record for approval' do
|
132
|
+
subject.should_receive(:approval)
|
133
|
+
subject.approve!
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#reject!' do
|
138
|
+
it 'rejects the record' do
|
139
|
+
subject.reject!
|
140
|
+
subject.should be_rejected
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'proxies to the approval record for approval' do
|
144
|
+
subject.should_receive(:approval)
|
145
|
+
subject.reject!
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -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
|