-
-
Save jarosluv/b6868e13736fc4e1be1321a933adca92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "rake" | |
gem "hanami", github: "hanami" | |
gem "i18n" | |
gem "minitest" | |
end | |
require "minitest/autorun" | |
require "hanami/controller" | |
require "dry/validation/messages/i18n" | |
I18n.load_path = Dir["ru.yml"] | |
I18n.default_locale = "ru" | |
I18n.backend.load_translations | |
class ApplicationSchema < Dry::Validation::Schema | |
configure do |config| | |
config.messages = :i18n | |
end | |
end | |
FooSchema = Dry::Validation.Schema(ApplicationSchema) do | |
configure do | |
def foo?(current) | |
false | |
end | |
end | |
required(:title) { foo? } | |
end | |
Hanami::Controller.configure do | |
handle_exceptions false | |
end | |
class CreateFoo | |
include Hanami::Action | |
params do | |
required(:foo).schema(FooSchema) | |
end | |
def call(params) | |
params.errors | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_plain_schema | |
params = { title: "OK" } | |
action = CreateFoo.new | |
assert_equal Hash[title: ["Что такое?"]], FooSchema.(params).errors | |
end | |
def test_controller_action | |
params = Hash[foo: { title: "OK" }] | |
action = CreateFoo.new | |
response = action.call(params) # Dry::Validation::MissingMessageError: message for foo? was not found | |
assert_equal response[0], 200 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ru: | |
errors: | |
foo?: Foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment