Skip to content

Instantly share code, notes, and snippets.

@jarosluv
Last active June 6, 2017 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarosluv/b6868e13736fc4e1be1321a933adca92 to your computer and use it in GitHub Desktop.
Save jarosluv/b6868e13736fc4e1be1321a933adca92 to your computer and use it in GitHub Desktop.
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
ru:
errors:
foo?: Foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment