dalliance 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +15 -0
- data/Gemfile +2 -0
- data/dalliance.gemspec +3 -3
- data/gemfiles/rails_3.1.gemfile +8 -0
- data/gemfiles/rails_3.1.gemfile.lock +144 -0
- data/gemfiles/rails_3.2.gemfile +8 -0
- data/gemfiles/rails_3.2.gemfile.lock +142 -0
- data/gemfiles/rails_4.0.gemfile +8 -0
- data/gemfiles/rails_4.0.gemfile.lock +130 -0
- data/gemfiles/rails_4.1.gemfile +8 -0
- data/gemfiles/rails_4.1.gemfile.lock +136 -0
- data/lib/dalliance/version.rb +2 -2
- data/lib/dalliance.rb +5 -5
- data/spec/dalliance/asynchronous_delayed_job_spec.rb +34 -32
- data/spec/dalliance/asynchronous_resque_spec.rb +38 -36
- data/spec/dalliance/dalliance_spec.rb +1 -1
- data/spec/dalliance/synchronous_spec.rb +33 -31
- data/spec/spec_helper.rb +10 -0
- data/spec/support/active_record.rb +2 -14
- metadata +29 -8
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe DallianceModel do
|
3
|
+
RSpec.describe DallianceModel do
|
4
4
|
subject { DallianceModel.create }
|
5
5
|
|
6
6
|
before(:all) do
|
@@ -35,8 +35,8 @@ describe DallianceModel do
|
|
35
35
|
subject.dalliance_background_process
|
36
36
|
subject.reload
|
37
37
|
|
38
|
-
subject.
|
39
|
-
Delayed::Job.count.
|
38
|
+
expect(subject).not_to be_successful
|
39
|
+
expect(Delayed::Job.count).to eq(1)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should call the dalliance_method w/ a Delayed::Worker" do
|
@@ -44,8 +44,8 @@ describe DallianceModel do
|
|
44
44
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
45
45
|
subject.reload
|
46
46
|
|
47
|
-
subject.
|
48
|
-
Delayed::Job.count.
|
47
|
+
expect(subject).to be_successful
|
48
|
+
expect(Delayed::Job.count).to eq(0)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should set the dalliance_status to completed" do
|
@@ -53,7 +53,7 @@ describe DallianceModel do
|
|
53
53
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
54
54
|
subject.reload
|
55
55
|
|
56
|
-
subject.
|
56
|
+
expect(subject).to be_completed
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should set the dalliance_progress to 100" do
|
@@ -61,17 +61,17 @@ describe DallianceModel do
|
|
61
61
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
62
62
|
subject.reload
|
63
63
|
|
64
|
-
subject.dalliance_progress.
|
64
|
+
expect(subject.dalliance_progress).to eq(100)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should set the dalliance_duration" do
|
68
|
-
subject.dalliance_duration.
|
68
|
+
expect(subject.dalliance_duration).to eq(nil)
|
69
69
|
|
70
70
|
subject.dalliance_background_process
|
71
71
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
72
72
|
subject.reload
|
73
73
|
|
74
|
-
subject.dalliance_duration.
|
74
|
+
expect(subject.dalliance_duration).not_to eq(nil)
|
75
75
|
end
|
76
76
|
|
77
77
|
context "another_queue" do
|
@@ -86,8 +86,8 @@ describe DallianceModel do
|
|
86
86
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
87
87
|
subject.reload
|
88
88
|
|
89
|
-
subject.
|
90
|
-
Delayed::Job.count.
|
89
|
+
expect(subject).not_to be_successful
|
90
|
+
expect(Delayed::Job.count).to eq(1)
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should call the dalliance_method w/ a Delayed::Worker (same queue)" do
|
@@ -95,8 +95,8 @@ describe DallianceModel do
|
|
95
95
|
Delayed::Worker.new(:queues => [queue]).work_off
|
96
96
|
subject.reload
|
97
97
|
|
98
|
-
subject.
|
99
|
-
Delayed::Job.count.
|
98
|
+
expect(subject).to be_successful
|
99
|
+
expect(Delayed::Job.count).to eq(0)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -113,7 +113,7 @@ describe DallianceModel do
|
|
113
113
|
|
114
114
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
115
115
|
|
116
|
-
Delayed::Job.count.
|
116
|
+
expect(Delayed::Job.count).to eq(0)
|
117
117
|
end
|
118
118
|
|
119
119
|
it "should store the error" do
|
@@ -121,10 +121,10 @@ describe DallianceModel do
|
|
121
121
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
122
122
|
subject.reload
|
123
123
|
|
124
|
-
subject.dalliance_error_hash.
|
125
|
-
subject.dalliance_error_hash[:error].
|
126
|
-
subject.dalliance_error_hash[:message].
|
127
|
-
subject.dalliance_error_hash[:backtrace].
|
124
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
125
|
+
expect(subject.dalliance_error_hash[:error]).to eq(RuntimeError.name) #We store the class name...
|
126
|
+
expect(subject.dalliance_error_hash[:message]).to eq('RuntimeError')
|
127
|
+
expect(subject.dalliance_error_hash[:backtrace]).not_to be_blank
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should set the dalliance_status to processing_error" do
|
@@ -132,7 +132,7 @@ describe DallianceModel do
|
|
132
132
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
133
133
|
subject.reload
|
134
134
|
|
135
|
-
subject.
|
135
|
+
expect(subject).to be_processing_error
|
136
136
|
end
|
137
137
|
|
138
138
|
it "should set the dalliance_progress to 0" do
|
@@ -140,19 +140,20 @@ describe DallianceModel do
|
|
140
140
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
141
141
|
subject.reload
|
142
142
|
|
143
|
-
subject.dalliance_progress.
|
143
|
+
expect(subject.dalliance_progress).to eq(0)
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should handle persistance errors" do
|
147
|
-
DallianceModel.dalliance_options[:dalliance_method] = :
|
147
|
+
DallianceModel.dalliance_options[:dalliance_method] = :dalliance_error_method
|
148
|
+
allow_any_instance_of(DallianceModel).to receive(:error_dalliance!).and_raise(RuntimeError.new)
|
148
149
|
|
149
150
|
subject.dalliance_background_process
|
150
151
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
151
152
|
subject.reload
|
152
153
|
|
153
|
-
subject.
|
154
|
-
subject.dalliance_error_hash.
|
155
|
-
subject.dalliance_error_hash[:error].
|
154
|
+
expect(subject).to be_processing_error
|
155
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
156
|
+
expect(subject.dalliance_error_hash[:error]).to eq('Persistance Failure: See Logs')
|
156
157
|
end
|
157
158
|
end
|
158
159
|
|
@@ -168,8 +169,8 @@ describe DallianceModel do
|
|
168
169
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
169
170
|
subject.reload
|
170
171
|
|
171
|
-
subject.dalliance_error_hash.
|
172
|
-
subject.dalliance_error_hash[:successful].
|
172
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
173
|
+
expect(subject.dalliance_error_hash[:successful]).to eq(['is invalid'])
|
173
174
|
end
|
174
175
|
|
175
176
|
it "should set the dalliance_status to validation_error" do
|
@@ -177,7 +178,7 @@ describe DallianceModel do
|
|
177
178
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
178
179
|
subject.reload
|
179
180
|
|
180
|
-
subject.
|
181
|
+
expect(subject).to be_validation_error
|
181
182
|
end
|
182
183
|
|
183
184
|
it "should set the dalliance_progress to 0" do
|
@@ -185,19 +186,20 @@ describe DallianceModel do
|
|
185
186
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
186
187
|
subject.reload
|
187
188
|
|
188
|
-
subject.dalliance_progress.
|
189
|
+
expect(subject.dalliance_progress).to eq(0)
|
189
190
|
end
|
190
191
|
|
191
192
|
it "should handle persistance errors" do
|
192
|
-
DallianceModel.dalliance_options[:dalliance_method] = :
|
193
|
+
DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method
|
194
|
+
allow_any_instance_of(DallianceModel).to receive(:validation_error_dalliance!).and_raise(RuntimeError.new)
|
193
195
|
|
194
196
|
subject.dalliance_background_process
|
195
197
|
Delayed::Worker.new(:queues => [:dalliance]).work_off
|
196
198
|
subject.reload
|
197
199
|
|
198
|
-
subject.
|
199
|
-
subject.dalliance_error_hash.
|
200
|
-
subject.dalliance_error_hash[:error].
|
200
|
+
expect(subject).to be_validation_error
|
201
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
202
|
+
expect(subject.dalliance_error_hash[:error]).to eq('Persistance Failure: See Logs')
|
201
203
|
end
|
202
204
|
end
|
203
205
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe DallianceModel do
|
3
|
+
RSpec.describe DallianceModel do
|
4
4
|
subject { DallianceModel.create }
|
5
5
|
|
6
6
|
before(:all) do
|
@@ -35,8 +35,8 @@ describe DallianceModel do
|
|
35
35
|
subject.dalliance_background_process
|
36
36
|
subject.reload
|
37
37
|
|
38
|
-
subject.
|
39
|
-
Resque.size(:dalliance).
|
38
|
+
expect(subject).not_to be_successful
|
39
|
+
expect(Resque.size(:dalliance)).to eq(1)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should call the dalliance_method w/ a Delayed::Worker" do
|
@@ -47,11 +47,11 @@ describe DallianceModel do
|
|
47
47
|
Resque::Worker.new(:dalliance).process
|
48
48
|
subject.reload
|
49
49
|
|
50
|
-
subject.
|
51
|
-
Resque.size(:dalliance).
|
50
|
+
expect(subject).to be_successful
|
51
|
+
expect(Resque.size(:dalliance)).to eq(0)
|
52
52
|
|
53
|
-
Resque::Stat[:processed].
|
54
|
-
Resque::Stat[:failed].
|
53
|
+
expect(Resque::Stat[:processed]).to eq(1)
|
54
|
+
expect(Resque::Stat[:failed]).to eq(0)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should set the dalliance_status to completed" do
|
@@ -59,7 +59,7 @@ describe DallianceModel do
|
|
59
59
|
Resque::Worker.new(:dalliance).process
|
60
60
|
subject.reload
|
61
61
|
|
62
|
-
subject.
|
62
|
+
expect(subject).to be_completed
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should set the dalliance_progress to 100" do
|
@@ -67,17 +67,17 @@ describe DallianceModel do
|
|
67
67
|
Resque::Worker.new(:dalliance).process
|
68
68
|
subject.reload
|
69
69
|
|
70
|
-
subject.dalliance_progress.
|
70
|
+
expect(subject.dalliance_progress).to eq(100)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should set the dalliance_duration" do
|
74
|
-
subject.dalliance_duration.
|
74
|
+
expect(subject.dalliance_duration).to eq(nil)
|
75
75
|
|
76
76
|
subject.dalliance_background_process
|
77
77
|
Resque::Worker.new(:dalliance).process
|
78
78
|
subject.reload
|
79
79
|
|
80
|
-
subject.dalliance_duration.
|
80
|
+
expect(subject.dalliance_duration).not_to eq(nil)
|
81
81
|
end
|
82
82
|
|
83
83
|
context "another_queue" do
|
@@ -96,8 +96,8 @@ describe DallianceModel do
|
|
96
96
|
Resque::Worker.new(:dalliance).process
|
97
97
|
subject.reload
|
98
98
|
|
99
|
-
subject.
|
100
|
-
Resque.size(queue).
|
99
|
+
expect(subject).not_to be_successful
|
100
|
+
expect(Resque.size(queue)).to eq(1)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should call the dalliance_method w/ a Delayed::Worker (same queue)" do
|
@@ -105,8 +105,8 @@ describe DallianceModel do
|
|
105
105
|
Resque::Worker.new(queue).process
|
106
106
|
subject.reload
|
107
107
|
|
108
|
-
subject.
|
109
|
-
Resque.size(queue).
|
108
|
+
expect(subject).to be_successful
|
109
|
+
expect(Resque.size(queue)).to eq(0)
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -126,10 +126,10 @@ describe DallianceModel do
|
|
126
126
|
|
127
127
|
Resque::Worker.new(:dalliance).process
|
128
128
|
|
129
|
-
Resque.size(:dalliance).
|
129
|
+
expect(Resque.size(:dalliance)).to eq(0)
|
130
130
|
|
131
|
-
Resque::Stat[:processed].
|
132
|
-
Resque::Stat[:failed].
|
131
|
+
expect(Resque::Stat[:processed]).to eq(1)
|
132
|
+
expect(Resque::Stat[:failed]).to eq(1)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should store the error" do
|
@@ -137,10 +137,10 @@ describe DallianceModel do
|
|
137
137
|
Resque::Worker.new(:dalliance).process
|
138
138
|
subject.reload
|
139
139
|
|
140
|
-
subject.dalliance_error_hash.
|
141
|
-
subject.dalliance_error_hash[:error].
|
142
|
-
subject.dalliance_error_hash[:message].
|
143
|
-
subject.dalliance_error_hash[:backtrace].
|
140
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
141
|
+
expect(subject.dalliance_error_hash[:error]).to eq(RuntimeError.name) #We store the class name...
|
142
|
+
expect(subject.dalliance_error_hash[:message]).to eq('RuntimeError')
|
143
|
+
expect(subject.dalliance_error_hash[:backtrace]).not_to be_blank
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should set the dalliance_status to processing_error" do
|
@@ -148,7 +148,7 @@ describe DallianceModel do
|
|
148
148
|
Resque::Worker.new(:dalliance).process
|
149
149
|
subject.reload
|
150
150
|
|
151
|
-
subject.
|
151
|
+
expect(subject).to be_processing_error
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should set the dalliance_progress to 0" do
|
@@ -156,19 +156,20 @@ describe DallianceModel do
|
|
156
156
|
Resque::Worker.new(:dalliance).process
|
157
157
|
subject.reload
|
158
158
|
|
159
|
-
subject.dalliance_progress.
|
159
|
+
expect(subject.dalliance_progress).to eq(0)
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should handle persistance errors" do
|
163
|
-
DallianceModel.dalliance_options[:dalliance_method] = :
|
163
|
+
DallianceModel.dalliance_options[:dalliance_method] = :dalliance_error_method
|
164
|
+
allow_any_instance_of(DallianceModel).to receive(:error_dalliance!).and_raise(RuntimeError.new)
|
164
165
|
|
165
166
|
subject.dalliance_background_process
|
166
167
|
Resque::Worker.new(:dalliance).process
|
167
168
|
subject.reload
|
168
169
|
|
169
|
-
subject.
|
170
|
-
subject.dalliance_error_hash.
|
171
|
-
subject.dalliance_error_hash[:error].
|
170
|
+
expect(subject).to be_processing_error
|
171
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
172
|
+
expect(subject.dalliance_error_hash[:error]).to eq('Persistance Failure: See Logs')
|
172
173
|
end
|
173
174
|
end
|
174
175
|
|
@@ -184,8 +185,8 @@ describe DallianceModel do
|
|
184
185
|
Resque::Worker.new(:dalliance).process
|
185
186
|
subject.reload
|
186
187
|
|
187
|
-
subject.dalliance_error_hash.
|
188
|
-
subject.dalliance_error_hash[:successful].
|
188
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
189
|
+
expect(subject.dalliance_error_hash[:successful]).to eq(['is invalid'])
|
189
190
|
end
|
190
191
|
|
191
192
|
it "should set the dalliance_status to validation_error" do
|
@@ -193,7 +194,7 @@ describe DallianceModel do
|
|
193
194
|
Resque::Worker.new(:dalliance).process
|
194
195
|
subject.reload
|
195
196
|
|
196
|
-
subject.
|
197
|
+
expect(subject).to be_validation_error
|
197
198
|
end
|
198
199
|
|
199
200
|
it "should set the dalliance_progress to 0" do
|
@@ -201,19 +202,20 @@ describe DallianceModel do
|
|
201
202
|
Resque::Worker.new(:dalliance).process
|
202
203
|
subject.reload
|
203
204
|
|
204
|
-
subject.dalliance_progress.
|
205
|
+
expect(subject.dalliance_progress).to eq(0)
|
205
206
|
end
|
206
207
|
|
207
208
|
it "should handle persistance errors" do
|
208
|
-
DallianceModel.dalliance_options[:dalliance_method] = :
|
209
|
+
DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method
|
210
|
+
allow_any_instance_of(DallianceModel).to receive(:validation_error_dalliance!).and_raise(RuntimeError.new)
|
209
211
|
|
210
212
|
subject.dalliance_background_process
|
211
213
|
Resque::Worker.new(:dalliance).process
|
212
214
|
subject.reload
|
213
215
|
|
214
|
-
subject.
|
215
|
-
subject.dalliance_error_hash.
|
216
|
-
subject.dalliance_error_hash[:error].
|
216
|
+
expect(subject).to be_validation_error
|
217
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
218
|
+
expect(subject.dalliance_error_hash[:error]).to eq('Persistance Failure: See Logs')
|
217
219
|
end
|
218
220
|
end
|
219
221
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe DallianceModel do
|
3
|
+
RSpec.describe DallianceModel do
|
4
4
|
subject { DallianceModel.create }
|
5
5
|
|
6
6
|
before(:all) do
|
@@ -14,24 +14,24 @@ describe DallianceModel do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should call the dalliance_method" do
|
17
|
-
|
17
|
+
expect { subject.dalliance_background_process }.to change(subject, :successful).from(false).to(true)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should set the dalliance_status to completed" do
|
21
|
-
|
21
|
+
expect { subject.dalliance_background_process }.to change(subject, :dalliance_status).from('pending').to('completed')
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should set the dalliance_progress to 100" do
|
25
|
-
|
25
|
+
expect { subject.dalliance_background_process }.to change(subject, :dalliance_progress).from(0).to(100)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should set the dalliance_duration" do
|
29
|
-
subject.dalliance_duration.
|
29
|
+
expect(subject.dalliance_duration).to eq(nil)
|
30
30
|
|
31
31
|
subject.dalliance_background_process
|
32
32
|
subject.reload
|
33
33
|
|
34
|
-
subject.dalliance_duration.
|
34
|
+
expect(subject.dalliance_duration).not_to eq(nil)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -47,32 +47,33 @@ describe DallianceModel do
|
|
47
47
|
it "should store the error" do
|
48
48
|
expect { subject.dalliance_background_process }.to raise_error(RuntimeError)
|
49
49
|
|
50
|
-
subject.dalliance_error_hash.
|
51
|
-
subject.dalliance_error_hash[:error].
|
52
|
-
subject.dalliance_error_hash[:message].
|
53
|
-
subject.dalliance_error_hash[:backtrace].
|
50
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
51
|
+
expect(subject.dalliance_error_hash[:error]).to eq(RuntimeError.name) #We store the class name...
|
52
|
+
expect(subject.dalliance_error_hash[:message]).to eq('RuntimeError')
|
53
|
+
expect(subject.dalliance_error_hash[:backtrace]).not_to be_blank
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should set the dalliance_status to processing_error" do
|
57
57
|
expect { subject.dalliance_background_process }.to raise_error(RuntimeError)
|
58
58
|
|
59
|
-
subject.
|
59
|
+
expect(subject).to be_processing_error
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should set the dalliance_progress to 0" do
|
63
63
|
expect { subject.dalliance_background_process }.to raise_error(RuntimeError)
|
64
64
|
|
65
|
-
subject.dalliance_progress.
|
65
|
+
expect(subject.dalliance_progress).to eq(0)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should handle persistance errors" do
|
69
|
-
DallianceModel.dalliance_options[:dalliance_method] = :
|
69
|
+
DallianceModel.dalliance_options[:dalliance_method] = :dalliance_error_method
|
70
|
+
allow_any_instance_of(DallianceModel).to receive(:error_dalliance!).and_raise(RuntimeError.new)
|
70
71
|
|
71
72
|
expect { subject.dalliance_background_process }.to raise_error(RuntimeError)
|
72
73
|
|
73
|
-
subject.
|
74
|
-
subject.dalliance_error_hash.
|
75
|
-
subject.dalliance_error_hash[:error].
|
74
|
+
expect(subject).to be_processing_error
|
75
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
76
|
+
expect(subject.dalliance_error_hash[:error]).to eq('Persistance Failure: See Logs')
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
@@ -84,57 +85,58 @@ describe DallianceModel do
|
|
84
85
|
it "should store the error" do
|
85
86
|
subject.dalliance_background_process
|
86
87
|
|
87
|
-
subject.dalliance_error_hash.
|
88
|
-
subject.dalliance_error_hash[:successful].
|
88
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
89
|
+
expect(subject.dalliance_error_hash[:successful]).to eq(['is invalid'])
|
89
90
|
end
|
90
91
|
|
91
92
|
it "should set the dalliance_status to validation_error" do
|
92
|
-
|
93
|
+
expect { subject.dalliance_background_process }.to change(subject, :dalliance_status).from('pending').to('validation_error')
|
93
94
|
end
|
94
95
|
|
95
96
|
it "should set the dalliance_progress to 0" do
|
96
97
|
subject.dalliance_background_process
|
97
98
|
|
98
|
-
subject.dalliance_progress.
|
99
|
+
expect(subject.dalliance_progress).to eq(0)
|
99
100
|
end
|
100
101
|
|
101
102
|
it "should handle persistance errors" do
|
102
|
-
DallianceModel.dalliance_options[:dalliance_method] = :
|
103
|
+
DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method
|
104
|
+
allow_any_instance_of(DallianceModel).to receive(:validation_error_dalliance!).and_raise(RuntimeError.new)
|
103
105
|
|
104
106
|
subject.dalliance_background_process
|
105
107
|
|
106
|
-
subject.
|
107
|
-
subject.dalliance_error_hash.
|
108
|
-
subject.dalliance_error_hash[:error].
|
108
|
+
expect(subject).to be_validation_error
|
109
|
+
expect(subject.dalliance_error_hash).not_to be_empty
|
110
|
+
expect(subject.dalliance_error_hash[:error]).to eq('Persistance Failure: See Logs')
|
109
111
|
end
|
110
112
|
end
|
111
113
|
|
112
114
|
context "destroy" do
|
113
115
|
it "should return false when pending?" do
|
114
116
|
subject.update_column(:dalliance_status, 'pending')
|
115
|
-
subject.destroy.
|
116
|
-
subject.errors[:dalliance_status].
|
117
|
+
expect(subject.destroy).to be_falsey
|
118
|
+
expect(subject.errors[:dalliance_status]).to eq(['is invalid'])
|
117
119
|
end
|
118
120
|
|
119
121
|
it "should return false when processing?" do
|
120
122
|
subject.update_column(:dalliance_status, 'processing')
|
121
|
-
subject.destroy.
|
122
|
-
subject.errors[:dalliance_status].
|
123
|
+
expect(subject.destroy).to be_falsey
|
124
|
+
expect(subject.errors[:dalliance_status]).to eq(['is invalid'])
|
123
125
|
end
|
124
126
|
|
125
127
|
it "should return true when validation_error?" do
|
126
128
|
subject.update_column(:dalliance_status, 'validation_error')
|
127
|
-
subject.destroy.
|
129
|
+
expect(subject.destroy).to be_truthy
|
128
130
|
end
|
129
131
|
|
130
132
|
it "should return true when processing_error?" do
|
131
133
|
subject.update_column(:dalliance_status, 'processing_error')
|
132
|
-
subject.destroy.
|
134
|
+
expect(subject.destroy).to be_truthy
|
133
135
|
end
|
134
136
|
|
135
137
|
it "should return true when completed?" do
|
136
138
|
subject.update_column(:dalliance_status, 'completed')
|
137
|
-
subject.destroy.
|
139
|
+
expect(subject.destroy).to be_truthy
|
138
140
|
end
|
139
141
|
end
|
140
142
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,6 +13,16 @@ require 'resque'
|
|
13
13
|
require 'dalliance'
|
14
14
|
|
15
15
|
RSpec.configure do |config|
|
16
|
+
config.raise_errors_for_deprecations!
|
17
|
+
|
18
|
+
config.expect_with :rspec do |c|
|
19
|
+
c.syntax = :expect
|
20
|
+
end
|
21
|
+
|
22
|
+
config.mock_with :rspec
|
23
|
+
|
24
|
+
config.expose_dsl_globally = false
|
25
|
+
|
16
26
|
#http://blog.rubyhead.com/2010/04/27/database-during-tests/
|
17
27
|
# config.before do
|
18
28
|
# ActiveRecord::Base.connection.begin_db_transaction
|
@@ -12,7 +12,7 @@ ActiveRecord::Schema.define do
|
|
12
12
|
t.integer :total_count
|
13
13
|
t.integer :progress
|
14
14
|
|
15
|
-
t.timestamps
|
15
|
+
t.timestamps null: false
|
16
16
|
end
|
17
17
|
|
18
18
|
add_index :dalliance_progress_meters, [:dalliance_progress_model_id, :dalliance_progress_model_type], :name => 'by_dalliance_progress_model'
|
@@ -27,7 +27,7 @@ ActiveRecord::Schema.define do
|
|
27
27
|
table.datetime :failed_at
|
28
28
|
table.string :locked_by
|
29
29
|
table.string :queue
|
30
|
-
table.timestamps
|
30
|
+
table.timestamps null: false
|
31
31
|
end
|
32
32
|
|
33
33
|
add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
|
@@ -62,16 +62,4 @@ class DallianceModel < ActiveRecord::Base
|
|
62
62
|
|
63
63
|
store_dalliance_validation_error!
|
64
64
|
end
|
65
|
-
|
66
|
-
def dalliance_error_method_with_state_machine_exception
|
67
|
-
self.stub(:error_dalliance!).and_raise(RuntimeError.new)
|
68
|
-
|
69
|
-
dalliance_error_method
|
70
|
-
end
|
71
|
-
|
72
|
-
def dalliance_validation_error_method_with_state_machine_exception
|
73
|
-
self.stub(:validation_error_dalliance!).and_raise(RuntimeError.new)
|
74
|
-
|
75
|
-
dalliance_validation_error_method
|
76
|
-
end
|
77
65
|
end
|