Skip to content

Commit

Permalink
Fix regression in and type
Browse files Browse the repository at this point in the history
  • Loading branch information
Goltergaul committed Nov 28, 2023
1 parent c1bd7ed commit 986fb47
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/definition/types/and.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(name, *args)
def conform(value)
last_result = nil
definitions.each do |definition|
last_result = definition.conform(value)
last_result = definition.conform(last_result.nil? ? value : last_result.value)
next if last_result.passed?

return ConformResult.new(last_result.value, errors: [
Expand Down
2 changes: 2 additions & 0 deletions lib/definition/value_object.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "delegate"

module Definition
class InvalidValueObjectError < StandardError
attr_accessor :conform_result
Expand Down
20 changes: 12 additions & 8 deletions spec/lib/definition/types/and_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,23 @@
describe "with coersion" do
subject(:definition) do
described_class.new("and_test",
definition_int,
definition_float).conform("1.3")
definition_1,
definition_2).conform(2)
end

let(:definition_int) do
conforming_definition(conform_with: 1)
let(:definition_1) do
Definition.Lambda(:conforming_def) do |value|
conform_with(value * 2)
end
end
let(:definition_float) do
conforming_definition(conform_with: 1.0)
let(:definition_2) do
Definition.Lambda(:conforming_def) do |value|
conform_with(value.to_s)
end
end

it "conforms" do
expect(definition).to conform_with(1.0)
it "conforms by passing on the corerced value output from def1 to def2" do
expect(definition).to conform_with("4")
end
end
end
Expand Down

0 comments on commit 986fb47

Please sign in to comment.