Merge pull request #337 from dry-rb/fallbacks
Add specs using fallbacks
This commit is contained in:
commit
5607f7b632
6
Gemfile
6
Gemfile
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue