Skip to content

Commit

Permalink
Fix #56; prevent manually setting the result
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak committed Oct 15, 2013
1 parent f368048 commit 30b9380
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/active_interaction/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def execute
raise NotImplementedError
end

# @private
def valid?(*args)
super || instance_variable_set(:@result, nil)
end

# @private
def self.transaction
return unless block_given?
Expand Down
22 changes: 22 additions & 0 deletions spec/active_interaction/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,28 @@ def execute; end
expect(outcome).to be_a described_class
end

context 'setting the result' do
let(:described_class) do
Class.new(ActiveInteraction::Base) do
boolean :attribute

validate do
@result = SecureRandom.hex
errors.add(:attribute, SecureRandom.hex)
end

def self.name
SecureRandom.hex
end
end
end

it 'sets the result to nil' do
expect(outcome).to be_invalid
expect(outcome.result).to be_nil
end
end

context 'failing validations' do
it 'returns an invalid outcome' do
expect(outcome).to be_invalid
Expand Down

0 comments on commit 30b9380

Please sign in to comment.