dalliance 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ module Dalliance
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 2
5
+ TINY = 3
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
data/lib/dalliance.rb CHANGED
@@ -79,12 +79,14 @@ module Dalliance
79
79
  #BEGIN state_machine(s)
80
80
  scope :pending, where(:dalliance_status => 'pending')
81
81
  scope :processing, where(:dalliance_status => 'processing')
82
+ scope :validation_error, where(:dalliance_status => 'validation_error')
82
83
  scope :processing_error, where(:dalliance_status => 'processing_error')
83
84
  scope :completed, where(:dalliance_status => 'completed')
84
85
 
85
86
  state_machine :dalliance_status, :initial => :pending do
86
87
  state :pending
87
88
  state :processing
89
+ state :validation_error
88
90
  state :processing_error
89
91
  state :completed
90
92
 
@@ -96,6 +98,10 @@ module Dalliance
96
98
  transition :pending => :processing
97
99
  end
98
100
 
101
+ event :validation_error_dalliance do
102
+ transition :processing => :validation_error
103
+ end
104
+
99
105
  event :error_dalliance do
100
106
  transition :processing => :processing_error
101
107
  end
@@ -129,8 +135,19 @@ module Dalliance
129
135
  end
130
136
  end
131
137
 
138
+ def store_dalliance_validation_error!
139
+ self.dalliance_error_hash = {}
140
+
141
+ self.errors.each do |attribute, error|
142
+ self.dalliance_error_hash[attribute] ||= []
143
+ self.dalliance_error_hash[attribute] << error
144
+ end
145
+
146
+ validation_error_dalliance!
147
+ end
148
+
132
149
  def error_or_completed?
133
- processing_error? || completed?
150
+ validation_error? || processing_error? || completed?
134
151
  end
135
152
 
136
153
  def pending_or_processing?
@@ -159,7 +176,7 @@ module Dalliance
159
176
 
160
177
  self.send(self.class.dalliance_options[:dalliance_method])
161
178
 
162
- finish_dalliance!
179
+ finish_dalliance! unless validation_error?
163
180
  rescue StandardError => e
164
181
  #Save the error for future analysis...
165
182
  self.dalliance_error_hash = {:error => e.class.name, :message => e.message, :backtrace => e.backtrace}
@@ -143,4 +143,37 @@ describe DallianceModel do
143
143
  subject.dalliance_progress.should == 0
144
144
  end
145
145
  end
146
+
147
+ context "validation error" do
148
+ before(:all) do
149
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method
150
+ DallianceModel.dalliance_options[:worker_class] = Dalliance::Workers::DelayedJob
151
+ DallianceModel.dalliance_options[:queue] = 'dalliance'
152
+ end
153
+
154
+ it "should store the error" do
155
+ subject.dalliance_background_process
156
+ Delayed::Worker.new(:queues => [:dalliance]).work_off
157
+ subject.reload
158
+
159
+ subject.dalliance_error_hash.should_not be_empty
160
+ subject.dalliance_error_hash[:successful].should == ['is invalid']
161
+ end
162
+
163
+ it "should set the dalliance_status to validation_error" do
164
+ subject.dalliance_background_process
165
+ Delayed::Worker.new(:queues => [:dalliance]).work_off
166
+ subject.reload
167
+
168
+ subject.should be_validation_error
169
+ end
170
+
171
+ it "should set the dalliance_progress to 0" do
172
+ subject.dalliance_background_process
173
+ Delayed::Worker.new(:queues => [:dalliance]).work_off
174
+ subject.reload
175
+
176
+ subject.dalliance_progress.should == 0
177
+ end
178
+ end
146
179
  end
@@ -159,4 +159,37 @@ describe DallianceModel do
159
159
  subject.dalliance_progress.should == 0
160
160
  end
161
161
  end
162
+
163
+ context "validation error" do
164
+ before(:all) do
165
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method
166
+ DallianceModel.dalliance_options[:worker_class] = Dalliance::Workers::Resque
167
+ DallianceModel.dalliance_options[:queue] = 'dalliance'
168
+ end
169
+
170
+ it "should store the error" do
171
+ subject.dalliance_background_process
172
+ Resque::Worker.new(:dalliance).process
173
+ subject.reload
174
+
175
+ subject.dalliance_error_hash.should_not be_empty
176
+ subject.dalliance_error_hash[:successful].should == ['is invalid']
177
+ end
178
+
179
+ it "should set the dalliance_status to validation_error" do
180
+ subject.dalliance_background_process
181
+ Resque::Worker.new(:dalliance).process
182
+ subject.reload
183
+
184
+ subject.should be_validation_error
185
+ end
186
+
187
+ it "should set the dalliance_progress to 0" do
188
+ subject.dalliance_background_process
189
+ Resque::Worker.new(:dalliance).process
190
+ subject.reload
191
+
192
+ subject.dalliance_progress.should == 0
193
+ end
194
+ end
162
195
  end
@@ -65,4 +65,27 @@ describe DallianceModel do
65
65
  subject.dalliance_progress.should == 0
66
66
  end
67
67
  end
68
+
69
+ context "validation error" do
70
+ before(:all) do
71
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method
72
+ end
73
+
74
+ it "should store the error" do
75
+ subject.dalliance_background_process
76
+
77
+ subject.dalliance_error_hash.should_not be_empty
78
+ subject.dalliance_error_hash[:successful].should == ['is invalid']
79
+ end
80
+
81
+ it "should set the dalliance_status to validation_error" do
82
+ lambda { subject.dalliance_background_process }.should change(subject, :dalliance_status).from('pending').to('validation_error')
83
+ end
84
+
85
+ it "should set the dalliance_progress to 0" do
86
+ subject.dalliance_background_process
87
+
88
+ subject.dalliance_progress.should == 0
89
+ end
90
+ end
68
91
  end
@@ -56,4 +56,10 @@ class DallianceModel < ActiveRecord::Base
56
56
  def dalliance_error_method
57
57
  raise RuntimeError
58
58
  end
59
+
60
+ def dalliance_validation_error_method
61
+ errors.add(:successful, :invalid)
62
+
63
+ store_dalliance_validation_error!
64
+ end
59
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalliance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-29 00:00:00.000000000 Z
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubyforge_project: dalliance
196
- rubygems_version: 1.8.24
196
+ rubygems_version: 1.8.23
197
197
  signing_key:
198
198
  specification_version: 3
199
199
  summary: Wrapper for an ActiveRecord model with a single ascynhronous method