Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/active_interaction/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def run_validations!
filter

super if errors.empty?
errors.empty?
end

private
Expand Down
6 changes: 3 additions & 3 deletions lib/active_interaction/modules/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module Validation
class << self
# @param context [Base]
# @param filters [Hash{Symbol => Filter}]
# @param inputs [Inputs]
def validate(context, filters, inputs)
# @param _inputs [Inputs]
def validate(context, filters, _inputs)
filters.each_with_object([]) do |(name, filter), errors|
input = filter.process(inputs[name], context)
input = filter.process(context.send(name), context)

input.errors.each do |error|
errors << [error.name, error.type, error.options]
Expand Down
18 changes: 18 additions & 0 deletions spec/active_interaction/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
float :thing
end

InteractionWithFilterAndValidator = Class.new(TestInteraction) do
string :thing
validates :thing, presence: true
end

InteractionWithDateFilter = Class.new(TestInteraction) do
date :thing
end
Expand Down Expand Up @@ -105,6 +110,19 @@ def execute
expect(interaction.thing).to eql Date.new(year, month, day)
end
end

context 'and a validator' do
let(:described_class) { InteractionWithFilterAndValidator }

it 'returns false on validation with no value given' do
expect(interaction.valid?).to be false
end

it 'passes validation when value is given later' do
interaction.thing = 'potato'
expect(interaction).to be_valid
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/active_interaction/validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:filter) { ActiveInteraction::Filter.new(:name, {}) }
let(:interaction) do
name = filter.name
klass = Class.new(ActiveInteraction::Base) { attr_writer(name) }
klass = Class.new(ActiveInteraction::Base) { attr_accessor(name) }
klass.filters[name] = filter
klass.new
end
Expand Down