Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return results from invalid outcomes #212

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/active_interaction/concerns/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ def result
#
# @return (see #result)
def result=(result)
if errors.empty?
@_interaction_result = result
@_interaction_valid = true
else
@_interaction_result = nil
@_interaction_valid = false
end
@_interaction_result = result
@_interaction_valid = errors.empty?
end

# @return [Boolean]
Expand Down
5 changes: 3 additions & 2 deletions spec/active_interaction/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def execute
described_class.send(:define_method, :execute) do
errors.add(:thing, 'error')
errors.add_sym(:thing, :error, 'error')
true
end
end

Expand All @@ -263,8 +264,8 @@ def execute
expect(outcome).to be_invalid
end

it 'sets the result to nil' do
expect(result).to be_nil
it 'sets the result' do
expect(result).to be true
end

it 'has errors' do
Expand Down
4 changes: 2 additions & 2 deletions spec/active_interaction/concerns/runnable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@
context 'with an error' do
include_context 'with an error'

it 'does not set the result' do
it 'sets the result' do
instance.result = result
expect(instance.result).to be_nil
expect(instance.result).to eql result
end
end

Expand Down