Merge pull request #337 from dry-rb/fallbacks

Add specs using fallbacks
This commit is contained in:
Nikita Shilnikov 2021-01-15 21:37:13 +03:00 committed by GitHub
commit 5607f7b632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -8,11 +8,11 @@ gemspec
gem "dry-configurable", github: "dry-rb/dry-configurable", branch: "master" if ENV["DRY_CONFIGURABLE_FROM_MASTER"].eql?("true")
gem "dry-logic", github: "dry-rb/dry-logic", branch: "master" if ENV["DRY_LOGIC_FROM_MASTER"].eql?("true")
gem "dry-types", github: "dry-rb/dry-types", branch: "master" if ENV["DRY_TYPES_FROM_MASTER"].eql?("true")
gem "dry-types", github: "dry-rb/dry-types", branch: "master"
group :test do
gem "dry-monads", require: false
gem "dry-struct", require: false
gem "dry-monads", require: false, github: "dry-rb/dry-monads"
gem "dry-struct", require: false, github: "dry-rb/dry-struct"
gem "i18n", "1.8.2", require: false
gem "transproc"
end

View File

@ -327,4 +327,22 @@ RSpec.describe Dry::Schema, "types specs" do
end
end
end
context "fallback" do
subject(:schema) do
Dry::Schema.define do
required(:role).value(Test::Role)
end
end
before do
Test::Role = Types::String.enum("user", "admin").fallback("user")
end
it "falls back when invalid value provided" do
expect(schema.(role: "user").to_h).to eql(role: "user")
expect(schema.(role: "admin").to_h).to eql(role: "admin")
expect(schema.(role: "nonsense").to_h).to eql(role: "user")
end
end
end