subroutine 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 481c515ae237b913f46e2d14a675158516d83ab2
4
- data.tar.gz: d57eb792cba74077af2c4dcbc4f500a941931808
3
+ metadata.gz: e7c6319f48d838f3994441f16a3688c7b0394ef7
4
+ data.tar.gz: 00631d11cdd531f528a861704cc1d486192f5e7f
5
5
  SHA512:
6
- metadata.gz: 7deb258fb423207af9997ca3900554492c0038ea891f81e0af696b367c4a6953ec58405977115ce42a07ac56cc34a689860b0ac56524b139a7560356e42a07fb
7
- data.tar.gz: 32b8ca20632f2bcaba78b1fac42478d0589ccdc3c04eb4a08eb4eba018215610ce23c2fc1667fcd89494e2edfad69268cfcc7538d8fbae458e3b7d8cd507868b
6
+ metadata.gz: b5c74968c39618e10977a8345a38b6bd817b12cfd9ac5331667ef70ed6f4228074b7c10f14f2ee86fb833b18072948d32cc0d87a2668af1133bccca32d9177a2
7
+ data.tar.gz: 2fc2619896094a171c49a14e89136952637cf1e1d1d46eea1a4e2dbcd629968316490409916e6fe745607ff7af66f481babc099eb2bfff54787463a12b5f0941
data/README.md CHANGED
@@ -390,7 +390,26 @@ class BaseOp < ::Subroutine::Op
390
390
  end
391
391
  ```
392
392
 
393
- ## Todo
393
+ ## Subroutine::Factory
394
394
 
395
- 1. Enable ActiveModel 3.0-3.2 users by removing the ActiveModel::Model dependency.
396
- 2. Demo app?
395
+ There is a separate gem [subroutine-factory](https://github.com/mnelson/subroutine-factory) which enables you to easily utilize factories and operations to produce
396
+ test data. It's a great replacement to FactoryGirl, as it ensures the data entering your DB is getting there via a real
397
+ world operation.
398
+
399
+ ```ruby
400
+ # support/factories/signups.rb
401
+ Subroutine::Factory.define :signup do
402
+ op ::SignupOp
403
+
404
+ inputs :email, sequence{|n| "foo{n}@example.com" }
405
+ inputs :password, "password123"
406
+
407
+ # by default, the op will be returned when the factory is used.
408
+ # this `output` returns the value of the accessor on the resulting op
409
+ output :user
410
+ end
411
+
412
+ # signup_test.rb
413
+ user = Subroutine::Factory.create :signup
414
+ user = Subroutine::Factory.create :signup, email: "foo@bar.com"
415
+ ```
@@ -0,0 +1,10 @@
1
+ module Subroutine
2
+ class FilteredErrors < SimpleDelegator
3
+
4
+ def add(*args)
5
+ return if __getobj__.instance_variable_get('@base')._error_ignores[args[0].to_sym]
6
+ __getobj__.add(*args)
7
+ end
8
+
9
+ end
10
+ end
data/lib/subroutine/op.rb CHANGED
@@ -3,6 +3,7 @@ require 'active_model'
3
3
 
4
4
  require "subroutine/failure"
5
5
  require "subroutine/type_caster"
6
+ require "subroutine/filtered_errors"
6
7
 
7
8
  module Subroutine
8
9
 
@@ -40,6 +41,12 @@ module Subroutine
40
41
 
41
42
  alias_method :fields, :field
42
43
 
44
+ def ignore_error(*field_names)
45
+ field_names.each do |f|
46
+ _ignore_errors(f)
47
+ end
48
+ end
49
+ alias_method :ignore_errors, :ignore_error
43
50
 
44
51
  def inputs_from(*ops)
45
52
  ops.each do |op|
@@ -53,6 +60,7 @@ module Subroutine
53
60
  super
54
61
  child._fields = self._fields.dup
55
62
  child._error_map = self._error_map.dup
63
+ child._error_ignores = self._error_ignores.dup
56
64
  end
57
65
 
58
66
 
@@ -80,6 +88,10 @@ module Subroutine
80
88
  end
81
89
  end
82
90
 
91
+ if options[:ignore_errors]
92
+ _ignore_errors(field_name)
93
+ end
94
+
83
95
  class_eval <<-EV, __FILE__, __LINE__ + 1
84
96
 
85
97
  def #{field_name}=(v)
@@ -103,6 +115,10 @@ module Subroutine
103
115
 
104
116
  end
105
117
 
118
+ def _ignore_errors(field_name)
119
+ self._error_ignores[field_name.to_sym] = true
120
+ end
121
+
106
122
  end
107
123
 
108
124
 
@@ -112,6 +128,9 @@ module Subroutine
112
128
  class_attribute :_error_map
113
129
  self._error_map = {}
114
130
 
131
+ class_attribute :_error_ignores
132
+ self._error_ignores = {}
133
+
115
134
  attr_reader :original_params
116
135
  attr_reader :params
117
136
 
@@ -121,6 +140,9 @@ module Subroutine
121
140
  @params = {}
122
141
  end
123
142
 
143
+ def errors
144
+ @filtered_errors ||= Subroutine::FilteredErrors.new(super)
145
+ end
124
146
 
125
147
  def submit!
126
148
  unless submit
@@ -2,7 +2,7 @@ module Subroutine
2
2
 
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 2
5
+ PATCH = 3
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -131,5 +131,18 @@ module Subroutine
131
131
 
132
132
  end
133
133
 
134
+ def test_it_ignores_specific_errors
135
+ op = ::WhateverSignupOp.submit
136
+ assert_equal [], op.errors[:whatever]
137
+ end
138
+
139
+ def test_it_does_not_inherit_ignored_errors
140
+ op = ::WhateverSignupOp.new
141
+ other = ::SignupOp.new
142
+ other.errors.add(:whatever, "fail")
143
+ op.send(:inherit_errors, other)
144
+ assert_equal [], op.errors[:whatever]
145
+ end
146
+
134
147
  end
135
148
  end
data/test/support/ops.rb CHANGED
@@ -57,6 +57,10 @@ class SignupOp < ::Subroutine::Op
57
57
  ::User
58
58
  end
59
59
  end
60
+ class WhateverSignupOp < ::SignupOp
61
+ string :whatever, ignore_errors: true
62
+ validates :whatever, presence: true
63
+ end
60
64
 
61
65
  class AdminSignupOp < ::SignupOp
62
66
 
@@ -73,8 +77,8 @@ end
73
77
  class BusinessSignupOp < ::Subroutine::Op
74
78
 
75
79
  string :business_name
76
- inputs_from ::SignupOp
77
80
 
81
+ inputs_from ::SignupOp
78
82
  end
79
83
 
80
84
  class DefaultsOp < ::Subroutine::Op
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-08 00:00:00.000000000 Z
11
+ date: 2015-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -101,6 +101,7 @@ files:
101
101
  - gemfiles/am42.gemfile
102
102
  - lib/subroutine.rb
103
103
  - lib/subroutine/failure.rb
104
+ - lib/subroutine/filtered_errors.rb
104
105
  - lib/subroutine/op.rb
105
106
  - lib/subroutine/type_caster.rb
106
107
  - lib/subroutine/version.rb