subroutine 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db2163ce0bb2002f164e3bda2b19e7cd7946f04c
4
- data.tar.gz: a6ec479f651d9d596f6dc7851c00b1c369e1c922
3
+ metadata.gz: adec63683815f30335f67edb81ae73e313cf7046
4
+ data.tar.gz: 07726344ba242224d384a4ad6c38af2f9985cddd
5
5
  SHA512:
6
- metadata.gz: c11cf049c0dfcf2abc8de33f5841df7fce0be49a3104fcbe99dc60bf08f50e3fab04c5c08145b9d7646185c374d39e8b8db4b837c41f10ea0be18a3d7dc3230a
7
- data.tar.gz: 069dcc45c333d6754dcd787a87b8c384a588589673d22271804e3f4907c1ea9e1f0a303ceff2cfbcd77ebf45a9b333c849cf1a66fe8cfe6230f16cf02c5501ed
6
+ metadata.gz: 7cfbdb1c872febd5ed53e2d6ef3466faf32fb20e02cfb4a8485c8c8e0f528ddfd3b10671063a22c173c6c81409337fd1e4f29fe218f5ae3e8797231108f207c5
7
+ data.tar.gz: 048c5ad5a14f44aba3f8bfedbdb02ed8617e7d6ffe92656b8a7f99140eda49d0216aac64f368da7182f9fd7a0ed515f6062a57af23ab6b9049a49d18a315bae2
data/lib/subroutine/op.rb CHANGED
@@ -180,35 +180,42 @@ module Subroutine
180
180
  end
181
181
 
182
182
  def submit!
183
- unless submit
184
- raise ::Subroutine::Failure.new(self)
185
- end
186
- true
187
- end
188
183
 
189
- # the action which should be invoked upon form submission (from the controller)
190
- def submit
191
- result = observe_submission do
192
- validate_and_perform
184
+ begin
185
+ observe_submission do
186
+ validate_and_perform
187
+ end
188
+ rescue Exception => e
189
+ if e.respond_to?(:record)
190
+ inherit_errors(e.record) unless e.record == self
191
+ raise ::Subroutine::Failure.new(self)
192
+ else
193
+ raise
194
+ end
193
195
  end
194
196
 
195
- if result
197
+ if errors.empty?
196
198
  _outputs.each_pair do |name, config|
197
199
  if config[:required] && !@outputs.key?(name)
198
200
  raise ::Subroutine::OutputNotSetError.new(name)
199
201
  end
200
202
  end
201
- end
202
203
 
203
- result
204
+ true
205
+ else
206
+ raise ::Subroutine::Failure.new(self)
207
+ end
208
+ end
204
209
 
210
+ # the action which should be invoked upon form submission (from the controller)
211
+ def submit
212
+ submit!
205
213
  rescue Exception => e
206
-
207
214
  if e.respond_to?(:record)
208
215
  inherit_errors(e.record) unless e.record == self
209
216
  false
210
217
  else
211
- raise e
218
+ raise
212
219
  end
213
220
  end
214
221
 
@@ -1,8 +1,8 @@
1
1
  module Subroutine
2
2
 
3
3
  MAJOR = 0
4
- MINOR = 4
5
- PATCH = 1
4
+ MINOR = 5
5
+ PATCH = 0
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -119,6 +119,11 @@ module Subroutine
119
119
  assert_equal "Password can't be blank", err.message
120
120
  end
121
121
 
122
+ def test_the_result_of_perform_doesnt_matter
123
+ op = ::FalsePerformOp.new
124
+ assert op.submit!
125
+ end
126
+
122
127
  def test_it_allows_submission_from_the_class
123
128
  op = SignupOp.submit
124
129
  assert_equal ["can't be blank"], op.errors[:email]
data/test/support/ops.rb CHANGED
@@ -201,6 +201,12 @@ class InheritedPolymorphicAssociationOp < ::Subroutine::Op
201
201
  inputs_from PolymorphicAssociationOp
202
202
  end
203
203
 
204
+ class FalsePerformOp < ::Subroutine::Op
205
+ def perform
206
+ false
207
+ end
208
+ end
209
+
204
210
  class MissingOutputOp < ::Subroutine::Op
205
211
  def perform
206
212
  output :foo, "bar"
@@ -224,6 +230,6 @@ end
224
230
  class NoOutputNoSuccessOp < ::Subroutine::Op
225
231
  outputs :foo
226
232
  def perform
227
- false
233
+ errors.add(:foo, "bar")
228
234
  end
229
235
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subroutine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel