active_interaction 0.4.0 → 0.5.0

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: 1c363a94aaacce981bd5b48b6681e193a01f7449
4
- data.tar.gz: 81bdc016e4c55ead1dc8d632fd361c1752ce4b9d
3
+ metadata.gz: 86843e7e3d2f88ef4972b87361eab66961892eeb
4
+ data.tar.gz: dc9517aa3246d6310f114a3cb9ee3055f33a4e6c
5
5
  SHA512:
6
- metadata.gz: 44c0c3dd501b88f1c23301a1b7baccbe3518a3b9f494c6c46ecf756d13e3825ca0886db66bde70bcc8db43c18df3ed9f3dbc129e0a53cb5044328bbc55be68e8
7
- data.tar.gz: d9199c57073feb9afd9f22d84a026eb6bdb66f0713c8e9a0f43a0b5f96ee3b07ab02dd433789c61dbabfeb18d13395911ce3ab7479fdb911c512752aa250183e
6
+ metadata.gz: 38e2212cb6e9a0ae10687cc07533e28406ca15d09c918fe5b7bf29202a4c384cf8179701878b360deaa17aa6d64965f65eeb9122292027553a1e7a075c6be936
7
+ data.tar.gz: 8049e3bab1696a64021bb89e37c5106351332b2eafb73d73c44bf62b6328fd3567ff0e0403c987a10e023386ba057be2c2906b9ad079701184ee76584570afc9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # [Master][]
2
2
 
3
+ # [0.5.0][]
4
+
5
+ - Allow adding errors in `execute` method with `errors.add`.
6
+ - Prevent manually setting the outcome's result.
7
+
3
8
  # [0.4.0][]
4
9
 
5
10
  - Support i18n translations.
@@ -43,7 +48,8 @@
43
48
 
44
49
  - Initial release.
45
50
 
46
- [master]: https://github.com/orgsync/active_interaction/compare/v0.4.0...master
51
+ [master]: https://github.com/orgsync/active_interaction/compare/v0.5.0...master
52
+ [0.5.0]: https://github.com/orgsync/active_interaction/compare/v0.4.0...v0.5.0
47
53
  [0.4.0]: https://github.com/orgsync/active_interaction/compare/v0.3.0...v0.4.0
48
54
  [0.3.0]: https://github.com/orgsync/active_interaction/compare/v0.2.2...v0.3.0
49
55
  [0.2.2]: https://github.com/orgsync/active_interaction/compare/v0.2.1...v0.2.2
data/README.md CHANGED
@@ -15,6 +15,8 @@ to this.
15
15
  Take back control. Slim down models and wrangle monstrous controller
16
16
  methods with ActiveInteraction.
17
17
 
18
+ Check out the full [documentation][] on RubyDoc.info.
19
+
18
20
  ## Installation
19
21
 
20
22
  This project uses [semantic versioning][].
@@ -22,7 +24,7 @@ This project uses [semantic versioning][].
22
24
  Add it to your Gemfile:
23
25
 
24
26
  ```ruby
25
- gem 'active_interaction', '~> 0.4.0'
27
+ gem 'active_interaction', '~> 0.5.0'
26
28
  ```
27
29
 
28
30
  And then execute:
@@ -44,22 +44,24 @@ module ActiveInteraction
44
44
  false
45
45
  end
46
46
 
47
+ # @private
47
48
  def self.i18n_scope
48
49
  :active_interaction
49
50
  end
50
51
 
52
+ # @private
51
53
  def i18n_scope
52
54
  self.class.i18n_scope
53
55
  end
54
56
 
55
57
  extend OverloadHash
56
58
 
57
- # Returns the output from {#execute} if there are no validation errors or
58
- # `nil` otherwise.
59
- #
60
- # @return [Nil] if there are validation errors.
61
- # @return [Object] if there are no validation errors.
62
- attr_reader :result
59
+ validate do
60
+ return unless @_interaction_errors
61
+ @_interaction_errors.each do |attribute, message|
62
+ errors.add(attribute, message)
63
+ end
64
+ end
63
65
 
64
66
  # @private
65
67
  def initialize(options = {})
@@ -89,6 +91,20 @@ module ActiveInteraction
89
91
  raise NotImplementedError
90
92
  end
91
93
 
94
+ # Returns the output from {#execute} if there are no validation errors or
95
+ # `nil` otherwise.
96
+ #
97
+ # @return [Nil] if there are validation errors.
98
+ # @return [Object] if there are no validation errors.
99
+ def result
100
+ @_interaction_result
101
+ end
102
+
103
+ # @private
104
+ def valid?(*args)
105
+ super || instance_variable_set(:@_interaction_result, nil)
106
+ end
107
+
92
108
  # @private
93
109
  def self.transaction
94
110
  return unless block_given?
@@ -114,7 +130,13 @@ module ActiveInteraction
114
130
  new(options).tap do |interaction|
115
131
  if interaction.valid?
116
132
  result = transaction { interaction.execute }
117
- interaction.instance_variable_set(:@result, result)
133
+
134
+ if interaction.errors.empty?
135
+ interaction.instance_variable_set(:@_interaction_result, result)
136
+ else
137
+ interaction.instance_variable_set(:@_interaction_errors,
138
+ interaction.errors.dup)
139
+ end
118
140
  end
119
141
  end
120
142
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveInteraction
2
- VERSION = Gem::Version.new('0.4.0')
2
+ VERSION = Gem::Version.new('0.5.0')
3
3
  end
@@ -148,6 +148,28 @@ describe ActiveInteraction::Base do
148
148
  expect(outcome).to be_a described_class
149
149
  end
150
150
 
151
+ context 'setting the result' do
152
+ let(:described_class) do
153
+ Class.new(ActiveInteraction::Base) do
154
+ boolean :attribute
155
+
156
+ validate do
157
+ @_interaction_result = SecureRandom.hex
158
+ errors.add(:attribute, SecureRandom.hex)
159
+ end
160
+
161
+ def self.name
162
+ SecureRandom.hex
163
+ end
164
+ end
165
+ end
166
+
167
+ it 'sets the result to nil' do
168
+ expect(outcome).to be_invalid
169
+ expect(outcome.result).to be_nil
170
+ end
171
+ end
172
+
151
173
  context 'failing validations' do
152
174
  it 'returns an invalid outcome' do
153
175
  expect(outcome).to be_invalid
@@ -161,6 +183,27 @@ describe ActiveInteraction::Base do
161
183
  context 'passing validations' do
162
184
  before { options.merge!(thing: thing) }
163
185
 
186
+ context 'failing runtime validations' do
187
+ before do
188
+ @execute = described_class.instance_method(:execute)
189
+ described_class.send(:define_method, :execute) do
190
+ errors.add(:thing, SecureRandom.hex)
191
+ end
192
+ end
193
+
194
+ after do
195
+ described_class.send(:define_method, :execute, @execute)
196
+ end
197
+
198
+ it 'returns an invalid outcome' do
199
+ expect(outcome).to be_invalid
200
+ end
201
+
202
+ it 'sets the result to nil' do
203
+ expect(outcome.result).to be_nil
204
+ end
205
+ end
206
+
164
207
  it 'returns a valid outcome' do
165
208
  expect(outcome).to be_valid
166
209
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_interaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lasseigne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-15 00:00:00.000000000 Z
12
+ date: 2013-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  version: '0'
220
220
  requirements: []
221
221
  rubyforge_project:
222
- rubygems_version: 2.0.6
222
+ rubygems_version: 2.1.8
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: Manage application specific business logic.