Skip to content

Commit

Permalink
Merge branch 'master' into v1.1.0
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGELOG.md
  • Loading branch information
AaronLasseigne committed Feb 6, 2014
2 parents 630c440 + 60cc0cf commit 9e8d68e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 38 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Support passing a single symbol to `:only` and `:except`. Previously an Array
was required.
- Speed up many filters by caching class constants.
- Stop creating duplicate errors on subsequent calls to `valid?`.

# [1.0.1][] (2014-02-04)

Expand Down Expand Up @@ -132,7 +133,7 @@
- Initial release.

[master]: https://github.com/orgsync/active_interaction/compare/v1.0.1...master
[1.0.0]: https://github.com/orgsync/active_interaction/compare/v1.0.0...v1.0.1
[1.0.1]: https://github.com/orgsync/active_interaction/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/orgsync/active_interaction/compare/v0.10.2...v1.0.0
[0.10.2]: https://github.com/orgsync/active_interaction/compare/v0.10.1...v0.10.2
[0.10.1]: https://github.com/orgsync/active_interaction/compare/v0.10.0...v0.10.1
Expand Down
23 changes: 4 additions & 19 deletions lib/active_interaction/concerns/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ module Runnable
extend ActiveSupport::Concern
include ActiveModel::Validations

included do
validate :runtime_errors
end

# @return [Errors]
def errors
@_interaction_errors
Expand All @@ -55,22 +51,20 @@ def result
def result=(result)
if errors.empty?
@_interaction_result = result
@_interaction_runtime_errors = nil
@_interaction_valid = true
else
@_interaction_result = nil
@_interaction_runtime_errors = errors.dup
@_interaction_valid = false
end
end

# @return [Boolean]
def valid?(*)
unless instance_variable_defined?(:@_interaction_valid)
@_interaction_valid = false
if instance_variable_defined?(:@_interaction_valid)
return @_interaction_valid
end

@_interaction_valid || super || (self.result = nil)
super
end

private
Expand Down Expand Up @@ -120,22 +114,13 @@ def run!
end
end

# @!group Validations

def runtime_errors
if @_interaction_runtime_errors
errors.merge!(@_interaction_runtime_errors)
end
end

#
module ClassMethods
def new(*)
super.tap do |instance|
{
:@_interaction_errors => Errors.new(instance),
:@_interaction_result => nil,
:@_interaction_runtime_errors => nil
:@_interaction_result => nil
}.each do |symbol, obj|
instance.instance_variable_set(symbol, obj)
end
Expand Down
18 changes: 0 additions & 18 deletions spec/active_interaction/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,6 @@ def execute
expect(outcome).to be_a described_class
end

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

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

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

context 'failing validations' do
it 'returns an invalid outcome' do
expect(outcome).to_not be_valid
Expand Down
5 changes: 5 additions & 0 deletions spec/active_interaction/concerns/runnable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@
it 'returns false' do
expect(instance).to_not be_valid
end

it 'does not duplicate errors on subsequent calls' do
instance.valid?
expect { instance.valid? }.to_not change { instance.errors.count }.by 1
end
end
end

Expand Down

0 comments on commit 9e8d68e

Please sign in to comment.